Re: [PATCH] mm/filemap: allocate folios according to the blocksize

Matthew Wilcox
2023-04-16T04:01:05Z

On Fri, Apr 14, 2023 at 03:49:08PM +0200, Hannes Reinecke wrote:
> @@ -3607,14 +3611,16 @@ static struct folio *do_read_cache_folio(struct address_space *mapping,
> pgoff_t index, filler_t filler, struct file *file, gfp_t gfp)
> {
> struct folio *folio;
> - int err;
> + int err, order = 0;
>
> + if (mapping->host->i_blkbits > PAGE_SHIFT)
> + order = mapping->host->i_blkbits - PAGE_SHIFT;

This pattern comes up a few times. What I did in a patch I wrote back
in December 2020 and never submitted (!) was this:

@@ -198,9 +198,15 @@ enum mapping_flags {
AS_EXITING = 4, /* final truncate in progress */
/* writeback related tags are not used */
AS_NO_WRITEBACK_TAGS = 5,
- AS_LARGE_FOLIO_SUPPORT = 6,
+ AS_FOLIO_ORDER_MIN = 8,
+ AS_FOLIO_ORDER_MAX = 13,
+ /* 8-17 are used for FOLIO_ORDER */
};

+#define AS_FOLIO_ORDER_MIN_MASK 0x00001f00
+#define AS_FOLIO_ORDER_MAX_MASK 0x0002e000
+#define AS_FOLIO_ORDER_MASK (AS_FOLIO_ORDER_MIN_MASK | AS_FOLIO_ORDER_MAX_MASK)

...

+static inline unsigned mapping_min_folio_order(struct address_space *mapping)
+{
+ return (mapping->flags & AS_FOLIO_ORDER_MIN_MASK) >> AS_FOLIO_ORDER_MIN;
+}

(do we really need 5 bits for each, or can we get by with eg 3 or 4 bits?)

Anyway, the point is that we could set this quite early in the creation
of the mapping, and eliminate the conditional setting of order.