Offers object and interface for allocating pages of memory.
Do not use the interface directly instead include PageCacheMacros.
PageCache-Object | Offers object and interface for allocating pages of memory. |
Copyright | This program is free software. |
Files | |
C-kern/ | Header file PageCache-Object. |
C-kern/ | Implementation file PageCache-Object impl. |
Types | |
struct pagecache_t | Export pagecache_t into global namespace. |
struct pagecache_it | Export pagecache_it into global namespace. |
Enumerations | |
pagesize_e | List of supported page sizes. |
Functions | |
test | |
unittest_memory_pagecache | Test functionality of pagecache_t and pagecache_it. |
pagecache_t | Uses iobj_DECLARE to declare interfaceable object. |
lifetime | |
pagecache_FREE | Static initializer. |
pagecache_INIT | Static initializer. |
query | |
isobject_pagecache | Returns true if member <pagecache_t.object> of pgcache is not null. |
call | |
allocpage_pagecache | Calls pgcache->iimpl->allocpage with pgcache->object as first parameter. |
releasepage_pagecache | Calls pgcache->iimpl->releasepage with pgcache->object as first parameter. |
sizeallocated_pagecache | Calls pgcache->iimpl->sizeallocated with pgcache->object as first parameter. |
allocstatic_pagecache | Calls pgcache->iimpl->allocstatic with pgcache->object as first parameter. |
freestatic_pagecache | Calls pgcache->iimpl->freestatic with pgcache->object as first parameter. |
sizestatic_pagecache | Calls pgcache->iimpl->sizestatic with pgcache->object as first parameter. |
emptycache_pagecache | Calls pgcache->iimpl->emptycache with pgcache->object as first parameter. |
pagecache_it | Interface which allows to allocate and relase pages of memory. |
allocpage | Allocates a single memory page of size pgsize. |
releasepage | Releases a single memory page. |
sizeallocated | Returns the sum of the size of all allocated pages. |
allocstatic | Allocates static memory which should live as long as pgcache. |
freestatic | Frees static memory. |
sizestatic | Size of memory allocated with allocstatic. |
emptycache | Releases all unused memory blocks back to the operating system. |
lifetime | |
pagecache_it_FREE | Static initializer. |
pagecache_it_INIT | Static initializer. |
query | |
pagesizeinbytes_pagecacheit | Translates enum pagesize_e into size in bytes. |
generic | |
genericcast_pagecacheit | Casts pointer pgcacheif into pointer to interface pagecache_it. |
pagecache_it_DECLARE | Declares an interface function table for accessing pagecache. |
inline implementation | |
pagecache_t | |
allocpage_pagecache | Implements pagecache_t.allocpage_pagecache. |
allocstatic_pagecache | Implements pagecache_t.allocstatic_pagecache. |
freestatic_pagecache | Implements pagecache_t.freestatic_pagecache. |
isobject_pagecache | Implements pagecache_t.isobject_pagecache. |
emptycache_pagecache | Implements pagecache_t.emptycache_pagecache. |
releasepage_pagecache | Implements pagecache_t.releasepage_pagecache. |
sizeallocated_pagecache | Implements pagecache_t.sizeallocated_pagecache. |
sizestatic_pagecache | Implements pagecache_t.sizestatic_pagecache. |
pagecache_it | |
genericcast_pagecacheit | Implements pagecache_it.genericcast_pagecacheit. |
pagecache_it_DECLARE | Implements pagecache_it.pagecache_it_DECLARE. |
pagesizeinbytes_pagecacheit | Implements pagecache_it.pagesizeinbytes_pagecacheit. |
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.
© 2013 Jörg Seebohn
Header file PageCache-Object.
Implementation file PageCache-Object impl.
typedef struct pagecache_t pagecache_t
Export pagecache_t into global namespace.
typedef struct pagecache_it pagecache_it
Export pagecache_it into global namespace.
List of supported page sizes. pagesize_256 - Request page size of 256 byte aligned to a 256 byte boundary. pagesize_1024 - Request page size of 1024 byte aligned to a 1024 byte boundary. pagesize_4096 - Request page size of 4096 byte aligned to a 4096 byte boundary. pagesize_16384 - Request page size of 16384 byte aligned to a 16384 byte boundary. pagesize_65536 - Request page size of 65536 byte aligned to a 65536 byte boundary. pagesize_1MB - Request page size of 1024*1024 byte aligned to a 1MB byte boundary.
test | |
unittest_memory_pagecache | Test functionality of pagecache_t and pagecache_it. |
int unittest_memory_pagecache( void )
Test functionality of pagecache_t and pagecache_it.
iobj_DECLARE( pagecache_t, pagecache )
Uses iobj_DECLARE to declare interfaceable object. See also pagecache_impl_t which is the default implementation.
lifetime | |
pagecache_FREE | Static initializer. |
pagecache_INIT | Static initializer. |
query | |
isobject_pagecache | Returns true if member <pagecache_t.object> of pgcache is not null. |
call | |
allocpage_pagecache | Calls pgcache->iimpl->allocpage with pgcache->object as first parameter. |
releasepage_pagecache | Calls pgcache->iimpl->releasepage with pgcache->object as first parameter. |
sizeallocated_pagecache | Calls pgcache->iimpl->sizeallocated with pgcache->object as first parameter. |
allocstatic_pagecache | Calls pgcache->iimpl->allocstatic with pgcache->object as first parameter. |
freestatic_pagecache | Calls pgcache->iimpl->freestatic with pgcache->object as first parameter. |
sizestatic_pagecache | Calls pgcache->iimpl->sizestatic with pgcache->object as first parameter. |
emptycache_pagecache | Calls pgcache->iimpl->emptycache with pgcache->object as first parameter. |
int allocpage_pagecache( const pagecache_t pgcache, uint8_t pgsize, /*out*/struct memblock_t * page )
Calls pgcache->iimpl->allocpage with pgcache->object as first parameter. See pagecache_it.allocpage.
int releasepage_pagecache( const pagecache_t pgcache, struct memblock_t * page )
Calls pgcache->iimpl->releasepage with pgcache->object as first parameter. See pagecache_it.releasepage.
size_t sizeallocated_pagecache( const pagecache_t pgcache )
Calls pgcache->iimpl->sizeallocated with pgcache->object as first parameter. See pagecache_it.sizeallocated.
int allocstatic_pagecache( const pagecache_t pgcache, size_t bytesize, /*out*/struct memblock_t * memblock )
Calls pgcache->iimpl->allocstatic with pgcache->object as first parameter. See pagecache_it.allocstatic.
int freestatic_pagecache( const pagecache_t pgcache, struct memblock_t * memblock )
Calls pgcache->iimpl->freestatic with pgcache->object as first parameter. See pagecache_it.freestatic.
size_t sizestatic_pagecache( const pagecache_t pgcache )
Calls pgcache->iimpl->sizestatic with pgcache->object as first parameter. See pagecache_it.sizestatic.
int emptycache_pagecache( const pagecache_t pgcache )
Calls pgcache->iimpl->emptycache with pgcache->object as first parameter. See pagecache_it.emptycache.
struct pagecache_it
Interface which allows to allocate and relase pages of memory.
allocpage | Allocates a single memory page of size pgsize. |
releasepage | Releases a single memory page. |
sizeallocated | Returns the sum of the size of all allocated pages. |
allocstatic | Allocates static memory which should live as long as pgcache. |
freestatic | Frees static memory. |
sizestatic | Size of memory allocated with allocstatic. |
emptycache | Releases all unused memory blocks back to the operating system. |
lifetime | |
pagecache_it_FREE | Static initializer. |
pagecache_it_INIT | Static initializer. |
query | |
pagesizeinbytes_pagecacheit | Translates enum pagesize_e into size in bytes. |
generic | |
genericcast_pagecacheit | Casts pointer pgcacheif into pointer to interface pagecache_it. |
pagecache_it_DECLARE | Declares an interface function table for accessing pagecache. |
int ( * allocpage ) (pagecache_t * pgcache, uint8_t pgsize, /*out*/struct memblock_t * page)
Allocates a single memory page of size pgsize. The page is aligned to its own size. pgsize must be a value from pagesize_e.
int ( * releasepage ) (pagecache_t * pgcache, struct memblock_t * page)
Releases a single memory page. It is kept in the cache and only returned to the operating system if a big chunk of memory is not in use. After return page is set to <memblock_FREE>. Calling this function with page set to <memblock_FREE> does nothing.
int ( * allocstatic ) (pagecache_t * pgcache, size_t bytesize, /*out*/struct memblock_t * memblock)
Allocates static memory which should live as long as pgcache. These blocks can only be freed by freeing pgcache. The size of memory is set in bytes with parameter bytesize. The allocated memory block (aligned to KONFIG_MEMALIGN) is returned in memblock. In case of no memory ENOMEM is returned. The size of the block if restricted to 128 bytes.
int ( * freestatic ) (pagecache_t * pgcache, struct memblock_t * memblock)
Frees static memory. If this function is not called in the reverse order of the call sequence of <allocstatic_pagecacheimpl> the value EINVAL is returned and nothing is done. After return memblock is set to <memblock_FREE>. Calling this function with memblock set to <memblock_FREE> does nothing.
size_t ( * sizestatic ) (const pagecache_t * pgcache)
Size of memory allocated with allocstatic.
#define pagecache_it_INIT( allocpage_f, releasepage_f, sizeallocated_f, allocstatic_f, sizestatic_f, freestatic_f, emptycache_f ) { (allocpage_f), (releasepage_f), (sizeallocated_f), (allocstatic_f), (sizestatic_f), (freestatic_f), (emptycache_f) }
Static initializer. Set all function pointers to the provided values.
allocpage_f | Function pointer to allocate memory pages. See pagecache_it.allocpage. |
releasepage_f | Function pointer to release memory pages. See pagecache_it.releasepage. |
sizeallocated_f | Function pointer to query the sum of the size of all allocated memory page. See pagecache_it.sizeallocated. |
allocstatic_f | Function pointer to allocate static blocks of memory. See pagecache_it.allocstatic. |
freestatic_f | Function pointer to free static blocks of memory. See pagecache_it.freestatic. |
sizestatic_f | Function pointer to query size of static allocated memory. See pagecache_it.sizestatic. |
emptycache_f | Function pointer to return unused memory blocks back to the OS. See pagecache_it.emptycache. |
size_t pagesizeinbytes_pagecacheit( pagesize_e pagesize )
Translates enum pagesize_e into size in bytes.
pagecache_it * genericcast_pagecacheit( void * pgcacheif, TYPENAME pagecache_t )
Casts pointer pgcacheif into pointer to interface pagecache_it. Parameter pgcacheif must point to a type declared with pagecache_it_DECLARE. The other parameters must be the same as in pagecache_it_DECLARE without the first.
void pagecache_it_DECLARE( TYPENAME declared_it, TYPENAME pagecache_t )
Declares an interface function table for accessing pagecache. The declared interface is structural compatible with pagecache_it. The difference between the newly declared interface and the generic interface is the type of the first parameter.
See pagecache_it for a list of declared functions.
declared_it | The name of the structure which is declared as the interface. The name should have the suffix “_it”. |
pagecache_t | The type of the pagecache object which is the first parameter of all interface functions. |
#define allocpage_pagecache( pgcache, pgsize, page ) ((pgcache).iimpl->allocpage((pgcache).object, (pgsize), (page)))
Implements pagecache_t.allocpage_pagecache.
#define allocstatic_pagecache( pgcache, bytesize, memblock ) ((pgcache).iimpl->allocstatic((pgcache).object, (bytesize), (memblock)))
Implements pagecache_t.allocstatic_pagecache.
#define freestatic_pagecache( pgcache, memblock ) ((pgcache).iimpl->freestatic((pgcache).object, (memblock)))
Implements pagecache_t.freestatic_pagecache.
#define isobject_pagecache( pgcache ) (0 != (pgcache)->object)
Implements pagecache_t.isobject_pagecache.
#define emptycache_pagecache( pgcache ) ((pgcache).iimpl->emptycache((pgcache).object))
Implements pagecache_t.emptycache_pagecache.
#define releasepage_pagecache( pgcache, page ) ((pgcache).iimpl->releasepage((pgcache).object, (page)))
Implements pagecache_t.releasepage_pagecache.
#define sizeallocated_pagecache( pgcache ) ((pgcache).iimpl->sizeallocated((pgcache).object))
Implements pagecache_t.sizeallocated_pagecache.
#define sizestatic_pagecache( pgcache ) ((pgcache).iimpl->sizestatic((pgcache).object))
Implements pagecache_t.sizestatic_pagecache.
#define genericcast_pagecacheit( pgcacheif, pagecache_t ) ( __extension__ ({ static_assert( offsetof(typeof(*(pgcacheif)), allocpage) == offsetof(pagecache_it, allocpage) && offsetof(typeof(*(pgcacheif)), releasepage) == offsetof(pagecache_it, releasepage) && offsetof(typeof(*(pgcacheif)), sizeallocated) == offsetof(pagecache_it, sizeallocated) && offsetof(typeof(*(pgcacheif)), allocstatic) == offsetof(pagecache_it, allocstatic) && offsetof(typeof(*(pgcacheif)), freestatic) == offsetof(pagecache_it, freestatic) && offsetof(typeof(*(pgcacheif)), sizestatic) == offsetof(pagecache_it, sizestatic) && sizeof(int) == sizeof((pgcacheif)->allocpage( (pagecache_t*)0, pagesize_16384, (struct memblock_t*)0)) && sizeof(int) == sizeof((pgcacheif)->releasepage( (pagecache_t*)0, (struct memblock_t*)0)) && sizeof(size_t) == sizeof((pgcacheif)->sizeallocated( (const pagecache_t*)0)) && sizeof(int) == sizeof((pgcacheif)->allocstatic( (pagecache_t*)0, (size_t)0, (struct memblock_t*)0)) && sizeof(int) == sizeof((pgcacheif)->freestatic( (pagecache_t*)0, (struct memblock_t*)0)) && sizeof(size_t) == sizeof((pgcacheif)->sizestatic( (const pagecache_t*)0)) && sizeof(int) == sizeof((pgcacheif)->emptycache( (pagecache_t*)0)), "ensure same structure") ; if (0) { int _err ; size_t _err2 ; _err = (pgcacheif)->allocpage( (pagecache_t*)0, pagesize_16384, (struct memblock_t*)0) ; _err += (pgcacheif)->releasepage( (pagecache_t*)0, (struct memblock_t*)0) ; _err2 = (pgcacheif)->sizeallocated( (const pagecache_t*)0) ; _err += (pgcacheif)->allocstatic( (pagecache_t*)0, (size_t)128, (struct memblock_t *)0) ; _err += (pgcacheif)->freestatic( (pagecache_t*)0, (struct memblock_t *)0) ; _err2 += (pgcacheif)->sizestatic( (const pagecache_t*)0) ; _err += (pgcacheif)->emptycache( (pagecache_t*)0) ; _err2 += (size_t)_err ; (void) _err2 ; } (pagecache_it*) (pgcacheif) ; }))
Implements pagecache_it.genericcast_pagecacheit.
#define pagecache_it_DECLARE( declared_it, pagecache_t ) typedef struct declared_it declared_it ; struct declared_it { int (*allocpage) (pagecache_t * pgcache, uint8_t pgsize, /*out*/struct memblock_t * page) ; int (*releasepage) (pagecache_t * pgcache, struct memblock_t * page) ; size_t (*sizeallocated) (const pagecache_t * pgcache) ; int (*allocstatic) (pagecache_t * pgcache, size_t bytesize, /*out*/struct memblock_t * memblock) ; int (*freestatic) (pagecache_t * pgcache, struct memblock_t * memblock) ; size_t (*sizestatic) (const pagecache_t * pgcache) ; int (*emptycache) (pagecache_t * pgcache) ; } ;
Implements pagecache_it.pagecache_it_DECLARE.
Implements pagecache_it.pagesizeinbytes_pagecacheit.
Export pagecache_t into global namespace.
typedef struct pagecache_t pagecache_t
Uses iobj_DECLARE to declare interfaceable object.
iobj_DECLARE( pagecache_t, pagecache )
Export pagecache_it into global namespace.
typedef struct pagecache_it pagecache_it
Interface which allows to allocate and relase pages of memory.
struct pagecache_it
Test functionality of pagecache_t and pagecache_it.
int unittest_memory_pagecache( void )
Implements iobj_t.iobj_DECLARE.
#define iobj_DECLARE( declared_t, typenameprefix ) struct declared_t { struct typenameprefix##_t * object ; struct typenameprefix##_it * iimpl ; }
Static initializer.
#define pagecache_FREE iobj_FREE
Static initializer.
#define pagecache_INIT( object, iimpl ) iobj_INIT(object, iimpl)
Returns true if member pagecache_t.object of pgcache is not null.
bool isobject_pagecache( const pagecache_t * pgcache )
Calls pgcache->iimpl->allocpage with pgcache->object as first parameter.
int allocpage_pagecache( const pagecache_t pgcache, uint8_t pgsize, /*out*/struct memblock_t * page )
Calls pgcache->iimpl->releasepage with pgcache->object as first parameter.
int releasepage_pagecache( const pagecache_t pgcache, struct memblock_t * page )
Calls pgcache->iimpl->sizeallocated with pgcache->object as first parameter.
size_t sizeallocated_pagecache( const pagecache_t pgcache )
Calls pgcache->iimpl->allocstatic with pgcache->object as first parameter.
int allocstatic_pagecache( const pagecache_t pgcache, size_t bytesize, /*out*/struct memblock_t * memblock )
Calls pgcache->iimpl->freestatic with pgcache->object as first parameter.
int freestatic_pagecache( const pagecache_t pgcache, struct memblock_t * memblock )
Calls pgcache->iimpl->sizestatic with pgcache->object as first parameter.
size_t sizestatic_pagecache( const pagecache_t pgcache )
Calls pgcache->iimpl->emptycache with pgcache->object as first parameter.
int emptycache_pagecache( const pagecache_t pgcache )
Allocates a single memory page of size pgsize.
int ( * allocpage ) (pagecache_t * pgcache, uint8_t pgsize, /*out*/struct memblock_t * page)
Releases a single memory page.
int ( * releasepage ) (pagecache_t * pgcache, struct memblock_t * page)
Returns the sum of the size of all allocated pages.
size_t ( * sizeallocated ) (const pagecache_t * pgcache)
Allocates static memory which should live as long as pgcache.
int ( * allocstatic ) (pagecache_t * pgcache, size_t bytesize, /*out*/struct memblock_t * memblock)
Frees static memory.
int ( * freestatic ) (pagecache_t * pgcache, struct memblock_t * memblock)
Size of memory allocated with allocstatic.
size_t ( * sizestatic ) (const pagecache_t * pgcache)
Releases all unused memory blocks back to the operating system.
int ( * emptycache ) (pagecache_t * pgcache)
Static initializer.
#define pagecache_it_FREE { 0, 0, 0, 0, 0, 0, 0 }
Static initializer.
#define pagecache_it_INIT( allocpage_f, releasepage_f, sizeallocated_f, allocstatic_f, sizestatic_f, freestatic_f, emptycache_f ) { (allocpage_f), (releasepage_f), (sizeallocated_f), (allocstatic_f), (sizestatic_f), (freestatic_f), (emptycache_f) }
Translates enum pagesize_e into size in bytes.
size_t pagesizeinbytes_pagecacheit( pagesize_e pagesize )
Casts pointer pgcacheif into pointer to interface pagecache_it.
pagecache_it * genericcast_pagecacheit( void * pgcacheif, TYPENAME pagecache_t )
Declares an interface function table for accessing pagecache.
void pagecache_it_DECLARE( TYPENAME declared_it, TYPENAME pagecache_t )
Implements pagecache_t.allocpage_pagecache.
#define allocpage_pagecache( pgcache, pgsize, page ) ((pgcache).iimpl->allocpage((pgcache).object, (pgsize), (page)))
Implements pagecache_t.allocstatic_pagecache.
#define allocstatic_pagecache( pgcache, bytesize, memblock ) ((pgcache).iimpl->allocstatic((pgcache).object, (bytesize), (memblock)))
Implements pagecache_t.freestatic_pagecache.
#define freestatic_pagecache( pgcache, memblock ) ((pgcache).iimpl->freestatic((pgcache).object, (memblock)))
Implements pagecache_t.isobject_pagecache.
#define isobject_pagecache( pgcache ) (0 != (pgcache)->object)
Implements pagecache_t.emptycache_pagecache.
#define emptycache_pagecache( pgcache ) ((pgcache).iimpl->emptycache((pgcache).object))
Implements pagecache_t.releasepage_pagecache.
#define releasepage_pagecache( pgcache, page ) ((pgcache).iimpl->releasepage((pgcache).object, (page)))
Implements pagecache_t.sizeallocated_pagecache.
#define sizeallocated_pagecache( pgcache ) ((pgcache).iimpl->sizeallocated((pgcache).object))
Implements pagecache_t.sizestatic_pagecache.
#define sizestatic_pagecache( pgcache ) ((pgcache).iimpl->sizestatic((pgcache).object))
Implements pagecache_it.genericcast_pagecacheit.
#define genericcast_pagecacheit( pgcacheif, pagecache_t ) ( __extension__ ({ static_assert( offsetof(typeof(*(pgcacheif)), allocpage) == offsetof(pagecache_it, allocpage) && offsetof(typeof(*(pgcacheif)), releasepage) == offsetof(pagecache_it, releasepage) && offsetof(typeof(*(pgcacheif)), sizeallocated) == offsetof(pagecache_it, sizeallocated) && offsetof(typeof(*(pgcacheif)), allocstatic) == offsetof(pagecache_it, allocstatic) && offsetof(typeof(*(pgcacheif)), freestatic) == offsetof(pagecache_it, freestatic) && offsetof(typeof(*(pgcacheif)), sizestatic) == offsetof(pagecache_it, sizestatic) && sizeof(int) == sizeof((pgcacheif)->allocpage( (pagecache_t*)0, pagesize_16384, (struct memblock_t*)0)) && sizeof(int) == sizeof((pgcacheif)->releasepage( (pagecache_t*)0, (struct memblock_t*)0)) && sizeof(size_t) == sizeof((pgcacheif)->sizeallocated( (const pagecache_t*)0)) && sizeof(int) == sizeof((pgcacheif)->allocstatic( (pagecache_t*)0, (size_t)0, (struct memblock_t*)0)) && sizeof(int) == sizeof((pgcacheif)->freestatic( (pagecache_t*)0, (struct memblock_t*)0)) && sizeof(size_t) == sizeof((pgcacheif)->sizestatic( (const pagecache_t*)0)) && sizeof(int) == sizeof((pgcacheif)->emptycache( (pagecache_t*)0)), "ensure same structure") ; if (0) { int _err ; size_t _err2 ; _err = (pgcacheif)->allocpage( (pagecache_t*)0, pagesize_16384, (struct memblock_t*)0) ; _err += (pgcacheif)->releasepage( (pagecache_t*)0, (struct memblock_t*)0) ; _err2 = (pgcacheif)->sizeallocated( (const pagecache_t*)0) ; _err += (pgcacheif)->allocstatic( (pagecache_t*)0, (size_t)128, (struct memblock_t *)0) ; _err += (pgcacheif)->freestatic( (pagecache_t*)0, (struct memblock_t *)0) ; _err2 += (pgcacheif)->sizestatic( (const pagecache_t*)0) ; _err += (pgcacheif)->emptycache( (pagecache_t*)0) ; _err2 += (size_t)_err ; (void) _err2 ; } (pagecache_it*) (pgcacheif) ; }))
Implements pagecache_it.pagecache_it_DECLARE.
#define pagecache_it_DECLARE( declared_it, pagecache_t ) typedef struct declared_it declared_it ; struct declared_it { int (*allocpage) (pagecache_t * pgcache, uint8_t pgsize, /*out*/struct memblock_t * page) ; int (*releasepage) (pagecache_t * pgcache, struct memblock_t * page) ; size_t (*sizeallocated) (const pagecache_t * pgcache) ; int (*allocstatic) (pagecache_t * pgcache, size_t bytesize, /*out*/struct memblock_t * memblock) ; int (*freestatic) (pagecache_t * pgcache, struct memblock_t * memblock) ; size_t (*sizestatic) (const pagecache_t * pgcache) ; int (*emptycache) (pagecache_t * pgcache) ; } ;
Allocates and frees virtual memory pages and caches them.
struct pagecache_impl_t
Alignment of allocated memory.
#define KONFIG_MEMALIGN 4