Subversion Repositories HelenOS-doc

Compare Revisions

Ignore whitespace Rev 63 → Rev 64

/design/trunk/src/ch_memory_management.xml
4,7 → 4,338
 
<title>Memory management</title>
 
<para>In previous chapters, this book described the scheduling subsystem as
the creator of the impression that threads execute in parallel. The memory
management subsystem, on the other hand, creates the impression that there
is enough physical memory for the kernel and that userspace tasks have the
entire address space only for themselves.</para>
 
<section>
<title>Physical memory management</title>
 
<section id="zones_and_frames">
<title>Zones and frames</title>
 
<para>HelenOS represents continuous areas of physical memory in
structures called frame zones (abbreviated as zones). Each zone contains
information about the number of allocated and unallocated physical
memory frames as well as the physical base address of the zone and
number of frames contained in it. A zone also contains an array of frame
structures describing each frame of the zone and, in the last, but not
the least important, front, each zone is equipped with a buddy system
that faciliates effective allocation of power-of-two sized block of
frames.</para>
 
<para>This organization of physical memory provides good preconditions
for hot-plugging of more zones. There is also one currently unused zone
attribute: <code>flags</code>. The attribute could be used to give a
special meaning to some zones in the future.</para>
 
<para>The zones are linked in a doubly-linked list. This might seem a
bit ineffective because the zone list is walked everytime a frame is
allocated or deallocated. However, this does not represent a significant
performance problem as it is expected that the number of zones will be
rather low. Moreover, most architectures merge all zones into
one.</para>
 
<para>For each physical memory frame found in a zone, there is a frame
structure that contains number of references and data used by buddy
system.</para>
</section>
 
<section id="frame_allocator">
<title>Frame allocator</title>
 
<para>The frame allocator satisfies kernel requests to allocate
power-of-two sized blocks of physical memory. Because of zonal
organization of physical memory, the frame allocator is always working
within a context of some frame zone. In order to carry out the
allocation requests, the frame allocator is tightly integrated with the
buddy system belonging to the zone. The frame allocator is also
responsible for updating information about the number of free and busy
frames in the zone. <figure>
<mediaobject id="frame_alloc">
<imageobject role="html">
<imagedata fileref="images/frame_alloc.png" format="PNG" />
</imageobject>
 
<imageobject role="fop">
<imagedata fileref="images.vector/frame_alloc.svg" format="SVG" />
</imageobject>
</mediaobject>
 
<title>Frame allocator scheme.</title>
</figure></para>
 
<formalpara>
<title>Allocation / deallocation</title>
 
<para>Upon allocation request via function <code>frame_alloc</code>,
the frame allocator first tries to find a zone that can satisfy the
request (i.e. has the required amount of free frames). Once a suitable
zone is found, the frame allocator uses the buddy allocator on the
zone's buddy system to perform the allocation. During deallocation,
which is triggered by a call to <code>frame_free</code>, the frame
allocator looks up the respective zone that contains the frame being
deallocated. Afterwards, it calls the buddy allocator again, this time
to take care of deallocation within the zone's buddy system.</para>
</formalpara>
</section>
 
<section id="buddy_allocator">
<title>Buddy allocator</title>
 
<para>In the buddy system, the memory is broken down into power-of-two
sized naturally aligned blocks. These blocks are organized in an array
of lists, in which the list with index i contains all unallocated blocks
of size <mathphrase>2<superscript>i</superscript></mathphrase>. The
index i is called the order of block. Should there be two adjacent
equally sized blocks in the list i<mathphrase />(i.e. buddies), the
buddy allocator would coalesce them and put the resulting block in list
<mathphrase>i + 1</mathphrase>, provided that the resulting block would
be naturally aligned. Similarily, when the allocator is asked to
allocate a block of size
<mathphrase>2<superscript>i</superscript></mathphrase>, it first tries
to satisfy the request from the list with index i. If the request cannot
be satisfied (i.e. the list i is empty), the buddy allocator will try to
allocate and split a larger block from the list with index i + 1. Both
of these algorithms are recursive. The recursion ends either when there
are no blocks to coalesce in the former case or when there are no blocks
that can be split in the latter case.</para>
 
<para>This approach greatly reduces external fragmentation of memory and
helps in allocating bigger continuous blocks of memory aligned to their
size. On the other hand, the buddy allocator suffers increased internal
fragmentation of memory and is not suitable for general kernel
allocations. This purpose is better addressed by the <link
linkend="slab">slab allocator</link>.<figure>
<mediaobject id="buddy_alloc">
<imageobject role="html">
<imagedata fileref="images/buddy_alloc.png" format="PNG" />
</imageobject>
 
<imageobject role="fop">
<imagedata fileref="images.vector/buddy_alloc.svg" format="SVG" />
</imageobject>
</mediaobject>
 
<title>Buddy system scheme.</title>
</figure></para>
 
<section>
<title>Implementation</title>
 
<para>The buddy allocator is, in fact, an abstract framework wich can
be easily specialized to serve one particular task. It knows nothing
about the nature of memory it helps to allocate. In order to beat the
lack of this knowledge, the buddy allocator exports an interface that
each of its clients is required to implement. When supplied with an
implementation of this interface, the buddy allocator can use
specialized external functions to find a buddy for a block, split and
coalesce blocks, manipulate block order and mark blocks busy or
available.</para>
 
<formalpara>
<title>Data organization</title>
 
<para>Each entity allocable by the buddy allocator is required to
contain space for storing block order number and a link variable
used to interconnect blocks within the same order.</para>
 
<para>Whatever entities are allocated by the buddy allocator, the
first entity within a block is used to represent the entire block.
The first entity keeps the order of the whole block. Other entities
within the block are assigned the magic value
<constant>BUDDY_INNER_BLOCK</constant>. This is especially important
for effective identification of buddies in a 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>
</formalpara>
</section>
</section>
 
<section id="slab">
<title>Slab allocator</title>
 
<para>The majority of memory allocation requests in the kernel is for
small, frequently used data structures. The basic idea behind the slab
allocator is that deployment of lists of preallocated, commonly used
objects. Whenever an object is to be allocated, the slab allocator takes
the first item from the list corresponding to the object type. This
avoids the overhead of allocating and dellocating commonly used types of
objects such as threads, B+tree nodes etc. Due to the fact that the
sizes of the requested and allocated object match, the slab allocator
significantly eliminates internal fragmentation. Moreover, each list can
have a constructor and a destructor, which leads to performance gains
because constructed and then destroyed objects don't need to be
reinitialized<footnote>
<para>Provided that the assumption that the destructor leaves the
object in a consistent state holds.</para>
</footnote>.</para>
 
<para>In the slab allocator, objects of one type are kept in continuous
areas of physical memory called slabs. Slabs can span from one to
several physical memory frames. Slabs of objects of one type are stored
in slab caches. When the allocator needs to allocate an object, it
searches available slabs. When the slab does not contain any free
obejct, a new slab is allocated and added to the cache. Contrary to
allocation, deallocated objects are returned to their respective slabs.
Empty slabs are deallocated immediately while empty slab caches are not
freed until HelenOS runs short of memory.</para>
 
<para><figure>
<mediaobject id="slab_alloc">
<imageobject role="html">
<imagedata fileref="images/slab_alloc.png" format="PNG" />
</imageobject>
 
<imageobject role="fop">
<imagedata fileref="images.vector/slab_alloc.svg" format="SVG" />
</imageobject>
</mediaobject>
 
<title>Slab allocator scheme.</title>
</figure></para>
 
<section>
<para>
<termdef />
 
 
<termdef />
</para>
</section>
 
<section>
<title>Implementation</title>
 
<para>The slab allocator is closely modelled after <ulink
url="http://www.usenix.org/events/usenix01/full_papers/bonwick/bonwick_html/">
OpenSolaris slab allocator by Jeff Bonwick and Jonathan Adams </ulink>
with the following exceptions:<itemizedlist>
<listitem></listitem>
 
<listitem>
empty magazines are deallocated when not needed
</listitem>
</itemizedlist> Following features are not currently supported but
would be easy to do: <itemizedlist>
<listitem>
cache coloring
</listitem>
 
<listitem>
dynamic magazine grow (different magazine sizes are already supported, but we would need to adjust allocation strategy)
</listitem>
</itemizedlist></para>
 
<section>
<title>Magazine layer</title>
 
<para>Due to the extensive bottleneck on SMP architures, caused by
global slab locking mechanism, making processing of all slab
allocation requests serialized, a new layer was introduced to the
classic slab allocator design. Slab allocator was extended to
support per-CPU caches 'magazines' to achieve good SMP scaling.
<termdef>Slab SMP perfromance bottleneck was resolved by introducing
a per-CPU caching scheme called as <glossterm>magazine
layer</glossterm></termdef>.</para>
 
<para>Magazine is a N-element cache of objects, so each magazine can
satisfy N allocations. Magazine behaves like a automatic weapon
magazine (LIFO, stack), so the allocation/deallocation become simple
push/pop pointer operation. Trick is that CPU does not access global
slab allocator data during the allocation from its magazine, thus
making possible parallel allocations between CPUs.</para>
 
<para>Implementation also requires adding another feature as the
CPU-bound magazine is actually a pair of magazines to avoid
thrashing when during allocation/deallocatiion of 1 item at the
magazine size boundary. LIFO order is enforced, which should avoid
fragmentation as much as possible.</para>
 
<para>Another important entity of magazine layer is the common full
magazine list (also called a depot), that stores full magazines that
may be used by any of the CPU magazine caches to reload active CPU
magazine. This list of magazines can be pre-filled with full
magazines during initialization, but in current implementation it is
filled during object deallocation, when CPU magazine becomes
full.</para>
 
<para>Slab allocator control structures are allocated from special
slabs, that are marked by special flag, indicating that it should
not be used for slab magazine layer. This is done to avoid possible
infinite recursions and deadlock during conventional slab allocaiton
requests.</para>
</section>
 
<section>
<title>Allocation/deallocation</title>
 
<para>Every cache contains list of full slabs and list of partialy
full slabs. Empty slabs are immediately freed (thrashing will be
avoided because of magazines).</para>
 
<para>The SLAB allocator allocates lots of space and does not free
it. When frame allocator fails to allocate the frame, it calls
slab_reclaim(). It tries 'light reclaim' first, then brutal reclaim.
The light reclaim releases slabs from cpu-shared magazine-list,
until at least 1 slab is deallocated in each cache (this algorithm
should probably change). The brutal reclaim removes all cached
objects, even from CPU-bound magazines.</para>
 
<formalpara>
<title>Allocation</title>
 
<para><emphasis>Step 1.</emphasis> When it comes to the allocation
request, slab allocator first of all checks availability of memory
in local CPU-bound magazine. If it is there, we would just "pop"
the CPU magazine and return the pointer to object.</para>
 
<para><emphasis>Step 2.</emphasis> If the CPU-bound magazine is
empty, allocator will attempt to reload magazin, swapping it with
second CPU magazine and returns to the first step.</para>
 
<para><emphasis>Step 3.</emphasis> Now we are in the situation
when both CPU-bound magazines are empty, which makes allocator to
access shared full-magazines depot to reload CPU-bound magazines.
If reload is succesful (meaning there are full magazines in depot)
algoritm continues at Step 1.</para>
 
<para><emphasis>Step 4.</emphasis> Final step of the allocation.
In this step object is allocated from the conventional slab layer
and pointer is returned.</para>
</formalpara>
 
<formalpara>
<title>Deallocation</title>
 
<para><emphasis>Step 1.</emphasis> During deallocation request,
slab allocator will check if the local CPU-bound magazine is not
full. In this case we will just push the pointer to this
magazine.</para>
 
<para><emphasis>Step 2.</emphasis> If the CPU-bound magazine is
full, allocator will attempt to reload magazin, swapping it with
second CPU magazine and returns to the first step.</para>
 
<para><emphasis>Step 3.</emphasis> Now we are in the situation
when both CPU-bound magazines are full, which makes allocator to
access shared full-magazines depot to put one of the magazines to
the depot and creating new empty magazine. Algoritm continues at
Step 1.</para>
</formalpara>
</section>
</section>
</section>
 
<!-- End of Physmem -->
</section>
 
<section>
<title>Virtual memory management</title>
 
<section>
252,381 → 583,4
stranky</para>
</section>
</section>
 
<!-- End of VM -->
 
<section>
<!-- Phys mem -->
 
<title>Physical memory management</title>
 
<section id="zones_and_frames">
<title>Zones and frames</title>
 
<para><!--graphic fileref="images/mm2.png" /--><!--graphic fileref="images/buddy_alloc.svg" format="SVG" /--></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>
 
<figure><mediaobject id="frame_alloc">
<imageobject role="html">
<imagedata fileref="images/frame_alloc.png" format="PNG" />
</imageobject>
 
<imageobject role="fop">
<imagedata fileref="images.vector/frame_alloc.svg" format="SVG" />
</imageobject>
</mediaobject>
<title>Frame allocator scheme.</title>
</figure>
 
<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 id="buddy_allocator">
<title>Buddy allocator</title>
 
<section>
<title>Overview</title>
 
<figure><mediaobject id="buddy_alloc">
<imageobject role="html">
<imagedata fileref="images/buddy_alloc.png" format="PNG" />
</imageobject>
 
<imageobject role="fop">
<imagedata fileref="images.vector/buddy_alloc.svg" format="SVG" />
</imageobject>
</mediaobject>
<title>Buddy system scheme.</title>
</figure>
 
<para>In the buddy allocator, the memory is broken down into
power-of-two sized naturally aligned blocks. These blocks are
organized in an array of lists, in which the list with index i
contains all unallocated blocks of size
<mathphrase>2<superscript>i</superscript></mathphrase>. The index i is
called the order of block. Should there be two adjacent equally sized
blocks in the list i<mathphrase />(i.e. buddies), the buddy allocator
would coalesce them and put the resulting block in list <mathphrase>i
+ 1</mathphrase>, provided that the resulting block would be naturally
aligned. Similarily, when the allocator is asked to allocate a block
of size <mathphrase>2<superscript>i</superscript></mathphrase>, it
first tries to satisfy the request from the list with index i. If the
request cannot be satisfied (i.e. the list i is empty), the buddy
allocator will try to allocate and split a larger block from the list
with index i + 1. Both of these algorithms are recursive. The
recursion ends either when there 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/mm1.png" format="EPS" /-->
 
<para>This approach greatly reduces external fragmentation of memory
and helps in allocating bigger continuous blocks of memory aligned to
their size. On the other hand, the buddy allocator suffers increased
internal fragmentation of memory and is not suitable for general
kernel allocations. This purpose is better addressed by the <link
linkend="slab">slab allocator</link>.</para>
</section>
 
<section>
<title>Implementation</title>
 
<para>The buddy allocator is, in fact, an abstract framework wich can
be easily specialized to serve one particular task. It knows nothing
about the nature of memory it helps to allocate. In order to beat the
lack of this knowledge, the buddy allocator exports an interface that
each of its clients is required to implement. When supplied with an
implementation of this interface, the buddy allocator can use
specialized external functions to find a buddy for a block, split and
coalesce blocks, manipulate block order and mark blocks busy or
available. For precise documentation of this interface, refer to
<emphasis>"HelenOS Generic Kernel Reference Manual"</emphasis>.</para>
 
<formalpara>
<title>Data organization</title>
 
<para>Each entity allocable by the buddy allocator is required to
contain space for storing block order number and a link variable
used to interconnect blocks within the same order.</para>
 
<para>Whatever entities are allocated by the buddy allocator, the
first entity within a block is used to represent the entire block.
The first entity keeps the order of the whole block. Other entities
within the block are assigned the magic value
<constant>BUDDY_INNER_BLOCK</constant>. This is especially important
for effective identification of buddies in a 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>
 
<para>The buddy allocator always uses the first frame to represent
the frame block. This frame contains <varname>buddy_order</varname>
variable to provide information about the block size it actually
represents (
<mathphrase>2<superscript>buddy_order</superscript></mathphrase>
frames block). Other frames in block have this value set to magic
<constant>BUDDY_INNER_BLOCK</constant> that is much greater than
buddy <varname>max_order</varname> value.</para>
 
<para>Each <varname>frame_t</varname> also contains pointer member
to hold frame structure in the linked list inside one order.</para>
</formalpara>
 
<formalpara>
<title>Allocation algorithm</title>
 
<para>Upon <mathphrase>2<superscript>i</superscript></mathphrase>
frames block allocation request, allocator checks if there are any
blocks available at the order list <varname>i</varname>. If yes,
removes block from order list and returns its address. If no,
recursively allocates
<mathphrase>2<superscript>i+1</superscript></mathphrase> frame
block, splits it into two
<mathphrase>2<superscript>i</superscript></mathphrase> frame blocks.
Then adds one of the blocks to the <varname>i</varname> order list
and returns address of another.</para>
</formalpara>
 
<formalpara>
<title>Deallocation algorithm</title>
 
<para>Check if block has so called buddy (another free
<mathphrase>2<superscript>i</superscript></mathphrase> frame block
that can be linked with freed block into the
<mathphrase>2<superscript>i+1</superscript></mathphrase> block).
Technically, buddy is a odd/even block for even/odd block
respectively. Plus we can put an extra requirement, that resulting
block must be aligned to its size. This requirement guarantees
natural block alignment for the blocks coming out the allocation
system.</para>
 
<para>Using direct pointer arithmetics,
<varname>frame_t::ref_count</varname> and
<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>
 
<section>
<title>Overview</title>
 
<para><termdef><glossterm>Slab</glossterm> represents a contiguous
piece of memory, usually made of several physically contiguous
pages.</termdef> <termdef><glossterm>Slab cache</glossterm> consists
of one or more slabs.</termdef></para>
 
<para>The majority of memory allocation requests in the kernel are for
small, frequently used data structures. For this purpose the slab
allocator is a perfect solution. The basic idea behind the slab
allocator is to have lists of commonly used objects available packed
into pages. This avoids the overhead of allocating and destroying
commonly used types of objects such threads, virtual memory structures
etc. Also due to the exact allocated size matching, slab allocation
completely eliminates internal fragmentation issue.</para>
</section>
 
<section>
<title>Implementation</title>
 
<figure><mediaobject id="slab_alloc">
<imageobject role="html">
<imagedata fileref="images/slab_alloc.png" format="PNG" />
</imageobject>
 
<imageobject role="fop">
<imagedata fileref="images.vector/slab_alloc.svg" format="SVG" />
</imageobject>
</mediaobject>
<title>Slab allocator scheme.</title>
</figure>
 
<para>The slab allocator is closely modelled after <ulink
url="http://www.usenix.org/events/usenix01/full_papers/bonwick/bonwick_html/">
OpenSolaris slab allocator by Jeff Bonwick and Jonathan Adams </ulink>
with the following exceptions: <itemizedlist>
<listitem>
empty slabs are deallocated immediately (in Linux they are kept in linked list, in Solaris ???)
</listitem>
 
<listitem>
empty magazines are deallocated when not needed (in Solaris they are held in linked list in slab cache)
</listitem>
</itemizedlist> Following features are not currently supported but
would be easy to do: <itemizedlist>
<listitem>
- cache coloring
</listitem>
 
<listitem>
- dynamic magazine grow (different magazine sizes are already supported, but we would need to adjust allocation strategy)
</listitem>
</itemizedlist></para>
 
<section>
<title>Magazine layer</title>
 
<para>Due to the extensive bottleneck on SMP architures, caused by
global slab locking mechanism, making processing of all slab
allocation requests serialized, a new layer was introduced to the
classic slab allocator design. Slab allocator was extended to
support per-CPU caches 'magazines' to achieve good SMP scaling.
<termdef>Slab SMP perfromance bottleneck was resolved by introducing
a per-CPU caching scheme called as <glossterm>magazine
layer</glossterm></termdef>.</para>
 
<para>Magazine is a N-element cache of objects, so each magazine can
satisfy N allocations. Magazine behaves like a automatic weapon
magazine (LIFO, stack), so the allocation/deallocation become simple
push/pop pointer operation. Trick is that CPU does not access global
slab allocator data during the allocation from its magazine, thus
making possible parallel allocations between CPUs.</para>
 
<para>Implementation also requires adding another feature as the
CPU-bound magazine is actually a pair of magazines to avoid
thrashing when during allocation/deallocatiion of 1 item at the
magazine size boundary. LIFO order is enforced, which should avoid
fragmentation as much as possible.</para>
 
<para>Another important entity of magazine layer is the common full
magazine list (also called a depot), that stores full magazines that
may be used by any of the CPU magazine caches to reload active CPU
magazine. This list of magazines can be pre-filled with full
magazines during initialization, but in current implementation it is
filled during object deallocation, when CPU magazine becomes
full.</para>
 
<para>Slab allocator control structures are allocated from special
slabs, that are marked by special flag, indicating that it should
not be used for slab magazine layer. This is done to avoid possible
infinite recursions and deadlock during conventional slab allocaiton
requests.</para>
</section>
 
<section>
<title>Allocation/deallocation</title>
 
<para>Every cache contains list of full slabs and list of partialy
full slabs. Empty slabs are immediately freed (thrashing will be
avoided because of magazines).</para>
 
<para>The SLAB allocator allocates lots of space and does not free
it. When frame allocator fails to allocate the frame, it calls
slab_reclaim(). It tries 'light reclaim' first, then brutal reclaim.
The light reclaim releases slabs from cpu-shared magazine-list,
until at least 1 slab is deallocated in each cache (this algorithm
should probably change). The brutal reclaim removes all cached
objects, even from CPU-bound magazines.</para>
 
<formalpara>
<title>Allocation</title>
 
<para><emphasis>Step 1.</emphasis> When it comes to the allocation
request, slab allocator first of all checks availability of memory
in local CPU-bound magazine. If it is there, we would just "pop"
the CPU magazine and return the pointer to object.</para>
 
<para><emphasis>Step 2.</emphasis> If the CPU-bound magazine is
empty, allocator will attempt to reload magazin, swapping it with
second CPU magazine and returns to the first step.</para>
 
<para><emphasis>Step 3.</emphasis> Now we are in the situation
when both CPU-bound magazines are empty, which makes allocator to
access shared full-magazines depot to reload CPU-bound magazines.
If reload is succesful (meaning there are full magazines in depot)
algoritm continues at Step 1.</para>
 
<para><emphasis>Step 4.</emphasis> Final step of the allocation.
In this step object is allocated from the conventional slab layer
and pointer is returned.</para>
</formalpara>
 
<formalpara>
<title>Deallocation</title>
 
<para><emphasis>Step 1.</emphasis> During deallocation request,
slab allocator will check if the local CPU-bound magazine is not
full. In this case we will just push the pointer to this
magazine.</para>
 
<para><emphasis>Step 2.</emphasis> If the CPU-bound magazine is
full, allocator will attempt to reload magazin, swapping it with
second CPU magazine and returns to the first step.</para>
 
<para><emphasis>Step 3.</emphasis> Now we are in the situation
when both CPU-bound magazines are full, which makes allocator to
access shared full-magazines depot to put one of the magazines to
the depot and creating new empty magazine. Algoritm continues at
Step 1.</para>
</formalpara>
</section>
</section>
</section>
 
<!-- End of Physmem -->
</section>
 
<section>
<title>Memory sharing</title>
 
<para>Not implemented yet(?)</para>
</section>
</chapter>