Test-MemoryManager impl

Implements <TestMemoryManager>.

Summary
Test-MemoryManager implImplements <TestMemoryManager>.
CopyrightThis program is free software.
Files
C-kern/api/test/mm/testmm.hHeader file Test-MemoryManager.
C-kern/test/mm/testmm.cImplementation file Test-MemoryManager impl.
Types
struct testmm_block_tShortcut for testmm_block_t.
struct testmm_page_tShortcut for testmm_page_t.
testmm_itDeclares testmm_it as subtype of mm_it.
testmm_block_tDescribes the header of an allocated memory block.
Functions
alignsize_testmmblockAligns a value to the next multiple of KONFIG_MEMALIGN.
testmm_page_tHolds one big data block consisting of many vm memory pages.
lifetime
testmm_t
static variables
s_testmm_interfaceContains single instance of interface testmm_it.
helper
context
installold_testmmInstalls the previous mm_t if the current mm is of type testmm_t.
installnew_testmmInstalls mm_t which must be of type testmm_t.
lifetime
query
allocate
test

Copyright

This program is free software.  You can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

Author

© 2012 Jörg Seebohn

Files

C-kern/api/test/mm/testmm.h

Header file Test-MemoryManager.

C-kern/test/mm/testmm.c

Implementation file Test-MemoryManager impl.

Types

struct testmm_block_t

typedef struct testmm_block_t testmm_block_t

Shortcut for testmm_block_t.

struct testmm_page_t

typedef struct testmm_page_t testmm_page_t

Shortcut for testmm_page_t.

testmm_it

Declares testmm_it as subtype of mm_it.  See mm_it_DECLARE.

testmm_block_t

struct testmm_block_t

Describes the header of an allocated memory block.

Summary
Functions
alignsize_testmmblockAligns a value to the next multiple of KONFIG_MEMALIGN.

Functions

alignsize_testmmblock

static inline size_t alignsize_testmmblock(size_t bytesize)

Aligns a value to the next multiple of KONFIG_MEMALIGN.  If KONFIG_MEMALIGN is less than sizeof(void*) the value sizeof(void*) is chosen instead of KONFIG_MEMALIGN.

Precondition

KONFIG_MEMALIGN must be a power of two for this algorithm to work.

return (bytesize + (memalign-1)) & (~(memalign-1)) ;
memalign == 0b001000
(~(memalign-1)) == ~ (0b001000 - 1) == ~ (0b000111) == 0b111000

testmm_page_t

struct testmm_page_t

Holds one big data block consisting of many vm memory pages.  The memory allocation strategy is simple.  Memory allocation requests are always satified from the beginning of the last free block.  If it is too small allocation fails.  Freed blocks are only marked as freed.  If a memory block marked as free is directly before the last free block it is merged with.  The last free block grows in this manner until all freed blocks are merged.

Summary

lifetime

testmm_t

Summary
static variables
s_testmm_interfaceContains single instance of interface testmm_it.
helper
context
installold_testmmInstalls the previous mm_t if the current mm is of type testmm_t.
installnew_testmmInstalls mm_t which must be of type testmm_t.
lifetime
query
allocate
test

static variables

s_testmm_interface

static testmm_it s_testmm_interface

Contains single instance of interface testmm_it.

helper

context

installold_testmm

static int installold_testmm(/*out*/mm_t *testmm)

Installs the previous mm_t if the current mm is of type testmm_t.  The mm of type testmm_t is returnd in testmm.

installnew_testmm

static int installnew_testmm(const mm_t *testmm)

Installs mm_t which must be of type testmm_t.  The previous mm is stored in the first allocated block of testmm.

lifetime

query

allocate

test

Offers interface for allocating & freeing blocks of memory.
Implements TestMemoryManager.
typedef struct testmm_block_t testmm_block_t
Shortcut for testmm_block_t.
struct testmm_block_t
Describes the header of an allocated memory block.
typedef struct testmm_page_t testmm_page_t
Shortcut for testmm_page_t.
struct testmm_page_t
Holds one big data block consisting of many vm memory pages.
Declares testmm_it as subtype of mm_it.
struct mm_it
The function table describing the interface to a memory manager.
static inline size_t alignsize_testmmblock(size_t bytesize)
Aligns a value to the next multiple of KONFIG_MEMALIGN.
static testmm_it s_testmm_interface
Contains single instance of interface testmm_it.
static int installold_testmm(/*out*/mm_t *testmm)
Installs the previous mm_t if the current mm is of type testmm_t.
static int installnew_testmm(const mm_t *testmm)
Installs mm_t which must be of type testmm_t.
#define mm_it_DECLARE(
   declared_it,
   memorymanager_t
) typedef struct declared_it declared_it ; struct declared_it { int (* malloc) (memorymanager_t * mman, size_t size, /*out*/struct memblock_t * memblock) ; int (* mresize) (memorymanager_t * mman, size_t newsize, struct memblock_t * memblock) ; int (* mfree) (memorymanager_t * mman, struct memblock_t * memblock) ; size_t (* sizeallocated) (memorymanager_t * mman) ; } ;
Implements mm_it.mm_it_DECLARE.
Close