所有物理内存都映射到内核的虚拟地址吗? [英] All physical memory is mapped into virtual address of kernel?

查看:215
本文介绍了所有物理内存都映射到内核的虚拟地址吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近正在研究设备驱动程序,并想起了虚拟内存的概念.虽然我在学生时代就参加了计算机体系结构课程,但是老实说,虚拟内存的概念是如此复杂,以至于总是让我感到困惑.我是EE专家,因此,请从大图片的角度进行说明,以真正区分该概念.我可以自己深入研究技术细节.

I am studying device driver recently, and get reminded of the concepts of virtual memory. Although I attended Computer Architecture classes when I was student, however, honestly speaking, virtual memory is so complicated from concepts that it always confused me. I am a EE guy, so, please explain from the view of BIG PICTURE that really distinguish this concept. I can dig into technique details myself.

当我们谈论虚拟内存时,我们在谈论一个进程的内存分配方法.进程是虚拟内存服务的进程,对吗?对于具有4GB地址空间的32位系统,通常将0-3G分配给用户空间虚拟地址,并将3-4G空间分配给内核.从下面列出的帖子中,这就是所谓的3G/1G部门:

When we are talking about virtual memory, we are talking about the memory allocation method for a process. Process is the one that virtual memory serves, right? For a 32-bit system with 4GB address space, 0-3G is usually assigned to user space virtual address, and 3-4G space is assigned to kernel. This is what called 3G/1G division, from the post listed below:

http://users.nccs.gov/~fwang2/linux/lk_addressing. txt

但是,这篇文章还说明了所有物理内存都已映射到内核空间,而对于用户空间则一无所知.这真的让我感到困惑.我在这里的帖子中列出了这一部分:

However, this post also illustrated that ALL PHYSICAL MEMORY IS MAPPED INTO KERNEL SPACE, and nothing for user space. This really confused me. I list this part in the post here:

因此,在3G/1G拆分中,内核具有1GB的虚拟地址空间. 请记住,要访问物理地址,您需要一个虚拟地址才能访问 首先,甚至对于内核.因此,如果您没有做任何特别的事情,那么1GB 虚拟地址有效地限制了内核可以访问的物理空间 1GB.好的,也许这是第三个不太明显的细节:内核需要进行访问 每个物理内存可以充分利用它.

Thus, in the 3G/1G split, kernel has the virtual address space of 1GB. Remember that to access a physical address, you need a virtual address to start with, even for kernel. So if you don't do anything special, the 1GB virtual address effectively limits the physical space a kernel can access to 1GB. Okay, maybe this is a third less obvious detail: kernel needs to access every physical memory to make full use of it.

在机器的物理空间远小于1GB的早期,它会 可以,整个物理内存都映射到此1GB虚拟地址.

In the early days, where a machine's physical space is much less than 1GB, it is OK, the whole physical memory is mapped to this 1GB virtual address.

   process address space 

4GB +---------------+
    |     512MB     |
    +---------------+ <------+     physical memory               
    |     512MB     |        | 
3GB +---------------+ <--+   +---> +------------+ 
    |               |    |         |   512 MB   |
    |     /////     |    +-------> +------------+
    |               |     
0GB +---------------+     

#

这篇文章还说明了物理内存高于2G时的情况:

#

And this post also illustrate the same thing when physical memory is above 2G:

                                       physical mem
   process address space    +------> +------------+
                            |        |  3200 M    |
                            |        |            |
4GB +---------------+ <-----+        |  HIGH MEM  |
    |     128 MB    |                |            |
    +---------------+ <---------+    |            |
    +---------------+ <------+  |    |            | 
    |     896 MB    |        |  +--> +------------+         
3GB +---------------+ <--+   +-----> +------------+ 
    |               |    |           |   896 MB   |
    |     /////     |    +---------> +------------+
    |               |     
0GB +---------------+     

#

我的问题是,为什么所有物理内存都映射到内核空间?较低的0-3G用户空间没有?

#

My questions is, why all physical memory mapped into kernel space? None to the lower 0-3G user space?

我想我错过了与该帖子背后的大图有关的东西,但是,我错过了什么?

I think I missed something related to the big picture behind that post, but, what I have missed?

感谢您的时间和精力!

Thanks for your time and efforts!

推荐答案

具有映射 DOES NOT 的页面自动表示它位于物理内存中的某个位置.它只为您提供物理内存中的where to look for the page地址.

在任何情况下,通常我们都有一个内存层次结构.如今,三层式的体系并不是很典型.因此,很有可能在这些缓存之一中找到给定的内存地址.如果不是,则内核将必须通过从内存中逐出(未锁定)页面来启动其页面替换算法.

In any case, typically we have a memory heirarchy. A three level hierarchy is not atypical these days. So it is very much likely that a given memory address could be found in one of these caches. If it isn't then the kernel will have to start it's page replacement algorithm by evicting (unlocked) pages from the memory.

用户页面和内核页面之间的唯一区别是AFAIK,内核页面具有更高"的特权代码,允许它访问特权指令,并且在32位Linux的情况下,任何给定进程的内核部分将始终具有固定的虚拟地址空间,它在流程上下文切换之间发生更改.为了简化并因此加快到物理地址的转换,该映射还通过预先配置的偏移进行固定.除此之外,用户空间页面和内核空间页面之间没有太大区别.它们都竞争"物理内存.

The only difference between user and kernel pages, AFAIK, is that kernel pages have a "higher" privileged code allowing it to access privileged instructions and in case of 32bit Linux the Kernel portion of any given process will always have a fixed virtual address space that does NOT change between process context switches. And to simplify and therefore fasten the translation to physial address, the mapping is also fixed by a pre-configured offset. Other than that there isn't much difference between a user space page and a kernel space page. Both of them "compete" for the physical memory.

无论如何,由调度程序确定接下来要运行哪个实体,是常规用户空间进程,内核控制路径(在当前进程中process带)还是内核线程.根据该决定,交换器将交换RAM中的页面以腾出空间,然后交换所选实体中的页面.

In any case, it is the scheduler which determines which entity to run next, whether it is a regular user space process, a kernel control path (piggybacking on the current process) or a kernel thread. Depending on that decision, the swapper will swap out pages from the RAM to make room and then will swap in pages from the chosen entity.

中断具有完全不同的上下文,绕过调度程序,完全让CPU摆布.在这种情况下,将运行ISR,该ISR也将访问虚拟内存.如果与ISR相对应的页面不驻留在内存中,则会发生双重错误,并且通常表明作者的编程不良.这些处理方式因体系结构而异.有些处理故障直到某个点,有些则抛出内核OOPs消息并停止.尽管如此,与您的问题相关的是,即使系统中具有最高优先级的ISR(位于进程/线程之上)也必须确保有足够的内存来完成这项工作.

An interrupt has an altogether different context bypassing the scheduler completely leaving the CPU at it's mercy. In that case the ISR will be run which will also access virtual memory. If the pages corresponding to the ISR are not resident in memory, a double fault will occur and it usually shows poor programming by the author. How these are handled vary from architecture to architecture. Some process the fault until a certain point, some throw a kernel OOPs message and halt. Nevertheless, what is relevant to your question here is that even the ISRs which have the highest priority in the system (way above processes/threads) have to make sure there is enough memory to do the job.

P.S:在此讨论中,我们假设所有缓存请求都未命中,因此我们必须一直到RAM(再次被装满).

P.S: In this discussion we are assuming all our cache requests are a miss so we have to go all the way to the RAM (which is again packed full).

这篇关于所有物理内存都映射到内核的虚拟地址吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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