Re: [PATCH v8 01/10] fs: Allow fine-grained control of folio sizes

From: Pankaj Raghav (Samsung)
Date: Tue Jul 09 2024 - 13:33:30 EST


On Tue, Jul 09, 2024 at 05:38:16PM +0100, Matthew Wilcox wrote:
> On Tue, Jul 09, 2024 at 04:29:07PM +0000, Pankaj Raghav (Samsung) wrote:
> > +++ b/include/linux/pagemap.h
> > @@ -394,13 +394,24 @@ static inline void mapping_set_folio_order_range(struct address_space *mapping,
> > unsigned int min,
> > unsigned int max)
> > {
> > - if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE))
> > + if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE)) {
> > + VM_WARN_ONCE(1,
> > + "THP needs to be enabled to support mapping folio order range");
> > return;
> > + }
>
> No. Filesystems call mapping_set_folio_order_range() without it being
> conditional on CONFIG_TRANSPARENT_HUGEPAGE. Usually that takes the
> form of an unconditional call to mapping_set_large_folios().

Ah, you are right.

Actually thinking more about it, we don't need VM_WARN_ONCE on
CONFIG_THP IS_ENABLED, because if we go the route where a FS will
call something like `mapping_max_folio_order_supported()` during mount
time, that will already return `0` as the maximum order that will be
supported.

So just something like this should be enough:
diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h
index 14e1415f7dcf..ef6b13854385 100644
--- a/include/linux/pagemap.h
+++ b/include/linux/pagemap.h
@@ -397,10 +397,18 @@ static inline void mapping_set_folio_order_range(struct address_space *mapping,
if (!IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE))
return;

- if (min > MAX_PAGECACHE_ORDER)
+ if (min > MAX_PAGECACHE_ORDER) {
+ VM_WARN_ONCE(1,
+ "min order > MAX_PAGECACHE_ORDER. Setting min_order to MAX_PAGECACHE_ORDER");
min = MAX_PAGECACHE_ORDER;
- if (max > MAX_PAGECACHE_ORDER)
+ }
+
+ if (max > MAX_PAGECACHE_ORDER) {
+ VM_WARN_ONCE(1,
+ "max order > MAX_PAGECACHE_ORDER. Setting max_order to MAX_PAGECACHE_ORDER");
max = MAX_PAGECACHE_ORDER;
+ }
+
if (max < min)
max = min;

If we have a helper such as mapping_max_folio_order_supported() that
could be invoked by FSs to see what page cache could support.

And FSs that call mapping_set_large_folios() as an optimization will not
see these random WARNINGS because we call this function with the actual
min and max range.

Let me know what you think.

--
Pankaj