aboutsummaryrefslogtreecommitdiffstats
path: root/tools/vm
diff options
context:
space:
mode:
authorNaoya Horiguchi <n-horiguchi@ah.jp.nec.com>2016-03-17 17:20:22 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-03-17 18:09:34 -0400
commitd9b2ddf8078f743729a054362ad96be076f224af (patch)
treef9117a790718e1262dcd948534f30ebfb683be80 /tools/vm
parent7f2bd006334291178bd2bce3e506d4c7a34a0643 (diff)
tools/vm/page-types.c: avoid memset() in walk_pfn() when count == 1
I found that page-types is very slow and my testing shows many timeout errors. Here's an example with a simple program allocating 1000 thps. $ time ./page-types -p $(pgrep -f test_alloc) ... real 0m17.201s user 0m16.889s sys 0m0.312s Most of time is spent in memset(). Currently memset() clears over whole buffer for every walk_pfn() call, which is inefficient when walk_pfn() is called from walk_vma(), because in that case walk_pfn() is called for each pfn. So this patch limits the zero initialization only for the first element. $ time ./page-types.patched -p $(pgrep -f test_alloc) ... real 0m0.182s user 0m0.046s sys 0m0.135s Fixes: 954e95584579 ("tools/vm/page-types.c: add memory cgroup dumping and filtering") Signed-off-by: Naoya Horiguchi <n-horiguchi@ah.jp.nec.com> Suggested-by: Konstantin Khlebnikov <koct9i@gmail.com> Cc: Vladimir Davydov <vdavydov@virtuozzo.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'tools/vm')
-rw-r--r--tools/vm/page-types.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/tools/vm/page-types.c b/tools/vm/page-types.c
index dab61c377f54..e92903fc7113 100644
--- a/tools/vm/page-types.c
+++ b/tools/vm/page-types.c
@@ -633,7 +633,15 @@ static void walk_pfn(unsigned long voffset,
633 unsigned long pages; 633 unsigned long pages;
634 unsigned long i; 634 unsigned long i;
635 635
636 memset(cgi, 0, sizeof cgi); 636 /*
637 * kpagecgroup_read() reads only if kpagecgroup were opened, but
638 * /proc/kpagecgroup might even not exist, so it's better to fill
639 * them with zeros here.
640 */
641 if (count == 1)
642 cgi[0] = 0;
643 else
644 memset(cgi, 0, sizeof cgi);
637 645
638 while (count) { 646 while (count) {
639 batch = min_t(unsigned long, count, KPAGEFLAGS_BATCH); 647 batch = min_t(unsigned long, count, KPAGEFLAGS_BATCH);