Mercurial > hg > orthanc
comparison OrthancServer/Resources/ImplementationNotes/memory_consumption.txt @ 5159:f5907aecbaed
conditional usage of malloc_trim
author | Alain Mazy <am@osimis.io> |
---|---|
date | Thu, 02 Feb 2023 11:28:35 +0100 |
parents | 02cfd23a556a |
children | 566e8d32bd3a |
comparison
equal
deleted
inserted
replaced
5158:02cfd23a556a | 5159:f5907aecbaed |
---|---|
109 from the system. | 109 from the system. |
110 | 110 |
111 Malloc_trim returns 1 if it actually released any memory, else 0. | 111 Malloc_trim returns 1 if it actually released any memory, else 0. |
112 On systems that do not support "negative sbrks", it will always | 112 On systems that do not support "negative sbrks", it will always |
113 return 0. | 113 return 0. |
114 | |
115 | |
116 glibc internals | |
117 --------------- | |
118 | |
119 Lots of useful info here: https://man7.org/linux/man-pages/man3/mallopt.3.html | |
120 | |
121 summary: | |
122 - malloc uses sbrk() or mmap() to allocate memory. mmap() is used to allocate | |
123 large memory chunks, larger than M_MMAP_THRESHOLD. | |
124 - about mmap(): On the other hand, there are some disadvantages to | |
125 the use of mmap(2): deallocated space is not placed on the | |
126 free list for reuse by later allocations; memory may be | |
127 wasted because mmap(2) allocations must be page-aligned; | |
128 and the kernel must perform the expensive task of zeroing | |
129 out memory allocated via mmap(2). Balancing these factors | |
130 leads to a default setting of 128*1024 for the | |
131 M_MMAP_THRESHOLD parameter. | |
132 - free() employs sbrk() to release memory back to the system and M_TRIM_THRESHOLD | |
133 specifies the minimum size that is released. So, even without | |
134 malloc_trim, Orthanc is able to give back memory to the system. | |
135 - free() never gives back block allocated by mmap() to the system, only malloc_trim() does ! |