From patchwork Mon Jan 10 04:23:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthew Wilcox X-Patchwork-Id: 12708188 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 7E536C433F5 for ; Mon, 10 Jan 2022 04:24:58 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 45F6A6B00B0; Sun, 9 Jan 2022 23:24:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3C9FB6B00B4; Sun, 9 Jan 2022 23:24:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B4A96B00B2; Sun, 9 Jan 2022 23:24:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0096.hostedemail.com [216.40.44.96]) by kanga.kvack.org (Postfix) with ESMTP id D5CCD6B00AD for ; Sun, 9 Jan 2022 23:24:47 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 99F2C181C49AF for ; Mon, 10 Jan 2022 04:24:47 +0000 (UTC) X-FDA: 79013086614.06.64903AB Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf02.hostedemail.com (Postfix) with ESMTP id 5E88E80005 for ; Mon, 10 Jan 2022 04:24:47 +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=sKOYhN/P0cXC4qhPysyjZBfoAmLRLRFdOpaxGNZHEz8=; b=PJspN4WZf/k+qjE/mGfGFFrgkY cA9Kf5HN8fC0T5MXeLaNiI+h4JFXcp/9uKj/3uMyuTO3+G9NY0mZ3v0iR+rS7St765/En7TFFYyaK afHgj6DavPUc5K/Gsvjr8ejQPe2KTJly2O5vES3UKprH4ErwcIuKqvQP9L6OXTEv598D/7XyE9ljw 8hMsHnVRf1L1j0kB+nF0cImF8Sw9s2rRq0e6wHGDOJ1gVRMGSTi/oKvvNaCPc+7DovYWH/cF8mhFs r0XVqQPnvjqP4glZTdD9RFs9qMq2qgOLgKuwdzz8EG0OLCYNN7CpZuOPMKe/A7VZvKgLI4LWkuluJ 33unxJwQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1n6mE8-0025wg-GU; Mon, 10 Jan 2022 04:24:12 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , John Hubbard , Christoph Hellwig , William Kucharski , linux-kernel@vger.kernel.org, Jason Gunthorpe Subject: [PATCH v2 08/28] gup: Handle page split race more efficiently Date: Mon, 10 Jan 2022 04:23:46 +0000 Message-Id: <20220110042406.499429-9-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20220110042406.499429-1-willy@infradead.org> References: <20220110042406.499429-1-willy@infradead.org> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 5E88E80005 X-Stat-Signature: zy6c5qbrp8xczoqoaxwrhdhq97x6rucd Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=PJspN4WZ; dmarc=none; spf=none (imf02.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: 1641788687-262335 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 --- mm/gup.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index afb638a30e44..dbb1b54d0def 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 = compound_head(page); + struct page *head; + +retry: + head = compound_head(page); 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) != head)) { put_page_refs(head, refs); - return NULL; + goto retry; } return head;