Subject: Re: [RFC PATCH net-2.6.26 (Plan A)] [TCP]: Lower stack usage in tcp4_seq_show().

From: Al Viro <[email-masked]>
Date: Tue, 15 Apr 2008 11:45:03 +0100

On Tue, Apr 15, 2008 at 07:24:34PM +0900, YOSHIFUJI Hideaki / ?$B5HF#1QL@ wrote:
> tcp4_seq_show() eats about 250 bytes.  By using buffer in seq_file
> directly, it will be reduced under 100 bytes.
> 
> One drawback is slight change of the format - the format was fixed
> size and now its size is variable.
> However, size of the line was 128 bytes in 2.2, and 150 bytes in 2.6,
> so the change may not matter, probably.

> -	sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X"
> -		" %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p",
> +	seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
> +		" %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p\n",

Or you can just do
	int len;
	...
	seq_printf(seq, "%4d: %08X:%04X %08X:%04X"
		" %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
>  		i,
>  		ireq->loc_addr,
>  		ntohs(inet_sk(sk)->sport),
		...,
		&len);
	seq_printf("%*s\n", TMPSZ - 1 - len, "");

and be done with that, keeping the output unchanged.  That's exactly what
%n is for - it allows to get the width of output so far, precisely for
such situations.