From patchwork Mon Apr 22 19:42:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Hildenbrand X-Patchwork-Id: 13638878 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 EF4A8C4345F for ; Mon, 22 Apr 2024 19:42:30 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 707C56B0087; Mon, 22 Apr 2024 15:42:30 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6B7DC6B0089; Mon, 22 Apr 2024 15:42:30 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 57F166B008A; Mon, 22 Apr 2024 15:42:30 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3AF576B0087 for ; Mon, 22 Apr 2024 15:42:30 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id C626780CC8 for ; Mon, 22 Apr 2024 19:42:29 +0000 (UTC) X-FDA: 82038189618.05.A0BAE40 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf20.hostedemail.com (Postfix) with ESMTP id 65F301C0010 for ; Mon, 22 Apr 2024 19:42:28 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=iZ5hleVX; spf=pass (imf20.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-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1713814948; a=rsa-sha256; cv=none; b=wDhHduOYUEHqNtAjlcBpCOVle9nZuPbATHSEOsORfYyMDMZuCS7fIfb6+YFt4y+OvRKrg4 2zonpX3w9FK3Qmo3KnUM9Vo/tlC9c3vet1a9PvVyoUG6mD/2RXQWoOdp3lN66BmAYc55R3 mHc+lLKQKGNT0iycpu0tfLJ+H5HYih4= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=iZ5hleVX; spf=pass (imf20.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=1713814948; 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=ucWdKV158GrYn1kO4pc3kHGoGPk+vBTZiotaaItH/pY=; b=OvWbteK2AfcJrF9YTqTcb1GtZSGWmPFaUcDJNJP76whpJO2AN6/pCTIM8k95N6qUIYLYFM nkAQHl+IDHdoD0ELbgXbYz9ACjSxpdeUP3vFONpcHkqmJ8bA+WpCvrMQRHlpna5oj5D7yI owZ9Sf0dYq4ZrhyIj7dy9FN65ezvpsc= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1713814947; 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=ucWdKV158GrYn1kO4pc3kHGoGPk+vBTZiotaaItH/pY=; b=iZ5hleVXcoeQjCYvE/+AGZERZUyF1YUC1+LM+VukZTSl74emuPPydM59HAzIII6GXdyi0q Yg6I7ZSztpW1fPuEy46e/lUUirm0j9j9f9XIJHBLTnRlflwB6IfZ+ZWAHAcHy+43QIGYD8 mPvy68EIYZf1mKOanCPa8g+RuyHdRAs= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-526-wSKHFJSgNk-g6QeCqelw5Q-1; Mon, 22 Apr 2024 15:42:22 -0400 X-MC-Unique: wSKHFJSgNk-g6QeCqelw5Q-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (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 CD7BC29ABA16; Mon, 22 Apr 2024 19:42:21 +0000 (UTC) Received: from t14s.fritz.box (unknown [10.39.192.9]) by smtp.corp.redhat.com (Postfix) with ESMTP id 86E1C40C5C2; Mon, 22 Apr 2024 19:42:18 +0000 (UTC) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Zi Yan , John Hubbard , Andrew Morton , Matthew Wilcox , Baolin Wang Subject: [PATCH v2] mm/huge_memory: improve split_huge_page_to_list_to_order() return value documentation Date: Mon, 22 Apr 2024 21:42:17 +0200 Message-ID: <20240422194217.442933-1-david@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.10 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 65F301C0010 X-Stat-Signature: md5shy7bhjhpbooyadqqtth486pxrmo1 X-Rspam-User: X-HE-Tag: 1713814948-697280 X-HE-Meta: U2FsdGVkX1++8G3I8H31wqDWphDt3nwd4aRzhDWNKuAf+nn/B90od3YHtF5bPGP9Ma//f99oE/h5+g9doQTFChEC1aCdl8Yus5hGGYz8Df+zJWDUL1HCUdShYL9Fmct6GOket41yEZcz62Yi78bNwIyL4oPE0cjYdfLJ1M3Y0sY0xXoZ/gOBWhMEyj0KcpCTrtfZcDSUpysCP8phWhHjBVjC4Pz96sbxKuSYI2XKtdHAYgarq3N8konsKtJtIlUC5xrmmYPse+9LTXz8O/H8gHtJzpA0NCyw8kw8XRT9/lRMalWbS60uToJh92xp+jv01M5QhR47/WSjztSrK+73v1Bx8rhoGuaJWb0iToicTuZxAA4wAaeHLJDdxr8GlVWEwkbuWaDVJei3Kgw4AvfaKwEp3PWmd2JeZ2XQz5KoN1t633CdZ+IpOkjP1Q61IWKyTyG5hwTzwLtKnsCo5gZQipVeOnfHsCnUYhhkbgI+e2JyS8voFf+B/lTug0KOsHaMD4/LI8UNmkIalnsENfiqte+REGSsulWBhcEG6kN2S4HSGa8OgeFGDdsfKvAMJjdGtCxOFkwCDswrZwZBNvij6xwoL3HarH6RDAt/z8O7McLYVn4pWvnEV2TCdSBocKXPs+1MLfb1zLQN7CklIzmUeRfreYi0QPv1z/ri204mZ29SnoOwACM5NgQMl77hYhzbAtlAfgAHbzIDMPZKMRO4fR5eFtiFTY9kupWBX8+sBRHQ3IPNhgrY0jdxVxd/Re6asNgiBzm+yk51bh4OEXd+1v4HRmy2e0gGpB8uGS7J3rHeeJ66C5ryq0EyrKYj8KFKPOnI6FcpmreMeeyKDE/nl5PCOij5qvCM4riC+OriTUbCOdJ+s3pgUM4NdtbfHj3fYYcpfzuhcLVUIlR0ei07k1q4ZLKhp1t9yR8hfcCZw877rwsrgZmYO6bBbxq6i2N8 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: ever since fd4a7ac32918 ("mm: migrate: try again if THP split is failed due to page refcnt") 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. Reviewed-by: Zi Yan Reviewed-by: John Hubbard Cc: Andrew Morton Cc: John Hubbard Cc: Matthew Wilcox Cc: Baolin Wang Signed-off-by: David Hildenbrand Reviewed-by: Baolin Wang --- v1 -> v2: * Also document concurrent removal from the page cache (likely we should return -EBUSY -- but likely it doesn't really matter). * Reference fd4a7ac32918 in patch description --- mm/huge_memory.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/mm/huge_memory.c b/mm/huge_memory.c index ee12726291f1b..a7406267323ed 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,16 @@ 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) or if + * the folio was concurrently removed from the page cache. + * + * 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)