Skip to content

RFC Make loopback device weight twice as little.

Pavel Emelyanov netdev 1 version In review

Get series with b4
b4 am [email protected]

Versions newest first

  1. v1 RFC Latest3 patches 3 repliesIn review

Patches in v1 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3Introduce the net_device_ops structure.include/linux/netdevice.h net/core/dev.c+48 -03 replies
2/3Move net_device->init callback on net_device_ops.net/core/dev.c+11 -20 replies
3/3Move net_device->uninit callback on net_device_ops.net/core/dev.c+11 -40 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v1 yet.

Read the v1 thread

Cover letter [RFC][PATCH 0/3] Make loopback device weight twice as little.

I noticed, that on a 32bit box with a non-debug config the sizeof(struct net_device) is slightly more than 1024. This means, that for example loopback device (with sizeof_priv == 0) is allocated from the size-2048 cache and thus we have ~1000 wasted bytes.

I know, that this is not that much, all the more so on most of the setups the lo device is single :) but with the net-namespaced kernel each namespace has its own loopback device, so this problem becomes more relevant.

I also guess, that the net_device struct allows many ways to get shrunk, but I noticed, that is has ~20 pointers on functions for different purposes, like init, hard_start_xmit, neigh_setup, etc.

The proposal is to _move_ all these callbacks on a new structure called net_device_ops and put a pointer on it on the net_device. I've checked how much will the net_device weigh after this and it turned out, that this difference (80 bytes) is enough to get the 1024-sized net_device and thus a halved loopback.

To make this change smooth, I propose the following plan (however, three patches I sent will demonstrate the idea better).

* First - declare an empty nd_default_ops and make all new devices point on this new ops temporarily.
* Then replace each call to dev->xxx() with the dev->nd_ops->xxx() one step by step. The ns_ops->xxx() will be the nd_default_ops->xxx then and they all will (temporarily) look like

	static void nd_default_xxx(struct net_device *dev, ...)
	{
		if (dev->xxx)
			dev->xxx(dev, ...)
	}

* After this patch switch all the drivers (lots of work :( but it can be done driver-by-driver, i.e. without HUGE patches) from on-device ops to nd_ops pointer.
* Finally - remove all the ops from the net_device and the default stubs described above.

Does this idea worth being developed further?

Thanks,
Pavel