CISCO IOS (Part 5)
Par Mathieu le dimanche 24 février 2008, 19:00 - Lien permanent
When we allocate memory to a process “malloc”, the Pool Manager takes
a free memory block and attaches it to a process. The Pool Manager maintains a
table of contiguous memory blocks. When a process frees a memory block, the
Pool Manager tries to concatenate it with its neighbors. Despite of this
concatenation, fragmentation is unavoidable. An extremely fragmented memory can
lead to “malloc” errors “%SYS-2-MALLOCFAIL”.
Indeed, the memory available can be sufficient, but not enough contiguous free
blocks available to allow a requested “malloc”.
In the last figure, there are only
small non-contiguous freed blocks: Now, if a process wants to allocate a larger
memory area, it will not be able to do it and it’ll have a “MALLOCFAIL” error.
The Chunk Manager will try to avoid this kind of situation by allocating the
memory to processes cleverly. The Chunk Manager is responsible of the Chunks
Allocation. A Chunk contains a finished number of memory blocks of equal size.
If we use every memory blocks of a Chunk, the Chunk Manager will allocate a new
memory area (Sibling). If no more blocks of this “Sibling” are used, it is
freed “Freed/Trimmed”. A process now has a larger allocated memory area split
into smaller memory blocks. When a process frees a memory block, it does in its
Chunk. There is no more fragmentation due to different processes freeing
memory.
In the last figure, there are only
small non-contiguous freed blocks: Now, if a process wants to allocate a larger
memory area, it will not be able to do it and it’ll have a “MALLOCFAIL” error.
The Chunk Manager will try to avoid this kind of situation by allocating the
memory to processes cleverly. The Chunk Manager is responsible of the Chunks
Allocation. A Chunk contains a finished number of memory blocks of equal size.
If we use every memory blocks of a Chunk, the Chunk Manager will allocate a new
memory area (Sibling). If no more blocks of this “Sibling” are used, it is
freed “Freed/Trimmed”. A process now has a larger allocated memory area split
into smaller memory blocks. When a process frees a memory block, it does in its
Chunk. There is no more fragmentation due to different processes freeing
memory.
#show chunk Chunk Manager: 407660 chunks created, 406281 chunks destroyed 9349 siblings created, 406279 siblings trimmed Chunk element Block Maximum Element Element Total Cfgsize Ohead size element inuse freed Ohead Name 16 4 940 33 2 31 360 String-DB owne 0x654C2408 16 4 940 33 0 33 360 String-DB cont 0x654C27B4 312 16 65588 197 38 159 4072 Extended ACL e 0x654C3484 96 16 20052 171 9 162 3584 ACL Header 0x654D34B8 8536 0 65588 7 1 6 5784 Parseinfo Bloc 0x654DA14C 16 0 456 15 1 14 164 tokenQ node 0x654EA180 20 0 456 13 13 0 144 Chain Cache No 0x654EA348 20 0 456 13 6 7 144 (sibling) 0x66BD0E50 20 0 460 13 13 0 148 (sibling) 0x66F33EE0Within a Chunk, the memory blocks have a header (or not, size = 0). The header size per chunk is fixed (0, 4, 16, 20, 24). Example: ACL Header is a Chunk of 171 elements max, with 96 elements since creation. Each block have a header of 16Bytes and weight 20,052Bytes. Actually there are only 9 memory blocks in use within this Chunk. Next post: The Buffers.