완료됨
largebin 사이즈의 청크를 요청할 때
malloc_consolidate()를 이용하여 fast bin에 있는 free chunk를 small bin에 병합을 하는데...
"large bin 사이즈 요청"과 "small bin에 fast bin 청크를 병합"하는 것이 무슨 관계가 있나요?
#시스템해킹
작성자 정보
답변
1
juno2
답변 등록: 25
https://code.woboq.org/userspace/glibc/malloc/malloc.c.html#3696
/*
If this is a large request, consolidate fastbins before continuing.
While it might look excessive to kill all fastbins before
even seeing if there is space available, this avoids
fragmentation problems normally associated with fastbins.
Also, in practice, programs tend to have runs of either small or
large requests, but less often mixtures, so consolidation is not
invoked all that often in most programs. And the programs that
it is called frequently in otherwise tend to fragment.
*/
위 mallo.c 주석에 따르면 큰 크기의 할당 요청이 들어왔을 경우 단편화를 막기 위해 남아있는 모든 fastbin을 합치게 됩니다. 또한 프로그램들은 연속적으로 작은 크기의 할당 요청 혹은 큰 크기의 할당 요청을 하기 때문에 대부분의 프로그램에서 malloc_consolidate 작업은 문제가 되지 않습니다. 이와 같은 이유로 large bin size의 할당 요청을 보내면 fastbin에 있는 청크들을 small bin과 병합하는 malloc_consolidate함수를 호출하는 것입니다.