All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Matthew Wilcox (Oracle)" <willy@infradead.org>
To: akpm@linux-foundation.org
Cc: "Matthew Wilcox (Oracle)" <willy@infradead.org>,
	linux-fsdevel@vger.kernel.org, linux-mm@kvack.org,
	linux-kernel@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	Jeff Layton <jlayton@kernel.org>,
	"Kirill A . Shutemov" <kirill.shutemov@linux.intel.com>,
	Vlastimil Babka <vbabka@suse.cz>,
	William Kucharski <william.kucharski@oracle.com>,
	David Howells <dhowells@redhat.com>
Subject: [PATCH v12 21/33] mm/filemap: Add __folio_lock_async()
Date: Tue, 22 Jun 2021 12:41:06 +0100	[thread overview]
Message-ID: <20210622114118.3388190-22-willy@infradead.org> (raw)
In-Reply-To: <20210622114118.3388190-1-willy@infradead.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) <willy@infradead.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Acked-by: Jeff Layton <jlayton@kernel.org>
Acked-by: Kirill A. Shutemov <kirill.shutemov@linux.intel.com>
Acked-by: Vlastimil Babka <vbabka@suse.cz>
Reviewed-by: William Kucharski <william.kucharski@oracle.com>
Reviewed-by: David Howells <dhowells@redhat.com>
---
 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 903458afd56c..4c6096382db3 100644
--- a/fs/io_uring.c
+++ b/fs/io_uring.c
@@ -3160,7 +3160,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 bba73c10c9fe..86c784572eeb 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -654,7 +654,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);
@@ -711,22 +710,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 70dc1798f6d6..a8177324c393 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_flag(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


  parent reply	other threads:[~2021-06-22 12:00 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-06-22 11:40 [PATCH v12 00/33] Memory folios Matthew Wilcox (Oracle)
2021-06-22 11:40 ` [PATCH v12 01/33] mm: Convert get_page_unless_zero() to return bool Matthew Wilcox (Oracle)
2021-06-23  7:46   ` Christoph Hellwig
2021-06-28 12:35   ` Kirill A. Shutemov
2021-06-22 11:40 ` [PATCH v12 02/33] mm: Introduce struct folio Matthew Wilcox (Oracle)
2021-06-22 11:40 ` [PATCH v12 03/33] mm: Add folio_pgdat(), folio_zone() and folio_zonenum() Matthew Wilcox (Oracle)
2021-06-22 11:40 ` [PATCH v12 04/33] mm/vmstat: Add functions to account folio statistics Matthew Wilcox (Oracle)
2021-06-22 11:40 ` [PATCH v12 05/33] mm/debug: Add VM_BUG_ON_FOLIO() and VM_WARN_ON_ONCE_FOLIO() Matthew Wilcox (Oracle)
2021-06-22 11:40 ` [PATCH v12 06/33] mm: Add folio reference count functions Matthew Wilcox (Oracle)
2021-06-22 11:40 ` [PATCH v12 07/33] mm: Add folio_put() Matthew Wilcox (Oracle)
2021-06-22 11:40 ` [PATCH v12 08/33] mm: Add folio_get() Matthew Wilcox (Oracle)
2021-06-22 11:40 ` [PATCH v12 09/33] mm: Add folio_try_get_rcu() Matthew Wilcox (Oracle)
2021-06-28 12:38   ` Kirill A. Shutemov
2021-06-22 11:40 ` [PATCH v12 10/33] mm: Add folio flag manipulation functions Matthew Wilcox (Oracle)
2021-06-22 11:40 ` [PATCH v12 11/33] mm/lru: Add folio LRU functions Matthew Wilcox (Oracle)
2021-06-28 12:40   ` Kirill A. Shutemov
2021-06-22 11:40 ` [PATCH v12 12/33] mm: Handle per-folio private data Matthew Wilcox (Oracle)
2021-06-22 11:40 ` [PATCH v12 13/33] mm/filemap: Add folio_index(), folio_file_page() and folio_contains() Matthew Wilcox (Oracle)
2021-06-22 11:40 ` [PATCH v12 14/33] mm/filemap: Add folio_next_index() Matthew Wilcox (Oracle)
2021-06-22 11:41 ` [PATCH v12 15/33] mm/filemap: Add folio_pos() and folio_file_pos() Matthew Wilcox (Oracle)
2021-06-22 11:41 ` [PATCH v12 16/33] mm/util: Add folio_mapping() and folio_file_mapping() Matthew Wilcox (Oracle)
2021-06-22 11:41 ` [PATCH v12 17/33] mm/memcg: Add folio wrappers for various functions Matthew Wilcox (Oracle)
2021-06-22 11:41 ` [PATCH v12 18/33] mm/filemap: Add folio_unlock() Matthew Wilcox (Oracle)
2021-06-22 11:41 ` [PATCH v12 19/33] mm/filemap: Add folio_lock() Matthew Wilcox (Oracle)
2021-06-22 11:41 ` [PATCH v12 20/33] mm/filemap: Add folio_lock_killable() Matthew Wilcox (Oracle)
2021-06-22 11:41 ` Matthew Wilcox (Oracle) [this message]
2021-06-22 11:41 ` [PATCH v12 22/33] mm/filemap: Add folio_wait_locked() Matthew Wilcox (Oracle)
2021-06-22 11:41 ` [PATCH v12 23/33] mm/filemap: Add __folio_lock_or_retry() Matthew Wilcox (Oracle)
2021-06-22 11:41 ` [PATCH v12 24/33] mm/swap: Add folio_rotate_reclaimable() Matthew Wilcox (Oracle)
2021-06-28 12:46   ` Kirill A. Shutemov
2021-06-22 11:41 ` [PATCH v12 25/33] mm/filemap: Add folio_end_writeback() Matthew Wilcox (Oracle)
2021-06-22 11:41 ` [PATCH v12 26/33] mm/writeback: Add folio_wait_writeback() Matthew Wilcox (Oracle)
2021-06-22 11:41 ` [PATCH v12 27/33] mm/writeback: Add folio_wait_stable() Matthew Wilcox (Oracle)
2021-06-22 11:41 ` [PATCH v12 28/33] mm/filemap: Add folio_wait_bit() Matthew Wilcox (Oracle)
2021-06-22 11:41 ` [PATCH v12 29/33] mm/filemap: Add folio_wake_bit() Matthew Wilcox (Oracle)
2021-06-22 11:41 ` [PATCH v12 30/33] mm/filemap: Convert page wait queues to be folios Matthew Wilcox (Oracle)
2021-06-22 11:41 ` [PATCH v12 31/33] mm/filemap: Add folio private_2 functions Matthew Wilcox (Oracle)
2021-06-28 12:47   ` Kirill A. Shutemov
2021-06-22 11:41 ` [PATCH v12 32/33] fs/netfs: Add folio fscache functions Matthew Wilcox (Oracle)
2021-06-28 12:49   ` Kirill A. Shutemov
2021-06-22 11:41 ` [PATCH v12 33/33] mm: Add folio_mapped() Matthew Wilcox (Oracle)
2021-06-28 12:51   ` Kirill A. Shutemov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210622114118.3388190-22-willy@infradead.org \
    --to=willy@infradead.org \
    --cc=akpm@linux-foundation.org \
    --cc=dhowells@redhat.com \
    --cc=hch@lst.de \
    --cc=jlayton@kernel.org \
    --cc=kirill.shutemov@linux.intel.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=vbabka@suse.cz \
    --cc=william.kucharski@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.