This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug malloc/15321] malloc/free can't give the memory back to kernel when main_arena is discontinous
- From: "ma.jiang at zte dot com.cn" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sourceware dot org
- Date: Wed, 26 Apr 2017 05:55:01 +0000
- Subject: [Bug malloc/15321] malloc/free can't give the memory back to kernel when main_arena is discontinous
- Auto-submitted: auto-generated
- References: <bug-15321-131@http.sourceware.org/bugzilla/>
https://sourceware.org/bugzilla/show_bug.cgi?id=15321
ma.jiang at zte dot com.cn changed:
What |Removed |Added
----------------------------------------------------------------------------
Attachment #10003|0 |1
is obsolete| |
Attachment #10003|test_case to show the peak |test_case to show the peak
description|memory usage retain after |memory usage retain after
|memory all freed |memory all freed(use write
| |to avoid mallocs in printf)
--- Comment #8 from ma.jiang at zte dot com.cn ---
Comment on attachment 10003
--> https://sourceware.org/bugzilla/attachment.cgi?id=10003
test_case to show the peak memory usage retain after memory all freed(use
write to avoid mallocs in printf)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/mman.h>
#include <assert.h>
#define MEM_SIZE 1024*512
char print_buf[2048];
const char msg1[1024] = "now we will see the peak physical memory usage\n";
const char msg2[1024] = "I have freed all memory, now I'm using \n";
int main(int argc,char *argv[])
{
int i = 0;
void **mem = (void**) malloc(sizeof(void*) * MEM_SIZE * 2);;
for (; i < MEM_SIZE;i++)
{
mem[i]=malloc(4096);
if(mem[i] == NULL)
{
printf("malloc failed.\n");
exit(1);
}
}
void *tt = mmap(mem[i-1]+1024*1024, 1024*213, PROT_READ |
PROT_WRITE,MAP_SHARED | MAP_ANONYMOUS, -1, 0);
for (; i < MEM_SIZE * 2; i++)
{
mem[i]=malloc(4096);
if(mem[i] == NULL)
{
printf("malloc failed.\n");
exit(1);
}
}
char cmd[1024];
write(1, msg1, strlen(msg1));
snprintf(cmd, sizeof(cmd), "cat /proc/%d/status |grep VmRSS:",
getpid());
system(cmd);
while(i--)
{
free(mem[i]);
mem[i]=NULL;
}
free(mem);
//assert(malloc_trim(0)==1);
write(1, msg2, strlen(msg2));
system(cmd);
return 0;
}
--
You are receiving this mail because:
You are on the CC list for the bug.