From patchwork Thu Apr 18 15:18:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13634955 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AF76AC4345F for ; Thu, 18 Apr 2024 15:18:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2CA276B0087; Thu, 18 Apr 2024 11:18:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 278E16B008C; Thu, 18 Apr 2024 11:18:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1691A6B0092; Thu, 18 Apr 2024 11:18:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E79406B0087 for ; Thu, 18 Apr 2024 11:18:46 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 946071A146D for ; Thu, 18 Apr 2024 15:18:46 +0000 (UTC) X-FDA: 82023009852.19.61B3A1E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf19.hostedemail.com (Postfix) with ESMTP id E7BF01A001D for ; Thu, 18 Apr 2024 15:18:43 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="L8JuPI/H"; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1713453524; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=fRqyqZZz/beIO4QHAyMNc12G8bTOX3CjIzAVeMQ2tbU=; b=a4SIlGDKSqVdOm0UL48WWdKMCZQ5nt+CsT3R5gq4umcQunnAlbA+kMUACUSvSKhVMYfuvz Yv0njAEs7FZ7cMKCCzEsKl0Y1eIWtqxblp7Hl+6dpvhj2D/gZr1tgToPPUO4U+ckxH4WLo Mev4I2M6MFRxQwRb0AuLmhC+UJveB7s= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713453524; a=rsa-sha256; cv=none; b=vbpHU/uy8zg29qiqwkVpXRfuQjNTPJHHBZYj6oKej58y3iSS50IgXHF+Gt5z2hWEa2OlXz Apv+MAF0hPtTaeqap6b9ds1MwPspbDmf4zkOWwOgZ816e+5n0nvgGliSoNeV+fD5ELnONa Hr6qS4Rop+sWxJ3kmCwYdOGJHoh0GE4= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="L8JuPI/H"; spf=pass (imf19.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713453523; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=fRqyqZZz/beIO4QHAyMNc12G8bTOX3CjIzAVeMQ2tbU=; b=L8JuPI/Hqtb6gowkDTzssuADx5l/BHCw1LSZ5pf7kPPeihd9221BfC9ShpIR1fz8KlXroY VOxh2pxMnvtClnlL0qPiSC/AcbQFrpMUMpwJE27vfcGyGm1sFK8I2IpfnAkp7b+TPNziFv ovDWJhwIvIlUjbWUnjMzLbs0iBfFhD8= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-362-XPqDrA9YMa6ZQad_-ry7Zw-1; Thu, 18 Apr 2024 11:18:37 -0400 X-MC-Unique: XPqDrA9YMa6ZQad_-ry7Zw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 56187104B501; Thu, 18 Apr 2024 15:18:37 +0000 (UTC) Received: from t14s.redhat.com (unknown [10.39.192.55]) by smtp.corp.redhat.com (Postfix) with ESMTP id 62A84C2595D; Thu, 18 Apr 2024 15:18:35 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , John Hubbard , Zi Yan , Matthew Wilcox , Andrew Morton Subject: [PATCH v1] mm/huge_memory: improve split_huge_page_to_list_to_order() return value documentation Date: Thu, 18 Apr 2024 17:18:34 +0200 Message-ID: <20240418151834.216557-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.8 X-Rspam-User: X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: E7BF01A001D X-Stat-Signature: y1c9wt61y4cs7q7ygpobuoeiehasks1j X-HE-Tag: 1713453523-953600 X-HE-Meta: U2FsdGVkX18Lgz6+u0/163Ipu9oLolabScuvtq0yrjaTtHZC57ahF7UrKh+k1RwcEA3L6S9EVWw298EcXq8YjR5c9NzJ8+aV/lLs16va2nbAX0IlpQa/Mp+ztPmUr4v7RnaYJC3QRhrcVVh9n+avIp06urysqoiaFSuHSv3ybNX+wdBDrG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Zvoo3mrP9jCGeoZ6iQ5O3fOL9SFlcLsh7fjYmp/PVNpILHQeMvry8tiz+NskZIv9j0y+Spns91iu41xsMZVLYo+DE+Qfs= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: The documentation is wrong and relying on it almost resulted in BUGs in new callers: we return -EAGAIN on unexpected folio references, not -EBUSY. Let's fix that and also document which other return values we can currently see and why they could happen. Cc: John Hubbard Cc: Zi Yan Cc: Matthew Wilcox Cc: Andrew Morton Signed-off-by: David Hildenbrand Reviewed-by: John Hubbard --- mm/huge_memory.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index ee12726291f1b..824eff9211db8 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -2956,7 +2956,7 @@ bool can_split_folio(struct folio *folio, int *pextra_pins) * * 3) The folio must not be pinned. Any unexpected folio references, including * GUP pins, will result in the folio not getting split; instead, the caller - * will receive an -EBUSY. + * will receive an -EAGAIN. * * 4) @new_order > 1, usually. Splitting to order-1 anonymous folios is not * supported for non-file-backed folios, because folio->_deferred_list, which @@ -2975,8 +2975,15 @@ bool can_split_folio(struct folio *folio, int *pextra_pins) * * Returns 0 if the huge page was split successfully. * - * Returns -EBUSY if @page's folio is pinned, or if the anon_vma disappeared - * from under us. + * Returns -EAGAIN if the folio has unexpected reference (e.g., GUP). + * + * Returns -EBUSY when trying to split the huge zeropage, if the folio is + * under writeback, if fs-specific folio metadata cannot currently be + * released, or if some unexpected race happened (e.g., anon VMA disappeared, + * truncation). + * + * Returns -EINVAL when trying to split to an order that is incompatible + * with the folio. Splitting to order 0 is compatible with all folios. */ int split_huge_page_to_list_to_order(struct page *page, struct list_head *list, unsigned int new_order)