Skip to content
Snippets Groups Projects
  • Yafang Shao's avatar
    22d1e078
    mm/readahead: fix large folio support in async readahead · 22d1e078
    Yafang Shao authored and Frieder Schrempf's avatar Frieder Schrempf committed
    commit 158cdce87c8c172787063998ad5dd3e2f658b963 upstream.
    
    When testing large folio support with XFS on our servers, we observed that
    only a few large folios are mapped when reading large files via mmap.
    After a thorough analysis, I identified it was caused by the
    `/sys/block/*/queue/read_ahead_kb` setting.  On our test servers, this
    parameter is set to 128KB.  After I tune it to 2MB, the large folio can
    work as expected.  However, I believe the large folio behavior should not
    be dependent on the value of read_ahead_kb.  It would be more robust if
    the kernel can automatically adopt to it.
    
    With /sys/block/*/queue/read_ahead_kb set to 128KB and performing a
    sequential read on a 1GB file using MADV_HUGEPAGE, the differences in
    /proc/meminfo are as follows:
    
    - before this patch
      FileHugePages:     18432 kB
      FilePmdMapped:      4096 kB
    
    - after this patch
      FileHugePages:   1067008 kB
      FilePmdMapped:   1048576 kB
    
    This shows that after applying the patch, the entire 1GB file is mapped to
    huge pages.  The stable list is CCed, as without this patch, large folios
    don't function optimally in the readahead path.
    
    It's worth noting that if read_ahead_kb is set to a larger value that
    isn't aligned with huge page sizes (e.g., 4MB + 128KB), it may still fail
    to map to hugepages.
    
    Link: https://lkml.kernel.org/r/20241108141710.9721-1-laoar.shao@gmail.com
    Link: https://lkml.kernel.org/r/20241206083025.3478-1-laoar.shao@gmail.com
    
    
    Fixes: 4687fdbb ("mm/filemap: Support VM_HUGEPAGE for file mappings")
    Signed-off-by: default avatarYafang Shao <laoar.shao@gmail.com>
    Tested-by: default avatarkernel test robot <oliver.sang@intel.com>
    Cc: Matthew Wilcox <willy@infradead.org>
    Cc: David Hildenbrand <david@redhat.com>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    22d1e078
    History
    mm/readahead: fix large folio support in async readahead
    Yafang Shao authored and Frieder Schrempf's avatar Frieder Schrempf committed
    commit 158cdce87c8c172787063998ad5dd3e2f658b963 upstream.
    
    When testing large folio support with XFS on our servers, we observed that
    only a few large folios are mapped when reading large files via mmap.
    After a thorough analysis, I identified it was caused by the
    `/sys/block/*/queue/read_ahead_kb` setting.  On our test servers, this
    parameter is set to 128KB.  After I tune it to 2MB, the large folio can
    work as expected.  However, I believe the large folio behavior should not
    be dependent on the value of read_ahead_kb.  It would be more robust if
    the kernel can automatically adopt to it.
    
    With /sys/block/*/queue/read_ahead_kb set to 128KB and performing a
    sequential read on a 1GB file using MADV_HUGEPAGE, the differences in
    /proc/meminfo are as follows:
    
    - before this patch
      FileHugePages:     18432 kB
      FilePmdMapped:      4096 kB
    
    - after this patch
      FileHugePages:   1067008 kB
      FilePmdMapped:   1048576 kB
    
    This shows that after applying the patch, the entire 1GB file is mapped to
    huge pages.  The stable list is CCed, as without this patch, large folios
    don't function optimally in the readahead path.
    
    It's worth noting that if read_ahead_kb is set to a larger value that
    isn't aligned with huge page sizes (e.g., 4MB + 128KB), it may still fail
    to map to hugepages.
    
    Link: https://lkml.kernel.org/r/20241108141710.9721-1-laoar.shao@gmail.com
    Link: https://lkml.kernel.org/r/20241206083025.3478-1-laoar.shao@gmail.com
    
    
    Fixes: 4687fdbb ("mm/filemap: Support VM_HUGEPAGE for file mappings")
    Signed-off-by: default avatarYafang Shao <laoar.shao@gmail.com>
    Tested-by: default avatarkernel test robot <oliver.sang@intel.com>
    Cc: Matthew Wilcox <willy@infradead.org>
    Cc: David Hildenbrand <david@redhat.com>
    Cc: <stable@vger.kernel.org>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>