From: Greg KH Subject: Re: RFC: seq_file: optimize memory re-alloc strategy for seq file sizes > PAGE_SIZE Date: Fri, 15 Jul 2011 17:18:43 +0200 Message-ID: <20110715151843.GB4747@suse.de> References: <4E1FFF94.4080803@st.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: linux-fsdevel@vger.kernel.org, Stuart MENEFY , srinivas.kandagatla@gmail.com To: Srinivas KANDAGATLA Return-path: Received: from cantor2.suse.de ([195.135.220.15]:37717 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751737Ab1GOPUS (ORCPT ); Fri, 15 Jul 2011 11:20:18 -0400 Content-Disposition: inline In-Reply-To: <4E1FFF94.4080803@st.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Fri, Jul 15, 2011 at 09:51:32AM +0100, Srinivas KANDAGATLA wrote: > Hi All, > I have noticed that, reading or dumping a full sysfs entry (ex: > /sys/kernel/debug/gpio ) That's not sysfs, it's debugfs. > which exceeds PAGE_SIZE restarts associated seq_file iterator > (calling start->show->stop) > morethan one time. > > In my case gpio entry just exceeded 8k which resulted in show > function getting > called 3 times. > > The reason is because the allocated buffer overflows and seq_file allocates > new buffer of next order and starts iteration from the start, which > is clear in > seq_file code. > However this is bit of conservative approach which results in: > - restarting iterator if file sz exceeds PAGE_SIZE( which is really > not necessary ) > - not reusing the formated buffer (which can be done by re-alloc and copy). > - Will help entires like dumping cacheline or pagetables to capture > its state with better accuracy. > > To address this situation, I think seq_file formating/printf > functions should > re-allocate buffer as soon as they detect buffer overflow. This is debugging code, why should performance matter? > This patch attempts to do the same by adding new function > buf_realloc which inturn > calls krealloc and all the seq_file formating or printing functions > call this > function whenever an overflow is detected and retry. > > > Main motive of this patch is to avoid restarting the iterator and NOT > performance, however there is a bit of gain in performance too. > > Performance figures(average over 100 times loop) for different sizes of > sysfs entries: > > without realloc: > --------------------------------- > SZ REAL USER SYS > --------------------------------- > | 4k | 0.012 0.002 0.009 > | 8k | 0.013 0.002 0.010 > | 16k | 0.015 0.003 0.012 > | 32k | 0.019 0.002 0.017 > -------------------------------- > > with realloc: > --------------------------------- > SZ REAL USER SYS > --------------------------------- > | 4k | 0.012 0.002 0.009 > | 8k | 0.012 0.002 0.009 > | 16k | 0.013 0.002 0.010 > | 32k | 0.015 0.003 0.012 > ------------------------------- > > > I discovered this issue while I was working on a different issue as > I happed > to stick a printk in show function, which got called 3 times when I > dumped the > entry with 'cat' :-). which I did not expect. > > > comments? :-) Again, debugfs doesn't matter for this type of thing, so adding complexity to the core kernel code for it shouldn't be done unless absolutely needed. thanks, greg k-h