Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mm/oom_kill: factor out zapping of VMA into zap_vma_for_reaping()

Let's factor it out so we can turn unmap_page_range() into a static
function instead, and so oom reaping has a clean interface to call.

Note that hugetlb is not supported, because it would require a bunch of
hugetlb-specific further actions (see zap_page_range_single_batched()).

Link: https://lkml.kernel.org/r/20260227200848.114019-7-david@kernel.org
Signed-off-by: David Hildenbrand (Arm) <david@kernel.org>
Reviewed-by: Lorenzo Stoakes (Oracle) <ljs@kernel.org>
Cc: Alexander Gordeev <agordeev@linux.ibm.com>
Cc: Alexei Starovoitov <ast@kernel.org>
Cc: Alice Ryhl <aliceryhl@google.com>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Andy Lutomirski <luto@kernel.org>
Cc: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Arve <arve@android.com>
Cc: "Borislav Petkov (AMD)" <bp@alien8.de>
Cc: Carlos Llamas <cmllamas@google.com>
Cc: Christian Borntraeger <borntraeger@linux.ibm.com>
Cc: Christian Brauner <brauner@kernel.org>
Cc: Claudio Imbrenda <imbrenda@linux.ibm.com>
Cc: Daniel Borkman <daniel@iogearbox.net>
Cc: Dave Airlie <airlied@gmail.com>
Cc: David Ahern <dsahern@kernel.org>
Cc: David Rientjes <rientjes@google.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Dimitri Sivanich <dimitri.sivanich@hpe.com>
Cc: Eric Dumazet <edumazet@google.com>
Cc: Gerald Schaefer <gerald.schaefer@linux.ibm.com>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Hartley Sweeten <hsweeten@visionengravers.com>
Cc: Heiko Carstens <hca@linux.ibm.com>
Cc: Ian Abbott <abbotti@mev.co.uk>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Jakub Kacinski <kuba@kernel.org>
Cc: Jani Nikula <jani.nikula@linux.intel.com>
Cc: Jann Horn <jannh@google.com>
Cc: Janosch Frank <frankja@linux.ibm.com>
Cc: Jarkko Sakkinen <jarkko@kernel.org>
Cc: Jason Gunthorpe <jgg@ziepe.ca>
Cc: Jonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Leon Romanovsky <leon@kernel.org>
Cc: Liam Howlett <liam.howlett@oracle.com>
Cc: Madhavan Srinivasan <maddy@linux.ibm.com>
Cc: Matthew Wilcox (Oracle) <willy@infradead.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Miguel Ojeda <ojeda@kernel.org>
Cc: Mike Rapoport <rppt@kernel.org>
Cc: Namhyung kim <namhyung@kernel.org>
Cc: Neal Cardwell <ncardwell@google.com>
Cc: Paolo Abeni <pabeni@redhat.com>
Cc: Pedro Falcato <pfalcato@suse.de>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Rodrigo Vivi <rodrigo.vivi@intel.com>
Cc: Shakeel Butt <shakeel.butt@linux.dev>
Cc: Suren Baghdasaryan <surenb@google.com>
Cc: Todd Kjos <tkjos@android.com>
Cc: Tvrtko Ursulin <tursulin@ursulin.net>
Cc: Vasily Gorbik <gor@linux.ibm.com>
Cc: Vincenzo Frascino <vincenzo.frascino@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

authored by

David Hildenbrand (Arm) and committed by
Andrew Morton
ba25127a f52f202d

+34 -22
+1 -4
mm/internal.h
··· 536 536 } 537 537 538 538 struct zap_details; 539 - void unmap_page_range(struct mmu_gather *tlb, 540 - struct vm_area_struct *vma, 541 - unsigned long addr, unsigned long end, 542 - struct zap_details *details); 543 539 void zap_page_range_single_batched(struct mmu_gather *tlb, 544 540 struct vm_area_struct *vma, unsigned long addr, 545 541 unsigned long size, struct zap_details *details); 542 + int zap_vma_for_reaping(struct vm_area_struct *vma); 546 543 int folio_unmap_invalidate(struct address_space *mapping, struct folio *folio, 547 544 gfp_t gfp); 548 545
+32 -4
mm/memory.c
··· 2054 2054 return addr; 2055 2055 } 2056 2056 2057 - void unmap_page_range(struct mmu_gather *tlb, 2058 - struct vm_area_struct *vma, 2059 - unsigned long addr, unsigned long end, 2060 - struct zap_details *details) 2057 + static void unmap_page_range(struct mmu_gather *tlb, struct vm_area_struct *vma, 2058 + unsigned long addr, unsigned long end, 2059 + struct zap_details *details) 2061 2060 { 2062 2061 pgd_t *pgd; 2063 2062 unsigned long next; ··· 2112 2113 } else 2113 2114 unmap_page_range(tlb, vma, start, end, details); 2114 2115 } 2116 + } 2117 + 2118 + /** 2119 + * zap_vma_for_reaping - zap all page table entries in the vma without blocking 2120 + * @vma: The vma to zap. 2121 + * 2122 + * Zap all page table entries in the vma without blocking for use by the oom 2123 + * killer. Hugetlb vmas are not supported. 2124 + * 2125 + * Returns: 0 on success, -EBUSY if we would have to block. 2126 + */ 2127 + int zap_vma_for_reaping(struct vm_area_struct *vma) 2128 + { 2129 + struct mmu_notifier_range range; 2130 + struct mmu_gather tlb; 2131 + 2132 + VM_WARN_ON_ONCE(is_vm_hugetlb_page(vma)); 2133 + 2134 + mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, vma->vm_mm, 2135 + vma->vm_start, vma->vm_end); 2136 + tlb_gather_mmu(&tlb, vma->vm_mm); 2137 + if (mmu_notifier_invalidate_range_start_nonblock(&range)) { 2138 + tlb_finish_mmu(&tlb); 2139 + return -EBUSY; 2140 + } 2141 + unmap_page_range(&tlb, vma, range.start, range.end, NULL); 2142 + mmu_notifier_invalidate_range_end(&range); 2143 + tlb_finish_mmu(&tlb); 2144 + return 0; 2115 2145 } 2116 2146 2117 2147 /**
+1 -14
mm/oom_kill.c
··· 548 548 * count elevated without a good reason. 549 549 */ 550 550 if (vma_is_anonymous(vma) || !(vma->vm_flags & VM_SHARED)) { 551 - struct mmu_notifier_range range; 552 - struct mmu_gather tlb; 553 - 554 - mmu_notifier_range_init(&range, MMU_NOTIFY_CLEAR, 0, 555 - mm, vma->vm_start, 556 - vma->vm_end); 557 - tlb_gather_mmu(&tlb, mm); 558 - if (mmu_notifier_invalidate_range_start_nonblock(&range)) { 559 - tlb_finish_mmu(&tlb); 551 + if (zap_vma_for_reaping(vma)) 560 552 ret = false; 561 - continue; 562 - } 563 - unmap_page_range(&tlb, vma, range.start, range.end, NULL); 564 - mmu_notifier_invalidate_range_end(&range); 565 - tlb_finish_mmu(&tlb); 566 553 } 567 554 } 568 555