Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp85216pxv; Wed, 14 Jul 2021 23:25:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8uExS3pUTkk7LYhpzGzOFSC9QB3ofQkxhT/eP1eZyQ7qO0K4Bm+licMPPlL7fxJlKp9Qs X-Received: by 2002:a05:6638:418f:: with SMTP id az15mr504805jab.8.1626330301365; Wed, 14 Jul 2021 23:25:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626330301; cv=none; d=google.com; s=arc-20160816; b=oKWh5TGMOSrTl/vJ6X264dM49ds/WTtSnUwXsBg7uiV9vNMBg6tHvmhRK+vH8fG96m cyaeNG9xjASnsKx5K4JVWuWwbv0yge5XQLeJOj50uzVaaXoJDUbu62st4vjuqjzy3iLO yUM99LmKgrZoj2tSXp8tJApzpDJVNi6CPGfab1zs8ROv7KdLigc889rS7jncZflclvQ5 mfQqP+7TL8M/stYnOGAhIYIeL4v9+gt2BSKraOnmBF3hKQaX8G2vnopiVDVFN/nn7dXj D5t4QCfyqH6apifC0yWpy/YnHa8CzQorWJklxhzJ51LDRQYLfv55qBF+vbknaCRU3wR5 v6SQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=hXjTMkAJddA0oyzU0dvuCZcSD0ThJT1ENMn6/tz7G2w=; b=CIMWxbVugiBSRRo3p5WwBm0rJS11CaPm1mBKlZcpfn09JDI2k/5D4qRrMniNC3bXC4 0JVUfjcq0lL8kbhmeJcq5bPeXE0QLmkLHZSF/JsbkLk8nUU2W9sKODGjSgxamITbICAf a/KF+peKCCgkiuUr2r9GZgXpo3DygOI2uLlndpc4vUbWZw2RlVFCscvclfc1sUSJ2eqB ta9+urfwVTDfgKE4NreIbXx91jzN2Rt/qWQb0Jo1OqOsnK6LVVwJdn4Ev552n4kXYA3w eOGViuGTnvSVjUTHyObJ/Xn+cLhTZPlvxhWjsv9BCRBqowtCk252hT8uuFJWwPux/CeW BMBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Wlvaij9n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p5si5934523jal.76.2021.07.14.23.24.43; Wed, 14 Jul 2021 23:25:01 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Wlvaij9n; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231430AbhGOD7W (ORCPT + 99 others); Wed, 14 Jul 2021 23:59:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49128 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230314AbhGOD7I (ORCPT ); Wed, 14 Jul 2021 23:59:08 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BED79C06175F; Wed, 14 Jul 2021 20:56:15 -0700 (PDT) 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=hXjTMkAJddA0oyzU0dvuCZcSD0ThJT1ENMn6/tz7G2w=; b=Wlvaij9nztLyBvJHijaPz57eVG cIfUjlvVteyGjxWhPRiRRrvNQs+G9jaEIQn+pYzmZyYQ2Q6nm0aaMO6qPqyZ852uFYdB0o5vDeGup h3h0kP8ww3rZJZbbEJR7GqAPArcuYL6o9MfHtypPyy+9sY0Rmv+Y49FZMZFPKDaTG4uCjpTXhYc4K +JWLL1H6A+cFQl3sdW1ke7kQDOXOFEZXAtXVKOH4Q+vY8jo0n4mPr9b9DQ4+c+nkhSXNTKwfUqveE W61enjBR9VT1Kx6VTlJE4szDbu/bNRC2EK5FJsGKBQHswI7OKAgRTiyMgerNgvpwXONXJct8VweUW pQi7y3hw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1m3sSI-002vHy-Hk; Thu, 15 Jul 2021 03:54:41 +0000 From: "Matthew Wilcox (Oracle)" To: linux-kernel@vger.kernel.org Cc: "Matthew Wilcox (Oracle)" , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Christoph Hellwig , Jeff Layton , "Kirill A . Shutemov" , Vlastimil Babka , William Kucharski , David Howells Subject: [PATCH v14 021/138] mm/filemap: Add folio_wait_locked() Date: Thu, 15 Jul 2021 04:35:07 +0100 Message-Id: <20210715033704.692967-22-willy@infradead.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210715033704.692967-1-willy@infradead.org> References: <20210715033704.692967-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Also add folio_wait_locked_killable(). Turn wait_on_page_locked() and wait_on_page_locked_killable() into wrappers. This eliminates a call to compound_head() from each call-site, reducing text size by 193 bytes for me. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Christoph Hellwig Acked-by: Jeff Layton Acked-by: Kirill A. Shutemov Acked-by: Vlastimil Babka Reviewed-by: William Kucharski Reviewed-by: David Howells --- include/linux/pagemap.h | 26 ++++++++++++++++++-------- mm/filemap.c | 4 ++-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 6f631a3e42dc..03fea8bbfd8e 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -733,23 +733,33 @@ extern void wait_on_page_bit(struct page *page, int bit_nr); extern int wait_on_page_bit_killable(struct page *page, int bit_nr); /* - * Wait for a page to be unlocked. + * Wait for a folio to be unlocked. * - * This must be called with the caller "holding" the page, - * ie with increased "page->count" so that the page won't + * This must be called with the caller "holding" the folio, + * ie with increased "page->count" so that the folio won't * go away during the wait.. */ +static inline void folio_wait_locked(struct folio *folio) +{ + if (folio_test_locked(folio)) + wait_on_page_bit(&folio->page, PG_locked); +} + +static inline int folio_wait_locked_killable(struct folio *folio) +{ + if (!folio_test_locked(folio)) + return 0; + return wait_on_page_bit_killable(&folio->page, PG_locked); +} + static inline void wait_on_page_locked(struct page *page) { - if (PageLocked(page)) - wait_on_page_bit(compound_head(page), PG_locked); + folio_wait_locked(page_folio(page)); } static inline int wait_on_page_locked_killable(struct page *page) { - if (!PageLocked(page)) - return 0; - return wait_on_page_bit_killable(compound_head(page), PG_locked); + return folio_wait_locked_killable(page_folio(page)); } int put_and_wait_on_page_locked(struct page *page, int state); diff --git a/mm/filemap.c b/mm/filemap.c index c97b804811fc..04fb4a84cf0d 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1649,9 +1649,9 @@ int __lock_page_or_retry(struct page *page, struct mm_struct *mm, mmap_read_unlock(mm); if (flags & FAULT_FLAG_KILLABLE) - wait_on_page_locked_killable(page); + folio_wait_locked_killable(folio); else - wait_on_page_locked(page); + folio_wait_locked(folio); return 0; } if (flags & FAULT_FLAG_KILLABLE) { -- 2.30.2