`
waterlife
  • 浏览: 65916 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

Linux内核之物理内存管理

阅读更多

Linux内核对于内存的管理摒弃了i386复杂的段式管理,而是采用了页式管理。Linux把整个的物理内存空间化为成一个个单独的页面,每页占4K空间大小。Linux把所有页面链接到一个全局的数组mem_map[]中,mem_map的每一个元素都是一个指针指向page数据结构。系统中的每个物理页面都对应着一个page数据结构,并根据需要把这些页面划分为不同的管理区:ZONE_DMA,ZONE_NORMAL和ZONE_HIGHMEM(用于物理内存超过1G空间的地址)。

 

typedef struct page {
	struct list_head list;		/* ->mapping has some page lists. */
	struct address_space *mapping;	/* The inode (or ...) we belong to. */
	unsigned long index;		/* Our offset within mapping. */
	struct page *next_hash;		/* Next page sharing our hash bucket in
					   the pagecache hash table. */
	atomic_t count;			/* Usage count, see below. */
	unsigned long flags;		/* atomic flags, some possibly
					   updated asynchronously */
	struct list_head lru;		/* Pageout list, eg. active_list;
					   protected by pagemap_lru_lock !! */
	struct page **pprev_hash;	/* Complement to *next_hash. */
	struct buffer_head * buffers;	/* Buffer maps us to a disk block. */

	/*
	 * On machines where all RAM is mapped into kernel address space,
	 * we can simply calculate the virtual address. On machines with
	 * highmem some memory is mapped into kernel virtual memory
	 * dynamically, so we need a place to store that address.
	 * Note that this field could be 16 bits on x86 ... ;)
	 *
	 * Architectures with slow multiplication can define
	 * WANT_PAGE_VIRTUAL in asm/page.h
	 */
#if defined(CONFIG_HIGHMEM) || defined(WANT_PAGE_VIRTUAL)
	void *virtual;			/* Kernel virtual address (NULL if
					   not kmapped, ie. highmem) */
#endif /* CONFIG_HIGMEM || WANT_PAGE_VIRTUAL */
} mem_map_t;

 

 

DMA管理区是单独进行管理的,不经过MMU映射,而一般的外设都对地址空间有一定的限制。地址空间不能太大,而且要求地址连续。

 

每个管理区都对应着一个zone_struct结构,这个结构体中有一组空闲队列free_area_t。这些队列中要有一个队列保持一些离散的物理页面,另一个队列要保持长度为2的指数的连续物理页面。

 

 

typedef struct zone_struct {
	/*
	 * Commonly accessed fields:
	 */
	spinlock_t		lock;
	unsigned long		free_pages;
	unsigned long		pages_min, pages_low, pages_high;
	int			need_balance;

	/*
	 * free areas of different sizes
	 */
	free_area_t		free_area[MAX_ORDER];

	/*
	 * wait_table		-- the array holding the hash table
	 * wait_table_size	-- the size of the hash table array
	 * wait_table_shift	-- wait_table_size
	 * 				== BITS_PER_LONG (1 << wait_table_bits)
	 *
	 * The purpose of all these is to keep track of the people
	 * waiting for a page to become available and make them
	 * runnable again when possible. The trouble is that this
	 * consumes a lot of space, especially when so few things
	 * wait on pages at a given time. So instead of using
	 * per-page waitqueues, we use a waitqueue hash table.
	 *
	 * The bucket discipline is to sleep on the same queue when
	 * colliding and wake all in that wait queue when removing.
	 * When something wakes, it must check to be sure its page is
	 * truly available, a la thundering herd. The cost of a
	 * collision is great, but given the expected load of the
	 * table, they should be so rare as to be outweighed by the
	 * benefits from the saved space.
	 *
	 * __wait_on_page() and unlock_page() in mm/filemap.c, are the
	 * primary users of these fields, and in mm/page_alloc.c
	 * free_area_init_core() performs the initialization of them.
	 */
	wait_queue_head_t	* wait_table;
	unsigned long		wait_table_size;
	unsigned long		wait_table_shift;

	/*
	 * Discontig memory support fields.
	 */
	struct pglist_data	*zone_pgdat;
	struct page		*zone_mem_map;
	unsigned long		zone_start_paddr;
	unsigned long		zone_start_mapnr;

	/*
	 * rarely used fields:
	 */
	char			*name;
	unsigned long		size;
} zone_t;

 

分享到:
评论

相关推荐

    基于ARM CPU的Linux物理内存管理

    第三部分介绍Linux内核对物理内存管理的思想和原理。如果能在原理和框架上理解内核对物理内存如何管理的,那么就能更快和深入地理解内核代码是如何实现内核管理的。 第四部分在源代码中介绍Linux内核是如何实现物理...

    Linux内核的内存管理探秘之三 物理内存的管理(二)页面周转与缓冲区.pdf

    Linux内核的内存管理探秘之三 物理内存的管理(二)页面周转与缓冲区.pdf

    Linux内核内存管理.zip

    linux内核中的内存管理方面的资料。物理内存映射成可操作的逻辑内存。

    Linux内核的内存管理探秘之二 物理内存的管理(一)分配与回收.pdf

    Linux内核的内存管理探秘之二 物理内存的管理(一)分配与回收.pdf

    包含LINUX内核同步、信号、内存、调度、文件系统.rar

    内存管理 涉及到 物理内存管理 和 虚拟内存管理 , 是 Linux 内核中 最复杂的模块 ; 虚拟内存管理 包括 : 反向映射 , KSM , MMAP 映射 , 缺页中断 , 共享内存 , 进程虚拟地址空间管理 , 页面回收 ; 物理内存管理 ...

    Linux内核源代码情景分析 (上下册 高清非扫描 )

    丛书名: Linux内核源代码情景分析 出版社:浙江大学出版社 目录 第1章 预备知识 1.1 Linux内核简介. 1.2 Intel X86 CPU系列的寻址方式 1.3 i386的页式内存管理机制 1.4 Linux内核源代码中的C语言代码 1.5 Linux...

    疯狂内核之——Linux虚拟内存

    第二章 内核级内存管理系统 58 2.1 Linux页面管理 58 2.1.1 NUMA架构 61 2.1.2 内存管理区 62 2.2 伙伴系统算法 65 2.2.1 数据结构 66 2.2.2 块分配 67 2.2.3 块释放 69 2.3 Linux页面级内存管理 72 2.3.1 分配一组...

    Linux学习心得——内存管理方法

    1. Linux 内核管理哪些物理空间;arm 版本的4G虚拟地址是如何组织的; 2. 内核空间如何获得虚拟/物理空间,并使用它们; 3. 用户空间如何获得虚拟/物理空间,并使用它们; 4. 内核空间和用户空间如何交互; 5. 整体...

    linux 内核源代码分析

    1. 1 Linux内核简介 1. 2 Intel X86 CPU系列的寻址方式 1. 3 i386的页式内存管理机制 1. 4 Linux内核源代码中的C语言代码 1.5 Linux内核源代码中的汇编语言代码 第2章 存储管理 2.1 Linux内存管理的基本框架...

    Linux2.6内核标准教程(共计8-- 第1个)

    然后对Linux内核的3大核心模块——内存管理、进程管理、中断和异常处理进行了深入的分析; 在此基础上,对时间度量、系统调用进行了分析和讨论;最后讲解了Linux内核中常见的同步机制,使读者掌握每处理器变量和RCU...

    linux内存管理结构图

    很清晰的描述了linux内存虚拟及物理内存的划分,包括: node介绍 zone介绍 3G~4G内核空间布局 内核整体mm管理结构

    Linux内核 内容很全

    内存管理 15 2.1 虚拟内存抽象模型 15 2.1.1 请求调页 17 2.1.2 交换 17 2.1.3 共享虚拟内存 18 2.1.4 物理寻址模式和虚拟寻址模式 18 2.1.5 访问控制 18 2.2 高速缓存 19 2.3 Linux页表 20...

    Linux 2.6内核分析.pdf

    内存管理是 Linux 内核的另一个核心组件,它负责管理系统中的内存,包括物理内存和虚拟内存。内存管理使用页式管理机制,通过页面、中间目录及页面表三个层次实现从线形地址到物理地址的映射。 文件系统是 Linux ...

    深入分析Linux内核源码

    深入分析Linux内核源码 前言 第一章 走进linux 1.1 GNU与Linux的成长 1.2 Linux的开发模式和运作机制 1.3走进Linux内核 1.3.1 Linux内核的特征 1.3.2 Linux内核版本的变化 1.4 分析Linux内核的意义 ...

    深入解析Linux内存管理ppt

    目录:页表管理 内核页表 物理内存 高端内存 地址映射 虚拟内存 地址空间 高速缓存 页框回收 交换机制 缺页异常 共享内存 文件映射 程序执行

    Linux2.6内核标准教程(共计8--第6个)

    然后对Linux内核的3大核心模块——内存管理、进程管理、中断和异常处理进行了深入的分析; 在此基础上,对时间度量、系统调用进行了分析和讨论;最后讲解了Linux内核中常见的同步机制,使读者掌握每处理器变量和RCU...

    Linux2.6内核标准教程(共计8--第8个)

    然后对Linux内核的3大核心模块——内存管理、进程管理、中断和异常处理进行了深入的分析; 在此基础上,对时间度量、系统调用进行了分析和讨论;最后讲解了Linux内核中常见的同步机制,使读者掌握每处理器变量和RCU...

    Linux操作系统的内存使用方法详细解析

    Linux在内存管理上份为两级,一级是线性区,一级是具体的物理页面,它对应我们机器上的物理内存。...注意一点,在进程只能访问虚拟内存,它实际上是看不到内核物理内存的使用,这对于进程是完全透明的。

    深入Linux内核架构(英文原版Professional Linux® Kernel Architecture)

    主要内容包括多任务、调度和进程管理,物理内存的管理以及内核与相关硬件的交互,用户空间的进程如何访问虚拟内存,如何编写设备驱动程序,模块机制以及虚拟文件系统,Ext文件系统属性和访问控制表的实现方式,内核...

    Linux2.6内核标准教程(共计8--第3个)

    然后对Linux内核的3大核心模块——内存管理、进程管理、中断和异常处理进行了深入的分析; 在此基础上,对时间度量、系统调用进行了分析和讨论;最后讲解了Linux内核中常见的同步机制,使读者掌握每处理器变量和RCU...

Global site tag (gtag.js) - Google Analytics