Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1589487pxf; Fri, 9 Apr 2021 12:12:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw3G9IzMvXqMh8RXtyC5eR0H06Khy3FupuxHpyh8BydVUfjd6B3ETs4k4Ihiz1qx83JopGH X-Received: by 2002:a05:6402:484:: with SMTP id k4mr18722497edv.321.1617995554998; Fri, 09 Apr 2021 12:12:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617995554; cv=none; d=google.com; s=arc-20160816; b=fjYU38DrQaruxDZ+b0mR8QNgJCdsdc2ZqmC/lHtmlwljSsahvsCnFgGskBayoko+17 ZmWbKLlEt11nmg6r4cOiTkHSzuTw8+i69S6l474cqoTFR+ochulO6m+EqUqa8SIdVSXg M20dE7vIjbtzMVc1cWFlaVYuL78UI4LF9vLu90NWtpPltMIMZ0kwjSGrviOeaot6ku6X MlR3pZa+hLzZtP2wTyeEVzzZsy3eEGW3q/uG3MBZg31m/O3SdZhEzqqHFlIOTEWCHr1Z DihHgWhrZ+/x++Kd0Wm7LzsAT1eAZbnVvwMrSW0UZ0QlIos7ZGZUFiRlogSqfEBNqp7I igdg== 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=bCrxs0KgNz4PwP0JkrR5Sshw3z3ISvND75CdVRdDORg=; b=xyTsaT1xBwmovcNrcXgMyZnLIlYCitrmzLBp8Mun82V9c4p7NjfkPmjNM2sH7IBllP oxjbrHULcffwbWOsADeatsbg+A0f8hjERQ1IQFOufnhWX6DqtTzqeEP4FiHfNY4lIRff QJrnrRFrVvjYIUzljT01H9fKMeOf0yG74RQugOrOhCoEqAmKiPuFLDkRho5LBpQryGc+ pHVpT7VrXLC6l0bx58TQKZb955X4o5XpazmBlmbZjoB0qohh4vqfS5Iz2bBJTSmXgX// WQE4SAoub9YJNNm+2sCc5SIRx4P/JTg+uhm7glw4IICGKsdk4FPriib0yKWplirkPg48 HzcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=Vtep1wOG; 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 do13si2271793ejc.87.2021.04.09.12.12.11; Fri, 09 Apr 2021 12:12:34 -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=Vtep1wOG; 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 S234917AbhDITIt (ORCPT + 99 others); Fri, 9 Apr 2021 15:08:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33794 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234441AbhDITIs (ORCPT ); Fri, 9 Apr 2021 15:08:48 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D62A9C061762; Fri, 9 Apr 2021 12:08:34 -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=bCrxs0KgNz4PwP0JkrR5Sshw3z3ISvND75CdVRdDORg=; b=Vtep1wOGEMq5mTSfc5v4TEJ/RG /X4pad/9teBXE7DuA0Q1S5YJ20l4/3/g8CWp8ahikkVTzijSRbPzIte6orzooPrsBsrog4FiUiEq4 tgb3YkBMEjGPgwfKkqsoFeSu7uCJk1bMob55AWja5rf2hFrfPT+ilUmTcn8Lg9Up3xw/pSnOB6Ziq Y4NZgfDhdWHC6jUSvX54p21cFUswdSdpnv/EgH2djAvtZtDi3Q+uI9l63hF+aRJxmVvxjTH8VW+hQ gz9C9b5UN/fxLWt0W9s/b68G16zOpjoKvksZodE72YVBUPwZIU57Q/V0WEIZ3S2m39ONJ9mL6Jf5b iRWL8I/g==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lUwTI-000oRl-JV; Fri, 09 Apr 2021 19:07:32 +0000 From: "Matthew Wilcox (Oracle)" To: linux-mm@kvack.org Cc: "Matthew Wilcox (Oracle)" , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-cachefs@redhat.com, linux-afs@lists.infradead.org, Christoph Hellwig , Jeff Layton Subject: [PATCH v7 21/28] mm/filemap: Add __lock_folio_or_retry Date: Fri, 9 Apr 2021 19:50:58 +0100 Message-Id: <20210409185105.188284-22-willy@infradead.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210409185105.188284-1-willy@infradead.org> References: <20210409185105.188284-1-willy@infradead.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Convert __lock_page_or_retry() to __lock_folio_or_retry(). This actually saves 4 bytes in the only caller of lock_page_or_retry() (due to better register allocation) and saves the 20 byte cost of calling page_folio() in __lock_folio_or_retry() for a total saving of 24 bytes. Signed-off-by: Matthew Wilcox (Oracle) Reviewed-by: Christoph Hellwig Acked-by: Jeff Layton --- include/linux/pagemap.h | 9 ++++++--- mm/filemap.c | 10 ++++------ mm/memory.c | 8 ++++---- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index c63f59d4ae60..00864e098693 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -716,7 +716,7 @@ static inline bool wake_page_match(struct wait_page_queue *wait_page, void __lock_folio(struct folio *folio); int __lock_folio_killable(struct folio *folio); -extern int __lock_page_or_retry(struct page *page, struct mm_struct *mm, +int __lock_folio_or_retry(struct folio *folio, struct mm_struct *mm, unsigned int flags); void unlock_page(struct page *page); void unlock_folio(struct folio *folio); @@ -777,13 +777,16 @@ static inline int lock_page_killable(struct page *page) * caller indicated that it can handle a retry. * * Return value and mmap_lock implications depend on flags; see - * __lock_page_or_retry(). + * __lock_folio_or_retry(). */ static inline int lock_page_or_retry(struct page *page, struct mm_struct *mm, unsigned int flags) { + struct folio *folio; might_sleep(); - return trylock_page(page) || __lock_page_or_retry(page, mm, flags); + + folio = page_folio(page); + return trylock_folio(folio) || __lock_folio_or_retry(folio, mm, flags); } /* diff --git a/mm/filemap.c b/mm/filemap.c index 9485ce2a4820..73c8d7102157 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1621,20 +1621,18 @@ static int __lock_folio_async(struct folio *folio, struct wait_page_queue *wait) /* * Return values: - * 1 - page is locked; mmap_lock is still held. - * 0 - page is not locked. + * 1 - folio is locked; mmap_lock is still held. + * 0 - folio is not locked. * mmap_lock has been released (mmap_read_unlock(), unless flags had both * FAULT_FLAG_ALLOW_RETRY and FAULT_FLAG_RETRY_NOWAIT set, in * which case mmap_lock is still held. * * If neither ALLOW_RETRY nor KILLABLE are set, will always return 1 - * with the page locked and the mmap_lock unperturbed. + * with the folio locked and the mmap_lock unperturbed. */ -int __lock_page_or_retry(struct page *page, struct mm_struct *mm, +int __lock_folio_or_retry(struct folio *folio, struct mm_struct *mm, unsigned int flags) { - struct folio *folio = page_folio(page); - if (fault_flag_allow_retry_first(flags)) { /* * CAUTION! In this case, mmap_lock is not released diff --git a/mm/memory.c b/mm/memory.c index cc71a445c76c..a2768ca793e5 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4067,7 +4067,7 @@ static vm_fault_t do_shared_fault(struct vm_fault *vmf) * We enter with non-exclusive mmap_lock (to exclude vma changes, * but allow concurrent faults). * The mmap_lock may have been released depending on flags and our - * return value. See filemap_fault() and __lock_page_or_retry(). + * return value. See filemap_fault() and __lock_folio_or_retry(). * If mmap_lock is released, vma may become invalid (for example * by other thread calling munmap()). */ @@ -4299,7 +4299,7 @@ static vm_fault_t wp_huge_pud(struct vm_fault *vmf, pud_t orig_pud) * concurrent faults). * * The mmap_lock may have been released depending on flags and our return value. - * See filemap_fault() and __lock_page_or_retry(). + * See filemap_fault() and __lock_folio_or_retry(). */ static vm_fault_t handle_pte_fault(struct vm_fault *vmf) { @@ -4403,7 +4403,7 @@ static vm_fault_t handle_pte_fault(struct vm_fault *vmf) * By the time we get here, we already hold the mm semaphore * * The mmap_lock may have been released depending on flags and our - * return value. See filemap_fault() and __lock_page_or_retry(). + * return value. See filemap_fault() and __lock_folio_or_retry(). */ static vm_fault_t __handle_mm_fault(struct vm_area_struct *vma, unsigned long address, unsigned int flags) @@ -4559,7 +4559,7 @@ static inline void mm_account_fault(struct pt_regs *regs, * By the time we get here, we already hold the mm semaphore * * The mmap_lock may have been released depending on flags and our - * return value. See filemap_fault() and __lock_page_or_retry(). + * return value. See filemap_fault() and __lock_folio_or_retry(). */ vm_fault_t handle_mm_fault(struct vm_area_struct *vma, unsigned long address, unsigned int flags, struct pt_regs *regs) -- 2.30.2