资源简介
仿照linux的buddy+slub内存管理算法,可以在裸机中应用标准内存管理库函数,如malloc free等
代码片段和文件信息
/*
* slab allocator implementation
*
* A slab allocator reserves a ZONE for each chunk size then lays the
* chunks out in an array within the zone. Allocation and deallocation
* is nearly instantanious and fragmentation/overhead losses are limited
* to a fixed worst-case amount.
*
* The downside of this slab implementation is in the chunk size
* multiplied by the number of zones. ~80 zones * 128K = 10MB of VM per cpu.
* In a kernel implementation all this memory will be physical so
* the zone size is adjusted downward on machines with less physical
* memory. The upside is that overhead is bounded... this is the *worst*
* case overhead.
*
* Slab management is done on a per-cpu basis and no locking or mutexes
* are required only a critical section. When one cpu frees memory
* belonging to another cpu‘s slab manager an asynchronous IPI message
* will be queued to execute the operation. In addition both the
* high level slab allocator and the low level zone allocator optimize
* M_ZERO requests and the slab allocator does not have to pre initialize
* the linked list of chunks.
*
* XXX Balancing is needed between cpus. Balance will be handled through
* asynchronous IPIs primarily by reassigning the z_Cpu ownership of chunks.
*
* XXX If we have to allocate a new zone and M_USE_RESERVE is set use of
* the new zone should be restricted to M_USE_RESERVE requests only.
*
* Alloc Size Chunking Number of zones
* 0-127 8 16
* 128-255 16 8
* 256-511 32 8
* 512-1023 64 8
* 1024-2047 128 8
* 2048-4095 256 8
* 4096-8191 512 8
* 8192-16383 1024 8
* 16384-32767 2048 8
* (if PAGE_SIZE is 4K the maximum zone allocation is 16383)
*
* Allocations >= zone_limit go directly to kmem.
*
* API REQUIREMENTS AND SIDE EFFECTS
*
* To operate as a drop-in replacement to the FreeBSD-4.x malloc() we
* have remained compatible with the following API requirements:
*
* + small power-of-2 sized allocations are power-of-2 aligned (kern_tty)
* + all power-of-2 sized allocations are power-of-2 aligned (twe)
* + malloc(0) is allowed and returns non-0 (ahc driver)
* + ability to allocate arbitrarily large chunks of memory
*/
/*
* Chunk structure for free elements
*/
#define ASSERT(a)
#define ALIGN(size align) (((size) + (align) - 1) & ~((align)-1))
/**
* @ingroup BasicDef
*
* @def ALIGN_DOWN(size align)
* Return the down number of aligned at specified width. ALIGN_DOWN(13 4)
* would return 12.
*/
#define ALIGN_DOWN(size align) ((size) & ~((align) -1))
#define PAGE_SIZE 4096
#define PAGE_MASK (PAGE_SIZE - 1)
#define PAGE_BITS 12
#define SLAB_DEBUG
#define MEM_STATS
/* some statistical variable */
#ifdef MEM_STATS
static unsigned int used_mem max_mem;
#endif
static void (*malloc_hook)(void *ptr unsigned int size)=NULL;
static void (*free_hook)(void *ptr)=NULL;
void malloc_sethook(void (*hook)(void *ptr unsigned int size))
{
malloc_hook
相关资源
- 自己编写的malloc源码
- 操作系统 内存管理课程设计报告
- malloclab.zip
- 操作系统实验,进程调度,作业调度
- TLSF开源算法
- 进程调度与内存管理:这是我花了很
- linux内存管理实验报告
- 操作系统实验五 内存管理
- 动态分区分配内存管理源代码附有实
- 操作系统实验之内存管理
- 操作系统内存管理实验报告及源代码
- nachos内存管理
- Malloc和mfree函数的实现原理
- cmu malloc lab solution
- Linux内存管理详解.ppt
- 2015 Spark技术峰会-Spark优化及实践经验
- malloc的实现源码
- 实现虚拟内存管理的nachos操作系统实
- CSAPP malloc lab答案满分
- 内存分配与释放 allocfree
- csapp lab malloclab
- 编写程序实现采用可变分区方法管理
- linux的内存管理-总结文档
- 操作系统实验实验四 模拟内存管理程
- 操作系统内存管理 采用可变分区方式
评论
共有 条评论