From: Uladzislau Rezki <urezki@gmail.com>
To: Serapheim Dimitropoulos <serapheim.dimitro@delphix.com>
Cc: akpm@linux-foundation.org, linux-mm@kvack.org,
linux-kernel@vger.kernel.org, osandov@osandov.com,
serapheim@delphix.com
Subject: Re: [PATCH] mm/vmalloc: use rb_tree instead of list for vread() lookups
Date: Mon, 8 Feb 2021 20:01:50 +0100 [thread overview]
Message-ID: <20210208190150.GA22808@pc638.lan> (raw)
In-Reply-To: <20210208155303.10523-1-serapheim@delphix.com>
On Mon, Feb 08, 2021 at 03:53:03PM +0000, Serapheim Dimitropoulos wrote:
> vread() has been linearly searching vmap_area_list for looking up
> vmalloc areas to read from. These same areas are also tracked by
> a rb_tree (vmap_area_root) which offers logarithmic lookup.
>
> This patch modifies vread() to use the rb_tree structure instead
> of the list and the speedup for heavy /proc/kcore readers can
> be pretty significant. Below are the wall clock measurements of
> a Python application that leverages the drgn debugging library
> to read and interpret data read from /proc/kcore.
>
> Before the patch:
> -----
> $ time sudo sdb -e 'dbuf | head 2500 | wc'
> (unsigned long)2500
>
> real 0m21.128s
> user 0m2.321s
> sys 0m19.227s
> -----
>
> With the patch:
> -----
> $ time sudo sdb -e 'dbuf | head 2500 | wc'
> (unsigned long)2500
>
> real 0m1.870s
> user 0m1.628s
> sys 0m0.660s
> -----
>
> Signed-off-by: Serapheim Dimitropoulos <serapheim@delphix.com>
> ---
> mm/vmalloc.c | 19 ++++++++++++-------
> 1 file changed, 12 insertions(+), 7 deletions(-)
>
> diff --git a/mm/vmalloc.c b/mm/vmalloc.c
> index 49ab9b6c001d..86343b879938 100644
> --- a/mm/vmalloc.c
> +++ b/mm/vmalloc.c
> @@ -2851,6 +2851,7 @@ long vread(char *buf, char *addr, unsigned long count)
> {
> struct vmap_area *va;
> struct vm_struct *vm;
> + struct rb_node *node;
> char *vaddr, *buf_start = buf;
> unsigned long buflen = count;
> unsigned long n;
> @@ -2860,17 +2861,15 @@ long vread(char *buf, char *addr, unsigned long count)
> count = -(unsigned long) addr;
>
> spin_lock(&vmap_area_lock);
> - list_for_each_entry(va, &vmap_area_list, list) {
> - if (!count)
> - break;
> -
> + va = __find_vmap_area((unsigned long)addr);
> + if (!va)
> + goto finished;
> + while (count) {
> if (!va->vm)
> - continue;
> + goto next_node;
>
> vm = va->vm;
> vaddr = (char *) vm->addr;
> - if (addr >= vaddr + get_vm_area_size(vm))
> - continue;
> while (addr < vaddr) {
> if (count == 0)
> goto finished;
> @@ -2889,6 +2888,12 @@ long vread(char *buf, char *addr, unsigned long count)
> buf += n;
> addr += n;
> count -= n;
> +
> +next_node:
> + node = rb_next(&va->rb_node);
> + if (!node)
> + break;
> + va = rb_entry(node, struct vmap_area, rb_node);
>
You can also improve it. Instead of rb_next() you can directly access
to a "next" element via "va->list" making it O(1) complexity.
--
Vlad Rezki
prev parent reply other threads:[~2021-02-08 19:01 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-08 15:53 Serapheim Dimitropoulos
2021-02-08 19:01 ` Uladzislau Rezki [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210208190150.GA22808@pc638.lan \
--to=urezki@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=osandov@osandov.com \
--cc=serapheim.dimitro@delphix.com \
--cc=serapheim@delphix.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox