glibc/malloc
Carlos O'Donell ca6be1655b Use ALIGN_DOWN in systrim.
While doing code review I converted another bespoke round down, and
corrected a comment.

The comment spoke about keeping at least one page allocated even
during systrim, which is not correct. The code does nothing to keep
a page allocated. The code does attempt to keep PAD padding as
documented in comments and MINSIZE as required by design.

Historically in 2002 when Ulrich wrote the code (fa8d436c) the math
was inlined into one statement which did reserve an extra page:
extra = ((top_size - pad - MINSIZE + (pagesz-1)) / pagesz - 1) * pagesz;
There is no reason given for this extra page.

In 2010 Anton Branchard's change (b9b42ee0) from division
to shifts removed the extra page by dropping the "+ (pagesiz-1), which
mean we might have attempted to return -0 via MORECORE. The fix by Will
Newton in 2014 added a check for extra being zero (51a7380b).

From first principles I see no reason why we should keep an extra
page of memory from being trimmed back to the OS. The only sensible
interface is to honour PAD padding as the function is documented,
with the caveat the MINSIZE is maintained for the top chunk.

Given that we've been using this code for 5+ years with no extra
page allocated is sufficient evidence that the comment should be changed
to match the code that I'm touching.

Tested on x86_64 and i686, no regressions.
2015-09-14 15:32:47 -04:00
..
arena.c
Depend
hooks.c
Makefile
malloc.c Use ALIGN_DOWN in systrim. 2015-09-14 15:32:47 -04:00
malloc.h
mallocbug.c
mcheck-init.c
mcheck.c
mcheck.h
memusage.c
memusage.sh
memusagestat.c
morecore.c
mtrace.c Move bits/libc-lock.h and bits/libc-lockP.h out of bits/ (bug 14912). 2015-09-08 21:11:03 +00:00
mtrace.pl Filter out NULL entries. 2015-09-01 08:35:38 -07:00
obstack.c
obstack.h
scratch_buffer_grow_preserve.c
scratch_buffer_grow.c
scratch_buffer_set_array_size.c
set-freeres.c
thread-freeres.c
tst-calloc.c
tst-malloc-backtrace.c
tst-malloc-usable.c
tst-malloc.c
tst-mallocfork.c
tst-mallocstate.c
tst-mallopt.c
tst-mcheck.c
tst-memalign.c
tst-mtrace.c
tst-mtrace.sh
tst-obstack.c
tst-posix_memalign.c
tst-pvalloc.c
tst-realloc.c
tst-scratch_buffer.c
tst-trim1.c
tst-valloc.c
Versions