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 X-Spam-Level: X-Spam-Status: No, score=-16.6 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E1654C4361B for ; Tue, 8 Dec 2020 19:47:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 807D023C17 for ; Tue, 8 Dec 2020 19:47:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 807D023C17 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 783A36B006C; Tue, 8 Dec 2020 14:47:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6C1F86B0071; Tue, 8 Dec 2020 14:47:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 317466B006C; Tue, 8 Dec 2020 14:47:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0059.hostedemail.com [216.40.44.59]) by kanga.kvack.org (Postfix) with ESMTP id 0E30E6B0068 for ; Tue, 8 Dec 2020 14:47:03 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id BDA1F3628 for ; Tue, 8 Dec 2020 19:47:02 +0000 (UTC) X-FDA: 77571148284.23.word00_550c316273e9 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id 9E72737606 for ; Tue, 8 Dec 2020 19:47:02 +0000 (UTC) X-HE-Tag: word00_550c316273e9 X-Filterd-Recvd-Size: 5333 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Tue, 8 Dec 2020 19:47:02 +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=xt5mgd5xPZqp/ehXI/kHMzNBJyy6JtKd8fa1WI3RK7s=; b=ZCufl/DRva/T7N4vYBk+eoB5hv rdIzHzWI6eIhcfpLfkQsthl8hpvq2DdzTPs4x0tjtLvb4FRp0/Llfowg8LMhJI7bKO84Wn0HWBHqa swDkv0YflMbW86v2yrLxQZJMQ1t0XI6ijqh8b56xv9e/J4tkGtQV20R3l14WacPgAwJuNlwW7kzFC iLyu5veeMzW/975HkpqBmSVMCMfN6Efnl4oNFCwTw1z9fVm15Xj7sFY3FdtwfdiP1QjCWvHwCK88E JWC0LfnGJc3+b0Kg3B9OLyewYJ3J6bfEC1EknxssnGNyNheNGlSycMh+H7QiC8c81EfYvOdJoM4CR u8PhJUUw==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kmiwt-00050r-9L; Tue, 08 Dec 2020 19:46:59 +0000 From: "Matthew Wilcox (Oracle)" To: linux-fsdevel@vger.kernel.org, linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org Subject: [RFC PATCH 07/11] mm: Add lock_folio_killable Date: Tue, 8 Dec 2020 19:46:49 +0000 Message-Id: <20201208194653.19180-8-willy@infradead.org> X-Mailer: git-send-email 2.21.3 In-Reply-To: <20201208194653.19180-1-willy@infradead.org> References: <20201208194653.19180-1-willy@infradead.org> MIME-Version: 1.0 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: This is like lock_page_killable() but for use by callers who know they have a folio. Convert __lock_page_killable() to be __lock_folio_killable(). This saves one call to compound_head() per contended call to lock_page_killable(). Signed-off-by: Matthew Wilcox (Oracle) --- include/linux/pagemap.h | 15 ++++++++++----- mm/filemap.c | 17 +++++++++-------- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 1d4a1828a434..060faeb8d701 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -584,7 +584,7 @@ static inline bool wake_page_match(struct wait_page_q= ueue *wait_page, } =20 extern void __lock_folio(struct folio *folio); -extern int __lock_page_killable(struct page *page); +extern int __lock_folio_killable(struct folio *folio); extern int __lock_page_async(struct page *page, struct wait_page_queue *= wait); extern int __lock_page_or_retry(struct page *page, struct mm_struct *mm, unsigned int flags); @@ -632,6 +632,14 @@ static inline void lock_page(struct page *page) lock_folio(page_folio(page)); } =20 +static inline int lock_folio_killable(struct folio *folio) +{ + might_sleep(); + if (!trylock_folio(folio)) + return __lock_folio_killable(folio); + return 0; +} + /* * lock_page_killable is like lock_page but can be interrupted by fatal * signals. It returns 0 if it locked the page and -EINTR if it was @@ -639,10 +647,7 @@ static inline void lock_page(struct page *page) */ static inline int lock_page_killable(struct page *page) { - might_sleep(); - if (!trylock_page(page)) - return __lock_page_killable(page); - return 0; + return lock_folio_killable(page_folio(page)); } =20 /* diff --git a/mm/filemap.c b/mm/filemap.c index 8e87906f5dd6..50535b21b452 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1534,14 +1534,13 @@ void __lock_folio(struct folio *folio) } EXPORT_SYMBOL(__lock_folio); =20 -int __lock_page_killable(struct page *__page) +int __lock_folio_killable(struct folio *folio) { - struct page *page =3D compound_head(__page); - wait_queue_head_t *q =3D page_waitqueue(page); - return wait_on_page_bit_common(q, page, PG_locked, TASK_KILLABLE, + wait_queue_head_t *q =3D page_waitqueue(&folio->page); + return wait_on_page_bit_common(q, &folio->page, PG_locked, TASK_KILLABL= E, EXCLUSIVE); } -EXPORT_SYMBOL_GPL(__lock_page_killable); +EXPORT_SYMBOL_GPL(__lock_folio_killable); =20 int __lock_page_async(struct page *page, struct wait_page_queue *wait) { @@ -1562,6 +1561,8 @@ int __lock_page_async(struct page *page, struct wai= t_page_queue *wait) int __lock_page_or_retry(struct page *page, struct mm_struct *mm, unsigned int flags) { + struct folio *folio =3D page_folio(page); + if (fault_flag_allow_retry_first(flags)) { /* * CAUTION! In this case, mmap_lock is not released @@ -1580,13 +1581,13 @@ int __lock_page_or_retry(struct page *page, struc= t mm_struct *mm, if (flags & FAULT_FLAG_KILLABLE) { int ret; =20 - ret =3D __lock_page_killable(page); + ret =3D __lock_folio_killable(folio); if (ret) { mmap_read_unlock(mm); return 0; } } else { - __lock_folio(page_folio(page)); + __lock_folio(folio); } =20 return 1; @@ -2778,7 +2779,7 @@ static int lock_page_maybe_drop_mmap(struct vm_faul= t *vmf, struct page *page, =20 *fpin =3D maybe_unlock_mmap_for_io(vmf, *fpin); if (vmf->flags & FAULT_FLAG_KILLABLE) { - if (__lock_page_killable(&folio->page)) { + if (__lock_folio_killable(folio)) { /* * We didn't have the right flags to drop the mmap_lock, * but all fault_handlers only check for fatal signals --=20 2.29.2