Skip to content

Commit

Permalink
tools/vm/page-types.c: avoid memset() in walk_pfn() when count == 1
Browse files Browse the repository at this point in the history
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: 954e955 ("tools/vm/page-types.c: add memory cgroup dumping and filtering")
Signed-off-by: Naoya Horiguchi <[email protected]>
Suggested-by: Konstantin Khlebnikov <[email protected]>
Cc: Vladimir Davydov <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
Signed-off-by: Linus Torvalds <[email protected]>
  • Loading branch information
Naoya Horiguchi authored and torvalds committed Mar 17, 2016
1 parent 7f2bd00 commit d9b2ddf
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion tools/vm/page-types.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,15 @@ static void walk_pfn(unsigned long voffset,
unsigned long pages;
unsigned long i;

memset(cgi, 0, sizeof cgi);
/*
* kpagecgroup_read() reads only if kpagecgroup were opened, but
* /proc/kpagecgroup might even not exist, so it's better to fill
* them with zeros here.
*/
if (count == 1)
cgi[0] = 0;
else
memset(cgi, 0, sizeof cgi);

while (count) {
batch = min_t(unsigned long, count, KPAGEFLAGS_BATCH);
Expand Down

0 comments on commit d9b2ddf

Please sign in to comment.