0

这是 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];
}       

谁能帮我这个?

4

1 回答 1

2

您是否阅读了该功能顶部的评论?

/*
 * The memory after the last cpu cache pointer is used for the
 * the node pointer.
 */

slab 分配器在array变量中使用额外的指针空间来存储节点指针(而不是array_cache指针)。array变量 in上方的注释暗示了这一点slab_def.h

/* 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];
于 2013-06-24T03:04:20.323 回答