Skip to content

Commit 0c563f1

Browse files
Matthew Wilcox (Oracle)akpm00
authored andcommitted
proc: remove VMA rbtree use from nommu
These users of the rbtree should probably have been walks of the linked list, but convert them to use walks of the maple tree. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Signed-off-by: Liam R. Howlett <[email protected]> Acked-by: Vlastimil Babka <[email protected]> Reviewed-by: Davidlohr Bueso <[email protected]> Tested-by: Yu Zhao <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: David Hildenbrand <[email protected]> Cc: David Howells <[email protected]> Cc: SeongJae Park <[email protected]> Cc: Sven Schnelle <[email protected]> Cc: Will Deacon <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent d0cf3dd commit 0c563f1

File tree

1 file changed

+21
-24
lines changed

1 file changed

+21
-24
lines changed

fs/proc/task_nommu.c

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,13 @@
2020
*/
2121
void task_mem(struct seq_file *m, struct mm_struct *mm)
2222
{
23+
VMA_ITERATOR(vmi, mm, 0);
2324
struct vm_area_struct *vma;
2425
struct vm_region *region;
25-
struct rb_node *p;
2626
unsigned long bytes = 0, sbytes = 0, slack = 0, size;
27-
28-
mmap_read_lock(mm);
29-
for (p = rb_first(&mm->mm_rb); p; p = rb_next(p)) {
30-
vma = rb_entry(p, struct vm_area_struct, vm_rb);
3127

28+
mmap_read_lock(mm);
29+
for_each_vma(vmi, vma) {
3230
bytes += kobjsize(vma);
3331

3432
region = vma->vm_region;
@@ -82,15 +80,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
8280

8381
unsigned long task_vsize(struct mm_struct *mm)
8482
{
83+
VMA_ITERATOR(vmi, mm, 0);
8584
struct vm_area_struct *vma;
86-
struct rb_node *p;
8785
unsigned long vsize = 0;
8886

8987
mmap_read_lock(mm);
90-
for (p = rb_first(&mm->mm_rb); p; p = rb_next(p)) {
91-
vma = rb_entry(p, struct vm_area_struct, vm_rb);
88+
for_each_vma(vmi, vma)
9289
vsize += vma->vm_end - vma->vm_start;
93-
}
9490
mmap_read_unlock(mm);
9591
return vsize;
9692
}
@@ -99,14 +95,13 @@ unsigned long task_statm(struct mm_struct *mm,
9995
unsigned long *shared, unsigned long *text,
10096
unsigned long *data, unsigned long *resident)
10197
{
98+
VMA_ITERATOR(vmi, mm, 0);
10299
struct vm_area_struct *vma;
103100
struct vm_region *region;
104-
struct rb_node *p;
105101
unsigned long size = kobjsize(mm);
106102

107103
mmap_read_lock(mm);
108-
for (p = rb_first(&mm->mm_rb); p; p = rb_next(p)) {
109-
vma = rb_entry(p, struct vm_area_struct, vm_rb);
104+
for_each_vma(vmi, vma) {
110105
size += kobjsize(vma);
111106
region = vma->vm_region;
112107
if (region) {
@@ -190,17 +185,19 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma)
190185
*/
191186
static int show_map(struct seq_file *m, void *_p)
192187
{
193-
struct rb_node *p = _p;
194-
195-
return nommu_vma_show(m, rb_entry(p, struct vm_area_struct, vm_rb));
188+
return nommu_vma_show(m, _p);
196189
}
197190

198191
static void *m_start(struct seq_file *m, loff_t *pos)
199192
{
200193
struct proc_maps_private *priv = m->private;
201194
struct mm_struct *mm;
202-
struct rb_node *p;
203-
loff_t n = *pos;
195+
struct vm_area_struct *vma;
196+
unsigned long addr = *pos;
197+
198+
/* See m_next(). Zero at the start or after lseek. */
199+
if (addr == -1UL)
200+
return NULL;
204201

205202
/* pin the task and mm whilst we play with them */
206203
priv->task = get_proc_task(priv->inode);
@@ -216,10 +213,10 @@ static void *m_start(struct seq_file *m, loff_t *pos)
216213
return ERR_PTR(-EINTR);
217214
}
218215

219-
/* start from the Nth VMA */
220-
for (p = rb_first(&mm->mm_rb); p; p = rb_next(p))
221-
if (n-- == 0)
222-
return p;
216+
/* start the next element from addr */
217+
vma = find_vma(mm, addr);
218+
if (vma)
219+
return vma;
223220

224221
mmap_read_unlock(mm);
225222
mmput(mm);
@@ -242,10 +239,10 @@ static void m_stop(struct seq_file *m, void *_vml)
242239

243240
static void *m_next(struct seq_file *m, void *_p, loff_t *pos)
244241
{
245-
struct rb_node *p = _p;
242+
struct vm_area_struct *vma = _p;
246243

247-
(*pos)++;
248-
return p ? rb_next(p) : NULL;
244+
*pos = vma->vm_end;
245+
return find_vma(vma->vm_mm, vma->vm_end);
249246
}
250247

251248
static const struct seq_operations proc_pid_maps_ops = {

0 commit comments

Comments
 (0)