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-kernel@vger.kernel.org, linux-mm@kvack.org,
	linux-fsdevel@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 v13 20/32] mm/filemap: Add __folio_lock_async()
Date: Mon, 12 Jul 2021 20:01:52 +0100	[thread overview]
Message-ID: <20210712190204.80979-21-willy@infradead.org> (raw)
In-Reply-To: <20210712190204.80979-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 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 3d78d96c163d..79ff079346aa 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 108cc825638f..19c1486d85d2 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-07-12 19:14 UTC|newest]

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

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=20210712190204.80979-21-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.