public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug malloc/27976] New: When the last heap in the user process into the non-main area has memory in use, even if the previous heap is already free, the previous heap will not be released
@ 2021-06-10 10:03 liu.dongyun at h3c dot com
  2021-06-10 10:45 ` [Bug malloc/27976] " liu.dongyun at h3c dot com
  2021-06-15  1:34 ` liu.dongyun at h3c dot com
  0 siblings, 2 replies; 3+ messages in thread
From: liu.dongyun at h3c dot com @ 2021-06-10 10:03 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=27976

            Bug ID: 27976
           Summary: When the last heap in the user process into the
                    non-main area has memory in use, even if the previous
                    heap is already free, the previous heap will not be
                    released
           Product: glibc
           Version: 2.17
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: malloc
          Assignee: unassigned at sourceware dot org
          Reporter: liu.dongyun at h3c dot com
  Target Milestone: ---

bug:The system has a total of 32G memory. When the last heap in the user
process into the non-main area has memory in use, even if the previous heap is
already free, the previous heap will not be released, resulting in the memory
cache reaching 20G.


for example:
I create a new thread and malloc(2000Bytes), the thread will attached to
non-main-arena.I trim the heap->size = 512*1024 befor test ,then run the follow
code. we can see the pLast not free,then the non-main-arena memory not free
.This may cause the memory cached in the non-main-area to be unusable after the
memory usage reaches its peak, and even most of the memory of the entire system
can be cached.When the last pLast of memory is released, most of the memory in
the entire non-main-area will be released to the system.

I tried to solve this problem by checking to release the heap that the current
chunk belongs to and unmmaped if it is all free.The method has achieved good
results.
---------------------------------------------------
void *pLast = NULL;
void  *free_last()
{
        free(pLast);
        return NULL;
}
void func1()
{
        void *pp[10240];
        int i = 0;

        for(i=0;i<10230;i++){

                pp[i] = malloc(2048);
                memset(pp[i], 0, 2048);
        }

        pLast = malloc(2048);
        printf("pLast == %p     \n",pLast);
        memset(pLast, 0, 2048);

        for(i=0;i<10230;i++)
      free(pp[i]);

     printf("finish  malloc free \n");

}

int main()
{
        int i = 0;
        void *p = NULL;
        pthread_t  tid;
        p = malloc(1024);
        memset(p, 0, 1024);
        pthread_create(&tid, NULL, func1, NULL);

        while(1)
        {
                i++;
                sleep(10);
        }

        free_last();

}
---------------------------------------------------

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug malloc/27976] When the last heap in the user process into the non-main area has memory in use, even if the previous heap is already free, the previous heap will not be released
  2021-06-10 10:03 [Bug malloc/27976] New: When the last heap in the user process into the non-main area has memory in use, even if the previous heap is already free, the previous heap will not be released liu.dongyun at h3c dot com
@ 2021-06-10 10:45 ` liu.dongyun at h3c dot com
  2021-06-15  1:34 ` liu.dongyun at h3c dot com
  1 sibling, 0 replies; 3+ messages in thread
From: liu.dongyun at h3c dot com @ 2021-06-10 10:45 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=27976

--- Comment #1 from liudongyun <liu.dongyun at h3c dot com> ---
Created attachment 13490
  --> https://sourceware.org/bugzilla/attachment.cgi?id=13490&action=edit
my idea

When the user calls the free function, check whether the heap where the current
chunk is located is free, and if so, release the entire heap

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Bug malloc/27976] When the last heap in the user process into the non-main area has memory in use, even if the previous heap is already free, the previous heap will not be released
  2021-06-10 10:03 [Bug malloc/27976] New: When the last heap in the user process into the non-main area has memory in use, even if the previous heap is already free, the previous heap will not be released liu.dongyun at h3c dot com
  2021-06-10 10:45 ` [Bug malloc/27976] " liu.dongyun at h3c dot com
@ 2021-06-15  1:34 ` liu.dongyun at h3c dot com
  1 sibling, 0 replies; 3+ messages in thread
From: liu.dongyun at h3c dot com @ 2021-06-15  1:34 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=27976

liudongyun <liu.dongyun at h3c dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Version|2.17                        |2.33

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-06-15  1:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-10 10:03 [Bug malloc/27976] New: When the last heap in the user process into the non-main area has memory in use, even if the previous heap is already free, the previous heap will not be released liu.dongyun at h3c dot com
2021-06-10 10:45 ` [Bug malloc/27976] " liu.dongyun at h3c dot com
2021-06-15  1:34 ` liu.dongyun at h3c dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).