1. 13 Mar, 2024 2 commits
    • Barry Song's avatar
      mm: prohibit the last subpage from reusing the entire large folio · cd197c3a
      Barry Song authored
      In a Copy-on-Write (CoW) scenario, the last subpage will reuse the entire
      large folio, resulting in the waste of (nr_pages - 1) pages.  This wasted
      memory remains allocated until it is either unmapped or memory reclamation
      occurs.
      
      The following small program can serve as evidence of this behavior
      
       main()
       {
       #define SIZE 1024 * 1024 * 1024UL
               void *p = malloc(SIZE);
               memset(p, 0x11, SIZE);
               if (fork() == 0)
                       _exit(0);
               memset(p, 0x12, SIZE);
               printf("done\n");
               while(1);
       }
      
      For example, using a 1024KiB mTHP by:
       echo always > /sys/kernel/mm/transparent_hugepage/hugepages-1024kB/enabled
      
      (1) w/o the patch, it takes 2GiB,
      
      Before running the test program,
       / # free -m
                      total        used        free      shared  buff/cache   available
       Mem:            5754          84        5692           0          17        5669
       Swap:              0           0           0
      
       / # /a.out &
       / # done
      
      After running the test program,
       / # free -m
                       total        used        free      shared  buff/cache   available
       Mem:            5754        2149        3627           0          19        3605
       Swap:              0           0           0
      
      (2) w/ the patch, it takes 1GiB only,
      
      Before running the test program,
       / # free -m
                       total        used        free      shared  buff/cache   available
       Mem:            5754          89        5687           0          17        5664
       Swap:              0           0           0
      
       / # /a.out &
       / # done
      
      After running the test program,
       / # free -m
                      total        used        free      shared  buff/cache   available
       Mem:            5754        1122        4655           0          17        4632
       Swap:              0           0           0
      
      This patch migrates the last subpage to a small folio and immediately
      returns the large folio to the system. It benefits both memory availability
      and anti-fragmentation.
      
      Link: https://lkml.kernel.org/r/20240308092721.144735-1-21cnbao@gmail.comSigned-off-by: default avatarBarry Song <v-songbaohua@oppo.com>
      Acked-by: default avatarDavid Hildenbrand <david@redhat.com>
      Cc: Ryan Roberts <ryan.roberts@arm.com>
      Cc: Lance Yang <ioworker0@gmail.com>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      cd197c3a
    • Peter Xu's avatar
      mm: recover pud_leaf() definitions in nopmd case · c087a5c3
      Peter Xu authored
      This reverts one change in commit 924bd6a8 ("mm/x86: drop two
      unnecessary pud_leaf() definitions").
      
      One issue with that is it broke nopmd builds for at least both arm64 and
      riscv (CONFIG_PGTABLE_LEVELS=2).  The other issue is it was overlooked that
      it's a common change rather than x86 specific (relevant to the commit
      message of the commit).
      
      Normally there's no need for empty definition of pXd_leaf() because of the
      fallback functions, however this logic may not apply to pgtable-nopmd.h,
      because that's a header that can even be used by arch *pgtable.h headers,
      which can use the *_leaf() definitions _before_ the fallback functions are
      defined.  Leave it there to pass PGTABLE_LEVELS=2 builds.
      
      Link: https://lkml.kernel.org/r/Ze8vFNV9YSdgC2S7@x1n
      Fixes: 924bd6a8 ("mm/x86: drop two unnecessary pud_leaf() definitions")
      Signed-off-by: default avatarPeter Xu <peterx@redhat.com>
      Reported-by: default avatarkernel test robot <lkp@intel.com>
      Closes: https://lore.kernel.org/oe-kbuild-all/202403090900.OwPqmRuI-lkp@intel.com/
      Closes: https://lore.kernel.org/oe-kbuild-all/202403101607.a42gaLOS-lkp@intel.com/
      Cc: Jason Gunthorpe <jgg@nvidia.com>
      Cc: Mike Rapoport (IBM) <rppt@kernel.org>
      Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
      c087a5c3
  2. 12 Mar, 2024 9 commits
  3. 06 Mar, 2024 29 commits