From mboxrd@z Thu Jan 1 00:00:00 1970 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 3C68EC433EF for ; Fri, 4 Feb 2022 20:21:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A6B226B0074; Fri, 4 Feb 2022 15:21:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 97CED6B0075; Fri, 4 Feb 2022 15:21:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 759CC6B0078; Fri, 4 Feb 2022 15:21:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0090.hostedemail.com [216.40.44.90]) by kanga.kvack.org (Postfix) with ESMTP id 5DA046B0074 for ; Fri, 4 Feb 2022 15:21:32 -0500 (EST) Received: from smtpin24.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 1CE608281C0E for ; Fri, 4 Feb 2022 20:21:32 +0000 (UTC) X-FDA: 79106217624.24.276209B Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf03.hostedemail.com (Postfix) with ESMTP id 9922F20006 for ; Fri, 4 Feb 2022 20:21:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=lvXYfUK4uxaq9EJmybHOLtM9xC/VzkMqzDT6RcEHXUU=; b=wTrV3Juc2XZPFMIUtSFKc+zf8v ZFZn2K6SZgdMMhyZoDtAHIVLGdYZtUikpHGAe8zmLPDx1Ws8nKIUBTRgHIE41Kv0dFP1fTiVu7k8H SJuiYtnHwYRiQETq7UW5GARue2e/FnxSNNs8nsqNfY8br9cfb3nWLBmbruRSMgJg2C7xMGmVb1meP E5ymOeK7FbcA248CsOcspI+bEhzkQ5/Bp3Fw5yfr4AmZ1JLy01AWYK5+04yupjU7WyanTvZpTYrnY ns1Tn41Jywu1Yj3BYsyq3eb4cT1pvfCe0JqL046RLeYcMe0fkflglS89jyqKoz6WRUle4GfYszYq+ eOS8+8SA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nG4jU-007LlJ-Br; Fri, 04 Feb 2022 19:59:00 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org, Christoph Hellwig , John Hubbard , Jason Gunthorpe , William Kucharski Subject: [PATCH 09/75] mm/gup: Handle page split race more efficiently Date: Fri, 4 Feb 2022 19:57:46 +0000 Message-Id: <20220204195852.1751729-10-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220204195852.1751729-1-willy@infradead.org> References: <20220204195852.1751729-1-willy@infradead.org> MIME-Version: 1.0 X-Rspam-User: nil X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 9922F20006 X-Stat-Signature: 98p7bop3dh8mnj4wtcp6d31m37gmkiit Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=wTrV3Juc; dmarc=none; spf=none (imf03.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org X-HE-Tag: 1644006091-126631 Content-Transfer-Encoding: quoted-printable 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: If we hit the page split race, the current code returns NULL which will presumably trigger a retry under the mmap_lock. This isn't necessary; we can just retry the compound_head() lookup. This is a very minor optimisation of an unlikely path, but conceptually it matches (eg) the page cache RCU-protected lookup. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Christoph Hellwig Reviewed-by: John Hubbard Reviewed-by: Jason Gunthorpe Reviewed-by: William Kucharski --- mm/gup.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index fa75b71820a2..923a0d44203c 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -68,7 +68,10 @@ static void put_page_refs(struct page *page, int refs) */ static inline struct page *try_get_compound_head(struct page *page, int = refs) { - struct page *head =3D compound_head(page); + struct page *head; + +retry: + head =3D compound_head(page); =20 if (WARN_ON_ONCE(page_ref_count(head) < 0)) return NULL; @@ -86,7 +89,7 @@ static inline struct page *try_get_compound_head(struct= page *page, int refs) */ if (unlikely(compound_head(page) !=3D head)) { put_page_refs(head, refs); - return NULL; + goto retry; } =20 return head; --=20 2.34.1