- 论坛徽章:
- 0
|
本帖最后由 l4rmbr 于 2014-03-24 22:57 编辑
回复 1# chishanmingshen
chishanmingshen,
动态的per_cpu数据的分配 ,主要实现是一种叫pcpu_chunk的重要数据结构。
它有效的组织per_cpu数据的创建,管理,分配,回收。
这个per_cpu分配接口是基于虚拟内存的底层实现的,Linux中采取了两种分配所需虚拟内存的方式,一种是基于
slab的kmalloc接口,一种就是基于vmalloc接口。
mm/percpu.c是实现percpu数据分配接口的主要文件,
至于底层的内存分配,该文件根据不同的配置,可以基于上述
kmalloc接口或vmalloc接口实现。看代码(v3.14-rc7):- 637 /*
- 638 * Chunk management implementation.
- 639 *
- 640 * To allow different implementations, chunk alloc/free and
- 641 * [de]population are implemented in a separate file which is pulled
- 642 * into this file and compiled together. The following functions
- 643 * should be implemented.
- 644 *
- 645 * pcpu_populate_chunk - populate the specified range of a chunk
- 646 * pcpu_depopulate_chunk - depopulate the specified range of a chunk
- 647 * pcpu_create_chunk - create a new chunk
- 648 * pcpu_destroy_chunk - destroy a chunk, always preceded by full depop
- 649 * pcpu_addr_to_page - translate address to physical address
- 650 * pcpu_verify_alloc_info - check alloc_info is acceptable during init
- 651 */
- 652 static int pcpu_populate_chunk(struct pcpu_chunk *chunk, int off, int size);
- 653 static void pcpu_depopulate_chunk(struct pcpu_chunk *chunk, int off, int size);
- 654 static struct pcpu_chunk *pcpu_create_chunk(void);
- 655 static void pcpu_destroy_chunk(struct pcpu_chunk *chunk);
- 656 static struct page *pcpu_addr_to_page(void *addr);
- 657 static int __init pcpu_verify_alloc_info(const struct pcpu_alloc_info *ai);
- 658
- 659 #ifdef CONFIG_NEED_PER_CPU_KM
- 660 #include "percpu-km.c"
- 661 #else
- 662 #include "percpu-vm.c"
- 663 #endif
复制代码 根据需要,底层分配代码是基于vmalloc的mm/percpu-vm.c, 或基于kmalloc的mm/percpu-km.c
所以,看mm/percpu-vm.c , 其中有个pcpu_create_chunk()函数,创建用于分配per_cpu的chunk,
其实现正是调用了pcpu_get_vm_areas() |
|