@@ -204,14 +204,21 @@ enum mapping_flags {
204
204
AS_EXITING = 4 , /* final truncate in progress */
205
205
/* writeback related tags are not used */
206
206
AS_NO_WRITEBACK_TAGS = 5 ,
207
- AS_LARGE_FOLIO_SUPPORT = 6 ,
208
- AS_RELEASE_ALWAYS , /* Call ->release_folio(), even if no private data */
209
- AS_STABLE_WRITES , /* must wait for writeback before modifying
207
+ AS_RELEASE_ALWAYS = 6 , /* Call ->release_folio(), even if no private data */
208
+ AS_STABLE_WRITES = 7 , /* must wait for writeback before modifying
210
209
folio contents */
211
- AS_INACCESSIBLE , /* Do not attempt direct R/W access to the mapping,
212
- including to move the mapping */
210
+ AS_INACCESSIBLE = 8 , /* Do not attempt direct R/W access to the mapping */
211
+ /* Bits 16-25 are used for FOLIO_ORDER */
212
+ AS_FOLIO_ORDER_BITS = 5 ,
213
+ AS_FOLIO_ORDER_MIN = 16 ,
214
+ AS_FOLIO_ORDER_MAX = AS_FOLIO_ORDER_MIN + AS_FOLIO_ORDER_BITS ,
213
215
};
214
216
217
+ #define AS_FOLIO_ORDER_BITS_MASK ((1u << AS_FOLIO_ORDER_BITS) - 1)
218
+ #define AS_FOLIO_ORDER_MIN_MASK (AS_FOLIO_ORDER_BITS_MASK << AS_FOLIO_ORDER_MIN)
219
+ #define AS_FOLIO_ORDER_MAX_MASK (AS_FOLIO_ORDER_BITS_MASK << AS_FOLIO_ORDER_MAX)
220
+ #define AS_FOLIO_ORDER_MASK (AS_FOLIO_ORDER_MIN_MASK | AS_FOLIO_ORDER_MAX_MASK)
221
+
215
222
/**
216
223
* mapping_set_error - record a writeback error in the address_space
217
224
* @mapping: the mapping in which an error should be set
@@ -367,9 +374,51 @@ static inline void mapping_set_gfp_mask(struct address_space *m, gfp_t mask)
367
374
#define MAX_XAS_ORDER (XA_CHUNK_SHIFT * 2 - 1)
368
375
#define MAX_PAGECACHE_ORDER min(MAX_XAS_ORDER, PREFERRED_MAX_PAGECACHE_ORDER)
369
376
377
+ /*
378
+ * mapping_set_folio_order_range() - Set the orders supported by a file.
379
+ * @mapping: The address space of the file.
380
+ * @min: Minimum folio order (between 0-MAX_PAGECACHE_ORDER inclusive).
381
+ * @max: Maximum folio order (between @min-MAX_PAGECACHE_ORDER inclusive).
382
+ *
383
+ * The filesystem should call this function in its inode constructor to
384
+ * indicate which base size (min) and maximum size (max) of folio the VFS
385
+ * can use to cache the contents of the file. This should only be used
386
+ * if the filesystem needs special handling of folio sizes (ie there is
387
+ * something the core cannot know).
388
+ * Do not tune it based on, eg, i_size.
389
+ *
390
+ * Context: This should not be called while the inode is active as it
391
+ * is non-atomic.
392
+ */
393
+ static inline void mapping_set_folio_order_range (struct address_space * mapping ,
394
+ unsigned int min ,
395
+ unsigned int max )
396
+ {
397
+ if (!IS_ENABLED (CONFIG_TRANSPARENT_HUGEPAGE ))
398
+ return ;
399
+
400
+ if (min > MAX_PAGECACHE_ORDER )
401
+ min = MAX_PAGECACHE_ORDER ;
402
+
403
+ if (max > MAX_PAGECACHE_ORDER )
404
+ max = MAX_PAGECACHE_ORDER ;
405
+
406
+ if (max < min )
407
+ max = min ;
408
+
409
+ mapping -> flags = (mapping -> flags & ~AS_FOLIO_ORDER_MASK ) |
410
+ (min << AS_FOLIO_ORDER_MIN ) | (max << AS_FOLIO_ORDER_MAX );
411
+ }
412
+
413
+ static inline void mapping_set_folio_min_order (struct address_space * mapping ,
414
+ unsigned int min )
415
+ {
416
+ mapping_set_folio_order_range (mapping , min , MAX_PAGECACHE_ORDER );
417
+ }
418
+
370
419
/**
371
420
* mapping_set_large_folios() - Indicate the file supports large folios.
372
- * @mapping: The file.
421
+ * @mapping: The address space of the file.
373
422
*
374
423
* The filesystem should call this function in its inode constructor to
375
424
* indicate that the VFS can use large folios to cache the contents of
@@ -380,7 +429,23 @@ static inline void mapping_set_gfp_mask(struct address_space *m, gfp_t mask)
380
429
*/
381
430
static inline void mapping_set_large_folios (struct address_space * mapping )
382
431
{
383
- __set_bit (AS_LARGE_FOLIO_SUPPORT , & mapping -> flags );
432
+ mapping_set_folio_order_range (mapping , 0 , MAX_PAGECACHE_ORDER );
433
+ }
434
+
435
+ static inline unsigned int
436
+ mapping_max_folio_order (const struct address_space * mapping )
437
+ {
438
+ if (!IS_ENABLED (CONFIG_TRANSPARENT_HUGEPAGE ))
439
+ return 0 ;
440
+ return (mapping -> flags & AS_FOLIO_ORDER_MAX_MASK ) >> AS_FOLIO_ORDER_MAX ;
441
+ }
442
+
443
+ static inline unsigned int
444
+ mapping_min_folio_order (const struct address_space * mapping )
445
+ {
446
+ if (!IS_ENABLED (CONFIG_TRANSPARENT_HUGEPAGE ))
447
+ return 0 ;
448
+ return (mapping -> flags & AS_FOLIO_ORDER_MIN_MASK ) >> AS_FOLIO_ORDER_MIN ;
384
449
}
385
450
386
451
/*
@@ -389,20 +454,17 @@ static inline void mapping_set_large_folios(struct address_space *mapping)
389
454
*/
390
455
static inline bool mapping_large_folio_support (struct address_space * mapping )
391
456
{
392
- /* AS_LARGE_FOLIO_SUPPORT is only reasonable for pagecache folios */
457
+ /* AS_FOLIO_ORDER is only reasonable for pagecache folios */
393
458
VM_WARN_ONCE ((unsigned long )mapping & PAGE_MAPPING_ANON ,
394
459
"Anonymous mapping always supports large folio" );
395
460
396
- return IS_ENABLED (CONFIG_TRANSPARENT_HUGEPAGE ) &&
397
- test_bit (AS_LARGE_FOLIO_SUPPORT , & mapping -> flags );
461
+ return mapping_max_folio_order (mapping ) > 0 ;
398
462
}
399
463
400
464
/* Return the maximum folio size for this pagecache mapping, in bytes. */
401
- static inline size_t mapping_max_folio_size (struct address_space * mapping )
465
+ static inline size_t mapping_max_folio_size (const struct address_space * mapping )
402
466
{
403
- if (mapping_large_folio_support (mapping ))
404
- return PAGE_SIZE << MAX_PAGECACHE_ORDER ;
405
- return PAGE_SIZE ;
467
+ return PAGE_SIZE << mapping_max_folio_order (mapping );
406
468
}
407
469
408
470
static inline int filemap_nr_thps (struct address_space * mapping )
0 commit comments