尽管"叉" ING一个过程,为什么Linux内核复制内核页表的内容为每个新创建的进程? [英] While "fork"ing a process, why does Linux kernel copy the content of kernel page table for every newly created process?
问题描述
下面的讨论适用于32位ARM Linux内核。
我注意到,在分叉过程中,内核页表的Linux内核的副本内容(母版页表,即 swapper_pg_dir )到每一个新创建的进程的页表。
问题是:
- 为什么还要做呢?
- 为什么不是所有的进程都共享内核页面的一个副本
表(海格1G关于32位ARM Linux的一部分),而不是memcpy的
每个新创建的进程交换程序页表? - 这是浪费内存?
相关来源$ C $ C( - >表示函数调用):结果
do_fork - > copy_process - > copy_mm - > dup_mm - > mm_init - > mm_alloc_pgd - > pgd_alloc - >
/ *
*拷贝过来的内核和IO PGD项
* /
init_pgd = pgd_offset_k(0);的memcpy(new_pgd + USER_PTRS_PER_PGD,init_pgd + USER_PTRS_PER_PGD,
(PTRS_PER_PGD - USER_PTRS_PER_PGD)*的sizeof(pgd_t));
有页表中的核心部分自己的副本的每个进程(较高1GB)是为了避免L1页表转换(即避免更新TTBR),当用户/内核土地被切换。需要注意的是用户/内核土地开关发生相当频繁。
为什么要避免更新TTBR?详细信息可以在这里找到:
<一href=\"http://stackoverflow.com/questions/27289861/what-is-the-downside-of-updating-arm-ttbrtranslate-table-base-register\">What是更新的下行ARM TTBR(翻译表基址寄存器)?
The discussion below applies to 32-bit ARM Linux kernel.
I noticed that during the forking process, Linux kernel copies the content of kernel page table(master page table, i.e. swapper_pg_dir) into the page table of every newly created process.
Questions are:
- Why bother doing that?
- Why can't all processes share a single copy of kernel page table(higer 1G part regarding 32bit ARM Linux), instead of memcpy the swapper page table for each newly created process?
- Is it a waste of memory?
Related source code("-->" stands for function call):
do_fork --> copy_process --> copy_mm --> dup_mm --> mm_init --> mm_alloc_pgd --> pgd_alloc -->
/*
* Copy over the kernel and IO PGD entries
*/
init_pgd = pgd_offset_k(0);
memcpy(new_pgd + USER_PTRS_PER_PGD, init_pgd + USER_PTRS_PER_PGD,
(PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
Each process having its own copy of page table for kernel part(higher 1GB) is to avoid L1 page table switching(i.e. avoid updating TTBR) when user/kernel land is being switched. Note that user/kernel land switch happens quite frequently.
Why avoiding updating TTBR? Details can be found here: What is the downside of updating ARM TTBR(Translate Table Base Register)?
这篇关于尽管&QUOT;叉&QUOT; ING一个过程,为什么Linux内核复制内核页表的内容为每个新创建的进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!