Re: [PATCH v2] proc: speedup /proc/stat handling

From: KAMEZAWA Hiroyuki
Date: Thu Jan 26 2012 - 04:56:43 EST


On Wed, 25 Jan 2012 17:04:16 -0800
Andrew Morton <akpm@xxxxxxxxxxxxxxxxxxxx> wrote:

> On Wed, 25 Jan 2012 06:29:32 +0100
> Eric Dumazet <eric.dumazet@xxxxxxxxx> wrote:
>
> > Le mardi 24 janvier 2012 __ 17:27 -0800, Andrew Morton a __crit :
> >
> > > I had a fiddle on an 8-way x86_64 machine. I'm unable to demonstrate
> > > any improvement for either of
> > >
> > > time (for i in $(seq 1000); do; cat /proc/self/stat > /dev/null; done)
> > > time (for i in $(seq 1000); do; cat /proc/1/stat > /dev/null; done)
> > >
> > > oh well.
> >
> > What size is /proc/stat ?
>
> About 40mm, but it depends on the font size.
>
> > wc -c /proc/stat
> >
> > If under 4096, there is no problem with existing code.
>
> akpm2:/home/akpm> wc -c /proc/stat
> 2800 /proc/stat
>
> > I had the problem on a 16-way machine.
>
> OK..


I wrote following patch just for my fun, which makes /proc/stat twice fast.
But I'm not sure whether this kind of dirty && special printk is worth to do or not..
because I can't see /proc/stat cost at shell-scripting.

With python script test (read /proc/stat 1000times)
==
#!/usr/bin/python

num = 0

with open("/proc/stat") as f:
while num < 1000 :
data = f.read()
f.seek(0, 0)
num = num + 1
==

*Before patch
[kamezawa@bluextal test]$ time ./stat_check.py

real 0m0.154s
user 0m0.020s
sys 0m0.130s

*After patch
[kamezawa@bluextal test]$ time ./stat_check.py

real 0m0.080s
user 0m0.029s
sys 0m0.048s


For ascii interface, format_decode() and number() seems to be
very costly...

==