物理/逻辑/虚拟内存地址之间的差异 [英] Difference between physical/logical/virtual memory address

查看:210
本文介绍了物理/逻辑/虚拟内存地址之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对操作系统中的物理/逻辑/虚拟地址一词有些困惑(我使用Linux-open SU​​SE)

I am a little confused about the terms physical/logical/virtual addresses in an Operating System(I use Linux- open SUSE)

这是我的理解:

  1. 物理地址-处理器处于系统模式时,处理器使用的地址为物理地址.

  1. Physical Address- When the processor is in system mode, the address used by the processor is physical address.

逻辑地址-当处理器处于用户模式时,使用的地址是逻辑地址.可以通过添加带有偏移值的基址寄存器将它们映射到某个物理地址.它以某种方式提供了内存保护.

Logical Address- When the processor is in user mode, the address used is the logical address. these are anyways mapped to some physical address by adding a base register with the offset value.It in a way provides a sort of memory protection.

我遇到了有关虚拟和逻辑地址/地址空间相同的讨论.是真的吗

I have come across discussion that virtual and logical addresses/address space are the same. Is it true?

任何帮助深表感谢.

推荐答案

对于在现代Linux系统上运行的Intel CPU,我的回答是正确的,我说的是用户级别的进程,而不是内核代码.不过,我认为它将为您提供足够的洞察力,以考虑其他可能性

关于问题3:

我遇到了虚拟和逻辑的讨论 地址/地址空间相同.是真的吗?

I have come across discussion that virtual and logical addresses/address space are the same. Is it true?

据我所知,至少在运行于Intel处理器之上的现代操作系统中,它们是相同的.

As far as I know they are the same, at least in modern OS's running on top of Intel processors.

在我进一步解释之前,让我尝试定义两个概念:

Let me try to define two notions before I explain more:

  • 物理地址:RAM芯片中物理位置的地址.
  • 逻辑/虚拟地址:程序用来访问其内容的地址.通常,以后会通过硬件芯片将其转换为物理地址(大多数情况下,甚至CPU都不知道这种转换).
  • Physical Address: The address of where something is physically located in the RAM chip.
  • Logical/Virtual Address: The address that your program uses to reach its things. It's typically converted to a physical address later by a hardware chip (mostly, not even the CPU is aware really of this conversion).

虚拟地址很好,一个虚拟地址,操作系统以及称为MMU(内存管理单元)的硬件电路使您的程序在系统中单独运行,它具有整个地址空间(具有32位)系统意味着您的程序会认为它具有4 GB的RAM;大致而言).

The virtual address is well, a virtual address, the OS along with a hardware circuit called the MMU (Memory Management Unit) delude your program that it's running alone in the system, it's got the whole address space(having 32-bits system means your program will think it has 4 GBs of RAM; roughly speaking).

很明显,如果您当时有多个程序在运行(您经常执行,GUI,Init进程,Shell,时钟应用程序,日历等),则将无法正常工作.

Obviously, if you have more than one program running at the time (you always do, GUI, Init process, Shell, clock app, calendar, whatever), this won't work.

将发生的情况是,操作系统会将您的大部分程序存储器放入硬盘中,它使用最多的部分将出现在RAM中,但是,这并不意味着它们将具有您的地址.和您的程序知道.

What will happen is that the OS will put most of your program memory in the hard disk, the parts it uses the most will be present in the RAM, but hey, that doesn't mean they'll have the address you and your program know.

示例:您的进程可能有一个名为(counter)的变量,该变量的虚拟地址为0xff(可以想象...),另一个名为(oftenNotUsed)的变量,其虚拟地址为(0xaa).

Example: Your process might have a variable named (counter) that's given the virtual address 0xff (imaginably...) and another variable named (oftenNotUsed) that's given the virtual address (0xaa).

如果您在所有链接发生之​​后都读了汇编代码的汇编,则可以使用这些地址访问它们,但是好吧,(oftenNotUsed)变量不会真正出现在RAM中的0xaa位置,它将位于硬盘,因为该进程未使用它.

If you read the assembly of your compiled code after all linking's happened, you'll be accessing them using those addresses but well, the (oftenNotUsed) variable won't be really there in RAM at 0xaa, it'll be in the hard disk because the process is not using it.

此外,变量(计数器)在物理上可能不会位于(0xff),它将在RAM中的其他位置,当您的CPU尝试获取0xff中的内容时,MMU和一部分OS将进行映射并从RAM中实际可用的位置获取该变量,CPU甚至不会注意到它不在0xff中.

Moreover, the variable (counter) probably won't be physically at (0xff), it'll be somewhere else in RAM, when your CPU tries to fetch what's in 0xff, the MMU and a part of the OS, will do a mapping and get that variable from where it's really available in the RAM, the CPU won't even notice it wasn't in 0xff.

现在,如果您的程序要求输入(oftenNotUsed)变量,会发生什么? MMU + OS会注意到此未命中",并将其从硬盘中获取给CPU,供其进入RAM,然后将其移交给CPU,就好像它位于地址(0xaa)中一样;这种获取意味着RAM中存在的一些数据将被发送回硬盘.

Now what happens if your program asks for the (oftenNotUsed) variable? The MMU+OS will notice this 'miss' and will fetch it for the CPU from the Harddisk into RAM then hand it over to the CPU as if it were in the address (0xaa); this fetching means some data that was present in RAM will be sent back to the Harddisk.

现在想象一下在系统中的每个进程中都运行此命令.每个进程都认为它们有4GB的RAM,没有人真正拥有它,但是一切正常,因为每个人的程序的某些部分实际上都在RAM中可用,但是大多数程序都位于硬盘中.不要将HD中的程序存储器的这一部分与可以通过文件操作访问的程序数据混淆.

Now imagine this running for every process in your system. Every process thinks they have 4GB of RAMs, no one actually have that but everything works because everyone has some parts of their program available physically in the RAM but most of the program resides in the HardDisk. Don't confuse this part of the program memory being put in HD with the program data you can access through file operations.

虚拟地址:您在程序中使用的地址(CPU用于获取数据的地址)不是真实的,而是通过MMU转换为某个物理地址;每个人都有一个,它的大小取决于您的系统(运行32位的Linux具有4GB的地址空间)

Virtual address: The address you use in your programs, the address that your CPU use to fetch data, is not real and gets translated via MMU to some physical address; everyone has one and its size depends on your system(Linux running 32-bit has 4GB address space)

物理地址:如果在操作系统之上运行,则永远无法到达该地址.不管虚拟地址是什么,数据都在这里驻留在RAM中.如果将数据来回发送到硬盘上以容纳更多空间供其他进程使用,则情况将有所改变.

Physical address: The address you'll never reach if you're running on top of an OS. It's where your data, regardless of its virtual address, resides in RAM. This will change if your data is sent back and forth to the hard disk to accommodate more space for other processes.

我上面提到的所有内容虽然是整个概念的简化版本,但被称为计算机系统的内存管理部分.

All of what I have mentioned above, although it's a simplified version of the whole concept, is what's called the memory management part of the the computer system.

  • 进程无法访问彼此的内存,每个人都有各自的虚拟地址,并且即使有时您可能会发现并发现两个进程试图访问相同的虚拟地址,每个进程也会对不同区域进行不同的转换.
  • 该系统可以很好地用作缓存系统,通常不会使用可用的全部4GB,那么为什么要浪费呢?让其他人共享它并让他们也使用它;当您的流程需要更多的资源时,操作系统会从HD中获取您的数据并替换其他流程的数据,这当然是要花钱的.

这篇关于物理/逻辑/虚拟内存地址之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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