Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp11814pxv; Wed, 14 Jul 2021 21:46:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx/QH1mnBIZwkiXVjuLfP+iI3/HIe6af1dljEKyahMptynspErC+P5OXLMD1b/CAGm1u+xz X-Received: by 2002:a92:cb0b:: with SMTP id s11mr1260909ilo.292.1626324367147; Wed, 14 Jul 2021 21:46:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626324367; cv=none; d=google.com; s=arc-20160816; b=cUvIBBnPaDHn6IHfwzty+7991+J80pgyZuSgSHShmRRqT8Fo73eD0fdAH2rfBfbahs t2YnEPy4UuanCm1wF2UObQXsxARIWbzvmCUsH4C15xWa0+NnKkaEsUzTGNc4iWx2RSDu /WKFC4qXpe1zH46uHKA78FBBej/nCcskrgyBvmGm/0KHjg/fo6BESudyCQfgqS/U07hM bBXmcke8w1eHQoDS805SL4rJzcri1juoUc+2caZzUmMaeAJhvvYKPyBXLJmk9rZE3+C5 x9KzLTOoyhrWAzRJJusPLuZ89amtcL116vNqBvFj5NkzrNDwVVetgRKLyoCs1ugeD5gC G4IA== 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=Me7+Wbns9PvazlfDbJDzSquWzNvF9/VtGMA22JOaiGk=; b=nvbV6s9NB3KfvawS6L3OVfGgAIT2s0DP7TX/rfLG2CvcljRbclP+IHisGr/90fbPBb 5FtSZpLPt5lMMHtjCDOqQxNbhdcIj/3Kj57tJJKHl5hLRhXz5WUO2svgmL2ws4PYFTH2 MXF/uaJUMXfxIMjNLEY4WiTAQNP1WbSaVQzYM3+GxbjCHmMtt22TdtckBPgGULx8U3vF x5DPgqJvKZv31hT0Hsn5WqyBWkhvX3Pi35bbsZwwbyNq3lrq8ClYB48OnhbLF2xSHUxH HkjtEFQFUx+jdWP7E9rcNbtU587cMAmVCxP8TQBaiAChM8S7bWXCrU1fsImuQ7H9j0QH ztbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=f1kA3HLA; 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 l14si5885998jah.73.2021.07.14.21.45.55; Wed, 14 Jul 2021 21:46:07 -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=f1kA3HLA; 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 S234685AbhGOD5t (ORCPT + 99 others); Wed, 14 Jul 2021 23:57:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231602AbhGOD5t (ORCPT ); Wed, 14 Jul 2021 23:57:49 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5BEEC06175F; Wed, 14 Jul 2021 20:54:56 -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=Me7+Wbns9PvazlfDbJDzSquWzNvF9/VtGMA22JOaiGk=; b=f1kA3HLAo3ZVGSEy5b+eOCzJ/t bbaBXhpiyCF0jDX4N4QUZ6lpVFpFvK2Rav19eHY0C8ybWm/DW1IKvfnPc133qr2NaJfOPYmuSrw3U 5mr3A64Pq456+f7a//E63qtLRzI04DCS7zq0Lgq//isqxQ8IIU7N8J9Z3ypHpokX54alEZv0aSLk2 Av6Bt+yQn/3+RrIRIli2poezYA2KRRwAEgOZowLDNhGxotYv5BToliRuHBhqEd07ZF9BrbDksq2B/ WwGMhaQO7abAOlnAdf16trFOFReIeTm/nvJdBBbBfhlFnNwkeoJX0mdyLREcp2U8y1xPUg6OCplyW c/qiUMYA==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1m3sRY-002vEv-Km; Thu, 15 Jul 2021 03:54:13 +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 020/138] mm/filemap: Add __folio_lock_async() Date: Thu, 15 Jul 2021 04:35:06 +0100 Message-Id: <20210715033704.692967-21-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 There aren't any actual callers of lock_page_async(), so remove it. Convert filemap_update_page() to call __folio_lock_async(). __folio_lock_async() is 21 bytes smaller than __lock_page_async(), but the real savings come from using a folio in filemap_update_page(), shrinking it from 515 bytes to 404 bytes, saving 110 bytes. The text shrinks by 132 bytes in total. 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 --- fs/io_uring.c | 2 +- include/linux/pagemap.h | 17 ----------------- mm/filemap.c | 31 ++++++++++++++++--------------- 3 files changed, 17 insertions(+), 33 deletions(-) diff --git a/fs/io_uring.c b/fs/io_uring.c index d94fb5835a20..7e30c7c361e6 100644 --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -3149,7 +3149,7 @@ static int io_read_prep(struct io_kiocb *req, const struct io_uring_sqe *sqe) } /* - * This is our waitqueue callback handler, registered through lock_page_async() + * This is our waitqueue callback handler, registered through __folio_lock_async() * when we initially tried to do the IO with the iocb armed our waitqueue. * This gets called when the page is unlocked, and we generally expect that to * happen when the page IO is completed and the page is now uptodate. This will diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index 88727c74e059..6f631a3e42dc 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -655,7 +655,6 @@ static inline bool wake_page_match(struct wait_page_queue *wait_page, void __folio_lock(struct folio *folio); int __folio_lock_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); void unlock_page(struct page *page); @@ -712,22 +711,6 @@ static inline int lock_page_killable(struct page *page) return folio_lock_killable(page_folio(page)); } -/* - * lock_page_async - Lock the page, unless this would block. If the page - * is already locked, then queue a callback when the page becomes unlocked. - * This callback can then retry the operation. - * - * Returns 0 if the page is locked successfully, or -EIOCBQUEUED if the page - * was already locked and the callback defined in 'wait' was queued. - */ -static inline int lock_page_async(struct page *page, - struct wait_page_queue *wait) -{ - if (!trylock_page(page)) - return __lock_page_async(page, wait); - return 0; -} - /* * lock_page_or_retry - Lock the page, unless this would block and the * caller indicated that it can handle a retry. diff --git a/mm/filemap.c b/mm/filemap.c index 962db5c38cd7..c97b804811fc 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -1597,18 +1597,18 @@ int __folio_lock_killable(struct folio *folio) } EXPORT_SYMBOL_GPL(__folio_lock_killable); -int __lock_page_async(struct page *page, struct wait_page_queue *wait) +static int __folio_lock_async(struct folio *folio, struct wait_page_queue *wait) { - struct wait_queue_head *q = page_waitqueue(page); + struct wait_queue_head *q = page_waitqueue(&folio->page); int ret = 0; - wait->page = page; + wait->page = &folio->page; wait->bit_nr = PG_locked; spin_lock_irq(&q->lock); __add_wait_queue_entry_tail(q, &wait->wait); - SetPageWaiters(page); - ret = !trylock_page(page); + folio_set_waiters(folio); + ret = !folio_trylock(folio); /* * If we were successful now, we know we're still on the * waitqueue as we're still under the lock. This means it's @@ -2381,41 +2381,42 @@ static int filemap_update_page(struct kiocb *iocb, struct address_space *mapping, struct iov_iter *iter, struct page *page) { + struct folio *folio = page_folio(page); int error; - if (!trylock_page(page)) { + if (!folio_trylock(folio)) { if (iocb->ki_flags & (IOCB_NOWAIT | IOCB_NOIO)) return -EAGAIN; if (!(iocb->ki_flags & IOCB_WAITQ)) { - put_and_wait_on_page_locked(page, TASK_KILLABLE); + put_and_wait_on_page_locked(&folio->page, TASK_KILLABLE); return AOP_TRUNCATED_PAGE; } - error = __lock_page_async(page, iocb->ki_waitq); + error = __folio_lock_async(folio, iocb->ki_waitq); if (error) return error; } - if (!page->mapping) + if (!folio->mapping) goto truncated; error = 0; - if (filemap_range_uptodate(mapping, iocb->ki_pos, iter, page)) + if (filemap_range_uptodate(mapping, iocb->ki_pos, iter, &folio->page)) goto unlock; error = -EAGAIN; if (iocb->ki_flags & (IOCB_NOIO | IOCB_NOWAIT | IOCB_WAITQ)) goto unlock; - error = filemap_read_page(iocb->ki_filp, mapping, page); + error = filemap_read_page(iocb->ki_filp, mapping, &folio->page); if (error == AOP_TRUNCATED_PAGE) - put_page(page); + folio_put(folio); return error; truncated: - unlock_page(page); - put_page(page); + folio_unlock(folio); + folio_put(folio); return AOP_TRUNCATED_PAGE; unlock: - unlock_page(page); + folio_unlock(folio); return error; } -- 2.30.2