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

Re: Memory alignment of pointers for sparc64



On Thu, 5 Sep 2002, Ben Collins wrote:

> On Wed, Sep 04, 2002 at 11:06:04PM -0700, Bill Moseley wrote:
> 
> I'm pretty sure you mean sparc and not sparc64 (even if you are running
> an ultra, it is still 32bit userspace). On sparc64, sizeof(void *) does
> in fact equal 8bytes (64bit bins).

Well, my knowledge of this stuff is poor.  On the sourceforge machine:

http://sourceforge.net/docman/display_doc.php?docid=10472&group_id=1#usf-cf-sparc-linux-1

It's returning sizeof(void *) == 4.

About all I understand of this problem is that our code allocates memory
on 4-byte boundaries, and that cased SIGBUS on this one machine.  I
printed out the results of malloc() calls and noticed it was always on
8-byte boundaries.  Hard-coding to 8-byte fixed our code.

>From the debian page I read that this runs 64 bit kernel and 32 bit user
space, so then I assumed (the important word here ;) ) the 8-byte
allocations were a hardware requirement.


> Why not force minimum 8byte allocations? Will it really cause that much
> of a usage problem? Would probably cause less fragmentation, I bet.

The point of this code is to allocate a lot of very small chunks of memory
that are not released.  Fragmentation is not an issue since the memmory is
not freed.

> Guess you could do:
> 
> #ifdef __sparc__
> # define PointerAlign 8
> #else
> # define PointerAlign sizeof(void *)
> #endif

That's what I was doing, but didn't want to use up space when it wasn't
necessary, since the point of the code was to reduce wasted memory.

> What was wrong with the original usage of sizeof(long)?

Good question.  That's my ignorance.  I assumed it was an addressing issue
-- that the SIGBUS was due to addressing incorrectly.  Is is really an
issue of trying to write a long into a location?  If so, then I suspect I
should be using sizeof(long).

I'll look at obstack, but in the mean time it seems like I have four
options:

1) set for 8 bytes on all __sparc__ machines.  that will waste a little
extra memory for each small call.

2) keep trying to find a defined() value that I could check (how does
malloc() know that it needs to be 8-byte aligned?)

3) find some autoconf macro that somehow checks this and sets a define.

4) allow a ./configure option to set some define -- (hey, the point of
autoconf is to be "auto")

Number two seems to the be best option, but I'm not sure how portable that
is.  Perhaps option four is the easiest.

I'll also run some tests with setting it to 8 bytes and see just how much
more RAM gets used.

Thanks very much for the help, Ben.


-- 
Bill Moseley moseley@hank.org



Reply to: