mirror of
https://github.com/torvalds/linux.git
synced 2026-11-07 06:17:02 +01:00
mm/khugepaged: drop redundant mm_struct pin in madvise_collapse()
Patch series "mm/collapse: separate a collapse from its callers", v5. There is no line between the collapse engine and the callers that ask for a collapse. khugepaged.c holds both, and they reach into each other. - Sixteen tests through the collapse path read cc->is_khugepaged to work out what they are allowed to do, when every one of those decisions was made by the caller before it asked. - collapse_single_pmd() does both halves of a collapse behind one call. Where it gives up mmap_lock between them is buried in the anonymous scan on one side and ahead of the file scan on the other. Start drawing the line. The caller states what it allows in a policy, and the collapse code reads the policy instead of asking who called. The scan of a PTE table and the collapse that follows get a function each, with the mmap_lock drop between them in one place. This patch (of 9): madvise_collapse() holds an mmgrab() reference across its work. It is redundant. Every caller already holds mm_users: - madvise(2) works on current->mm, which lives as long as the task is in the syscall; - process_madvise(2) reaches a remote mm through mm_access(), which takes an mm_users reference and holds it until the syscall returns; - io_uring passes current->mm; - DAMON takes one with get_task_mm() and drops it after the call. Drop the mmgrab()/mmdrop() pair. Link: https://lore.kernel.org/20261014171145.3292736-1-kas@kernel.org Link: https://lore.kernel.org/20261014171145.3292736-2-kas@kernel.org Signed-off-by: Kiryl Shutsemau (Meta) <kas@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Acked-by: David Hildenbrand (Arm) <david@kernel.org> Reviewed-by: Zi Yan <ziy@nvidia.com> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com> Reviewed-by: Lance Yang <lance.yang@linux.dev> Assisted-by: LLM Cc: Lorenzo Stoakes <ljs@kernel.org> Cc: Liam R. Howlett <liam@infradead.org> Cc: Nico Pache <nico.pache@linux.dev> Cc: Ryan Roberts <ryan.roberts@arm.com> Cc: Dev Jain <dev.jain@arm.com> Cc: Barry Song <baohua@kernel.org> Cc: Usama Arif <usama.arif@linux.dev> Cc: Vlastimil Babka <vbabka@kernel.org> Cc: Jann Horn <jannh@google.com>
This commit is contained in:
parent
514c9247db
commit
b83970d696
|
|
@ -3255,7 +3255,6 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start,
|
|||
cc->is_khugepaged = false;
|
||||
cc->progress = 0;
|
||||
|
||||
mmgrab(mm);
|
||||
lru_add_drain_all();
|
||||
|
||||
for (addr = hstart; addr < hend; addr += HPAGE_PMD_SIZE) {
|
||||
|
|
@ -3311,7 +3310,6 @@ int madvise_collapse(struct vm_area_struct *vma, unsigned long start,
|
|||
}
|
||||
out_nolock:
|
||||
mmap_assert_locked(mm);
|
||||
mmdrop(mm);
|
||||
kfree(cc);
|
||||
|
||||
return thps == ((hend - hstart) >> HPAGE_PMD_SHIFT) ? 0
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user