[PATCH v13 42/70] fs/proc/base: use maple tree iterators in place of linked list

Liam Howlett posted 70 patches 3 years, 7 months ago
There is a newer version of this series
[PATCH v13 42/70] fs/proc/base: use maple tree iterators in place of linked list
Posted by Liam Howlett 3 years, 7 months ago
From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
---
 fs/proc/base.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 93f7e3d971e4..0b72a6d8aac3 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -2350,6 +2350,7 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
 	GENRADIX(struct map_files_info) fa;
 	struct map_files_info *p;
 	int ret;
+	MA_STATE(mas, NULL, 0, 0);
 
 	genradix_init(&fa);
 
@@ -2377,6 +2378,7 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
 	}
 
 	nr_files = 0;
+	mas.tree = &mm->mm_mt;
 
 	/*
 	 * We need two passes here:
@@ -2388,7 +2390,8 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
 	 * routine might require mmap_lock taken in might_fault().
 	 */
 
-	for (vma = mm->mmap, pos = 2; vma; vma = vma->vm_next) {
+	pos = 2;
+	mas_for_each(&mas, vma, ULONG_MAX) {
 		if (!vma->vm_file)
 			continue;
 		if (++pos <= ctx->pos)
-- 
2.35.1
Re: [PATCH v13 42/70] fs/proc/base: use maple tree iterators in place of linked list
Posted by Davidlohr Bueso 3 years, 7 months ago
On Mon, 22 Aug 2022, Liam Howlett wrote:

>From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>

-ENOCHANGELOG.

>
>Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
>---
> fs/proc/base.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
>diff --git a/fs/proc/base.c b/fs/proc/base.c
>index 93f7e3d971e4..0b72a6d8aac3 100644
>--- a/fs/proc/base.c
>+++ b/fs/proc/base.c
>@@ -2350,6 +2350,7 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
> 	GENRADIX(struct map_files_info) fa;
> 	struct map_files_info *p;
> 	int ret;
>+	MA_STATE(mas, NULL, 0, 0);
>
> 	genradix_init(&fa);
>
>@@ -2377,6 +2378,7 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
> 	}
>
> 	nr_files = 0;
>+	mas.tree = &mm->mm_mt;
>
> 	/*
> 	 * We need two passes here:
>@@ -2388,7 +2390,8 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
> 	 * routine might require mmap_lock taken in might_fault().
> 	 */
>
>-	for (vma = mm->mmap, pos = 2; vma; vma = vma->vm_next) {
>+	pos = 2;
>+	mas_for_each(&mas, vma, ULONG_MAX) {
> 		if (!vma->vm_file)
> 			continue;
> 		if (++pos <= ctx->pos)
>
>-- 
>2.35.1
>
[PATCH] fs/proc/base: use maple tree iterators in place of linked list
Posted by Liam Howlett 3 years, 7 months ago
From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>

Use mas_for_each to iterate the list of VMAs instead of a for loop
across the linked list.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
---
 fs/proc/base.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index 93f7e3d971e4..0b72a6d8aac3 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -2350,6 +2350,7 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
 	GENRADIX(struct map_files_info) fa;
 	struct map_files_info *p;
 	int ret;
+	MA_STATE(mas, NULL, 0, 0);
 
 	genradix_init(&fa);
 
@@ -2377,6 +2378,7 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
 	}
 
 	nr_files = 0;
+	mas.tree = &mm->mm_mt;
 
 	/*
 	 * We need two passes here:
@@ -2388,7 +2390,8 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
 	 * routine might require mmap_lock taken in might_fault().
 	 */
 
-	for (vma = mm->mmap, pos = 2; vma; vma = vma->vm_next) {
+	pos = 2;
+	mas_for_each(&mas, vma, ULONG_MAX) {
 		if (!vma->vm_file)
 			continue;
 		if (++pos <= ctx->pos)
-- 
2.35.1
Re: [PATCH] fs/proc/base: use maple tree iterators in place of linked list
Posted by Davidlohr Bueso 3 years, 7 months ago
On Wed, 24 Aug 2022, Liam Howlett wrote:

>From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>
>
>Use mas_for_each to iterate the list of VMAs instead of a for loop
>across the linked list.

Hmm so why isn't this using the standard VMA_ITERATOR?

>
>Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
>---
> fs/proc/base.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
>diff --git a/fs/proc/base.c b/fs/proc/base.c
>index 93f7e3d971e4..0b72a6d8aac3 100644
>--- a/fs/proc/base.c
>+++ b/fs/proc/base.c
>@@ -2350,6 +2350,7 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
> 	GENRADIX(struct map_files_info) fa;
> 	struct map_files_info *p;
> 	int ret;
>+	MA_STATE(mas, NULL, 0, 0);
>
> 	genradix_init(&fa);
>
>@@ -2377,6 +2378,7 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
> 	}
>
> 	nr_files = 0;
>+	mas.tree = &mm->mm_mt;
>
> 	/*
> 	 * We need two passes here:
>@@ -2388,7 +2390,8 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
> 	 * routine might require mmap_lock taken in might_fault().
> 	 */
>
>-	for (vma = mm->mmap, pos = 2; vma; vma = vma->vm_next) {
>+	pos = 2;
>+	mas_for_each(&mas, vma, ULONG_MAX) {
> 		if (!vma->vm_file)
> 			continue;
> 		if (++pos <= ctx->pos)
>-- 
>2.35.1
Re: [PATCH] fs/proc/base: use maple tree iterators in place of linked list
Posted by Liam Howlett 3 years, 7 months ago
* Davidlohr Bueso <dave@stgolabs.net> [220825 12:19]:
> On Wed, 24 Aug 2022, Liam Howlett wrote:
> 
> > From: "Liam R. Howlett" <Liam.Howlett@Oracle.com>
> > 
> > Use mas_for_each to iterate the list of VMAs instead of a for loop
> > across the linked list.
> 
> Hmm so why isn't this using the standard VMA_ITERATOR?

the VMA_ITERATOR is for the easy cases.  This one was probably skipped
due to the pos = 2 in the for loop and the unknown mm_struct.  I worked
around that in my patch and I think we could switch to the vma iterator,
but it won't be any better than what is there now.  We will need to
declare the struct and call vma_iter_init() once the mm_struct is known.
It would get rid of the ULONG_MAX in the mas_for_each() line though.

> 
> > 
> > Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
> > ---
> > fs/proc/base.c | 5 ++++-
> > 1 file changed, 4 insertions(+), 1 deletion(-)
> > 
> > diff --git a/fs/proc/base.c b/fs/proc/base.c
> > index 93f7e3d971e4..0b72a6d8aac3 100644
> > --- a/fs/proc/base.c
> > +++ b/fs/proc/base.c
> > @@ -2350,6 +2350,7 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
> > 	GENRADIX(struct map_files_info) fa;
> > 	struct map_files_info *p;
> > 	int ret;
> > +	MA_STATE(mas, NULL, 0, 0);
> > 
> > 	genradix_init(&fa);
> > 
> > @@ -2377,6 +2378,7 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
> > 	}
> > 
> > 	nr_files = 0;
> > +	mas.tree = &mm->mm_mt;
> > 
> > 	/*
> > 	 * We need two passes here:
> > @@ -2388,7 +2390,8 @@ proc_map_files_readdir(struct file *file, struct dir_context *ctx)
> > 	 * routine might require mmap_lock taken in might_fault().
> > 	 */
> > 
> > -	for (vma = mm->mmap, pos = 2; vma; vma = vma->vm_next) {
> > +	pos = 2;
> > +	mas_for_each(&mas, vma, ULONG_MAX) {
> > 		if (!vma->vm_file)
> > 			continue;
> > 		if (++pos <= ctx->pos)
> > -- 
> > 2.35.1