前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >【Linux 内核 内存管理】物理内存组织结构 ⑤ ( 内存区域 zone 类型简介 | 内存区域类型zone_type 枚举源码分析 | zone_type 枚举源码 )

【Linux 内核 内存管理】物理内存组织结构 ⑤ ( 内存区域 zone 类型简介 | 内存区域类型zone_type 枚举源码分析 | zone_type 枚举源码 )

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

文章目录

内存管理系统

3

级结构 :

① 内存节点 Node ,

② 内存区域 Zone ,

③ 内存页 Page ,

Linux 内核中 , 使用 上述

3

级结构 描述 和 管理 " 物理内存 " ;

一、内存区域 zone 类型简介


" 内存节点 " 是内存管理的 最顶层结构 ,

" 内存节点 " 再向下划分 , 就是 " 内存区域 " ,

" 内存区域 " 的类型 在 Linux 内核中使用 enum zone_type 枚举类型进行描述 , zone_type 枚举定义在 Linux 内核源码的 linux-4.12\include\linux\mmzone.h#293 位置 ;

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

二、内存区域类型 zone_type 枚举源码分析


1、ZONE_DMA 直接内存访问区域

ZONE_DMA 其中的 DMA 是 Direct Memory Access , 直接内存访问 区域 ;

使用 DMA 内存情况 : 有些设备架构比较老 , 无法直接访问整个内存 , 需要使用 DMA 直接内存访问区域 ;

如 ISA 总线 , ( Industry Standard Architecture 工业标准体系结构 ) , 只支持

16

位的 I/O 设备访问 ,

代码语言:javascript
复制
#ifdef CONFIG_ZONE_DMA
	/*
	 * ZONE_DMA is used when there are devices that are not able
	 * to do DMA to all of addressable memory (ZONE_NORMAL). Then we
	 * carve out the portion of memory that is needed for these devices.
	 * The range is arch specific.
	 *
	 * Some examples
	 *
	 * Architecture		Limit
	 * ---------------------------
	 * parisc, ia64, sparc	<4G
	 * s390			<2G
	 * arm			Various
	 * alpha		Unlimited or 0-16MB.
	 *
	 * i386, x86_64 and multiple other arches
	 * 			<16M.
	 */
	ZONE_DMA,
#endif

2、ZONE_DMA32 内存区域

ZONE_DMA32 中的 DMA32 是 DMA32 内存区域 ,

对应的是

64

位系统 , DMA32 区域 可以支持 以下两种设备的访问 :

① 只能直接访问 16 MB 以下的内存设备 ;

② 只能直接访问 4 GB 以下的内存设备 ;

如果要同时满足上述两个条件 , 必须使用 ZONE_DMA32 内存区域 ;

代码语言:javascript
复制
#ifdef CONFIG_ZONE_DMA32
	/*
	 * x86_64 needs two ZONE_DMAs because it supports devices that are
	 * only able to do DMA to the lower 16M but also 32 bit devices that
	 * can only do DMA areas below 4G.
	 */
	ZONE_DMA32,
#endif

3、ZONE_NORMAL 普通内存区域

ZONE_NORMAL 是 " 普通内存区域 " , 该内存区域 可以 直接映射到 " 内核虚拟地址空间 " ;

代码语言:javascript
复制
	/*
	 * Normal addressable memory is in ZONE_NORMAL. DMA operations can be
	 * performed on pages in ZONE_NORMAL if the DMA devices support
	 * transfers to all addressable memory.
	 */
	ZONE_NORMAL,

4、ZONE_HIGHMEM 高端内存区域

ZONE_HIGHMEM 中的 HIGHMEM 是 " 高端内存区域 " , 这是

32

位架构中的概念 ,

DMADMA32 又称为 " 低端内存区域 " ,

内核空间 与 用户空间 比例为

1:3

, 内核空间 1 GB , 因此不能将 1 GB 以上的内存 , 映射到 内核地址 中 ;

代码语言:javascript
复制
#ifdef CONFIG_HIGHMEM
	/*
	 * A memory area that is only addressable by the kernel through
	 * mapping portions into its own address space. This is for example
	 * used by i386 to allow the kernel to address the memory beyond
	 * 900MB. The kernel will set up special mappings (page
	 * table entries on i386) for each page that the kernel needs to
	 * access.
	 */
	ZONE_HIGHMEM,
#endif

5、ZONE_MOVABLE 可移动区域

ZONE_MOVABLE 是 " 可移动区域 " , 这是为了防止 " 内存碎片 " 的 伪内存区 ;

代码语言:javascript
复制
	ZONE_MOVABLE,

6、ZONE_DEVICE 设备区域

ZONE_DEVICE 是 " 设备区域 " , 这是为了支持 " 内存热插拔 " 而设置的内存区域 , 每个 设备区域 使用 zone 结构体表示 ;

代码语言:javascript
复制
#ifdef CONFIG_ZONE_DEVICE
	ZONE_DEVICE,
#endif

三、zone_type 枚举源码


代码语言:javascript
复制
enum zone_type {
#ifdef CONFIG_ZONE_DMA
	/*
	 * ZONE_DMA is used when there are devices that are not able
	 * to do DMA to all of addressable memory (ZONE_NORMAL). Then we
	 * carve out the portion of memory that is needed for these devices.
	 * The range is arch specific.
	 *
	 * Some examples
	 *
	 * Architecture		Limit
	 * ---------------------------
	 * parisc, ia64, sparc	<4G
	 * s390			<2G
	 * arm			Various
	 * alpha		Unlimited or 0-16MB.
	 *
	 * i386, x86_64 and multiple other arches
	 * 			<16M.
	 */
	ZONE_DMA,
#endif
#ifdef CONFIG_ZONE_DMA32
	/*
	 * x86_64 needs two ZONE_DMAs because it supports devices that are
	 * only able to do DMA to the lower 16M but also 32 bit devices that
	 * can only do DMA areas below 4G.
	 */
	ZONE_DMA32,
#endif
	/*
	 * Normal addressable memory is in ZONE_NORMAL. DMA operations can be
	 * performed on pages in ZONE_NORMAL if the DMA devices support
	 * transfers to all addressable memory.
	 */
	ZONE_NORMAL,
#ifdef CONFIG_HIGHMEM
	/*
	 * A memory area that is only addressable by the kernel through
	 * mapping portions into its own address space. This is for example
	 * used by i386 to allow the kernel to address the memory beyond
	 * 900MB. The kernel will set up special mappings (page
	 * table entries on i386) for each page that the kernel needs to
	 * access.
	 */
	ZONE_HIGHMEM,
#endif
	ZONE_MOVABLE,
#ifdef CONFIG_ZONE_DEVICE
	ZONE_DEVICE,
#endif
	__MAX_NR_ZONES

};

源码路径 : linux-4.12\include\linux\mmzone.h#293

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022-04-18,如有侵权请联系 cloudcommunity@tencent.com 删除

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

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

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

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 文章目录
  • 一、内存区域 zone 类型简介
  • 二、内存区域类型 zone_type 枚举源码分析
    • 1、ZONE_DMA 直接内存访问区域
      • 2、ZONE_DMA32 内存区域
        • 3、ZONE_NORMAL 普通内存区域
          • 4、ZONE_HIGHMEM 高端内存区域
            • 5、ZONE_MOVABLE 可移动区域
              • 6、ZONE_DEVICE 设备区域
              • 三、zone_type 枚举源码
              领券
              问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档