From 299244116ac6f2717f20f93404e135c7cad7e187 Mon Sep 17 00:00:00 2001 From: "yang.yang29@zte.com.cn" Date: Mon, 15 Apr 2024 06:00:41 +0000 Subject: [PATCH] mm/vmalloc: use rb_tree instead of list for vread() lookups commit f608788cd2d6cae27d1a3d2253544ca76b353764 upstream. 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 ----- Link: https://lkml.kernel.org/r/20210209190253.108763-1-serapheim@delphix.com Signed-off-by: Serapheim Dimitropoulos Reviewed-by: Uladzislau Rezki (Sony) Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Yang Yang Reviewed-by: Xuexin Jiang Link: https://gitee.com/anolis/embedded-kernel/pulls/298 --- mm/vmalloc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 84c24b495e81..53859510ba5b 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3581,7 +3581,10 @@ long vwrite(char *buf, char *addr, unsigned long count) buflen = count; 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; -- Gitee