[malloc] Add cache discard mechanism

Add a facility allowing cached data to be discarded in order to
satisfy memory allocations that would otherwise fail.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2010-07-21 11:58:50 +01:00
parent 68613047f0
commit 9dc51afa2c
2 changed files with 85 additions and 46 deletions

View File

@@ -18,6 +18,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
*
*/
#include <stdlib.h>
#include <ipxe/tables.h>
extern size_t freemem;
@@ -56,4 +57,20 @@ static inline void free_dma ( void *ptr, size_t size ) {
free_memblock ( ptr, size );
}
/** A cache discarder */
struct cache_discarder {
/**
* Discard some cached data
*
* @ret discarded Number of cached items discarded
*/
unsigned int ( * discard ) ( void );
};
/** Cache discarder table */
#define CACHE_DISCARDERS __table ( struct cache_discarder, "cache_discarders" )
/** Declare a cache discarder */
#define __cache_discarder __table_entry ( CACHE_DISCARDERS, 01 )
#endif /* _IPXE_MALLOC_H */