没有合适的资源?快使用搜索试试~ 我知道了~
Chapter2.docx
需积分: 5 0 下载量 192 浏览量
2021-04-11
22:16:00
上传
评论
收藏 131KB DOCX 举报
温馨提示
试读
32页
Linux is available for a wide range of architectures, so an architecture-independent way of describing memory is needed. This chapter describes the structures used to keep account of memory banks, pages and flags that affect VM behavior.
资源推荐
资源详情
资源评论
Chapter2.Describing Physical
Memory
Linux is available for a wide range of architectures, so an architecture-independent
way of describing memory is needed. This chapter describes the structures used to
keep account of memory banks, pages and ags that aect VM behavior.
Linux 可用于多种体系结构,因此需要一种与体系结构无关的内存描述方式。 本章介绍用于保留影
响虚拟机行为的内存库,页面和标志的结构。
The "rst principal concept prevalent in the VM is Non Uniform Memory Access (NUMA).
With large-scale machines, memory may be arranged into banks that incur a dierent
cost to access depending on their distance from the processor. For example, a bank of
memory might be assigned to each CPU, or a bank of memory very suitable for Direct
Memory Access (DMA) near device cards might be assigned.
VM 中流行的第一个主要概念是非统一内存访问(NUMA)。 对于大型机器,可能会将内存排列到
存储体中,这取决于它们与处理器之间的距离而导致不同的访问成本。 例如,可以为每个 CPU 分
配一组内存,或者可以为非常靠近设备卡的直接内存访问(DMA)分配一组内存。
Each bank is called a node, and the concept is represented under Linux by a struct
pglist_data even if the architecture is Uniform Memory Access (UMA). This struct is
always referenced by its typedef pg_data_t. Every node in the system is kept on a
NULL terminated list called pgdat_list, and each node is linked to the next with the
"eld pg_data_t→node_next. For UMA architectures like PC desktops, only one static
pg_data_t structure called contig_page_data is used. Nodes are discussed further in
Section 2.1.
每个存储体都称为一个节点,并且在 Linux 下,即使体系结构是统一内存访问(UMA),该概念也
由 pglist_data 结构表示。 该结构始终由其 typedef pg_data_t 引用。 系统中的每个节点都保存
在一个名为 pgdat_list 的 NULL 终止列表中,并且每个节点都通过字段 pg_data_t→node_next
链接到下一个节点。 对于 PC 台式机等 UMA 体系结构,仅使用一种称为 contig_page_data 的静
态 pg_data_t 结构。 在第 2.1 节中将进一步讨论节点。
1
Each node is divided into a number of blocks called zones, which represent ranges
within memory. Zones should not be confused with zone-based allocators because
they are unrelated. A zone is described by a struct zone_struct, type-deed to zone_t,
and each one is of type ZONE_DMA, ZONE_NORMAL or ZONE_HIGHMEM. Each zone
type is suitable for a dierent type of use. ZONE_DMA is memory in the lower physical
memory ranges that certain Industry Standard Architecture (ISA) devices require.
Memory within ZONE_NORMAL is directly mapped by the kernel into the upper region
of the linear address space, which is discussed further in Section 4.1. ZONE_HIGHMEM
is the remaining available memory in the system and is not directly mapped by the
kernel.
每个节点都分为许多称为区域的块,它们代表内存中的范围。 区域不应与基于区域的分配器混淆,
因为它们是无关的。 区域由 struct zone_struct 描述,类型定义为 zone_t,每个区域的类型为
ZONE_DMA,ZONE_NORMAL 或 ZONE_HIGHMEM。 每种区域类型都适合不同的使用类型。
ZONE_DMA 是某些行业标准体系结构(ISA)设备所需的较低物理内存范围内的内存。 内核将
ZONE_NORMAL 中的内存直接映射到线性地址空间的上部区域,这将在 4.1 节中进一步讨论。
ZONE_HIGHMEM 是系统中剩余的可用内存,并不由内核直接映射。
With the x86, the zones are the following:
ZONE_DMA
First 16MiB of memory 内存的前
16MiB
ZONE_NOR
MAL
16MiB - 896MiB
ZONE_HIGH
MEM
896 MiB - End
Many kernel operations can only take place using ZONE_NORMAL, so it is the most
performance-critical zone. Zones are discussed further in Section 2.2. The system’s
memory is comprised of "xed-size chunks called page frames. Each physical page
frame is represented by a struct page, and all the structs are kept in a global
mem_map array, which is usually stored at the beginning of ZONE_NORMAL or just
after the area reserved for the loaded kernel image in low memory machines. Section
2.4 discusses struct pages in detail, and Section 3.7 discusses the global mem_map
array in detail. The basic relationship between all these structs is illustrated in Figure
2.1.
2
许多内核操作只能使用 ZONE_NORMAL 进行,因此它是性能最关键的区域。 在第 2.2 节中将进一
步讨论区域。 系统的内存由称为页面框架的固定大小的块组成。 每个物理页框架都由一个 struct
page 表示,所有结构都保存在全局 mem_map 数组中,该数组通常存储在 ZONE_NORMAL 的开
头或在低内存机器中为已加载内核映像保留的区域之后。 第 2.4 节详细讨论了 struct page,第
3.7 节详细讨论了全局 mem_map 数组。 所有这些结构之间的基本关系如图 2.1 所示。
Figure2.1.Relationship Between Nodes, Zones and Pages
Because the amount of memory directly accessible by the kernel (ZONE_NORMAL) is
limited in size, Linux supports the concept of high memory, which is discussed further
in Section 2.7. This chapter discusses how nodes, zones and pages are represented
before introducing high memory management.
由于内核可直接访问的内存(ZONE_NORMAL)受到大小限制,因此 Linux 支持高内存的概念,
这将在 2.7 节中进一步讨论。 本章讨论在介绍高级内存管理之前如何表示节点,区域和页面。
Nodes
As I have mentioned, each node in memory is described by a pg_data_t, which is a
typedef for a struct pglist_data. When allocating a page, Linux uses a node-local
allocation policy to allocate memory from the node closest to the running CPU.
Because processes tend to run on the same CPU, it is likely the memory from the
current node will be used. The struct is declared as follows in <linux/mmzone.h>:
3
正如我已经提到的,内存中的每个节点都由 pg_data_t 描述,它是 pglist_data 结构的 typedef。
分配页面时,Linux 使用本地节点分配策略从最靠近运行 CPU 的节点分配内存。 因为进程倾向于
在同一 CPU 上运行,所以很可能会使用当前节点的内存。 在<linux / mmzone.h>中,该结构声
明如下:
129 typedef struct pglist_data {
130 zone_t node_zones[MAX_NR_ZONES];
131 zonelist_t node_zonelists[GFP_ZONEMASK+1];
132 int nr_zones;
133 struct page *node_mem_map;
134 unsigned long *valid_addr_bitmap;
135 struct bootmem_data *bdata;
136 unsigned long node_start_paddr;
137 unsigned long node_start_mapnr;
138 unsigned long node_size;
139 int node_id;
140 struct pglist_data *node_next;
141 } pg_data_t;
We now briey describe each of these "elds: 现在,我们简要描述以下每个字段:
node_zones.The zones for this node are ZONE_HIGHMEM, ZONE_NORMAL,
ZONE_DMA. 该节点的区域是 ZONE_HIGHMEM,ZONE_NORMAL,ZONE_DMA。
node_zonelists.This is the order of zones that allocations are preferred from.
build_zonelists() in mm/page_alloc.c sets up the order when called by
free_area_init_core(). A failed allocation in ZONE_HIGHMEM may fall back to
ZONE_NORMAL or back to ZONE_DMA. 这是首选分配区域的顺序。 mm / page_alloc.c 中的
build_zonelists()设置由 free_area_init_core()调用时的顺序。 ZONE_HIGHMEM 中的分
配失败可能会退回到 ZONE_NORMAL 或 ZONE_DMA。
nr_zones.This is the number of zones in this node between one and three. Not all
nodes will have three. A CPU bank may not have ZONE_DMA, for example. 这是此节点中
1 到 3 之间的区域数。 并非所有节点都具有三个。 例如,一个 CPU 组可能没有 ZONE_DMA。
4
node_mem_map.This is the "rst page of the struct page array that represents each
physical frame in the node. It will be placed somewhere within the global mem_map
array. 这是 struct 页面数组的第一页,代表节点中的每个物理帧。 它将放置在全局 mem_map 数
组内的某个位置。
valid_addr_bitmap.This is a bitmap that describes “holes” in the memory node that
no memory exists for. In reality, this is only used by the Sparc and Sparc64
architectures and is ignored by all others. 这是一个位图,描述了不存在内存的内存节点中的
“漏洞”。 实际上,这仅由 Sparc 和 Sparc64 体系结构使用,而所有其他结构均将其忽略。
bdata.This is only of interest to the boot memory allocator discussed in Chapter 5. 这
仅对第 5 章中讨论的启动内存分配器有用。
node_start_paddr.This is the starting physical address of the node. An unsigned
long does not work optimally because it breaks for ia32 with Physical Address
Extension (PAE) and for some PowerPC variants such as the PPC440GP. PAE is
discussed further in Section 2.7. A more suitable solution would be to record this as a
Page Frame Number (PFN). A PFN is simply an index within physical memory that is
counted in page-sized units. PFN for a physical address could be trivially de"ned as
(page_phys_addr >> PAGE_SHIFT). 这是节点的起始物理地址。 无符号长整数不能最佳地工作,
因为它会因带有物理地址扩展(PAE)的 ia32 和某些 PowerPC 变体(例如 PPC440GP)而中断。
PAE 将在 2.7 节中进一步讨论。 一个更合适的解决方案是将其记录为页面框架编号(PFN)。
PFN 只是物理内存中的索引,以页大小为单位进行计数。 物理地址的 PFN 可以简单定义为
(page_phys_addr >> PAGE_SHIFT)。
node_start_mapnr.This gives the page oset within the global mem_map. It is
calculated in free_area_init_core() by calculating the number of pages between
mem_map and the local mem_map for this node called lmem_map. 这将在全局
mem_map 中提供页面偏移量。 在 free_area_init_core()中,通过计算此节点(称为
lmem_map)的 mem_map 与本地 mem_map 之间的页数来计算该值。
node_size.This is the total number of pages in this zone. 这是该区域中的总页数。
5
剩余31页未读,继续阅读
资源评论
mounter625
- 粉丝: 1049
- 资源: 85
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功