前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【Linux 内核 内存管理】memblock 分配器 ③ ( memblock_region 内存块区域 | memblock_region 结构体成员分析 | memblock 分配器标志位 )

【Linux 内核 内存管理】memblock 分配器 ③ ( memblock_region 内存块区域 | memblock_region 结构体成员分析 | memblock 分配器标志位 )

作者头像
韩曙亮
发布2023-03-30 14:55:54
3440
发布2023-03-30 14:55:54
举报
文章被收录于专栏:韩曙亮的移动开发专栏

文章目录

一、memblock_region 内存块区域


memblock 分配器 中 , 内存块区域 使用 struct memblock_region 结构体进行描述 ,

该结构体定义在 Linux 内核源码的 linux-4.12\include\linux\memblock.h#31 位置

代码语言:javascript
复制
/* Definition of memblock flags. */
enum {
	MEMBLOCK_NONE		= 0x0,	/* No special request */
	MEMBLOCK_HOTPLUG	= 0x1,	/* hotpluggable region */
	MEMBLOCK_MIRROR		= 0x2,	/* mirrored region */
	MEMBLOCK_NOMAP		= 0x4,	/* don't add to kernel direct mapping */
};

struct memblock_region {
	phys_addr_t base;
	phys_addr_t size;
	unsigned long flags;
#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP
	int nid;
#endif
};

源码路径 : linux-4.12\include\linux\memblock.h#31

在这里插入图片描述
在这里插入图片描述

二、memblock_region 结构体成员分析


1、base 成员

base 成员 表示 " 内存块区域 " 的起始地址 ;

代码语言:javascript
复制
	phys_addr_t base;

2、size 成员

size 成员 表示 " 内存块区域 " 的大小 ;

代码语言:javascript
复制
	phys_addr_t size;

3、flags 成员

flags 成员 表示 " 内存块区域 " 的标志位 ;

代码语言:javascript
复制
	unsigned long flags;

可设置的标志位如下 :

代码语言:javascript
复制
/* Definition of memblock flags. */
enum {
	MEMBLOCK_NONE		= 0x0,	/* No special request */
	MEMBLOCK_HOTPLUG	= 0x1,	/* hotpluggable region */
	MEMBLOCK_MIRROR		= 0x2,	/* mirrored region */
	MEMBLOCK_NOMAP		= 0x4,	/* don't add to kernel direct mapping */
};

4、nid 成员

nid 成员 表示 " 内存块区域 " 的节点编号 ;

代码语言:javascript
复制
#ifdef CONFIG_HAVE_MEMBLOCK_NODE_MAP
	int nid;
#endif

三、memblock 分配器标志枚举


memblock 分配器标志是一个枚举类型 ,

该 枚举 定义在 Linux 内核源码的 linux-4.12\include\linux\memblock.h#23 位置 ;

代码语言:javascript
复制
/* Definition of memblock flags. */
enum {
	MEMBLOCK_NONE		= 0x0,	/* No special request */
	MEMBLOCK_HOTPLUG	= 0x1,	/* hotpluggable region */
	MEMBLOCK_MIRROR		= 0x2,	/* mirrored region */
	MEMBLOCK_NOMAP		= 0x4,	/* don't add to kernel direct mapping */
};

1、MEMBLOCK_NONE

MEMBLOCK_NONE 表示 " 没有特殊要求的区域 " ;

代码语言:javascript
复制
	MEMBLOCK_NONE		= 0x0,	/* No special request */

2、MEMBLOCK_HOTPLUG

MEMBLOCK_HOTPLUG 表示 " 支持热插拔区域 " , 在运行过程中 , 物理内存可以 " 热插拔 " ;

代码语言:javascript
复制
	MEMBLOCK_HOTPLUG	= 0x1,	/* hotpluggable region */

3、MEMBLOCK_MIRROR

MEMBLOCK_MIRROR 表示 " 镜像区域 " ;

Linux 内核将 内存中的数据 , 进行了复制备份 , 分别存放在 " 主内存 " 和 " 镜像内存 " 中 ;

代码语言:javascript
复制
	MEMBLOCK_MIRROR		= 0x2,	/* mirrored region */

4、MEMBLOCK_NOMAP

MEMBLOCK_NONE 表示 " 线性映射区域 " , 该区域不添加到内核映射区域 ;

代码语言:javascript
复制
	MEMBLOCK_NOMAP		= 0x4,	/* don't add to kernel direct mapping */
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-04-19,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 文章目录
  • 一、memblock_region 内存块区域
  • 二、memblock_region 结构体成员分析
    • 1、base 成员
      • 2、size 成员
        • 3、flags 成员
          • 4、nid 成员
          • 三、memblock 分配器标志枚举
            • 1、MEMBLOCK_NONE
              • 2、MEMBLOCK_HOTPLUG
                • 3、MEMBLOCK_MIRROR
                  • 4、MEMBLOCK_NOMAP
                  领券
                  问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档