fs-proc-task_mmu-read-proc-pid-maps-under-per-vma-lock.patch removed from -mm tree
The quilt patch titled
Subject: fs/proc/task_mmu: read proc/pid/maps under per-vma lock
has been removed from the -mm tree. Its filename was
fs-proc-task_mmu-read-proc-pid-maps-under-per-vma-lock.patch
This patch was dropped because it was merged into the mm-stable branch of git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm
------------------------------------------------------
From: Suren Baghdasaryan <[email protected]>
Subject: fs/proc/task_mmu: read proc/pid/maps under per-vma lock
Date: Sat, 19 Jul 2025 11:28:54 -0700
With maple_tree supporting vma tree traversal under RCU and per-vma locks, /proc/pid/maps can be read while holding individual vma locks instead of locking the entire address space.
A completely lockless approach (walking vma tree under RCU) would be quite complex with the main issue being get_vma_name() using callbacks which might not work correctly with a stable vma copy, requiring original (unstable) vma - see special_mapping_name() for example.
When per-vma lock acquisition fails, we take the mmap_lock for reading, lock the vma, release the mmap_lock and continue. This fallback to mmap read lock guarantees the reader to make forward progress even during lock contention. This will interfere with the writer but for a very short time while we are acquiring the per-vma lock and only when there was contention on the vma reader is interested in.
We shouldn't see a repeated fallback to mmap read locks in practice, as this require a very unlikely series of lock contentions (for instance due to repeated vma split operations). However even if this did somehow happen, we would still progress.
One case requiring special handling is when a vma changes between the time it was found and the time it got locked. A problematic case would be if a vma got shrunk so that its vm_start moved higher in the address space and a new vma was installed at the beginning:
reader found: |--------VMA A--------| VMA is modified: |-VMA B-|----VMA A----|
reader locks modified VMA A
reader reports VMA A: | gap |----VMA A----|
This would result in reporting a gap in the address space that does not exist. To prevent this we retry the lookup after locking the vma, however we do that only when we identify a gap and detect that the address space was changed after we found the vma.
This change is designed to reduce mmap_lock contention and prevent a process reading /proc/pid/maps files (often a low priority task, such as monitoring/data collection services) from blocking address space updates. Note that this change has a userspace visible disadvantage: it allows for sub-page data tearing as opposed to the previous mechanism where data tearing could happen only between pages of generated output data. Since current userspace considers data tearing between pages to be acceptable, we assume is will be able to handle sub-page data tearing as well.
---
fs/proc/internal.h | 5 + fs/proc/task_mmu.c | 141 +++++++++++++++++++++++++++++++++--- include/linux/mmap_lock.h | 11 ++ mm/madvise.c | 3 mm/mmap_lock.c | 93 +++++++++++++++++++++++ 5 files changed, 244 insertions(+), 9 deletions(-)
fs/proc/internal.h renamed from fs/proc/internal.h~fs-proc-task_mmu-read-proc-pid-maps-under-per-vma-lock +5 -0
@@ -384,6 +384,11 @@ struct proc_maps_private {struct task_struct *task;struct mm_struct *mm;struct vma_iterator iter; +loff_t last_pos; +#ifdef CONFIG_PER_VMA_LOCK +bool mmap_locked; +struct vm_area_struct *locked_vma; +#endif #ifdef CONFIG_NUMA struct mempolicy *task_mempolicy;#endif
fs/proc/task_mmu.c renamed from fs/proc/task_mmu.c~fs-proc-task_mmu-read-proc-pid-maps-under-per-vma-lock +133 -8
179 lines not on this page · raw message
include/linux/mmap_lock.h renamed from include/linux/mmap_lock.h~fs-proc-task_mmu-read-proc-pid-maps-under-per-vma-lock +11 -0
@@ -309,6 +309,17 @@ void vma_mark_detached(struct vm_area_ststruct vm_area_struct *lock_vma_under_rcu (struct mm_struct *mm,unsigned long address); +/* +* Locks next vma pointed by the iterator. Confirms the locked vma has not +* been modified and will retry under mmap_lock protection if modification +* was detected. Should be called from read RCU section. +* Returns either a valid locked VMA, NULL if no more VMAs or -EINTR if the +* process was interrupted. +*/ +struct vm_area_struct *lock_next_vma (struct mm_struct *mm, +struct vma_iterator *iter, +unsigned long address); +#else /* CONFIG_PER_VMA_LOCK */ static inline void mm_lock_seqcount_init (struct mm_struct *mm) {}
mm/madvise.c renamed from mm/madvise.c~fs-proc-task_mmu-read-proc-pid-maps-under-per-vma-lock +2 -1
@@ -108,7 +108,8 @@ void anon_vma_name_free(struct kref *krestruct anon_vma_name *anon_vma_name (struct vm_area_struct *vma) { -mmap_assert_locked (vma->vm_mm); +if (!rwsem_is_locked (&vma->vm_mm->mmap_lock)) +vma_assert_locked (vma);return vma->anon_name; }
mm/mmap_lock.c renamed from mm/mmap_lock.c~fs-proc-task_mmu-read-proc-pid-maps-under-per-vma-lock +93 -0
99 lines not on this page · raw message
_
Patches currently in -mm which might be from [email protected] are