Merge tag 'mm-stable-2024-09-20-02-31' of git://git.kernel.org/pub/scm/linux/kernel...
authorLinus Torvalds <torvalds@linux-foundation.org>
Sat, 21 Sep 2024 14:29:05 +0000 (07:29 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Sat, 21 Sep 2024 14:29:05 +0000 (07:29 -0700)
Pull MM updates from Andrew Morton:
 "Along with the usual shower of singleton patches, notable patch series
  in this pull request are:

   - "Align kvrealloc() with krealloc()" from Danilo Krummrich. Adds
     consistency to the APIs and behaviour of these two core allocation
     functions. This also simplifies/enables Rustification.

   - "Some cleanups for shmem" from Baolin Wang. No functional changes -
     mode code reuse, better function naming, logic simplifications.

   - "mm: some small page fault cleanups" from Josef Bacik. No
     functional changes - code cleanups only.

   - "Various memory tiering fixes" from Zi Yan. A small fix and a
     little cleanup.

   - "mm/swap: remove boilerplate" from Yu Zhao. Code cleanups and
     simplifications and .text shrinkage.

   - "Kernel stack usage histogram" from Pasha Tatashin and Shakeel
     Butt. This is a feature, it adds new feilds to /proc/vmstat such as

       $ grep kstack /proc/vmstat
       kstack_1k 3
       kstack_2k 188
       kstack_4k 11391
       kstack_8k 243
       kstack_16k 0

     which tells us that 11391 processes used 4k of stack while none at
     all used 16k. Useful for some system tuning things, but
     partivularly useful for "the dynamic kernel stack project".

   - "kmemleak: support for percpu memory leak detect" from Pavel
     Tikhomirov. Teaches kmemleak to detect leaksage of percpu memory.

   - "mm: memcg: page counters optimizations" from Roman Gushchin. "3
     independent small optimizations of page counters".

   - "mm: split PTE/PMD PT table Kconfig cleanups+clarifications" from
     David Hildenbrand. Improves PTE/PMD splitlock detection, makes
     powerpc/8xx work correctly by design rather than by accident.

   - "mm: remove arch_make_page_accessible()" from David Hildenbrand.
     Some folio conversions which make arch_make_page_accessible()
     unneeded.

   - "mm, memcg: cg2 memory{.swap,}.peak write handlers" fro David
     Finkel. Cleans up and fixes our handling of the resetting of the
     cgroup/process peak-memory-use detector.

   - "Make core VMA operations internal and testable" from Lorenzo
     Stoakes. Rationalizaion and encapsulation of the VMA manipulation
     APIs. With a view to better enable testing of the VMA functions,
     even from a userspace-only harness.

   - "mm: zswap: fixes for global shrinker" from Takero Funaki. Fix
     issues in the zswap global shrinker, resulting in improved
     performance.

   - "mm: print the promo watermark in zoneinfo" from Kaiyang Zhao. Fill
     in some missing info in /proc/zoneinfo.

   - "mm: replace follow_page() by folio_walk" from David Hildenbrand.
     Code cleanups and rationalizations (conversion to folio_walk())
     resulting in the removal of follow_page().

   - "improving dynamic zswap shrinker protection scheme" from Nhat
     Pham. Some tuning to improve zswap's dynamic shrinker. Significant
     reductions in swapin and improvements in performance are shown.

   - "mm: Fix several issues with unaccepted memory" from Kirill
     Shutemov. Improvements to the new unaccepted memory feature,

   - "mm/mprotect: Fix dax puds" from Peter Xu. Implements mprotect on
     DAX PUDs. This was missing, although nobody seems to have notied
     yet.

   - "Introduce a store type enum for the Maple tree" from Sidhartha
     Kumar. Cleanups and modest performance improvements for the maple
     tree library code.

   - "memcg: further decouple v1 code from v2" from Shakeel Butt. Move
     more cgroup v1 remnants away from the v2 memcg code.

   - "memcg: initiate deprecation of v1 features" from Shakeel Butt.
     Adds various warnings telling users that memcg v1 features are
     deprecated.

   - "mm: swap: mTHP swap allocator base on swap cluster order" from
     Chris Li. Greatly improves the success rate of the mTHP swap
     allocation.

   - "mm: introduce numa_memblks" from Mike Rapoport. Moves various
     disparate per-arch implementations of numa_memblk code into generic
     code.

   - "mm: batch free swaps for zap_pte_range()" from Barry Song. Greatly
     improves the performance of munmap() of swap-filled ptes.

   - "support large folio swap-out and swap-in for shmem" from Baolin
     Wang. With this series we no longer split shmem large folios into
     simgle-page folios when swapping out shmem.

   - "mm/hugetlb: alloc/free gigantic folios" from Yu Zhao. Nice
     performance improvements and code reductions for gigantic folios.

   - "support shmem mTHP collapse" from Baolin Wang. Adds support for
     khugepaged's collapsing of shmem mTHP folios.

   - "mm: Optimize mseal checks" from Pedro Falcato. Fixes an mprotect()
     performance regression due to the addition of mseal().

   - "Increase the number of bits available in page_type" from Matthew
     Wilcox. Increases the number of bits available in page_type!

   - "Simplify the page flags a little" from Matthew Wilcox. Many legacy
     page flags are now folio flags, so the page-based flags and their
     accessors/mutators can be removed.

   - "mm: store zero pages to be swapped out in a bitmap" from Usama
     Arif. An optimization which permits us to avoid writing/reading
     zero-filled zswap pages to backing store.

   - "Avoid MAP_FIXED gap exposure" from Liam Howlett. Fixes a race
     window which occurs when a MAP_FIXED operqtion is occurring during
     an unrelated vma tree walk.

   - "mm: remove vma_merge()" from Lorenzo Stoakes. Major rotorooting of
     the vma_merge() functionality, making ot cleaner, more testable and
     better tested.

   - "misc fixups for DAMON {self,kunit} tests" from SeongJae Park.
     Minor fixups of DAMON selftests and kunit tests.

   - "mm: memory_hotplug: improve do_migrate_range()" from Kefeng Wang.
     Code cleanups and folio conversions.

   - "Shmem mTHP controls and stats improvements" from Ryan Roberts.
     Cleanups for shmem controls and stats.

   - "mm: count the number of anonymous THPs per size" from Barry Song.
     Expose additional anon THP stats to userspace for improved tuning.

   - "mm: finish isolate/putback_lru_page()" from Kefeng Wang: more
     folio conversions and removal of now-unused page-based APIs.

   - "replace per-quota region priorities histogram buffer with
     per-context one" from SeongJae Park. DAMON histogram
     rationalization.

   - "Docs/damon: update GitHub repo URLs and maintainer-profile" from
     SeongJae Park. DAMON documentation updates.

   - "mm/vdpa: correct misuse of non-direct-reclaim __GFP_NOFAIL and
     improve related doc and warn" from Jason Wang: fixes usage of page
     allocator __GFP_NOFAIL and GFP_ATOMIC flags.

   - "mm: split underused THPs" from Yu Zhao. Improve THP=always policy.
     This was overprovisioning THPs in sparsely accessed memory areas.

   - "zram: introduce custom comp backends API" frm Sergey Senozhatsky.
     Add support for zram run-time compression algorithm tuning.

   - "mm: Care about shadow stack guard gap when getting an unmapped
     area" from Mark Brown. Fix up the various arch_get_unmapped_area()
     implementations to better respect guard areas.

   - "Improve mem_cgroup_iter()" from Kinsey Ho. Improve the reliability
     of mem_cgroup_iter() and various code cleanups.

   - "mm: Support huge pfnmaps" from Peter Xu. Extends the usage of huge
     pfnmap support.

   - "resource: Fix region_intersects() vs add_memory_driver_managed()"
     from Huang Ying. Fix a bug in region_intersects() for systems with
     CXL memory.

   - "mm: hwpoison: two more poison recovery" from Kefeng Wang. Teaches
     a couple more code paths to correctly recover from the encountering
     of poisoned memry.

   - "mm: enable large folios swap-in support" from Barry Song. Support
     the swapin of mTHP memory into appropriately-sized folios, rather
     than into single-page folios"

* tag 'mm-stable-2024-09-20-02-31' of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm: (416 commits)
  zram: free secondary algorithms names
  uprobes: turn xol_area->pages[2] into xol_area->page
  uprobes: introduce the global struct vm_special_mapping xol_mapping
  Revert "uprobes: use vm_special_mapping close() functionality"
  mm: support large folios swap-in for sync io devices
  mm: add nr argument in mem_cgroup_swapin_uncharge_swap() helper to support large folios
  mm: fix swap_read_folio_zeromap() for large folios with partial zeromap
  mm/debug_vm_pgtable: Use pxdp_get() for accessing page table entries
  set_memory: add __must_check to generic stubs
  mm/vma: return the exact errno in vms_gather_munmap_vmas()
  memcg: cleanup with !CONFIG_MEMCG_V1
  mm/show_mem.c: report alloc tags in human readable units
  mm: support poison recovery from copy_present_page()
  mm: support poison recovery from do_cow_fault()
  resource, kunit: add test case for region_intersects()
  resource: make alloc_free_mem_region() works for iomem_resource
  mm: z3fold: deprecate CONFIG_Z3FOLD
  vfio/pci: implement huge_fault support
  mm/arm64: support large pfn mappings
  mm/x86: support large pfn mappings
  ...

59 files changed:
1  2 
Documentation/admin-guide/cgroup-v2.rst
Documentation/admin-guide/kernel-parameters.txt
Documentation/filesystems/vfs.rst
MAINTAINERS
arch/arm64/Kconfig
arch/arm64/include/asm/pgtable.h
arch/arm64/kvm/nested.c
arch/loongarch/include/asm/Kbuild
arch/mips/Kconfig
arch/powerpc/configs/ppc64_defconfig
arch/powerpc/include/asm/book3s/64/pgtable.h
arch/powerpc/include/asm/mmu_context.h
arch/x86/Kconfig
arch/x86/include/asm/mmu_context.h
arch/x86/xen/mmu_pv.c
drivers/block/zram/zram_drv.c
drivers/block/zram/zram_drv.h
fs/exec.c
fs/proc/internal.h
fs/xfs/xfs_log_recover.c
include/linux/cgroup-defs.h
include/linux/fs.h
include/linux/huge_mm.h
include/linux/mm.h
include/linux/slab.h
include/linux/writeback.h
include/trace/events/mmflags.h
init/Kconfig
kernel/cgroup/cgroup.c
kernel/events/uprobes.c
kernel/exit.c
kernel/fork.c
kernel/resource.c
kernel/sched/core.c
kernel/sched/fair.c
lib/Kconfig.debug
lib/maple_tree.c
mm/damon/vaddr.c
mm/filemap.c
mm/gup.c
mm/huge_memory.c
mm/hugetlb.c
mm/internal.h
mm/madvise.c
mm/memcontrol.c
mm/memory.c
mm/memory_hotplug.c
mm/mmap.c
mm/mseal.c
mm/page-writeback.c
mm/page_alloc.c
mm/shmem.c
mm/slab_common.c
mm/userfaultfd.c
mm/vmalloc.c
mm/vmscan.c
mm/zsmalloc.c
tools/testing/selftests/mm/Makefile
tools/testing/selftests/mm/mseal_test.c

Simple merge
diff --cc MAINTAINERS
Simple merge
index e430ff33c80d2dd92c0e738351f5e5322430f1e9,6607ed8fdbb4e2381d28f66274fbbec623512752..49f054dcd4de6a37239acf80dca665dafb2b1980
@@@ -101,7 -99,7 +101,8 @@@ config ARM6
        select ARCH_SUPPORTS_NUMA_BALANCING
        select ARCH_SUPPORTS_PAGE_TABLE_CHECK
        select ARCH_SUPPORTS_PER_VMA_LOCK
+       select ARCH_SUPPORTS_HUGE_PFNMAP if TRANSPARENT_HUGEPAGE
 +      select ARCH_SUPPORTS_RT
        select ARCH_WANT_BATCHED_UNMAP_TLB_FLUSH
        select ARCH_WANT_COMPAT_IPC_PARSE_VERSION if COMPAT
        select ARCH_WANT_DEFAULT_BPF_JIT
Simple merge
Simple merge
index 4635b755b2b43efd27841e07488e68cc5821cc34,8fa22cc52774d8a4ccbf56f2000cbba9db490805..5b5a6c90e6e20771b1074a6262230861cc51bcb4
@@@ -6,7 -6,9 +6,8 @@@ generic-y += mcs_spinlock.
  generic-y += parport.h
  generic-y += early_ioremap.h
  generic-y += qrwlock.h
 -generic-y += qspinlock.h
  generic-y += user.h
  generic-y += ioctl.h
+ generic-y += mmzone.h
  generic-y += statfs.h
  generic-y += param.h
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc fs/exec.c
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
index 7a570e0437c9e092d6d16e41a60ec7517533327d,0b0539f4ee1a86ac561ac7b1b0342ac540643cfd..67d0ab3c3bbab60c6f0f526d56a3ba6835d4b939
@@@ -316,29 -326,14 +328,29 @@@ unsigned long thp_get_unmapped_area_vmf
                unsigned long len, unsigned long pgoff, unsigned long flags,
                vm_flags_t vm_flags);
  
- bool can_split_folio(struct folio *folio, int *pextra_pins);
+ bool can_split_folio(struct folio *folio, int caller_pins, int *pextra_pins);
  int split_huge_page_to_list_to_order(struct page *page, struct list_head *list,
                unsigned int new_order);
 +int min_order_for_split(struct folio *folio);
 +int split_folio_to_list(struct folio *folio, struct list_head *list);
  static inline int split_huge_page(struct page *page)
  {
 -      return split_huge_page_to_list_to_order(page, NULL, 0);
 +      struct folio *folio = page_folio(page);
 +      int ret = min_order_for_split(folio);
 +
 +      if (ret < 0)
 +              return ret;
 +
 +      /*
 +       * split_huge_page() locks the page before splitting and
 +       * expects the same page that has been split to be locked when
 +       * returned. split_folio(page_folio(page)) cannot be used here
 +       * because it converts the page to folio and passes the head
 +       * page to be split.
 +       */
 +      return split_huge_page_to_list_to_order(page, NULL, ret);
  }
- void deferred_split_folio(struct folio *folio);
+ void deferred_split_folio(struct folio *folio, bool partially_mapped);
  
  void __split_huge_pmd(struct vm_area_struct *vma, pmd_t *pmd,
                unsigned long address, bool freeze, struct folio *folio);
@@@ -501,13 -502,7 +519,13 @@@ static inline int split_huge_page(struc
  {
        return 0;
  }
- static inline void deferred_split_folio(struct folio *folio) {}
 +
 +static inline int split_folio_to_list(struct folio *folio, struct list_head *list)
 +{
 +      return 0;
 +}
 +
+ static inline void deferred_split_folio(struct folio *folio, bool partially_mapped) {}
  #define split_huge_pmd(__vma, __pmd, __address)       \
        do { } while (0)
  
index 13bff7cf03b733f197271b31ef5a8c8c207b29b9,d750be768121705b84355b7534ee555a583ea2b9..b6243744707798001e1cba1612386cff06669ca2
@@@ -97,10 -97,6 +97,14 @@@ extern const int mmap_rnd_compat_bits_m
  extern int mmap_rnd_compat_bits __read_mostly;
  #endif
  
 +#ifndef PHYSMEM_END
++# ifdef MAX_PHYSMEM_BITS
 +# define PHYSMEM_END  ((1ULL << MAX_PHYSMEM_BITS) - 1)
++# else
++# define PHYSMEM_END  (-1ULL)
++# endif
 +#endif
 +
  #include <asm/page.h>
  #include <asm/processor.h>
  
@@@ -4223,14 -4137,61 +4152,71 @@@ void vma_pgtable_walk_end(struct vm_are
  
  int reserve_mem_find_by_name(const char *name, phys_addr_t *start, phys_addr_t *size);
  
 +#ifdef CONFIG_64BIT
 +int do_mseal(unsigned long start, size_t len_in, unsigned long flags);
 +#else
 +static inline int do_mseal(unsigned long start, size_t len_in, unsigned long flags)
 +{
 +      /* noop on 32 bit */
 +      return 0;
 +}
 +#endif
 +
+ #ifdef CONFIG_MEM_ALLOC_PROFILING
+ static inline void pgalloc_tag_split(struct folio *folio, int old_order, int new_order)
+ {
+       int i;
+       struct alloc_tag *tag;
+       unsigned int nr_pages = 1 << new_order;
+       if (!mem_alloc_profiling_enabled())
+               return;
+       tag = pgalloc_tag_get(&folio->page);
+       if (!tag)
+               return;
+       for (i = nr_pages; i < (1 << old_order); i += nr_pages) {
+               union codetag_ref *ref = get_page_tag_ref(folio_page(folio, i));
+               if (ref) {
+                       /* Set new reference to point to the original tag */
+                       alloc_tag_ref_set(ref, tag);
+                       put_page_tag_ref(ref);
+               }
+       }
+ }
+ static inline void pgalloc_tag_copy(struct folio *new, struct folio *old)
+ {
+       struct alloc_tag *tag;
+       union codetag_ref *ref;
+       tag = pgalloc_tag_get(&old->page);
+       if (!tag)
+               return;
+       ref = get_page_tag_ref(&new->page);
+       if (!ref)
+               return;
+       /* Clear the old ref to the original allocation tag. */
+       clear_page_tag_ref(&old->page);
+       /* Decrement the counters of the tag on get_new_folio. */
+       alloc_tag_sub(ref, folio_nr_pages(new));
+       __alloc_tag_ref_set(ref, tag);
+       put_page_tag_ref(ref);
+ }
+ #else /* !CONFIG_MEM_ALLOC_PROFILING */
+ static inline void pgalloc_tag_split(struct folio *folio, int old_order, int new_order)
+ {
+ }
+ static inline void pgalloc_tag_copy(struct folio *new, struct folio *old)
+ {
+ }
+ #endif /* CONFIG_MEM_ALLOC_PROFILING */
  #endif /* _LINUX_MM_H */
Simple merge
Simple merge
index 37265977d5246aa4def5366417a9985a715dfac3,58f2699331b66f88405a076f68b92b27100490b3..bb8a59c6caa21971862b6f200263c74cedff3882
@@@ -131,19 -129,9 +129,9 @@@ IF_HAVE_PG_ARCH_3(arch_3
        __def_pageflag_names                                            \
        ) : "none"
  
- #define DEF_PAGETYPE_NAME(_name) { PG_##_name, __stringify(_name) }
- #define __def_pagetype_names                                          \
-       DEF_PAGETYPE_NAME(slab),                                        \
-       DEF_PAGETYPE_NAME(hugetlb),                                     \
-       DEF_PAGETYPE_NAME(offline),                                     \
-       DEF_PAGETYPE_NAME(guard),                                       \
-       DEF_PAGETYPE_NAME(table),                                       \
-       DEF_PAGETYPE_NAME(buddy)
  #if defined(CONFIG_X86)
  #define __VM_ARCH_SPECIFIC_1 {VM_PAT,     "pat"           }
 -#elif defined(CONFIG_PPC)
 +#elif defined(CONFIG_PPC64)
  #define __VM_ARCH_SPECIFIC_1 {VM_SAO,     "sao"           }
  #elif defined(CONFIG_PARISC)
  #define __VM_ARCH_SPECIFIC_1 {VM_GROWSUP,     "growsup"       }
diff --cc init/Kconfig
Simple merge
Simple merge
Simple merge
diff --cc kernel/exit.c
Simple merge
diff --cc kernel/fork.c
Simple merge
index 1681ab5012e12b456084ed839d597135700bb744,4c9cb0363f9a2109ace3264fb9ca43abc2334f1c..b730bd28b422a484bb4fc5e2591d2457c1088b38
@@@ -1860,8 -1817,18 +1859,12 @@@ EXPORT_SYMBOL(resource_list_free)
  #ifdef CONFIG_GET_FREE_REGION
  #define GFR_DESCENDING                (1UL << 0)
  #define GFR_REQUEST_REGION    (1UL << 1)
- #define GFR_DEFAULT_ALIGN (1UL << PA_SECTION_SHIFT)
+ #ifdef PA_SECTION_SHIFT
+ #define GFR_DEFAULT_ALIGN     (1UL << PA_SECTION_SHIFT)
+ #else
+ #define GFR_DEFAULT_ALIGN     PAGE_SIZE
+ #endif
  
 -#ifdef MAX_PHYSMEM_BITS
 -#define MAX_PHYS_ADDR         ((1ULL << MAX_PHYSMEM_BITS) - 1)
 -#else
 -#define MAX_PHYS_ADDR         (-1ULL)
 -#endif
 -
  static resource_size_t gfr_start(struct resource *base, resource_size_t size,
                                 resource_size_t align, unsigned long flags)
  {
Simple merge
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc mm/filemap.c
Simple merge
diff --cc mm/gup.c
Simple merge
index b71f744d360cc74a06197dea521e7a6993457186,2a73efea02d73787c6cf717bebacaa435525cd8a..0580ac9e47b936e774831089203be0a803ebb66c
@@@ -3548,10 -3860,8 +3898,10 @@@ static int split_huge_pages_pid(int pid
         */
        for (addr = vaddr_start; addr < vaddr_end; addr += PAGE_SIZE) {
                struct vm_area_struct *vma = vma_lookup(mm, addr);
-               struct page *page;
+               struct folio_walk fw;
                struct folio *folio;
 +              struct address_space *mapping;
 +              unsigned int target_order = new_order;
  
                if (!vma)
                        break;
  
                if (!folio_trylock(folio))
                        goto next;
+               folio_get(folio);
+               folio_walk_end(&fw, vma);
  
 -              if (!split_folio_to_order(folio, new_order))
 +              if (!folio_test_anon(folio) && folio->mapping != mapping)
 +                      goto unlock;
 +
 +              if (!split_folio_to_order(folio, target_order))
                        split++;
  
 +unlock:
 +
                folio_unlock(folio);
- next:
                folio_put(folio);
+               cond_resched();
+               continue;
+ next:
+               folio_walk_end(&fw, vma);
                cond_resched();
        }
        mmap_read_unlock(mm);
diff --cc mm/hugetlb.c
Simple merge
diff --cc mm/internal.h
Simple merge
diff --cc mm/madvise.c
Simple merge
diff --cc mm/memcontrol.c
Simple merge
diff --cc mm/memory.c
Simple merge
Simple merge
diff --cc mm/mmap.c
Simple merge
diff --cc mm/mseal.c
Simple merge
Simple merge
diff --cc mm/page_alloc.c
Simple merge
diff --cc mm/shmem.c
Simple merge
Simple merge
Simple merge
diff --cc mm/vmalloc.c
Simple merge
diff --cc mm/vmscan.c
Simple merge
diff --cc mm/zsmalloc.c
Simple merge
Simple merge