免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 997 | 回复: 5
打印 上一主题 下一主题

[内存管理] percpu-km.c 和 percpu-vm.c 之间的区别 [复制链接]

论坛徽章:
9
程序设计版块每日发帖之星
日期:2016-02-11 06:20:00程序设计版块每日发帖之星
日期:2016-02-14 06:20:00程序设计版块每日发帖之星
日期:2016-02-14 06:20:0015-16赛季CBA联赛之吉林
日期:2016-03-23 17:25:0015-16赛季CBA联赛之浙江
日期:2016-04-01 08:25:0615-16赛季CBA联赛之山西
日期:2016-04-01 10:09:1915-16赛季CBA联赛之广夏
日期:2016-06-03 15:58:212016科比退役纪念章
日期:2016-07-28 17:42:5215-16赛季CBA联赛之广东
日期:2017-02-20 23:32:43
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2016-02-02 10:00 |只看该作者 |倒序浏览
我在研究内核 Percpu Allocator 的时候,该分配器 部分函数的实现提供了两种实现方式,两种方式分别定义在 percpu-km.c 和 percpu-vm.c 中.
1. 请问这两个文件有什么基本区别?
2. Percpu Allocator 使用哪个文件的函数作为自己的接口函数?

论坛徽章:
20
程序设计版块每日发帖之星
日期:2015-08-17 06:20:00程序设计版块每日发帖之星
日期:2016-07-16 06:20:00程序设计版块每日发帖之星
日期:2016-07-18 06:20:00每日论坛发贴之星
日期:2016-07-18 06:20:00黑曼巴
日期:2016-12-26 16:00:3215-16赛季CBA联赛之江苏
日期:2017-06-26 11:05:5615-16赛季CBA联赛之上海
日期:2017-07-21 18:12:5015-16赛季CBA联赛之青岛
日期:2017-09-04 17:32:0515-16赛季CBA联赛之吉林
日期:2018-03-26 10:02:16程序设计版块每日发帖之星
日期:2016-07-15 06:20:0015-16赛季CBA联赛之江苏
日期:2016-07-07 18:37:512015亚冠之萨济拖拉机
日期:2015-08-17 12:21:08
2 [报告]
发表于 2016-02-04 11:04 |只看该作者
/*
* Chunk management implementation.
*
* To allow different implementations, chunk alloc/free and
* [de]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

论坛徽章:
20
程序设计版块每日发帖之星
日期:2015-08-17 06:20:00程序设计版块每日发帖之星
日期:2016-07-16 06:20:00程序设计版块每日发帖之星
日期:2016-07-18 06:20:00每日论坛发贴之星
日期:2016-07-18 06:20:00黑曼巴
日期:2016-12-26 16:00:3215-16赛季CBA联赛之江苏
日期:2017-06-26 11:05:5615-16赛季CBA联赛之上海
日期:2017-07-21 18:12:5015-16赛季CBA联赛之青岛
日期:2017-09-04 17:32:0515-16赛季CBA联赛之吉林
日期:2018-03-26 10:02:16程序设计版块每日发帖之星
日期:2016-07-15 06:20:0015-16赛季CBA联赛之江苏
日期:2016-07-07 18:37:512015亚冠之萨济拖拉机
日期:2015-08-17 12:21:08
3 [报告]
发表于 2016-02-04 11:11 |只看该作者
本帖最后由 nswcfd 于 2016-02-04 11:11 编辑

以上只是表面区别,细节还没研究过,楼主搞清楚了可以跟大家分享一下

论坛徽章:
9
程序设计版块每日发帖之星
日期:2016-02-11 06:20:00程序设计版块每日发帖之星
日期:2016-02-14 06:20:00程序设计版块每日发帖之星
日期:2016-02-14 06:20:0015-16赛季CBA联赛之吉林
日期:2016-03-23 17:25:0015-16赛季CBA联赛之浙江
日期:2016-04-01 08:25:0615-16赛季CBA联赛之山西
日期:2016-04-01 10:09:1915-16赛季CBA联赛之广夏
日期:2016-06-03 15:58:212016科比退役纪念章
日期:2016-07-28 17:42:5215-16赛季CBA联赛之广东
日期:2017-02-20 23:32:43
4 [报告]
发表于 2016-02-04 11:16 |只看该作者
回复 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.
*/

   

论坛徽章:
20
程序设计版块每日发帖之星
日期:2015-08-17 06:20:00程序设计版块每日发帖之星
日期:2016-07-16 06:20:00程序设计版块每日发帖之星
日期:2016-07-18 06:20:00每日论坛发贴之星
日期:2016-07-18 06:20:00黑曼巴
日期:2016-12-26 16:00:3215-16赛季CBA联赛之江苏
日期:2017-06-26 11:05:5615-16赛季CBA联赛之上海
日期:2017-07-21 18:12:5015-16赛季CBA联赛之青岛
日期:2017-09-04 17:32:0515-16赛季CBA联赛之吉林
日期:2018-03-26 10:02:16程序设计版块每日发帖之星
日期:2016-07-15 06:20:0015-16赛季CBA联赛之江苏
日期:2016-07-07 18:37:512015亚冠之萨济拖拉机
日期:2015-08-17 12:21:08
5 [报告]
发表于 2016-02-04 11:27 |只看该作者
听起来是个循环依赖?
slub -> per_cpu -> slub ?

貌似slab/slub的初始化过程有个分阶段初始化的过程,不知道跟这个循环有没有关系?

论坛徽章:
9
程序设计版块每日发帖之星
日期:2016-02-11 06:20:00程序设计版块每日发帖之星
日期:2016-02-14 06:20:00程序设计版块每日发帖之星
日期:2016-02-14 06:20:0015-16赛季CBA联赛之吉林
日期:2016-03-23 17:25:0015-16赛季CBA联赛之浙江
日期:2016-04-01 08:25:0615-16赛季CBA联赛之山西
日期:2016-04-01 10:09:1915-16赛季CBA联赛之广夏
日期:2016-06-03 15:58:212016科比退役纪念章
日期:2016-07-28 17:42:5215-16赛季CBA联赛之广东
日期:2017-02-20 23:32:43
6 [报告]
发表于 2016-02-04 11:36 |只看该作者
回复 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 有关.
     我再继续研究研究.  

   
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP