Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp2088863pxf; Sat, 20 Mar 2021 04:14:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwXciCH3X3ffVVfKvamkrFIDOiYSiu/ev4iwwCAUiXvu29Kk2epMqP8dzIQ+9eljp2qq+GF X-Received: by 2002:a17:906:c24b:: with SMTP id bl11mr9432374ejb.80.1616238880934; Sat, 20 Mar 2021 04:14:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616238880; cv=none; d=google.com; s=arc-20160816; b=vQpajF6gwAvDkdsGYccGpdYgysVH2xdjCpdnUdcuXMVgowdjdxpDkOMfzK0iJnPpTn O1aksaFwsABOze6JiRrOIhdkJPe3tF4Ia2yVWHmr09YnbqZAm3EldGeSlDMvuqflovjt Qc9d4xutFH7tyuezLRx3zgh2wTdlklUDdd6om+RDLYjhpTeacDmNwXEED286zP2tqQfD wPwsJgSGeqLquo2c7x9ub9MtlCG1kKSUZ1kuL205L+MV5vLmtHugq5CL9Pds9y/Za7HD tf4id9uG8RJD8xiMhY8E6RvbrnOifxoVphZ2FkrbW2Or7nloPobm1CDnqjRcv3b+MyCV tjMw== 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=p8Z3SG+7sSppmZrkCtMgIpMAxffrWUao7nK9dOhrrxw=; b=Gz/hnU9K5HvpMb0lnUXHXRZS9z83acudROtSPotNlWai+qlvhCJA2173SAHIMXNprg gpmE7x35n0x+k0Cf/3ZvVKRk3168ErGmE1MxPSNI0SEYu4sm0eZXdH2+Oxepw/jq+xi5 F3Els6lAGSWtgDcJ/HJH4ySMm7NKU6RxjGEBsOXzJc9z5X+tFpWEgb8vS612YsQre0GB h9rOi/V0zuXfZd8EiwqOieIbYf65Kx3DwmFJAy1Q4cvfQ7cLfQv7uCMDs5DQBbROJTZr 25RVFPX/r6j5y8Pr5a/HzajUwwyPTvopbP7w+jiMXShfYQdHhjAGNLgRb5pBfo5fvEmf D9Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=pl6iJr1K; 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 f26si6732069ejr.164.2021.03.20.04.14.18; Sat, 20 Mar 2021 04:14:40 -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=pl6iJr1K; 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 S230173AbhCTFnq (ORCPT + 99 others); Sat, 20 Mar 2021 01:43:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230224AbhCTFne (ORCPT ); Sat, 20 Mar 2021 01:43:34 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6AFBAC061762; Fri, 19 Mar 2021 22:43: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=p8Z3SG+7sSppmZrkCtMgIpMAxffrWUao7nK9dOhrrxw=; b=pl6iJr1KYFqAQu1zSUU8Iw5uck SIT+RYVXf02CZ/wxBMsytTmj45WxJkAXU/sKL52mbNVEert6aaSbBnjCavT3ZLBTw5r0laXGFJkwN UUb11YtJ5dQst7OVs2bnceCBOVM+WqjTtREEdp1IPK3PnUaCT34cjQZ1IHloqpISsq/KK3EjPfEJe GBxXd+M5Uye7bNPHuNZAweNRbbmNRtncjlqfhSm/4iVz7uH3tSKC8TuwrZP/NDmNTB1kpSaJGEOGS 4diUnc5ARnlYL24WVwQFOUBGHnKhdrNaT/Recg9fyY7n6F4dVtbjOIjme2oV0s5wCettnkUZkQOFW BrYDHJMA==; Received: from willy by casper.infradead.org with local (Exim 4.94 #2 (Red Hat Linux)) id 1lNUON-005SeL-JX; Sat, 20 Mar 2021 05:43:22 +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 Subject: [PATCH v5 19/27] mm/filemap: Add __lock_folio_or_retry Date: Sat, 20 Mar 2021 05:40:56 +0000 Message-Id: <20210320054104.1300774-20-willy@infradead.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210320054104.1300774-1-willy@infradead.org> References: <20210320054104.1300774-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) --- 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 3cd1b5e28593..38f4ee28a3a5 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -695,7 +695,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); @@ -757,13 +757,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 12dc672adc2e..35e16db2e2be 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1582,20 +1582,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 d3273bd69dbb..9c3554972e2d 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -4056,7 +4056,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()). */ @@ -4288,7 +4288,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) { @@ -4392,7 +4392,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) @@ -4548,7 +4548,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