[Openswan dev] Small optimisation for lots of interfaces

David McCullough davidm at snapgear.com
Fri Nov 25 14:56:02 CET 2005


Jivin Herbert Xu lays it down ...
> David McCullough <davidm at snapgear.com> wrote:
> > 
> > Actually,  I think that it is more likely to be the fact that it opens
> > /proc/net/dev and parses it for every interface,  just so it can show
> > the "stats" for the interfaces.  At least my quick look at the ifconfig code
> > suggests this is the case.
> 
> You must be using a different ifconfig than me.  Mine opens it only once
> but does this many ioctls for each interface:

No,  I just didn't have strace to confirm what the code appeared to be
doing,  you are right.

It opens it once at the start.

> 4545  1132882691.760015 ioctl(4, 0x8913, 0xbffff8dc) = 0
> 4545  1132882691.760146 ioctl(4, 0x8927, 0xbffff8dc) = 0
> 4545  1132882691.760274 ioctl(4, 0x891d, 0xbffff8dc) = 0
> 4545  1132882691.760401 ioctl(4, 0x8921, 0xbffff8dc) = 0
> 4545  1132882691.760528 ioctl(4, 0x8970, 0xbffff8dc) = 0
> 4545  1132882691.760654 ioctl(4, 0x8970, 0xbffff8dc) = 0
> 4545  1132882691.760781 ioctl(4, 0x8942, 0xbffff8dc) = 0
> 4545  1132882691.760908 ioctl(4, 0x8915, 0xbffff8dc) = 0
> 4545  1132882691.761037 ioctl(4, 0x8917, 0xbffff8dc) = 0
> 4545  1132882691.761165 ioctl(4, 0x8919, 0xbffff8dc) = 0
> 4545  1132882691.761293 ioctl(4, 0x891b, 0xbffff8dc) = 0
> 
> How long does
> 
> cat /proc/net/dev > /dev/null

Since these are all aliases,  /proc/net/dev is tiny,

	# time cat /proc/net/dev > /dev/null

	real    0m0.008s
	user    0m0.000s
	sys     0m0.000s

Which truly shows how little I looked at it.  Here is what I see with
strace, per aliased interface:

	ioctl(5, 0x8913, 0xbffffc2c)            = 0
	ioctl(5, 0x8927, 0xbffffc2c)            = 0
	ioctl(5, 0x891d, 0xbffffc2c)            = 0
	ioctl(5, 0x8921, 0xbffffc2c)            = 0
	ioctl(5, 0x8970, 0xbffffc2c)            = 0
	ioctl(5, 0x8970, 0xbffffc2c)            = 0
	ioctl(5, 0x8942, 0xbffffc2c)            = 0
	ioctl(4, 0x8915, 0xbffffc2c)            = 0
	ioctl(4, 0x8917, 0xbffffc2c)            = 0
	ioctl(4, 0x8919, 0xbffffc2c)            = 0
	ioctl(4, 0x891b, 0xbffffc2c)            = 0
	write(1, "eth0:34 ...
	open("/proc/net/if_inet6", O_RDONLY)    = 6
	ioctl(6, SNDCTL_TMR_TIMEBASE, 0xbffffaf0) = -1 ENOTTY
	read(6, "fe8000000000000002d0cffffe000001"..., 256) = 108
	read(6, "", 256)                        = 0
	close(6)                                = 0
	write(1, "          UP BROADCAST NOTRAILER"..., 72) = 72
	write(1, "          Interrupt:23 Base addr"..., 44) = 44
	write(1, "\n", 1) = 1

So it could be due to us having ipv6 support enabled ?  Thats a lot of
file opens/reads to be doing,  not to mention ioctls ;-)

Cheers,
Davidm

-- 
David McCullough, davidm at cyberguard.com.au, Custom Embedded Solutions + Security
Ph:+61 734352815 Fx:+61 738913630 http://www.uCdot.org http://www.cyberguard.com


More information about the Dev mailing list