*BSD News Article 45953


Return to BSD News archive

Path: sserve!newshost.anu.edu.au!harbinger.cc.monash.edu.au!simtel!noc.netcom.net!news.sprintlink.net!howland.reston.ans.net!swrinde!elroy.jpl.nasa.gov!usc!sol.ctr.columbia.edu!hamblin.math.byu.edu!park.uvsc.edu!usenet
From: Terry Lambert <terry@cs.weber.edu>
Newsgroups: comp.unix.bsd.netbsd.misc
Subject: Re: sizeof (struct proc) == 256.  Why?
Date: 14 Jun 1995 00:00:58 GMT
Organization: Utah Valley State College, Orem, Utah
Lines: 45
Message-ID: <3rl8rq$ije@park.uvsc.edu>
References: <3rkiee$o5i@siesta.cs.wustl.edu>
NNTP-Posting-Host: hecate.artisoft.com

amc@siesta.cs.wustl.edu (Adam M. Costello) wrote:
] In NetBSD, sizeof (struct proc) == 256.  There is even a p_spare member
] whose only purpose is to pad the structure up to 256 bytes.  What is the
] reason for this?
] 
] (I'm hacking the kernel, and might want to add a few members, but I
] don't want to screw anything up.)

The same reason inodes are padded, etc.: to make it so they are
an even power of two, less than or equal to the page size.

The point in doing this should be obvious, but if it's not, consider
that pages as allocated in the kernel are not necessarily physically
contiguous, so there would be a problem if one out of 7 or 9 proc
structures (or whatever) spanned a page boundry.

There is also the issue of ensuring the structures are aligned on
efficient access boundries, and that they meet boundry alignment
restrictions for non-Intel processers (RISC processers have a
penchant for erroring out with non aligned large object accesses).

Try the following on a handy SPARC (or RS/6000 or MIPS or Alpha)
box:

	main()
	{
		int	foo = -1;
		char	*cp;
		int	*ip;

		cp = (char *)&foo;
		cp++;

		ip = (int *)cp;

		printf( "boom! 0x%08x\n", *ip);
	}



                                        Terry Lambert
                                        terry@cs.weber.edu
---
Any opinions in this posting are my own and not those of my present
or previous employers.