All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] mm: move more expensive part of XA setup out of mapping check
@ 2021-10-26 16:01 Jens Axboe
  2021-10-26 18:08 ` Matthew Wilcox
  0 siblings, 1 reply; 3+ messages in thread
From: Jens Axboe @ 2021-10-26 16:01 UTC (permalink / raw)
  To: Andrew Morton; +Cc: Linux Memory Management List, LKML

The fast path here is not needing any writeback, yet we spend time setting
up the xarray lookup data upfront. Move the part that actually needs to
iterate the address space mapping into a separate helper, saving ~30% of
the time here.

Signed-off-by: Jens Axboe <axboe@kernel.dk>

---

diff --git a/mm/filemap.c b/mm/filemap.c
index 850920276846..0e4021edac0b 100644
--- a/mm/filemap.c
+++ b/mm/filemap.c
@@ -638,6 +638,30 @@ static bool mapping_needs_writeback(struct address_space *mapping)
 	return mapping->nrpages;
 }
 
+static bool filemap_range_has_writeback(struct address_space *mapping,
+					loff_t start_byte, loff_t end_byte)
+{
+	XA_STATE(xas, &mapping->i_pages, start_byte >> PAGE_SHIFT);
+	pgoff_t max = end_byte >> PAGE_SHIFT;
+	struct page *page;
+
+	if (end_byte < start_byte)
+		return false;
+
+	rcu_read_lock();
+	xas_for_each(&xas, page, max) {
+		if (xas_retry(&xas, page))
+			continue;
+		if (xa_is_value(page))
+			continue;
+		if (PageDirty(page) || PageLocked(page) || PageWriteback(page))
+			break;
+	}
+	rcu_read_unlock();
+	return page != NULL;
+
+}
+
 /**
  * filemap_range_needs_writeback - check if range potentially needs writeback
  * @mapping:           address space within which to check
@@ -655,29 +679,12 @@ static bool mapping_needs_writeback(struct address_space *mapping)
 bool filemap_range_needs_writeback(struct address_space *mapping,
 				   loff_t start_byte, loff_t end_byte)
 {
-	XA_STATE(xas, &mapping->i_pages, start_byte >> PAGE_SHIFT);
-	pgoff_t max = end_byte >> PAGE_SHIFT;
-	struct page *page;
-
 	if (!mapping_needs_writeback(mapping))
 		return false;
 	if (!mapping_tagged(mapping, PAGECACHE_TAG_DIRTY) &&
 	    !mapping_tagged(mapping, PAGECACHE_TAG_WRITEBACK))
 		return false;
-	if (end_byte < start_byte)
-		return false;
-
-	rcu_read_lock();
-	xas_for_each(&xas, page, max) {
-		if (xas_retry(&xas, page))
-			continue;
-		if (xa_is_value(page))
-			continue;
-		if (PageDirty(page) || PageLocked(page) || PageWriteback(page))
-			break;
-	}
-	rcu_read_unlock();
-	return page != NULL;
+	return filemap_range_has_writeback(mapping, start_byte, end_byte);
 }
 EXPORT_SYMBOL_GPL(filemap_range_needs_writeback);
 
-- 
Jens Axboe


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm: move more expensive part of XA setup out of mapping check
  2021-10-26 16:01 [PATCH] mm: move more expensive part of XA setup out of mapping check Jens Axboe
@ 2021-10-26 18:08 ` Matthew Wilcox
  2021-10-26 18:11   ` Jens Axboe
  0 siblings, 1 reply; 3+ messages in thread
From: Matthew Wilcox @ 2021-10-26 18:08 UTC (permalink / raw)
  To: Jens Axboe; +Cc: Andrew Morton, Linux Memory Management List, LKML

On Tue, Oct 26, 2021 at 10:01:20AM -0600, Jens Axboe wrote:
> The fast path here is not needing any writeback, yet we spend time setting
> up the xarray lookup data upfront. Move the part that actually needs to
> iterate the address space mapping into a separate helper, saving ~30% of
> the time here.

No objection to this patch, but it did remind me that I never saw an answer to
https://lore.kernel.org/all/CAHk-=wg_-EwefQ_3Osz4iJxTrTk3tfrV53Z7-jaGg=tm9i5TXg@mail.gmail.com/
(and nor did lore)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] mm: move more expensive part of XA setup out of mapping check
  2021-10-26 18:08 ` Matthew Wilcox
@ 2021-10-26 18:11   ` Jens Axboe
  0 siblings, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2021-10-26 18:11 UTC (permalink / raw)
  To: Matthew Wilcox; +Cc: Andrew Morton, Linux Memory Management List, LKML

On 10/26/21 12:08 PM, Matthew Wilcox wrote:
> On Tue, Oct 26, 2021 at 10:01:20AM -0600, Jens Axboe wrote:
>> The fast path here is not needing any writeback, yet we spend time setting
>> up the xarray lookup data upfront. Move the part that actually needs to
>> iterate the address space mapping into a separate helper, saving ~30% of
>> the time here.
> 
> No objection to this patch, but it did remind me that I never saw an answer to
> https://lore.kernel.org/all/CAHk-=wg_-EwefQ_3Osz4iJxTrTk3tfrV53Z7-jaGg=tm9i5TXg@mail.gmail.com/
> (and nor did lore)

Totally missed that, and yes there could be cases where that lookup is
going to be way too slow. I'll take a look.

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-10-26 18:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-26 16:01 [PATCH] mm: move more expensive part of XA setup out of mapping check Jens Axboe
2021-10-26 18:08 ` Matthew Wilcox
2021-10-26 18:11   ` Jens Axboe

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.