• Rik van Riel's avatar
    mm,thp,shmem: limit shmem THP alloc gfp_mask · 164cc4fe
    Rik van Riel authored
    Patch series "mm,thp,shm: limit shmem THP alloc gfp_mask", v6.
    
    The allocation flags of anonymous transparent huge pages can be controlled
    through the files in /sys/kernel/mm/transparent_hugepage/defrag, which can
    help the system from getting bogged down in the page reclaim and
    compaction code when many THPs are getting allocated simultaneously.
    
    However, the gfp_mask for shmem THP allocations were not limited by those
    configuration settings, and some workloads ended up with all CPUs stuck on
    the LRU lock in the page reclaim code, trying to allocate dozens of THPs
    simultaneously.
    
    This patch applies the same configurated limitation of THPs to shmem
    hugepage allocations, to prevent that from happening.
    
    This way a THP defrag setting of "never" or "defer+madvise" will result in
    quick allocation failures without direct reclaim when no 2MB free pages
    are available.
    
    With this patch applied, THP allocations for tmpfs will be a little more
    aggressive than today for files mmapped with MADV_HUGEPAGE, and a little
    less aggressive for files that are not mmapped or mapped without that
    flag.
    
    This patch (of 4):
    
    The allocation flags of anonymous transparent huge pages can be controlled
    through the files in /sys/kernel/mm/transparent_hugepage/defrag, which can
    help the system from getting bogged down in the page reclaim and
    compaction code when many THPs are getting allocated simultaneously.
    
    However, the gfp_mask for shmem THP allocations were not limited by those
    configuration settings, and some workloads ended up with all CPUs stuck on
    the LRU lock in the page reclaim code, trying to allocate dozens of THPs
    simultaneously.
    
    This patch applies the same configurated limitation of THPs to shmem
    hugepage allocations, to prevent that from happening.
    
    Controlling the gfp_mask of THP allocations through the knobs in sysfs
    allows users to determine the balance between how aggressively the system
    tries to allocate THPs at fault time, and how much the application may end
    up stalling attempting those allocations.
    
    This way a THP defrag setting of "never" or "defer+madvise" will result in
    quick allocation failures without direct reclaim when no 2MB free pages
    are available.
    
    With this patch applied, THP allocations for tmpfs will be a little more
    aggressive than today for files mmapped with MADV_HUGEPAGE, and a little
    less aggressive for files that are not mmapped or mapped without that
    flag.
    
    Link: https://lkml.kernel.org/r/20201124194925.623931-1-riel@surriel.com
    Link: https://lkml.kernel.org/r/20201124194925.623931-2-riel@surriel.comSigned-off-by: default avatarRik van Riel <riel@surriel.com>
    Acked-by: default avatarMichal Hocko <mhocko@suse.com>
    Acked-by: default avatarVlastimil Babka <vbabka@suse.cz>
    Cc: Xu Yu <xuyu@linux.alibaba.com>
    Cc: Mel Gorman <mgorman@suse.de>
    Cc: Andrea Arcangeli <aarcange@redhat.com>
    Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
    Cc: Hugh Dickins <hughd@google.com>
    Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
    Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
    164cc4fe
shmem.c 109 KB