Re: 'net_device' padding

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 9 Feb 2007 17:36:27 +0900 Roman Mashak wrote:

> Hello,
> 
> as I understood 'dev_base' points to the beginning of 'net_device' 
> structure, not to the beginning of block allocated by alloc_netdev().

What 'dev_base' is that?  The global dev_base is a linked list
of all struct net_device's in the system.

> So 'net_device' introduces a field named 'padded', which is used to get the 
> start address of the whole memory block.

OK, back to each struct net_device.

> What I don't understand is:
> 1) how come that this structure needs any padding

Each struct net_device allocation is padded to 32 bytes.  I guess
this is for cacheline alignment, but I don't see any comments
about that.

> 2) where is this padding physically done - at the head of structure or on 
> the end?

Yes.  It depends on where kzalloc() returned memory.

	p = kzalloc(alloc_size, GFP_KERNEL);
	if (!p) {
		printk(KERN_ERR "alloc_netdev: Unable to allocate device.\n");
		return NULL;
	}

	dev = (struct net_device *)
		(((long)p + NETDEV_ALIGN_CONST) & ~NETDEV_ALIGN_CONST);
	dev->padded = (char *)dev - (char *)p;

kzalloc() returns p, then p is adjusted to the next 32-byte
boundary (if it's already on a 32-byte boundardy, it won't be
changed).  So dev could be 'p' increased by any value from 0 to
28.

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux