free(), getpagesize(), and space optimizations.

Peter Barfuss bofh.h4x at gmail.com
Thu Dec 16 10:06:13 UTC 2010


Hi,

In its current implementation, free() needs to call malloc_getpagesize
once in order to determine the size of a page (most commonly 4K, but
ultimately architecture/CPU model-dependent). Thus malloc_getpagesize
calls code to detect it at load: problem: currently this routine is
sysconf(_SC_PAGESIZE). Despite this basically immediately collapsing
to a call to getpagesize() internally in sysconf.c, followed by a
break and a return, the linker is unable to actually optimize
statically linking in the relevant portions of sysconf(), as it cannot
tell that you don't need all of sysconf() and its associated API
helper functions, linking in about 5K worth of garbage code, which is
sort of annoying.

The way I patched it is by making malloc_getpagesize refer directly to
__getpagesize(), which seems to be exactly the way that it's done
internally in sysconf() anyway, and I have not had any issues with
this, despite running a lot of software under it since, so I've
decided to forward the patch here.

Comments?

-Peter
-------------- next part --------------
A non-text attachment was scrubbed...
Name: getpagesize.diff
Type: application/octet-stream
Size: 272 bytes
Desc: not available
URL: <http://lists.busybox.net/pipermail/uclibc/attachments/20101216/5a10f6e5/attachment.obj>


More information about the uClibc mailing list