I am confused about heapand free list. I have a few questions, and I have my own understanding of how malloc works in C. Please correct me if I am wrong.
heap
free list
My understanding of memory allocation (available for improvement): - When we call malloc, it allocates memory on the heap, and it does this by selecting a data block of the appropriate size from free list, right?
When a specific memory block is returned by malloc, it is removed from the free list, and the physical address of this memory block is updated in the page table.
When the memory is free using free(), the data block is inserted back into the free list and possibly reduces the fragmentation connected to the neighboring block, and the bit presentin the page table entry is cleared.
free()
present
Thus, the whole heap is a free list (a linked list of free blocks) + allocated data blocks.
Is this a general picture of memory allocation?
EDIT: from Linux kernel development (Robert Love) Chapter on memory management, Slab allocation
" , . , , . , , . , ."
" , ".
malloc() ; , , .
malloc()
malloc() brk(), . , :
brk()
, (), , , . free() , , free() brk() , . , , " " malloc().
, , , , . Robert Love , Linux, malloc() . , , -.
, , - . @Wyzard, malloc brk (sbrk, mmap), . malloc , , . .
- . mmap brk , , . , . - , . - , , .
, :
- . , , . , , , , , . , , , ( ), .
, , , ( ). , , , - .
( ). slab - , . , , . , x86 16 4 ( 64- ). , , , .
, , , . , .
,
C .
c call_stack, malloc. _break, sbrk(), .
Linux task_struct, .