BACKGROUND the kernel reserves part of physical memory for its own text and static data structures Page-level Allocator: This does the job of allocating memory The page-level allocator has two principal clients, paging system and kernel memory allocator. Paging system: is a part of virtual memory system. It allocates pages to user processes to hold portions of their address space. Kernel memory allocator: provides buffers of memory to various kernel subsytems.
efficient use of memory pool return a failure status instead of just blocking monitor which parts of its pool are allocated and which are free an efficient KMA must avoid fragmentation Functional Requirements -- KMA
Evaluation Criteria -- KMA must be space-efficient i.e. minimize wastage. Can be measured by utilization factor must be fast must have a simple programming interface should not force to free the entire allocated area all at once must guard against the wastage of memory must be able to interact with the paging system
Different Allocation Methods: Resource Map Allocator set of pairs that monitor areas of free memory the pool becomes fragmented by the allocation and release of chunks of memory creates one map entry for each contiguous free region. the kernel can satisfy new allocation requests using one of three policies: First Fit, Best Fit, Worst Fit Unix chooses the first-fit method.
Analysis -- Advantages easy to implement not restricted to memory allocation no wastage of space can release any part of the region allows reuse of memory by coalescing
Disadvantages Fragmentation--creation of small free regions results in low utilization Fragmentation--If the map has fixed number of entries, it might overflow needs an allocator for its own entries if the map grows dynamically Needs sorting which is expensive Must perform a linear search which is time consuming
Simple Power-of-Two Free Lists uses a set of free lists each buffer has a one-word header malloc() allocates memory. It returns to the caller a pointer to the byte immediately following the header in the buffer. free() releases the buffer no provision to free only part of the allocated buffer
Analysis Advantages: avoids the lengthy linear searches and eliminates the fragmentation problem. worst-case performance is well bounded when a buffer is available presents a familiar programming interface Disadvantages: poor memory utilization no provision for coalescing adjacent free buffers
The McKusick-Karels Allocator eliminates space wastage memory comprises of a set of contiguous pages uses an additional page usage array (kmemsizes[ ]) to manage its pages. Each page may be in one of three states: Free Divided into buffers of a particular size Part of a buffer that spanned multiple pages do not need a header to store a free list pointer
The McKusick-Karels Allocator (Cont..) locates the page by using free() replaces malloc() by a macro Analysis: saves the memory by eliminating the header is faster, wastes less memory, and can handle large and small requests efficiently The drawbacks are: There is no provision for moving memory from one list to another and there is no way to return memory to the paging system
The Buddy System combines free buffer coalescing with a power-of- two allocator. When a buffer is split, each half is called the buddy of the other uses a bitmap to monitor each chunk of the block BC D D’ A’ Bitmap Free list headers
Analysis -- Advantage: allows memory to be reused allows exchange of memory between the allocator and the paging system Disadvantage: When allocate and release requests alternate, the overhead is more Another drawback is the programming interface
The SVR4 Lazy Buddy Algorithm defers coalescing depending on the state of the buffer class any time, a class has N buffers, of which A buffers are active, L are locally free, and G are globally free. Depending on these parameters, a buffer class is in one of the following states: Lazy, Reclaiming, Accelerated Slack = N – 2L- G system is in the lazy state when slack is 2 or more, in the reclaiming state when the slack is 1, and in the accelerated state when slack is zero
The SVR4 Lazy Buddy Algorithm (Cont..) If the list is in lazy state nothing is done and this buffer is called delayed buffer If the list is in reclaiming state, the allocator marks it as free in the bit map and coalesces it if possible If the list is in accelerated state, the allocator coalesces two buffers– the one just released and an additional delayed buffer, if there is one substantial improvement over the basic buddy system
The Mach-OSF/1 Zone Allocator provides fast memory allocation and performs garbage collection each class of objects is assigned its own zone any single page is only used for one zone initializes the zones it will need using the function zinit (size, max, alloc, name) zinit() allocates a zone structure from the zone of zones all active zone structures are maintained on a linked list