percpu-km.c 和 percpu-vm.c 之间的区别
我在研究内核 Percpu Allocator 的时候,该分配器 部分函数的实现提供了两种实现方式,两种方式分别定义在 percpu-km.c 和 percpu-vm.c 中.1. 请问这两个文件有什么基本区别?
2. Percpu Allocator 使用哪个文件的函数作为自己的接口函数?
/*
* Chunk management implementation.
*
* To allow different implementations, chunk alloc/free and
* population are implemented in a separate file which is pulled
* into this file and compiled together.The following functions
* should be implemented.
*
* pcpu_populate_chunk - populate the specified range of a chunk
* pcpu_depopulate_chunk - depopulate the specified range of a chunk
* pcpu_create_chunk - create a new chunk
* pcpu_destroy_chunk - destroy a chunk, always preceded by full depop
* pcpu_addr_to_page - translate address to physical address
* pcpu_verify_alloc_info - check alloc_info is acceptable during init
*/
static int pcpu_populate_chunk(struct pcpu_chunk *chunk, int off, int size);
static void pcpu_depopulate_chunk(struct pcpu_chunk *chunk, int off, int size);
static struct pcpu_chunk *pcpu_create_chunk(void);
static void pcpu_destroy_chunk(struct pcpu_chunk *chunk);
static struct page *pcpu_addr_to_page(void *addr);
static int __init pcpu_verify_alloc_info(const struct pcpu_alloc_info *ai);
#ifdef CONFIG_NEED_PER_CPU_KM
#include "percpu-km.c"
#else
#include "percpu-vm.c"
#endif 本帖最后由 nswcfd 于 2016-02-04 11:11 编辑
以上只是表面区别,细节还没研究过,楼主搞清楚了可以跟大家分享一下:lol 回复 2# nswcfd
谢谢!
我在做 SLUB 分配器初始化的时候,需要从 Percpu 分配器内分配内存.
经测试之后只有 percpu-km.c 里面的代码可以完成 SLUB 的初始化, percpu-vm.c 的分配依赖于 SLUB 分配器.
所以在 SLUB 期间我使用的是 percpu-km.c
我看来 percpu-km.c 的代码中有讲这些函数用在 nommu 的体系中,但我的代码是基于 MMU 去实现的.
这里有点纠结不懂,既然我的 MMU 代码只有使用 percpu-km.c 才能对 SLUB 初始化,但源码中又那么说,不知道我使用 percpu-km.c 可不可以?
/*
* mm/percpu-km.c - kernel memory based chunk allocation
*
* Copyright (C) 2010 SUSE Linux Products GmbH
* Copyright (C) 2010 Tejun Heo <tj@kernel.org>
*
* This file is released under the GPLv2.
*
* Chunks are allocated as a contiguous kernel memory using gfp
* allocation.This is to be used on nommu architectures.
*
* To use percpu-km,
*
* - define CONFIG_NEED_PER_CPU_KM from the arch Kconfig.
*
* - CONFIG_NEED_PER_CPU_PAGE_FIRST_CHUNK must not be defined.It's
* not compatible with PER_CPU_KM.EMBED_FIRST_CHUNK should work
* fine.
*
* - NUMA is not supported.When setting up the first chunk,
* @cpu_distance_fn should be NULL or report all CPUs to be nearer
* than or at LOCAL_DISTANCE.
*
* - It's best if the chunk size is power of two multiple of
* PAGE_SIZE.Because each chunk is allocated as a contiguous
* kernel memory block using alloc_pages(), memory will be wasted if
* chunk size is not aligned.percpu-km code will whine about it.
*/
听起来是个循环依赖?
slub -> per_cpu -> slub ?
貌似slab/slub的初始化过程有个分阶段初始化的过程,不知道跟这个循环有没有关系? 回复 5# nswcfd
HI:
如果使用 percpu-vm.c 的话就是 SLUB Allocator 依赖 Percpu Allocator 依赖 SLUB Allocator.
所以我改用 percpu-km.c 之后, Percpu Allocator 依赖 Bootmem Allocator,此时 Bootmem Allocator 已经初始化完毕,可以使用,
所以我使用了 percpu-km.c ,接下来我要继续研究什么上下文运用 percpu-vm.c ,粗略的了解到 percpu-vm.c 与 SMP 有关.
我再继续研究研究.:D
页:
[1]