• Baolin Wang's avatar
    mm: memory: extend finish_fault() to support large folio · 43e027e4
    Baolin Wang authored
    Patch series "add mTHP support for anonymous shmem", v5.
    
    Anonymous pages have already been supported for multi-size (mTHP)
    allocation through commit 19eaf449, that can allow THP to be
    configured through the sysfs interface located at
    '/sys/kernel/mm/transparent_hugepage/hugepage-XXkb/enabled'.
    
    However, the anonymous shmem will ignore the anonymous mTHP rule
    configured through the sysfs interface, and can only use the PMD-mapped
    THP, that is not reasonable.  Many implement anonymous page sharing
    through mmap(MAP_SHARED | MAP_ANONYMOUS), especially in database usage
    scenarios, therefore, users expect to apply an unified mTHP strategy for
    anonymous pages, also including the anonymous shared pages, in order to
    enjoy the benefits of mTHP.  For example, lower latency than PMD-mapped
    THP, smaller memory bloat than PMD-mapped THP, contiguous PTEs on ARM
    architecture to reduce TLB miss etc.
    
    As discussed in the bi-weekly MM meeting[1], the mTHP controls should
    control all of shmem, not only anonymous shmem, but support will be added
    iteratively.  Therefore, this patch set starts with support for anonymous
    shmem.
    
    The primary strategy is similar to supporting anonymous mTHP.  Introduce a
    new interface '/mm/transparent_hugepage/hugepage-XXkb/shmem_enabled',
    which can have almost the same values as the top-level
    '/sys/kernel/mm/transparent_hugepage/shmem_enabled', with adding a new
    additional "inherit" option and dropping the testing options 'force' and
    'deny'.  By default all sizes will be set to "never" except PMD size,
    which is set to "inherit".  This ensures backward compatibility with the
    anonymous shmem enabled of the top level, meanwhile also allows
    independent control of anonymous shmem enabled for each mTHP.
    
    Use the page fault latency tool to measure the performance of 1G anonymous shmem
    with 32 threads on my machine environment with: ARM64 Architecture, 32 cores,
    125G memory:
    base: mm-unstable
    user-time    sys_time    faults_per_sec_per_cpu     faults_per_sec
    0.04s        3.10s         83516.416                  2669684.890
    
    mm-unstable + patchset, anon shmem mTHP disabled
    user-time    sys_time    faults_per_sec_per_cpu     faults_per_sec
    0.02s        3.14s         82936.359                  2630746.027
    
    mm-unstable + patchset, anon shmem 64K mTHP enabled
    user-time    sys_time    faults_per_sec_per_cpu     faults_per_sec
    0.08s        0.31s         678630.231                 17082522.495
    
    From the data above, it is observed that the patchset has a minimal impact
    when mTHP is not enabled (some fluctuations observed during testing). 
    When enabling 64K mTHP, there is a significant improvement of the page
    fault latency.
    
    [1] https://lore.kernel.org/all/f1783ff0-65bd-4b2b-8952-52b6822a0835@redhat.com/
    
    
    This patch (of 6):
    
    Add large folio mapping establishment support for finish_fault() as a
    preparation, to support multi-size THP allocation of anonymous shmem pages
    in the following patches.
    
    Keep the same behavior (per-page fault) for non-anon shmem to avoid
    inflating the RSS unintentionally, and we can discuss what size of mapping
    to build when extending mTHP to control non-anon shmem in the future.
    
    [baolin.wang@linux.alibaba.com: avoid going beyond the PMD pagetable size]
      Link: https://lkml.kernel.org/r/b0e6a8b1-a32c-459e-ae67-fde5d28773e6@linux.alibaba.com
    [baolin.wang@linux.alibaba.com: use 'PTRS_PER_PTE' instead of 'PTRS_PER_PTE - 1']
      Link: https://lkml.kernel.org/r/e1f5767a-2c9b-4e37-afe6-1de26fe54e41@linux.alibaba.com
    Link: https://lkml.kernel.org/r/cover.1718090413.git.baolin.wang@linux.alibaba.com
    Link: https://lkml.kernel.org/r/3a190892355989d42f59cf9f2f98b94694b0d24d.1718090413.git.baolin.wang@linux.alibaba.comSigned-off-by: default avatarBaolin Wang <baolin.wang@linux.alibaba.com>
    Reviewed-by: default avatarZi Yan <ziy@nvidia.com>
    Reviewed-by: default avatarKefeng Wang <wangkefeng.wang@huawei.com>
    Cc: Daniel Gomez <da.gomez@samsung.com>
    Cc: David Hildenbrand <david@redhat.com>
    Cc: "Huang, Ying" <ying.huang@intel.com>
    Cc: Hugh Dickins <hughd@google.com>
    Cc: Lance Yang <ioworker0@gmail.com>
    Cc: Pankaj Raghav <p.raghav@samsung.com>
    Cc: Ryan Roberts <ryan.roberts@arm.com>
    Cc: Yang Shi <shy828301@gmail.com>
    Cc: Barry Song <v-songbaohua@oppo.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    43e027e4
memory.c 181 KB