Subversion Repositories HelenOS-doc

Compare Revisions

Ignore whitespace Rev 23 → Rev 24

/design/trunk/src/ch_memory_management.xml
4,7 → 4,9
 
<title>Memory management</title>
 
<section>
 
 
<section><!-- VM -->
<title>Virtual memory management</title>
 
<section>
18,11 → 20,81
 
<para></para>
</section>
</section>
</section><!-- End of VM -->
 
<section>
 
<section><!-- Phys mem -->
<title>Physical memory management</title>
 
 
<section id="zones_and_frames">
<title>Zones and frames</title>
<para> <graphic fileref="images/mm2.png" /> </para>
 
 
<para>On some architectures not whole physical memory is available for conventional usage. This limitations
require from kernel to maintain a table of available and unavailable ranges of physical memory addresses.
Main idea of zones is in creating memory zone entity, that is a continuous chunk of memory available for allocation.
If some chunk is not available, we simply do not put it in any zone.
</para>
<para>
Zone is also serves for informational purposes, containing information about number of free and busy frames. Physical memory
allocation is also done inside the certain zone. Allocation of zone frame must be organized by the
<link linkend="frame_allocator">frame allocator</link> associated with the zone.
</para>
<para>Some of the architectures (mips32, ppc32) have only one zone, that covers whole
physical memory, and the others (like ia32) may have multiple zones. Information about zones on current machine is stored
in BIOS hardware tables or can be hardcoded into kernel during compile time.</para>
</section>
 
<section id="frame_allocator">
<title>Frame allocator</title>
 
<formalpara>
<title>Overview</title>
<para>Frame allocator provides physical memory allocation for the kernel. Because of zonal organization of physical memory,
frame allocator is always working in context of some zone, thus making impossible to allocate a piece of memory, which lays in different zone, which
cannot happen, because two adjacent zones can be merged into one. Frame allocator is also being responsible to update information on
the number of free/busy frames in zone.
Physical memory allocation inside one <link
linkend="zones_and_frames">memory zone</link> is being handled by an
instance of <link linkend="buddy_allocator">buddy allocator</link>
tailored to allocate blocks of physical memory frames.
</para>
</formalpara>
<formalpara>
<title>Allocation / deallocation</title>
<para>
Upon allocation request, frame allocator tries to find first zone, that can satisfy the incoming request (has required amount of free frames to allocate).
During deallocation, frame allocator needs to find zone, that contain deallocated frame.
This approach could bring up two potential problems:
<itemizedlist>
<listitem>
Linear search of zones does not any good to performance, but number of zones is not expected to be high. And if yes, list of zones can be replaced with more time-efficient B-tree.
</listitem>
<listitem>
Quickly find out if zone contains required number of frames to allocate and if this chunk of memory is properly aligned. This issue is perfectly solved bu the buddy allocator.
</listitem>
</itemizedlist>
</para>
</formalpara>
</section>
 
</section>
 
 
 
<section id="buddy_allocator">
<title>Buddy allocator</title>
 
47,7 → 119,7
are no blocks to coalesce in the former case or when there are no
blocks that can be split in the latter case.</para>
 
<graphic fileref="images/buddy_alloc.eps" format="EPS" />
<graphic fileref="images/mm1.png" format="EPS" />
 
<para>This approach greatly reduces external fragmentation of memory
and helps in allocating bigger continuous blocks of memory aligned to
84,43 → 156,12
within the block are assigned the magic value
<constant>BUDDY_INNER_BLOCK</constant>. This is especially important
for effective identification of buddies in one-dimensional array
because the entity that represents a potential buddy cannot be associated
with <constant>BUDDY_INNER_BLOCK</constant> (i.e. if it is associated
with <constant>BUDDY_INNER_BLOCK</constant> then it is not a
buddy).</para>
because the entity that represents a potential buddy cannot be
associated with <constant>BUDDY_INNER_BLOCK</constant> (i.e. if it
is associated with <constant>BUDDY_INNER_BLOCK</constant> then it is
not a buddy).</para>
</formalpara>
</section>
</section>
 
<section id="zones_and_frames">
<title>Zones and frames</title>
 
<para>Physical memory is divided into zones. Each zone represents
continuous area of physical memory frames. Allocation of frames is
handled by the <link linkend="frame_allocator">frame allocator</link>
associated with the zone. Zone also contains information about free and
occupied frames and its base addresss in the memory. Some of the
architectures (mips32, ppc32) have only one zone, that covers whole
physical memory. Other architectures (ia32) have multiple zones.</para>
</section>
 
<section id="frame_allocator">
<title>Frame allocator</title>
 
<section>
<title>Overview</title>
 
<para>Physical memory allocation inside one <link
linkend="zones_and_frames">memory zone</link> is being handled by an
instance of <link linkend="buddy_allocator">buddy allocator</link>
tailored to allocate blocks of physical memory frames.</para>
 
<graphic fileref="images/mm1.png" />
</section>
 
<section>
<title>Implementation</title>
 
<formalpara>
<title>Data organization</title>
 
169,19 → 210,22
<varname>frame_t::buddy_order</varname> variables, finding buddy is
done at constant time.</para>
</formalpara>
</section>
</section>
 
 
<section id="slab">
<title>Slab allocator</title>
 
<para>Kernel memory allocation is handled by slab.</para>
</section>
</section><!-- End of Physmem -->
 
</section>
 
 
<section>
<title>Memory sharing</title>
 
<para>Not implemented yet(?)</para>
</section>
</section>
</chapter>