Kernel Page Global Directory (PGD) of Page table of Process created in Linux Kernel
2014-07-09 15:02
351 查看
Kernel Page Global Directory (PGD) of User process created
在早期版本:在fork一个进程的时候,必须建立进程自己的内核页目录项(内核页目录项要与用户空间
的页目录放在同一个物理地址连续的页面上,所以不能共享,但所有进程的内核页表与进
程0共享)
3G用户,页目录中一项映射4M的空间(一项页目录1024项页表,每项页表对应1个页面4K
),即:
#define PGDIR_SHIFT 22
#define PGDIR_SIZE (1UL << PGDIR_SHIFT)
>>> sys_fork->do_fork->copy_mm->mm_init->pgd_alloc->get_pgd_slow
#if CONFIG_X86_PAE
。。。。。。。。。。。。。
#else
extern __inline__ pgd_t *get_pgd_slow(void)
{
>>> 分配页目录表(包含1024项页目录),即为一个进程分配的页目录可以映射的空间为
1024*4M=4G
pgd_t *pgd = (pgd_t *)__get_free_page(GFP_KERNEL);
if (pgd) {
>>> #define USER_PTRS_PER_PGD (TASK_SIZE/PGDIR_SIZE)
>>> TASK_SIZE为3G大小,USER_PTRS_PER_PGD为用户空间对应的页目录项数目(
3G/4M=768)
>>> 将用户空间的页目录项清空
memset(pgd, 0, USER_PTRS_PER_PGD * sizeof(pgd_t));
>>> 将内核页目录表(swapper_pg_dir)的第768项到1023项拷贝到进程的页目录表的第
768项到1023项中
memcpy(pgd + USER_PTRS_PER_PGD, swapper_pg_dir + USER_PTRS_PER_PGD,
(PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
}
return pgd;
}
#endif
比較後來的版本:
pgd_t *pgd_alloc(struct mm_struct *mm) -> pgd_ctor(mm, pgd); //关键代码,将指向内核空间的页目录项拷贝到新分配的pgd对应的项目中。 -> clone_pgd_range(pgd + KERNEL_PGD_BOUNDARY, //item points to the kernel space swapper_pg_dir + KERNEL_PGD_BOUNDARY, KERNEL_PGD_PTRS);
ref.
[1] http://biancheng.dnbcw.info/linux/321897.html
[2] http://m.blog.csdn.net/blog/SunnyBeiKe/6898253
相关文章推荐
- 基于POSIX在Linux下C语言实现读取整个目录文件[Get a List of Files in a Directory with C]
- Analysis of Process Multi-Thread Manangement Based on a simpilified Linux Kernel--myKernel
- Repeating Table Header on Each Page of the Report in the SSRS 2008
- unable to find the sources of your current Linux kernel. Specify KERN_DIR=<directory> and run Make a
- The Directory Tree of Linux Kernel 0.11
- Implement a New Process Scheduler in Linux Kernel
- How to count the number of threads in a process on Linux
- The Proccess of Loading and Executing a Specific Program in Linux Kernel
- Linux kernel Process Management 1——Conparison and Contrast between linux 2.4 VS linux 2.6 in process kernel stack layout
- Resolving “nf_conntrack: table full, dropping packet.” flood message in dmesg Linux kernel log
- Use of pushglobaltable and setfenv in Lua5.3
- How to find PID of process listening on a port in Linux? netstat and lsof command examples
- Analyse the Booting process of Linux Kernel
- 查找idt table 所對應的page table in Linux
- Describe the process of opening a file in Linux system, what actions the operating system w
- Android之JNI ERROR (app bug): accessed stale global reference 0xb39533f2 (index 19708 in a table of s
- Get and display the size of file and directory in Linux system using du command 获取和现实linux文件大小(三)
- Linux Device Drivers 3rd Edition Data Types in the Kernel
- Here's an example that shows how to enumerate through the features of a selection set, returning the value of each field in the attribute table except for the geometry colum.