gpt4 book ai didi

c - 为什么kem_cache->node可以分配地址或array_cache?

转载 作者:太空宇宙 更新时间:2023-11-04 08:55:39 25 4
gpt4 key购买 nike

这是 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.harray 变量上方的注释暗示了这一点:

/* 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];

关于c - 为什么kem_cache->node可以分配地址或array_cache?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17267271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com