Linux内核:在pageing_init时零页面分配的作用 [英] Linux kernel: Role of zero page allocation at paging_init time

查看:532
本文介绍了Linux内核:在pageing_init时零页面分配的作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在启动时为arch/arm保留内核内存.

I am trying to understand the kernel memory reservation at bootup for arch/arm.

setup_arch()中有一个用于调用页面表,初始化区域内存映射等的pageing_init()调用.在分配实际的mem_map之前,它还会分配一个zero page.

There's a call paging_init() for setting page tables, initialization of zone memory map etc in setup_arch(). It also allocate one zero page before allocating actual mem_map.

void __init paging_init(const struct machine_desc *mdesc)
{
    void *zero_page;
    ---
    zero_page = early_alloc(PAGE_SIZE);
    ---
    empty_zero_page = virt_to_page(zero_page);
    __flush_dcache_page(NULL, empty_zero_page);
}

有人可以解释zero page的作用吗?

Can someone please explain the role of zero page?

此问题是的一部分

推荐答案

零页面是一个用零填充的页面.您可以映射到此页面,并获得宽零位虚拟区域.每当您将写入此页面之一时, COW 都将起作用,您将获得一个新的.反之亦然:如果您的存储区域中的数据为零,则可以将此数据映射到零页,并使用"0"数据释放这些页.换句话说,这与内核如何节省内存有关.

Zero page is a page filled with zeros. You can make a mapping to this page and get wide zeroed virtual region. Whenever you will write to one of this pages the COW will work and you will get a new one. The reverse is true too: if you have a memory region with zero data, you can map this data to zero page and free these pages with "0" data. In other words that is about how kernel can save memory.

p.s.请注意,COW并非直接与零页面相连,而是一个更广泛和更笼统的概念

p.s. Note that COW is not directly connected with zero pages, it is a more wide and general concept

来自@artless_noise的添加:

它还允许分配一个大数组,但不消耗内存.所有页面最初都是零页面,并且映射到相同的物理零页面.如果数组稀疏,则只有少数条目(4k大小)会占用内存.内核不需要清理(零)分配的内存.在填充条目中不会浪费'tlb'和'cache'.

It also allows a large array to be allocated, but not consume memory. All pages are initially the zero page and map to the same physical zero page. If the array is sparse, then only the few entries (in 4k size) will consume memory. The kernel doesn't need to sanitize (zero) allocated memory. The 'tlb' and 'cache' are not wasted in filling entries.

这篇关于Linux内核:在pageing_init时零页面分配的作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆