diff options
| author | Kiryl Shutsemau (Meta) <kas@kernel.org> | 2026-09-28 11:06:15 +0100 |
|---|---|---|
| committer | Andrew Morton <akpm@linux-foundation.org> | 2026-10-08 23:06:27 -0700 |
| commit | ad99b2bfc5092a1ec212fbc359a38eb827cfa53a (patch) | |
| tree | 56b2165ee4e5c09bd95bbe5ce16b73b5a25f82d9 /tools/lib/python | |
| parent | 3ad6d4744382275ec1e4db8b563b3a238f6a5e0e (diff) | |
| download | linux-next-ad99b2bfc5092a1ec212fbc359a38eb827cfa53a.tar.gz linux-next-ad99b2bfc5092a1ec212fbc359a38eb827cfa53a.zip | |
mm/khugepaged: drop redundant mm_struct pin in madvise_collapse()
Patch series "mm/collapse: separate a collapse from its callers", v4.
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 and
drops mmap_lock somewhere in the middle. Which of its paths dropped it
is not something a caller can see, so it hands back a bool and the
caller keeps track.
- MADV_COLLAPSE's implementation -- the walk over the user's range, the
per-PMD loop, the errno translation -- sits in khugepaged.c, which is
the daemon's file.
So: draw the line. State what a caller allows in a policy, split the call
in two with the lock as the boundary, and move the syscall to madvise.c.
What the engine offers is then three calls, with the lock state written
down against each, and a policy the caller fills for itself:
collapse_control_init(cc) once, before the first table
collapse_policy_*(&cc->policy) what this caller allows
collapse_scan_pmd(vma, addr, ...) per table, under mmap_lock
collapse_run_pmd(mm, addr, ...) when a scan found work, no mmap_lock
The engine stays in khugepaged.c for now; what changes is that it has an
interface, and that neither half has to ask about the other. madvise.c
gains the operation it should have had all along.
This patch (of 13):
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/20260928100630.21870-1-kirill@shutemov.name
Link: https://lore.kernel.org/20260928100630.21870-2-kirill@shutemov.name
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>
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: Lance Yang <lance.yang@linux.dev>
Cc: Usama Arif <usama.arif@linux.dev>
Cc: Vlastimil Babka <vbabka@kernel.org>
Cc: Jann Horn <jannh@google.com>
Diffstat (limited to 'tools/lib/python')
0 files changed, 0 insertions, 0 deletions
