mirror of git://sourceware.org/git/glibc.git
* malloc/arena.c (grow_heap): Split out code to shrink heap into...
(shrink_heap): ... this new function. (heap_trim): Call shrink_heap instead of grow_heap.
This commit is contained in:
parent
17edb30c62
commit
cbf5760e62
|
|
@ -1,5 +1,9 @@
|
||||||
2007-12-11 Ulrich Drepper <drepper@redhat.com>
|
2007-12-11 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
|
* malloc/arena.c (grow_heap): Split out code to shrink heap into...
|
||||||
|
(shrink_heap): ... this new function.
|
||||||
|
(heap_trim): Call shrink_heap instead of grow_heap.
|
||||||
|
|
||||||
* malloc/malloc.c (_int_malloc): sYSMALLOc might fail, in this
|
* malloc/malloc.c (_int_malloc): sYSMALLOc might fail, in this
|
||||||
case don't call alloc_perturb.
|
case don't call alloc_perturb.
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -704,8 +704,8 @@ new_heap(size, top_pad) size_t size, top_pad;
|
||||||
return h;
|
return h;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Grow or shrink a heap. size is automatically rounded up to a
|
/* Grow a heap. size is automatically rounded up to a
|
||||||
multiple of the page size if it is positive. */
|
multiple of the page size. */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
#if __STD_C
|
#if __STD_C
|
||||||
|
|
@ -717,7 +717,6 @@ grow_heap(h, diff) heap_info *h; long diff;
|
||||||
size_t page_mask = malloc_getpagesize - 1;
|
size_t page_mask = malloc_getpagesize - 1;
|
||||||
long new_size;
|
long new_size;
|
||||||
|
|
||||||
if(diff >= 0) {
|
|
||||||
diff = (diff + page_mask) & ~page_mask;
|
diff = (diff + page_mask) & ~page_mask;
|
||||||
new_size = (long)h->size + diff;
|
new_size = (long)h->size + diff;
|
||||||
if((unsigned long) new_size > (unsigned long) HEAP_MAX_SIZE)
|
if((unsigned long) new_size > (unsigned long) HEAP_MAX_SIZE)
|
||||||
|
|
@ -729,8 +728,23 @@ grow_heap(h, diff) heap_info *h; long diff;
|
||||||
return -2;
|
return -2;
|
||||||
h->mprotect_size = new_size;
|
h->mprotect_size = new_size;
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
new_size = (long)h->size + diff;
|
h->size = new_size;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Shrink a heap. */
|
||||||
|
|
||||||
|
static int
|
||||||
|
#if __STD_C
|
||||||
|
shrink_heap(heap_info *h, long diff)
|
||||||
|
#else
|
||||||
|
shrink_heap(h, diff) heap_info *h; long diff;
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
long new_size;
|
||||||
|
|
||||||
|
new_size = (long)h->size - diff;
|
||||||
if(new_size < (long)sizeof(*h))
|
if(new_size < (long)sizeof(*h))
|
||||||
return -1;
|
return -1;
|
||||||
/* Try to re-map the extra heap space freshly to save memory, and
|
/* Try to re-map the extra heap space freshly to save memory, and
|
||||||
|
|
@ -741,17 +755,17 @@ grow_heap(h, diff) heap_info *h; long diff;
|
||||||
if (1)
|
if (1)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if((char *)MMAP((char *)h + new_size, -diff, PROT_NONE,
|
if((char *)MMAP((char *)h + new_size, diff, PROT_NONE,
|
||||||
MAP_PRIVATE|MAP_FIXED) == (char *) MAP_FAILED)
|
MAP_PRIVATE|MAP_FIXED) == (char *) MAP_FAILED)
|
||||||
return -2;
|
return -2;
|
||||||
h->mprotect_size = new_size;
|
h->mprotect_size = new_size;
|
||||||
}
|
}
|
||||||
#ifdef _LIBC
|
#ifdef _LIBC
|
||||||
else
|
else
|
||||||
madvise ((char *)h + new_size, -diff, MADV_DONTNEED);
|
madvise ((char *)h + new_size, diff, MADV_DONTNEED);
|
||||||
#endif
|
#endif
|
||||||
/*fprintf(stderr, "shrink %p %08lx\n", h, new_size);*/
|
/*fprintf(stderr, "shrink %p %08lx\n", h, new_size);*/
|
||||||
}
|
|
||||||
h->size = new_size;
|
h->size = new_size;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
@ -811,7 +825,7 @@ heap_trim(heap, pad) heap_info *heap; size_t pad;
|
||||||
if(extra < (long)pagesz)
|
if(extra < (long)pagesz)
|
||||||
return 0;
|
return 0;
|
||||||
/* Try to shrink. */
|
/* Try to shrink. */
|
||||||
if(grow_heap(heap, -extra) != 0)
|
if(shrink_heap(heap, extra) != 0)
|
||||||
return 0;
|
return 0;
|
||||||
ar_ptr->system_mem -= extra;
|
ar_ptr->system_mem -= extra;
|
||||||
arena_mem -= extra;
|
arena_mem -= extra;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue