Skip to contentSkip to conversation

Do not allocate unneeded memory for dev->priv alignment.

PATCH In review Pavel Emelyanov 3 participants 5 messages Apr 7, 2008 – Apr 16, 2008

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 2/2 Do not allocate unneeded memory for dev->priv alignment.

The alloc_netdev_mq() tries to produce 32-bytes alignment for both the net_device itself and its private data. The second alignment is achieved by adding the NETDEV_ALIGN_CONST to the whole size of the memory to be allocated.

However, for those devices that do not need the private area, this addition just makes the net_device weight 1024 + 32 = 1068 bytes, i.e. consume twice as much memory.

Since loopback device is such (sizeof_priv == 0 for it), and each net namespace creates one, this can save a noticeable amount of memory for kernel with net namespaces turned on.

After this set the lo device is actually allocated from a size-1024 kmem cache on i386 box even with NETPOLL and WIRELESS_EXT turned on.

---
 net/core/dev.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
net/core/dev.c +2 -1
index 7aa0112..80e103a 100644
@@ -4000,7 +4000,8 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
 	alloc_size = (sizeof(*dev) + NETDEV_ALIGN_CONST +
 		     (sizeof(struct net_device_subqueue) * (queue_count - 1))) &
 		     ~NETDEV_ALIGN_CONST;
-	alloc_size += sizeof_priv + NETDEV_ALIGN_CONST;
+	if (sizeof_priv)
+		alloc_size += sizeof_priv + NETDEV_ALIGN_CONST;
 
 	p = kzalloc(alloc_size, GFP_KERNEL);
 	if (!p) {
Signature · 1 line
1.5.3.4
#1 lore raw

Pavel Emelyanov wrote, On 04/07/2008 06:31 PM:
...

Quoted 9 lines
---
 net/core/dev.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
net/core/dev.c +0 -0
index 7aa0112..80e103a 100644

net/core/dev.c struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name, · line 4007

Quoted 9 lines
net/core/dev.c +2 -1
@@ -4000,7 +4000,8 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
 	alloc_size = (sizeof(*dev) + NETDEV_ALIGN_CONST +
 		     (sizeof(struct net_device_subqueue) * (queue_count - 1))) &
 		     ~NETDEV_ALIGN_CONST;
-	alloc_size += sizeof_priv + NETDEV_ALIGN_CONST;
+	if (sizeof_priv)
+		alloc_size += sizeof_priv + NETDEV_ALIGN_CONST;
 
 	p = kzalloc(alloc_size, GFP_KERNEL);
 	if (!p) {

IMHO this second "+ NETDEV_ALIGN_CONST" is needed here because of "~NETDEV_ALIGN_CONST".

Regards,
Jarek P.

#2 lore raw
Quoted 19 lines · Jarek Poplawski

Pavel Emelyanov wrote, On 04/07/2008 06:31 PM:
...

Quoted 16 lines
---
 net/core/dev.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
net/core/dev.c +2 -1
index 7aa0112..80e103a 100644
@@ -4000,7 +4000,8 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
 	alloc_size = (sizeof(*dev) + NETDEV_ALIGN_CONST +
 		     (sizeof(struct net_device_subqueue) * (queue_count - 1))) &
 		     ~NETDEV_ALIGN_CONST;
-	alloc_size += sizeof_priv + NETDEV_ALIGN_CONST;
+	if (sizeof_priv)
+		alloc_size += sizeof_priv + NETDEV_ALIGN_CONST;
 
Quoted 5 lines

net/core/dev.c struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name, · line 4007

Quoted 2 lines
net/core/dev.c +0 -0
 	p = kzalloc(alloc_size, GFP_KERNEL);
 	if (!p) {

IMHO this second "+ NETDEV_ALIGN_CONST" is needed here because of "~NETDEV_ALIGN_CONST".

Hmm, AFAIC, the net_device alignment is done earlier, while this one makes sense in case the priv pointer alignment.

Quoted 3 lines

Regards,
Jarek P.

#3 lore raw
Quoted 20 lines · Pavel Emelyanov
Quoted 19 lines · Jarek Poplawski

Pavel Emelyanov wrote, On 04/07/2008 06:31 PM:
...

Quoted 16 lines
---
 net/core/dev.c |    3 ++-
 1 files changed, 2 insertions(+), 1 deletions(-)
net/core/dev.c +2 -1
index 7aa0112..80e103a 100644
@@ -4000,7 +4000,8 @@ struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name,
 	alloc_size = (sizeof(*dev) + NETDEV_ALIGN_CONST +
 		     (sizeof(struct net_device_subqueue) * (queue_count - 1))) &
 		     ~NETDEV_ALIGN_CONST;
-	alloc_size += sizeof_priv + NETDEV_ALIGN_CONST;
+	if (sizeof_priv)
+		alloc_size += sizeof_priv + NETDEV_ALIGN_CONST;
 
Quoted 8 lines
Quoted 5 lines

net/core/dev.c struct net_device *alloc_netdev_mq(int sizeof_priv, const char *name, · line 4007

Quoted 2 lines
net/core/dev.c +0 -0
 	p = kzalloc(alloc_size, GFP_KERNEL);
 	if (!p) {

IMHO this second "+ NETDEV_ALIGN_CONST" is needed here because of "~NETDEV_ALIGN_CONST".

Hmm, AFAIC, the net_device alignment is done earlier, while this one makes sense in case the priv pointer alignment.

Hmm, one NETDEV_ALIGN_CONST is later used just for net_device alignment, and you could not fit this struct after "~NETDEV_ALIGN_CONST" without adding anything. So you should probably skip "~NETDEV_ALIGN_CONST" in this no priv case too?

Jarek P.

maintainer
#4 lore raw

From: Jarek Poplawski <[email protected]>
Date: Tue, 8 Apr 2008 09:22:53 +0000

Quoted 8 lines · Pavel Emelyanov
Quoted 2 lines

Hmm, AFAIC, the net_device alignment is done earlier, while this one makes sense in case the priv pointer alignment.

Hmm, one NETDEV_ALIGN_CONST is later used just for net_device alignment, and you could not fit this struct after "~NETDEV_ALIGN_CONST" without adding anything. So you should probably skip "~NETDEV_ALIGN_CONST" in this no priv case too?

The Linux NETDEV Patch Robot has determined that these other NETDEV_ALIGN_CONST instances need to be retained, therefore Pavel's patch will be applied to net-2.6.26.

*beep* *beep*

Thank you for your valuable feedback.

*beep* *beep*

Keep hacking.