Re: /proc/net/tcp6 inconsistent line length
From: <hidden>
Date: 2012-01-17 14:14:38
On Tue, 17 Jan 2012 13:33:01 -0000 "David Laight" [off-list ref] wrote:
quoted
My application parses /proc/net/tcp6 at least 4 times per second, so the overhead of figuring out the length of each line and subtracting the offset is quite expensive.I'd be surprised if you can detect the cost of calling strchr(buf, '\n') on each line at the frequency. It is probably far less than the other processing you do on the line. David
Thank you, David. I first fread() the whole file to membuf and then process it thusly trying to find a line that matches my source port (porthex) :
while(1){
memcpy(buffer,&tcp6_membuf[184+170*i],4);
if ( !memcmp ( porthex, buffer, 4 ) ){ //match!
goto endloop;
}
i++;
continue;
N.B. 184 is the offset of source port on line 2 from the beginning of file (line 1 is used for column headings)
my /proc/net/tcp6 file contains 300 - 500 lines and I parse it at least from 4 to 10 times per sec. So the maximum is 5000 iterations per sec. It would be very costly CPU wise to do strchr(buf, '\n')
I'm not skillful enough to understand the code in kernel sources.
My concern boils down to this:
Was /proc/net/tcp* meant to have an equal length of each line?
If yes, then I discovered a bug.
If no, then would it be possible to patch the kernel to enable an equal length on each line?