转stackoverflow一个问题,关于内核是如何管理页表(pgd,pud,pmd,pte)本身所占的内存

碎碎念

我今天莫名开始纠结起,关于linux页表方面的问题。然后就想到,
【页表本身也是要占有一部分内存的,所以内核又是如何管理页表本身所占有的这部分内存的呢?】
找了很久,没太满意的答案。甚至都没有具体方向,所以也不太有希望从源码中找到答案。
暂时就以在stackoverflow上找到的这个提问,作为这次疑惑的收尾吧,可能要很久很久之后才能得到圆满的解答了。

回复的大致意思是:
【根据linux内核相关wiki,页表就是常驻在内存中的,不会换出。】
也不知道实际是如何的,还是希望有从动态层面上研究过内核的大神,来救救孩子。

问题

Are page tables always in memory? Would page tables be swapped out?

I think page tables is maintained by Linux kernel, so the memory need for page tables should not be swapped out, for the reason that the kernel do not have page fault thing. But, if the pgd, pmd, pte tables are all in main memory and never swapped out, the meaning of multilevel paging can not save any memory.

So I am confused about the how page tables themselves are managed.

回复

well, according to wikipedia, it is true that page tables aren’t swapped out - but swapping out tables isn’t what makes them memory efficient! lets take an example: our physical memory is 4GB in size, every page is 4KB so we would have needed 4MB size table in order to map every address. the solution to this problem isn’t swapping out part of the table, but creating a hierarchy of tables, so you can allocate only the parts in the hierarchy which you need. it is explained quite thoroughly here: Why using hierarchical page tables?

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值