Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1013770
  • 博文数量: 123
  • 博客积分: 5051
  • 博客等级: 大校
  • 技术积分: 1356
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-14 10:56
文章分类
文章存档

2012年(1)

2011年(21)

2010年(13)

2009年(55)

2008年(33)

分类: LINUX

2009-07-17 11:30:53

内存区管理重要的数据结构

1、kmem_cache
高速缓存描述符:kmem_cache(管理一个高速缓存)
struct kmem_cache {
    struct array_cache *array[NR_CPUS];
    unsigned int batchcount;     //要转移本地高速缓存的大批对象的数量
    unsigned int limit;        //本地高速缓存中空闲对象的最大数目
    unsigned int shared;
    unsigned int buffer_size;    //高速缓存的大小
    u32 reciprocal_buffer_size;
    
    unsigned int flags;    //描述高速缓存永久属性的一组标志
    unsigned int num;    //封装在一个单独slab中的对象个数
    unsigned int     gfporder; // 一个单独slab中包含的连续页框数目的对数
    gfp_t gfpflags;
    size_t colour;        //slab使用的颜色个数
    unsigned_int colour_off; //slab中的基本对齐偏移

    struct kmem_cache *slabp_cache;
   
    unsigned int slab_size;     //slab的大小
    unsigned int dflags;         //动态标志
   
    void (*ctor)(void *,struct kmem_cache *,unsigned long);            //构造函数
    const char *name;        //存放高速缓存名字的字符数组
    struct list_head next;        //高速缓存描述符双向链表使用的指针
    ...
    struct kmem_list3 *nodelists[MAX_NUMNODES];//高速缓存中的slab链表
       
    //下面三个参数待定   
    unsigned int objsize;    //高速缓存中包含的对象的大小
    unsigned int free_limit;//整个slab高速缓存中空闲对象的上限
    spinlock_t    spinlock;//高速缓存自旋锁
}

2、kmem_list3
高速缓存中的slab链表:kmem_list3
所有对象所依靠的slab链表
kmem_list3 {
    struct list_head slabs_partial;    //含有部分对象的链表
    struct list_head slabs_full;    //满对象链表
    struct list_head slabs_free;    //空对象链表
    unsigned long free_objects;
    unsigned int free_limit;
    unsigned int colour_next;    //每节点高速缓存的颜色
    spinlock_t list_lock;
    struct array_cache *shared;    //每节点的共享高速缓存
    struct array_cache **alien;    //其他节点
    unsigned long next_reap;   
    int free_touched;    //???
}
struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];


2、slab
slab描述符:slab
struct slab {
    struct list_head list;        //slab描述符的三个双向循环链表中的一个
    unsigned long colouroff;    //slab中第一个对象
    void *s_mem;            //slab中第一个对象的地址
    unsigned int inuse;        //当前正在使用的slab中的对象的个数
    kmem_bufctl_t free;        //slab中一个空闲对象的下标。
    unsigned short nodeid;
}

3、cache_sizes
描述通用高速缓存大小尺寸对应的描述符:cache_sizes
struct cache_sizes {
    size_t             cs_size;
    struct kmem_cache    *cs_cachep;
    struct kmem_cache    *cs_dmacachep;
};

4、malloc_sizes
高速缓存描述符数组:malloc_sizes
malloc_sizes这是一个数组,可以看作一个表,用来指向26个高速缓存描述符的
struct cache_sizes malloc_sizes[] = {
#define CACHE(x) {.cs_size = (x) },
#include
/*
#if (PAGE_SIZE == 4096)
    CACHE(32)
#endif
    CACHE(64)
#if L1_CACHE_BYTES < 64    // L1_CACHE_BYTES = 128
    CACHE(96)
#endif
    CACHE(128)
#if L1_CACHE_BYTES < 128
    CACHE(192)
#endif
    CACHE(256)
    CACHE(512)
    CACHE(1024)
    CACHE(2048)
    CACHE(4096)
    CACHE(8192)
    CACHE(16384)
    CACHE(32768)
    CACHE(65536)
    CACHE(131072)
#if KMALLOC_MAX_SIZE >= 262144
    CACHE(262144)
#endif
#if KMALLOC_MAX_SIZE >= 524288
    CACHE(524288)
#endif
#if KMALLOC_MAX_SIZE >= 1048576
    CACHE(1048576)
#endif
#if KMALLOC_MAX_SIZE >= 2097152
    CACHE(2097152)
#endif
#if KMALLOC_MAX_SIZE >= 4194304
    CACHE(4194304)
#endif
#if KMALLOC_MAX_SIZE >= 8388608
    CACHE(8388608)
#endif
#if KMALLOC_MAX_SIZE >= 16777216
    CACHE(16777216)
#endif
#if KMALLOC_MAX_SIZE >= 33554432
    CACHE(33554432)
#endif
*/
    CACHE(ULONG_MAX);
#undef CACHE
}

5、cache_names
数据结构cache_names:
struct cache_names {
    char *name;
    char *name_dma;   
};
全局静态变量:cache_names[]
static struct cache_names __initdata cache_names[] = {
#define CACHE(x) {.name = "size-" #x,.name_dma = "size-" #x "(DMA)" },
#include
    {NULL,}
#undef CACHE
};
由此可以看出,cache_names是受到cache_sizes的影响的.

6、array_cache
结构体array_cache,空闲对象的本地高速缓存的一个描述符
struct array_cache {
    unsigned int avail;    //指向本地高速缓存可用对象的指针的个数
    unsigned int limit;    //本地高速缓存的大小,也就是本地高速缓存中指针的最大个数
    unsigned int batchcount;    //本地高速缓存重新填充或者是腾空时使用的块大小
    unsigned int touched;        //如果本地高随缓存最近已经被使用过,就将该标志设置为1
    spinlock_t lock;
    void *entry[0];
};

7、arraycache_init
结构体arraycache_init
struct arraycache_init {
    struct array_cache cache;
    void *entries[BOOT_CPUCACHE_ENTRIES];   
};
static struct arraycache_init initarray_cache __initdata={{0,BOOT_CPUCACHE_ENTRIES,1,0}};
 
阅读(1590) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~