Re: __alloc_init_space

Laurent Bercot <[email protected]>
Newsgroups gmane.linux.lib.dietlibc
Message-ID <[email protected]>
> Hi!,  I found a nice way to import DJB alloc trick in dietlibc.
> In qmail DJB uses a static buffer of 4K in alloc.c.  After using
> it is impossible to free the buffer!
> 
> I want to add such static buffer in programs with arbitrary length.

 Please don't.
 This feature works well for DJB (and a small number of other people)
because his coding style is focused on very short-lived programs, that
either exit or exec after zero, one or two malloc()s; the static buffer
trick allows these programs to not allocate anything on the heap, save
a few system calls and give a few guarantees ("program does not dynamically
allocate memory"). This is a clever, but minor, optimization.

 However, no matter how smart it is, this coding style is very specific
and a libc should be optimized for the generic case. Unfortunately, in
the generic case, the static buffer trick is actually detrimental, because
it's impossible to reclaim the 4 kB once they're used. It's one page per
executable, and it can add up.
 The diet libc implements malloc()/free() with mmap()/munmap(). This is
simple and fast, and works. And the kernel can actually reclaim a page
that has been unmapped ! This is much more useful in the general case.

 Using the static buffer trick should be a case-by-case decision, not a
system-wide decision. It belongs to the application (just as it is in
djbware right now), not to the libc.

-- 
 Laurent
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.