mm/filemap.c | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-)
Hopefully this is the last revision. The only change from the previous revision is that the logic for deciding THP order was simplified and the max is now capped to 2M. Thanks Pedro and Jan for the suggestion and the dicusssion! The benchmark results on Neoverse V2 (Grace), arm64 with 64K base pages, 512MB executable file on ext4, averaged over 3 runs: Phase | Baseline | Patched | Improvement -----------|--------------|--------------|------------------ Cold fault | 83.4 ms | 41.3 ms | 50% faster Random | 76.0 ms | 58.3 ms | 23% faster The patches are on top of mm-unstable from 28 May (8a74e22643189e0ae339afc91110ddb4cab1941b) which include patch [1] that make mmap_miss accounting symmetric for VM_SEQ_READ which was pointed out by sashiko in the previous revision. [1] https://lore.kernel.org/all/20260525145751.2671248-1-usama.arif@linux.dev/ v6 -> v7: https://lore.kernel.org/all/20260528165635.2068012-1-usama.arif@linux.dev/ - Simplify logic and just cap the max THP order to 2M (Pedro and Jan) v5 -> v6: https://lore.kernel.org/all/20260522162422.3856502-1-usama.arif@linux.dev/ - Based on top of patch [1] (sashiko) - Changes to commit message to make it more accurate for patch 1 and skip mmap_miss decrement as well. (sashiko) - Keep old behaviour if large folio mappings is not enabled (sashiko). - sashiko pointed to a TOCTOU data race that was pre-existing. My patch could make it worse. Dont make it worse by introducing thp_order local variable. v3 -> v5: https://lore.kernel.org/all/20260402181326.3107102-1-usama.arif@linux.dev/ - (Looks like I messed up the versioning here and went directly form v3 to v5.) - Drop patches for elf thp unmapped area alignment and deal with them separately. These patches will just bring folios smaller than PMD at the same level as PMD. The 2 patches now should be much easier to merge. - Tackle size of THP for exec pages at the same point as PMD instead of tackling using exec_folio_order() (Ryan during LSFMM, Thanks!) v2 -> v3: https://lore.kernel.org/all/20260320140315.979307-1-usama.arif@linux.dev/ - Take into account READ_ONLY_THP_FOR_FS for elf alignment by aligning to HPAGE_PMD_SIZE limited to 2M (Rui) - Reviewed-by tags for patch 1 from Kiryl and Jan - Remove preferred_exec_order() (Jan) - Change ra->order to HPAGE_PMD_ORDER if vma_pages(vma) >= HPAGE_PMD_NR otherwise use exec_folio_order() with gfp &= ~__GFP_RECLAIM for do_sync_mmap_readahead(). - Change exec_folio_order() to return 2M (cont-pte size) for 64K base page size for arm64. - remove bprm->file NULL check (Matthew) - Change filp to file (Matthew) - Improve checking of p_vaddr and p_vaddr (Rui and Matthew) v1 -> v2: https://lore.kernel.org/all/20260310145406.3073394-1-usama.arif@linux.dev/ - disable mmap_miss logic for VM_EXEC (Jan Kara) - Align in elf only when segment VA and file offset are already aligned (Rui) - preferred_exec_order() for VM_EXEC sync mmap_readahead which takes into account zone high watermarks (as an approximation of memory pressure) (David, or atleast my approach to what David suggested in [1] :)) - Extend max alignment to mapping_max_folio_size() instead of exec_folio_order() Usama Arif (2): mm: bypass mmap_miss heuristic for VM_EXEC readahead mm: use mapping_max_folio_order() for force_thp_readahead order mm/filemap.c | 44 +++++++++++++++++++++++++++++--------------- 1 file changed, 29 insertions(+), 15 deletions(-) -- 2.52.0
On Mon, 1 Jun 2026 03:21:16 -0700 Usama Arif <usama.arif@linux.dev> wrote:
> Hopefully this is the last revision. The only change from the previous
> revision is that the logic for deciding THP order was simplified and
> the max is now capped to 2M. Thanks Pedro and Jan for the suggestion
> and the dicusssion!
>
> The benchmark results on Neoverse V2 (Grace), arm64 with 64K base pages,
> 512MB executable file on ext4, averaged over 3 runs:
>
> Phase | Baseline | Patched | Improvement
> -----------|--------------|--------------|------------------
> Cold fault | 83.4 ms | 41.3 ms | 50% faster
> Random | 76.0 ms | 58.3 ms | 23% faster
>
> The patches are on top of mm-unstable from 28 May
> (8a74e22643189e0ae339afc91110ddb4cab1941b) which include patch [1]
> that make mmap_miss accounting symmetric for VM_SEQ_READ which was pointed
> out by sashiko in the previous revision.
We lost the [0/N] cover letter. Please do retain (and maintain!) that
across revisions. I used the one from the v6 patchset.
> v6 -> v7: https://lore.kernel.org/all/20260528165635.2068012-1-usama.arif@linux.dev/
> - Simplify logic and just cap the max THP order to 2M (Pedro and Jan)
Here's how v7 altered mm.git:
mm/filemap.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
--- a/mm/filemap.c~b
+++ a/mm/filemap.c
@@ -3320,17 +3320,12 @@ static struct file *do_sync_mmap_readahe
/* Use the readahead code, even if readahead is disabled */
if (IS_ENABLED(CONFIG_TRANSPARENT_HUGEPAGE) && (vm_flags & VM_HUGEPAGE)) {
/*
- * Preserve PMD-sized readahead where it already fits in
- * the page cache. Otherwise cap the new fallback path at
- * 2MB: this is the common PMD-sized hugepage size, and it
- * avoids memory pressure from very large forced readahead
- * when mapping_max_folio_order() is high (for example,
- * 128MB with 64K base pages on arm64).
+ * Cap max THP order at 2MB: this is the common PMD-sized
+ * hugepage size, and it avoids memory pressure from very
+ * large forced readahead when mapping_max_folio_order() is
+ * high (for example, 128MB with 64K base pages on arm64).
*/
- if (HPAGE_PMD_ORDER <= MAX_PAGECACHE_ORDER) {
- force_thp_readahead = true;
- thp_order = HPAGE_PMD_ORDER;
- } else if (mapping_large_folio_support(mapping)) {
+ if (mapping_large_folio_support(mapping)) {
force_thp_readahead = true;
thp_order = min_t(unsigned int,
mapping_max_folio_order(mapping),
_
© 2016 - 2026 Red Hat, Inc.