linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Serapheim Dimitropoulos <serapheim.dimitro@delphix.com>
To: akpm@linux-foundation.org, linux-mm@kvack.org
Cc: linux-kernel@vger.kernel.org, osandov@osandov.com,
	urezki@gmail.com, serapheim@delphix.com
Subject: [PATCH v2] mm/vmalloc: use rb_tree instead of list for vread() lookups
Date: Tue,  9 Feb 2021 19:02:53 +0000	[thread overview]
Message-ID: <20210209190253.108763-1-serapheim@delphix.com> (raw)

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 3000 | wc'
(unsigned long)3000

real	0m22.446s
user	0m2.321s
sys	0m20.690s
-----

With the patch:
-----
$ time sudo sdb -e 'dbuf | head 3000 | wc'
(unsigned long)3000

real	0m2.104s
user	0m2.043s
sys	0m0.921s
-----

Signed-off-by: Serapheim Dimitropoulos <serapheim@delphix.com>
---
Changed in v2:

- Use __find_vmap_area() for initial lookup but keep iteration via
  va->list.

 mm/vmalloc.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/mm/vmalloc.c b/mm/vmalloc.c
index 49ab9b6c001d..eb133d000394 100644
--- a/mm/vmalloc.c
+++ b/mm/vmalloc.c
@@ -2860,7 +2860,10 @@ 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) {
+	va = __find_vmap_area((unsigned long)addr);
+	if (!va)
+		goto finished;
+	list_for_each_entry_from(va, &vmap_area_list, list) {
 		if (!count)
 			break;
 
-- 
2.17.1


             reply	other threads:[~2021-02-10  0:30 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-02-09 19:02 Serapheim Dimitropoulos [this message]
2021-02-09 19:49 ` [PATCH v2] mm/vmalloc: use rb_tree instead of list for vread() lookups Uladzislau Rezki

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=20210209190253.108763-1-serapheim@delphix.com \
    --to=serapheim.dimitro@delphix.com \
    --cc=akpm@linux-foundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mm@kvack.org \
    --cc=osandov@osandov.com \
    --cc=serapheim@delphix.com \
    --cc=urezki@gmail.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;
as well as URLs for NNTP newsgroup(s).