这是 mm/slab.c 中的一个函数,它出现在 kmem_cache 的启动初始化中。我不明白这个函数以及 array_cache 实际使用的是 kmem_cache->array。
static void setup_node_pointer(struct kmem_cache *cachep)
{
cachep->node = (struct kmem_cache_node **)&cachep->array[nr_cpu_ids];
}
谁能帮我解决这个问题?
您是否阅读了该函数顶部的评论?
/*
* The memory after the last cpu cache pointer is used for the
* the node pointer.
*/
slab 分配器正在使用 array
变量中的额外指针空间来存储节点指针(而不是 array_cache
指针)。 slab_def.h
中 array
变量上方的注释暗示了这一点:
/* 6) per-cpu/per-node data, touched during every alloc/free */
/*
* We put array[] at the end of kmem_cache, because we want to size
* this array to nr_cpu_ids slots instead of NR_CPUS
* (see kmem_cache_init())
* We still use [NR_CPUS] and not [1] or [0] because cache_cache
* is statically defined, so we reserve the max number of cpus.
*
* We also need to guarantee that the list is able to accomodate a
* pointer for each node since "nodelists" uses the remainder of
* available pointers.
*/
struct kmem_cache_node **node;
struct array_cache *array[NR_CPUS + MAX_NUMNODES];
我是一名优秀的程序员,十分优秀!