资源简介
仿照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
相关资源
- 基于numa架构的tcmalloc内存管理算法
- malloc函数及用法
- C malloc函数用法
- 操作系统课程设计 内存管理
- 操作系统内存管理仿真
- 操作系统原理实验报告+源代码哲学家
- glibc内存管理ptmalloc源代码分析
- malloc实现源码
- linux源代码分析之内存管理
- CSAPP: malloc lab 文档及解答
- XV6阅读报告包含进程线程、内存管理
- malloclab-handout.tar
- 操作系统进程管理和内存管理demo
-
zw_ob
jective-C高级编程iOS与OSX多线程和 - 内存管理算法模拟(首次分配、邻近
- 十六进制转物理地址
- qemu内存管理流程
- 内存管理选择题.txt
- malloclab全套资料及参考答案
- 虚拟内存管理基于时钟策略的页面置
- 伙伴系统Buddy System 内存管理
- csapp lab6 malloc lab 96pt
- 操作系统实验三源代码加实验报告
- nginx slab内存管理精简源码及注释
- 系统级编程lab7 第七次实验 四川大学
- 四川大学操作系统虚拟内存管理实验
- 操作系统进程管理与内存管理QT实现界
- csapp malloc lab 原创北大&cmu; 仅供参考
- 简单的内存管理结构
- 用C实现的段页式内存管理
评论
共有 条评论