Re: G_MEM_ALIGN may not be correct



On Tue, 2004-12-21 at 16:46 -0800, David Mosberger wrote:
> Hi,
> 
> I hope it's appropriate to discuss glib issues on this list.  If not,
> my apologies (please direct me to a more appropriate place in that
> case).

Yes, this is the right place. (Generally good to make sure issues also
end up in bugzilla ... just because something is discussed here is
no guarantee that we'll remember to fix it.)

> I noticed that gmem.h declares:
> 
> #if GLIB_SIZEOF_VOID_P > GLIB_SIZEOF_LONG
> #  define G_MEM_ALIGN   GLIB_SIZEOF_VOID_P
> #else   /* GLIB_SIZEOF_VOID_P <= GLIB_SIZEOF_LONG */
> #  define G_MEM_ALIGN   GLIB_SIZEOF_LONG
> #endif  /* GLIB_SIZEOF_VOID_P <= GLIB_SIZEOF_LONG */
> 
> (I verified that this code is still in the CVS-version of glib.)
> 
> Unfortunately, this isn't sufficient for ia64 (and perhaps other
> platforms) because on that platform, malloc-like routines need to
> guarantee 16-byte alignment due to the fact that "long double" typed
> variables need to be 16-byte aligned.
> 
> There are several ways to solve this problem.  For example, we could
> mirror the glibc malloc, which uses 2*sizeof(size_t) alignment, or we
> could mirror what the GNU obstack implementation does (that would
> require config-time checking of alignment, though).  Of course, we
> could also just check for #ifdef __ia64, though that seems fragile and
> too platform-specific.
> 
> Does anybody have a preference for how to get this fixed?

fragment from glib/gobject/gtype.c:

/* The 2*sizeof(size_t) alignment here is borrowed from
 * GNU libc, so it should be good most everywhere.
 * It is more conservative than is needed on some 64-bit
 * platforms, but ia64 does require a 16-byte alignment.
 * The SIMD extensions for x86 and ppc32 would want a
 * larger alignment than this, but we don't need to
 * do better than malloc.
 */
#define STRUCT_ALIGNMENT (2 * sizeof (gsize))
#define ALIGN_STRUCT(offset) \
      ((offset + (STRUCT_ALIGNMENT - 1)) & -STRUCT_ALIGNMENT)

The downside of this route in in gmem.c is that we take GList (etc.)
nodes on x86_64 (etc.) and change them from 24 bytes to 32 bytes.
Which is a fair bit of memory wastage. So, perhaps adding configure
checks
or platform specifics for G_MEM_ALIGN (used only for memchunks) makes
sense. 

Regards,
						Owen

Attachment: signature.asc
Description: This is a digitally signed message part



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