This document discusses different methods for allocating memory in the kernel, including the buddy system, slab allocation, and their variations. The buddy system allocates variable sized blocks using a splitting algorithm to satisfy requests. Slab allocation pre-allocates fixed sized blocks for specific data types to improve performance. Variations include the binary, weighted, and Fibonacci buddy systems, which split blocks into different predetermined sizes.
Navi Mumbai Call Girls Service Pooja 9892124323 Real Russian Girls Looking Mo...
Kernel Memory Allocation and Management Techniques
1. KERNEL MEMORY ALLOCATION,
REVIEW OF RELOCATION,
PROGRAM FORMS
Roopak Bhama
(MCA/25003/18)
BIRLA INSTITUTE OF TECHNOLOGY
MESRA, JAIPUR CAMPUS
2. WHAT IS KERNEL
• A kernel is actually a large block of code which keeps
the system up and running from the time of booting,
till shutdown.
• It is responsible for managing and allocating resources
like memory, processors etc.
• It also allows OS to communicate and control various
external hardware devices like pen drive, memory card,
keyboard etc.
3. MICRO KERNEL
• Mostly used by OS.
• It manages all system
resources.
• User Services and Kernel
Services are implemented in
different address space.
• The kernel program runs in
another memory area called
“kernel space”.
• Kernel programming means
power to access anything
and everything in a system.
MONOLITHIC KERNEL
MICRO KERNEL VS MONOLITHIC
KERNEL
4. USER PROGRAM
• User program or
applications runs in a
memory area called “user
space”.
• Cannot access kernel space
directly, so system calls are
made which acts as software
interrupts.
• The kernel program runs in
another memory area called
“kernel space”.
• Kernel programming means
power to access anything
and everything in a system,
called supper access mode.
KERNEL PROGRAM
USER PROGRAM VS KERNEL
PROGRAM
5. DIFFERENCE BETWEEN KERNEL
AND USER PROGRAM
• Execution Differences
• Kernel modules have separate address space.
• Kernel modules have higher execution privilege.
• Kernel modules do not execute sequentially
• Structural Differences
• Kernel modules do not define a main program.
• instead of main(), looks for open() as it’s a software interface
for I/O
• Kernel modules use different header files.
• Kernel modules can be customized for hardware.
6. ALLOCATING KERNEL MEMORY
• Unix divides memory into fixed size of continuous block
of virtual memory page.
• Page size is a power of two – typical size is 4 Kbytes.
• It is treated differently from user memory.
• Kernel request memory of different structures of variable
sizes
• minimize waste due to fragmentation
• Two strategies are used for memory managing
• Buddy System
• Slab System
7. THE BUDDY SYSTEM
• Buddy allocation system is an algorithm in which a
larger memory block is divided into small parts to
satisfy the request. Each equal half of a split buffer is
called a buddy.
• In the same manner one of the two buddies will
further divide into smaller parts until the request is
fulfilled.
8. THE BUDDY SYSTEM
• Advantages – flexible – allows to use buffers of different
sizes, easy exchange of memory between the allocator
and the paging system.
• Disadvantage - poor performance, inconvenient
programming interface, impossible to release a part of a
buffer.
9. THE BINARY BUDDY SYSTEM
• The buddy system maintains a list of the free blocks of
each size (called a free list), so that it is easy to find a
block of the desired size, if one is available.
• It provides storage in block sizes which are powers of
2, from a pool of available memory space of size 2k.
• When a block of size 2k is requested, the available
space list is examined. If a block of the proper size is
available, it is used. Otherwise, an iterative request for
a block of size 2k+1 is made.
• The effectiveness is determined by measuring two
types of losses in storage utilization: internal memory
fragmentation and external memory fragmentation.
10. THE BINARY BUDDY SYSTEM
• Internal fragmentation is the
result of allocating only blocks
of predetermined sizes, so
that a request for memory
must be rounded up to the
next larger block size.
• External fragmentation is
the result of breaking down
memory into separate blocks
which cannot be combined
into a desired larger block.
11. WEIGHTED BUDDY SYSTEM
• The differences between binary and weighted methods
lie in how the blocks are split, the mechanism of
address calculation.
• In Binary, 2k is followed while creating memory blocks
but in Weighted, 3*2k is followed.
• A block of size 2k+2 is split into two blocks of sizes
3*2k and 2k. Blocks of size 3*2k are split into sizes and
2k.
• Blocks split from the same parent block are called
buddies. Since the buddies of a pair have different
sizes, they are called weighted buddies.
13. FIBONACCI BUDDY SYSTEM
• This is the system in which blocks are divided into sizes
which are Fibonacci numbers.
• 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 144, 233, 377, 610.
• Advantages
• Memory Allocation is implemented using binary tree.
• Fast to allocate and deallocate.
• Cost to allocate and deallocate memory is low.
• Easy address calculation
• Coalescing – Defined as how quickly adjacent buddies can be
combined to form larger segments.
14. SLAB ALLOCATION
• In slab allocation memory chunks suitable to fit data
objects of certain type or size are pre allocated. Cache
does not free the space immediately. Two terms
required are:
• Slab
• made up of one or more physically contiguous pages.
• The slab is the actual container of data
• Cache
• represents a small amount of very fast memory.
• A cache consists of one or more slabs. There is a single
cache for each unique kernel data structure.
16. IMPLEMENTING SLAB
ALLOCATION
• The slab allocation algorithm uses caches to store
kernel objects. When a cache is created a number of
objects which are initially marked as free are allocated
to the cache.
• When a new object for a kernel data structure is
needed, the allocator can assign any free object from
the cache to satisfy the request. The object assigned
from the cache is marked as used.
• In Linux, a slab may in one of three possible states:
• Full – All objects in the slab are marked as used
• Empty – All objects in the slab are marked as free
• Partial – The slab consists of both