SlideShare a Scribd company logo
1 of 16
Download to read offline
Understanding DLmalloc
Haifeng Li
2014-4-10
Outline
• Why Use DLmalloc
• Basic structures
– Chunk & Bins
• Key Algorithms
– Memory allocation
• Small request
• Large request
– Realloc
– Free
– Trim
Why Use DLmalloc
• If don’t use DLmalloc
– Application should use system call brk or sbrk to
get memory from Kernel.
– Disadvantage:
• Will trap into the kernel
• Lost cache locality
• Key role of DLmalloc
– Maintain the free bulks for next use without
system call.
Chunk & bins
• All available space are organized by chunks in
DLmalloc.
– Small chunk: Chunk size [16,248]
– Large chunk: Chunk size [256, 2^31]
• All available chunks are maintained in bins,
grouped by size.
– Small chunk corresponds to smallbins
– Large chunk corresponds to largebins
Small Chunk
Allocated
prev size
Current size| status
Free
Front pointer
Back pointer
Data
prev size
Current size| status
Data
Allocated
struct malloc_chunk {
size_t prev_foot; /* Size of previous chunk (if free). */
size_t head; /* Size and inuse bits. */
struct malloc_chunk* fd; /* double links -- used only if free. */
struct malloc_chunk* bk;
}; #define SIZE_T_ONE ((size_t)1)
#define SIZE_T_TWO ((size_t)2)
#define PINUSE_BIT (SIZE_T_ONE)
#define CINUSE_BIT (SIZE_T_TWO)
Small bins
43210 3130292827...
chunk
...
...
chunk
chunk
...
chunk
43210smallmap ...
smallbins
...
chunk
16 248index>>3
...
Large Chunk
Allocated
prev size
Current size| status
Free
Front pointer
Back pointer
Unused Data
prev size
Current size| status
Data
Allocated
Child 0
Child 1
parent
struct malloc_tree_chunk {
/* The first four fields must be compatible with malloc_chunk */
size_t prev_foot;
size_t head;
struct malloc_tree_chunk* fd;
struct malloc_tree_chunk* bk;
struct malloc_tree_chunk* child[2];
struct malloc_tree_chunk* parent;
bindex_t index;
};
Large bins
The tree is named Tries.
[768,1024)[512,768)[384,512)[256,384) ........
node
node
chunk chunk
43210largemap ...
largebins
...
node
chunk chunk
Management structure
struct malloc_state {
binmap_t smallmap;
binmap_t treemap;
size_t dvsize;
size_t topsize;
…
mchunkptr dv;
mchunkptr top;
…
mchunkptr smallbins[(NSMALLBINS+1)*2];
tbinptr treebins[NTREEBINS];
…
msegment seg;
…
};
Reference: http://g.oswego.edu/dl/html/malloc.html
Optimization
• Designed Victim
– This is the preferred chunk for servicing small
requests that don't have exact fits. It is normally
the chunk split off most recently to service
another small request. Its size is cached in dvsize.
The link fields of this chunk are not maintained
since it is not kept in a bin.
Small Request Algorithm
1. If one exists, use a remainderless chunk in
associated smallbin.
2. If it is big enough, use the dv chunk.
3. If big enough and bigger chunk exists, split
the smallest available chunk in a bin(small
bin or larger bin), saving remainder in dv.
4. If it is big enough, use the top chunk.
5. If available, get memory from system and use
it
Get memory from system
1. If Top is empty and request bigger than
256KB
– Use mmap(). mmaped chunk’s head doesn’t use
status bit.(art’s case doesn’t use mmap())
2. Use brk to allocated page-align of request.
3. If brk fails, use mmap().(mmap is enabled)
4. Give back old top to chunk bins and use new
allocated space as top.
Large Request
1. Find the smallest available binned chunk that
fits, and use it. if it is better fitting than dv
chunk, splitting if necessary.
2. If better fitting than any binned chunk, use
the dv chunk.
3. If it is big enough, use the top chunk.
4. If available, get memory from system(brk or
mmap) and use it
realloc Pseudo-code
• void* dlrealloc(void* oldmem, size_t bytes)
– If oldmem = 0, call dlmalloc(bytes).
– If bytes = 0, call dlfree(oldmem).
– If bytes < oldsize and gap >16, split off remainder
– If bytes > oldsize
• If the adjacent chunk is free and big enough, extend it.
• Else
» call dlmalloc(bytes)
» memcpy it to new space.
» Give oldspace back to chunklist.
Free
• If free chunk is mapped(by mmap()), just
munmap it.
• Else try to merge previous and next free
chunk , insert into small/large chunk bins
except for Top and DV.
Trim
• If Top size is larger than 2MB, will call sys_trim.
– unmap or sbrk top space to 1 Page
– unmap all free mmapped segments

More Related Content

What's hot

Admission Control in Impala
Admission Control in ImpalaAdmission Control in Impala
Admission Control in Impala
Cloudera, Inc.
 
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
You didnt see it’s coming? "Dawn of hardened Windows Kernel" You didnt see it’s coming? "Dawn of hardened Windows Kernel"
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
Peter Hlavaty
 
[CB16] House of Einherjar :GLIBC上の新たなヒープ活用テクニック by 松隈大樹
[CB16] House of Einherjar :GLIBC上の新たなヒープ活用テクニック by 松隈大樹[CB16] House of Einherjar :GLIBC上の新たなヒープ活用テクニック by 松隈大樹
[CB16] House of Einherjar :GLIBC上の新たなヒープ活用テクニック by 松隈大樹
CODE BLUE
 
研究動向から考えるx86/x64最適化手法
研究動向から考えるx86/x64最適化手法研究動向から考えるx86/x64最適化手法
研究動向から考えるx86/x64最適化手法
Takeshi Yamamuro
 

What's hot (20)

Physical Memory Management.pdf
Physical Memory Management.pdfPhysical Memory Management.pdf
Physical Memory Management.pdf
 
Admission Control in Impala
Admission Control in ImpalaAdmission Control in Impala
Admission Control in Impala
 
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
You didnt see it’s coming? "Dawn of hardened Windows Kernel" You didnt see it’s coming? "Dawn of hardened Windows Kernel"
You didnt see it’s coming? "Dawn of hardened Windows Kernel"
 
Slab Allocator in Linux Kernel
Slab Allocator in Linux KernelSlab Allocator in Linux Kernel
Slab Allocator in Linux Kernel
 
Ceph Day Beijing - Ceph All-Flash Array Design Based on NUMA Architecture
Ceph Day Beijing - Ceph All-Flash Array Design Based on NUMA ArchitectureCeph Day Beijing - Ceph All-Flash Array Design Based on NUMA Architecture
Ceph Day Beijing - Ceph All-Flash Array Design Based on NUMA Architecture
 
[CB16] House of Einherjar :GLIBC上の新たなヒープ活用テクニック by 松隈大樹
[CB16] House of Einherjar :GLIBC上の新たなヒープ活用テクニック by 松隈大樹[CB16] House of Einherjar :GLIBC上の新たなヒープ活用テクニック by 松隈大樹
[CB16] House of Einherjar :GLIBC上の新たなヒープ活用テクニック by 松隈大樹
 
Cassandra by example - the path of read and write requests
Cassandra by example - the path of read and write requestsCassandra by example - the path of read and write requests
Cassandra by example - the path of read and write requests
 
MacOS memory allocator (libmalloc) Exploitation
MacOS memory allocator (libmalloc) ExploitationMacOS memory allocator (libmalloc) Exploitation
MacOS memory allocator (libmalloc) Exploitation
 
Overlayfs and VFS
Overlayfs and VFSOverlayfs and VFS
Overlayfs and VFS
 
DataStax: Extreme Cassandra Optimization: The Sequel
DataStax: Extreme Cassandra Optimization: The SequelDataStax: Extreme Cassandra Optimization: The Sequel
DataStax: Extreme Cassandra Optimization: The Sequel
 
Bucket your partitions wisely - Cassandra summit 2016
Bucket your partitions wisely - Cassandra summit 2016Bucket your partitions wisely - Cassandra summit 2016
Bucket your partitions wisely - Cassandra summit 2016
 
The Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast StorageThe Linux Block Layer - Built for Fast Storage
The Linux Block Layer - Built for Fast Storage
 
Ceph Day Taipei - Accelerate Ceph via SPDK
Ceph Day Taipei - Accelerate Ceph via SPDK Ceph Day Taipei - Accelerate Ceph via SPDK
Ceph Day Taipei - Accelerate Ceph via SPDK
 
研究動向から考えるx86/x64最適化手法
研究動向から考えるx86/x64最適化手法研究動向から考えるx86/x64最適化手法
研究動向から考えるx86/x64最適化手法
 
Spark tunning in Apache Kylin
Spark tunning in Apache KylinSpark tunning in Apache Kylin
Spark tunning in Apache Kylin
 
Understanding DPDK algorithmics
Understanding DPDK algorithmicsUnderstanding DPDK algorithmics
Understanding DPDK algorithmics
 
The Impala Cookbook
The Impala CookbookThe Impala Cookbook
The Impala Cookbook
 
Log Structured Merge Tree
Log Structured Merge TreeLog Structured Merge Tree
Log Structured Merge Tree
 
Linux tuning to improve PostgreSQL performance
Linux tuning to improve PostgreSQL performanceLinux tuning to improve PostgreSQL performance
Linux tuning to improve PostgreSQL performance
 
Memory Management with Page Folios
Memory Management with Page FoliosMemory Management with Page Folios
Memory Management with Page Folios
 

Viewers also liked (6)

Understanding binder in android
Understanding binder in androidUnderstanding binder in android
Understanding binder in android
 
Understanding Monitor in Dalvik
Understanding Monitor in DalvikUnderstanding Monitor in Dalvik
Understanding Monitor in Dalvik
 
Understanding Semi-Space Garbage Collector in ART
Understanding Semi-Space Garbage Collector in ARTUnderstanding Semi-Space Garbage Collector in ART
Understanding Semi-Space Garbage Collector in ART
 
Process Scheduler and Balancer in Linux Kernel
Process Scheduler and Balancer in Linux KernelProcess Scheduler and Balancer in Linux Kernel
Process Scheduler and Balancer in Linux Kernel
 
AARCH64 VMSA Under Linux Kernel
AARCH64 VMSA Under Linux KernelAARCH64 VMSA Under Linux Kernel
AARCH64 VMSA Under Linux Kernel
 
Understanding SLAB in Linux Kernel
Understanding SLAB in Linux KernelUnderstanding SLAB in Linux Kernel
Understanding SLAB in Linux Kernel
 

Similar to Understanding DLmalloc

coa-Unit5-ppt1 (1).pptx
coa-Unit5-ppt1 (1).pptxcoa-Unit5-ppt1 (1).pptx
coa-Unit5-ppt1 (1).pptx
Ruhul Amin
 
4 dynamic memory allocation
4 dynamic memory allocation4 dynamic memory allocation
4 dynamic memory allocation
Frijo Francis
 

Similar to Understanding DLmalloc (20)

Dynamic Memory Allocation(DMA)
Dynamic Memory Allocation(DMA)Dynamic Memory Allocation(DMA)
Dynamic Memory Allocation(DMA)
 
Linux kernel memory allocators
Linux kernel memory allocatorsLinux kernel memory allocators
Linux kernel memory allocators
 
Lecture 25
Lecture 25Lecture 25
Lecture 25
 
C dynamic ppt
C dynamic pptC dynamic ppt
C dynamic ppt
 
Percona FT / TokuDB
Percona FT / TokuDBPercona FT / TokuDB
Percona FT / TokuDB
 
Lessons Learned From Running 1800 Clusters (Brooke Jensen, Instaclustr) | Cas...
Lessons Learned From Running 1800 Clusters (Brooke Jensen, Instaclustr) | Cas...Lessons Learned From Running 1800 Clusters (Brooke Jensen, Instaclustr) | Cas...
Lessons Learned From Running 1800 Clusters (Brooke Jensen, Instaclustr) | Cas...
 
4 memory management bb
4   memory management bb4   memory management bb
4 memory management bb
 
Computer organization memory hierarchy
Computer organization memory hierarchyComputer organization memory hierarchy
Computer organization memory hierarchy
 
Data Structure - Dynamic Memory Allocation
Data Structure - Dynamic Memory AllocationData Structure - Dynamic Memory Allocation
Data Structure - Dynamic Memory Allocation
 
Everything I Ever Learned About JVM Performance Tuning @Twitter
Everything I Ever Learned About JVM Performance Tuning @TwitterEverything I Ever Learned About JVM Performance Tuning @Twitter
Everything I Ever Learned About JVM Performance Tuning @Twitter
 
Memory (Computer Organization)
Memory (Computer Organization)Memory (Computer Organization)
Memory (Computer Organization)
 
memory.ppt
memory.pptmemory.ppt
memory.ppt
 
#GeodeSummit - Off-Heap Storage Current and Future Design
#GeodeSummit - Off-Heap Storage Current and Future Design#GeodeSummit - Off-Heap Storage Current and Future Design
#GeodeSummit - Off-Heap Storage Current and Future Design
 
Presentation on Heap Sort
Presentation on Heap Sort Presentation on Heap Sort
Presentation on Heap Sort
 
coa-Unit5-ppt1 (1).pptx
coa-Unit5-ppt1 (1).pptxcoa-Unit5-ppt1 (1).pptx
coa-Unit5-ppt1 (1).pptx
 
4 dynamic memory allocation
4 dynamic memory allocation4 dynamic memory allocation
4 dynamic memory allocation
 
Fast and Scalable Python
Fast and Scalable PythonFast and Scalable Python
Fast and Scalable Python
 
Windows 10 Nt Heap Exploitation (English version)
Windows 10 Nt Heap Exploitation (English version)Windows 10 Nt Heap Exploitation (English version)
Windows 10 Nt Heap Exploitation (English version)
 
Spectrum Scale Memory Usage
Spectrum Scale Memory UsageSpectrum Scale Memory Usage
Spectrum Scale Memory Usage
 
Hadoop architecture by ajay
Hadoop architecture by ajayHadoop architecture by ajay
Hadoop architecture by ajay
 

Recently uploaded

TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
mohitmore19
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) SolutionIntroducing Microsoft’s new Enterprise Work Management (EWM) Solution
Introducing Microsoft’s new Enterprise Work Management (EWM) Solution
 
5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf5 Signs You Need a Fashion PLM Software.pdf
5 Signs You Need a Fashion PLM Software.pdf
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
Define the academic and professional writing..pdf
Define the academic and professional writing..pdfDefine the academic and professional writing..pdf
Define the academic and professional writing..pdf
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 

Understanding DLmalloc

  • 2. Outline • Why Use DLmalloc • Basic structures – Chunk & Bins • Key Algorithms – Memory allocation • Small request • Large request – Realloc – Free – Trim
  • 3. Why Use DLmalloc • If don’t use DLmalloc – Application should use system call brk or sbrk to get memory from Kernel. – Disadvantage: • Will trap into the kernel • Lost cache locality • Key role of DLmalloc – Maintain the free bulks for next use without system call.
  • 4. Chunk & bins • All available space are organized by chunks in DLmalloc. – Small chunk: Chunk size [16,248] – Large chunk: Chunk size [256, 2^31] • All available chunks are maintained in bins, grouped by size. – Small chunk corresponds to smallbins – Large chunk corresponds to largebins
  • 5. Small Chunk Allocated prev size Current size| status Free Front pointer Back pointer Data prev size Current size| status Data Allocated struct malloc_chunk { size_t prev_foot; /* Size of previous chunk (if free). */ size_t head; /* Size and inuse bits. */ struct malloc_chunk* fd; /* double links -- used only if free. */ struct malloc_chunk* bk; }; #define SIZE_T_ONE ((size_t)1) #define SIZE_T_TWO ((size_t)2) #define PINUSE_BIT (SIZE_T_ONE) #define CINUSE_BIT (SIZE_T_TWO)
  • 7. Large Chunk Allocated prev size Current size| status Free Front pointer Back pointer Unused Data prev size Current size| status Data Allocated Child 0 Child 1 parent struct malloc_tree_chunk { /* The first four fields must be compatible with malloc_chunk */ size_t prev_foot; size_t head; struct malloc_tree_chunk* fd; struct malloc_tree_chunk* bk; struct malloc_tree_chunk* child[2]; struct malloc_tree_chunk* parent; bindex_t index; };
  • 8. Large bins The tree is named Tries. [768,1024)[512,768)[384,512)[256,384) ........ node node chunk chunk 43210largemap ... largebins ... node chunk chunk
  • 9. Management structure struct malloc_state { binmap_t smallmap; binmap_t treemap; size_t dvsize; size_t topsize; … mchunkptr dv; mchunkptr top; … mchunkptr smallbins[(NSMALLBINS+1)*2]; tbinptr treebins[NTREEBINS]; … msegment seg; … }; Reference: http://g.oswego.edu/dl/html/malloc.html
  • 10. Optimization • Designed Victim – This is the preferred chunk for servicing small requests that don't have exact fits. It is normally the chunk split off most recently to service another small request. Its size is cached in dvsize. The link fields of this chunk are not maintained since it is not kept in a bin.
  • 11. Small Request Algorithm 1. If one exists, use a remainderless chunk in associated smallbin. 2. If it is big enough, use the dv chunk. 3. If big enough and bigger chunk exists, split the smallest available chunk in a bin(small bin or larger bin), saving remainder in dv. 4. If it is big enough, use the top chunk. 5. If available, get memory from system and use it
  • 12. Get memory from system 1. If Top is empty and request bigger than 256KB – Use mmap(). mmaped chunk’s head doesn’t use status bit.(art’s case doesn’t use mmap()) 2. Use brk to allocated page-align of request. 3. If brk fails, use mmap().(mmap is enabled) 4. Give back old top to chunk bins and use new allocated space as top.
  • 13. Large Request 1. Find the smallest available binned chunk that fits, and use it. if it is better fitting than dv chunk, splitting if necessary. 2. If better fitting than any binned chunk, use the dv chunk. 3. If it is big enough, use the top chunk. 4. If available, get memory from system(brk or mmap) and use it
  • 14. realloc Pseudo-code • void* dlrealloc(void* oldmem, size_t bytes) – If oldmem = 0, call dlmalloc(bytes). – If bytes = 0, call dlfree(oldmem). – If bytes < oldsize and gap >16, split off remainder – If bytes > oldsize • If the adjacent chunk is free and big enough, extend it. • Else » call dlmalloc(bytes) » memcpy it to new space. » Give oldspace back to chunklist.
  • 15. Free • If free chunk is mapped(by mmap()), just munmap it. • Else try to merge previous and next free chunk , insert into small/large chunk bins except for Top and DV.
  • 16. Trim • If Top size is larger than 2MB, will call sys_trim. – unmap or sbrk top space to 1 Page – unmap all free mmapped segments