逻辑地址和物理地址之间的区别?

发布于 2024-09-19 01:57:27 字数 721 浏览 16 评论 0原文

我正在阅读《操作系统概念》,现在正在读第 8 章!不过,我可以做一些澄清,或者保证我的理解是正确的。

逻辑地址:根据书中所述,逻辑地址是由CPU生成的。这究竟意味着什么? (在执行生成的地址系统中......)我假设当为程序编译代码时,程序不知道代码将加载到内存中的位置。编译器所做的只是建立程序布局的总体草图以及图像的布局方式,但不会为其分配任何实际地址。当程序执行时,CPU 获取编译器生成的布局图像,并将一些地址(逻辑地址)分发给代码生成的地址。

物理地址:直到CPU生成一组逻辑地址(由基地址和偏移量组成)之后才会生成物理地址。逻辑地址通过 MMU 或其他设备,并且沿线的某个位置将逻辑地址映射到物理 RAM 地址。

那么实际的区别是什么呢?我可以看到一个好处。使用逻辑地址为应用程序提供了更多自由。如果物理地址是硬编码的,那么程序的成功将在很大程度上取决于物理计算机、可用的 RAM 地址等。

使用逻辑地址转换为物理地址是否会强加两个步骤而不是一对一的步骤,因此更多的头?

那么生成后逻辑地址驻留在哪里呢?当 CPU 为进程提供服务时,它们可能存在于 CPU 的寄存器中,但是在此之前和之后,它们去了哪里?我知道这是依赖于实现的。我假设它们可能存储在 CPU 上的某些特殊寄存器空间或缓冲区中,例如 TLB,对吗?如果不是,那么该表可能存在于实际的 RAM 本身中,并且 CPU 仅保存指向 RAM 中表的基地址的指针/地址,对吗?

将地址保存在 RAM 中似乎与逻辑内存地址的目的适得其反。我只能假设我的理解是不正确的。

I am reading Operating Systems Concept and I am on the 8th chapter! However I could use some clarification, or reassurance that my understanding is correct.

Logical Addresses: Logical addresses are generated by the CPU, according to the book. What exactly does this mean? (In an execute-generated address system..) I assume when code is compiled for a program, the program has no idea where the code will be loaded in memory. All the compiler does is set up a general sketch of the program layout and how the image should be laid out, but doesn't assign any real addresses to it. When the program is executed the CPU takes this layout image that the compiler made and hands out some addresses (logical ones) to the ones generated from the code.

Physical Addresses: The physical addresses are not generated until after the CPU generates some set of logical addresses (consisting of a base address and an offset). The logical addresses go through the MMU or another device and somewhere along the line the logical addresses are mapped to physical RAM addresses.

What then is the actual difference? I can see one benefit. Using logical addresses gives more freedom to the applications. If the physical addresses were hard coded, then the program success would depend heavily on the physical computer machine, available RAM addresses etc.

Doesn't the use of logical addresses converted to physical address impose two steps instead of a one to one, and therefore more over head?

Where then do the logical addresses reside after generation? They may exist in a register on the CPU while the CPU is servicing a process, but before and after, where do they go? I understand this is implementation dependent. I assume they may be stored in some special register space or buffer on the CPU such as a TLB, correct? If not, then the table may exist in the actual RAM itself, and the CPU only holds a pointer/address to the base address of the table in RAM, correct?

It seems holding the addresses in RAM is counter productive to the purpose of logical memory addresses. I can only assume my understanding is incorrect.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

亢潮 2024-09-26 01:57:27

这个答案绝不是详尽无遗的,但它足以解释它,让事情变得顺利。

在虚拟内存系统中,逻辑地址和物理地址之间存在脱节。

可以为应用程序提供(比方说)4G 的虚拟地址空间。这是它的可用内存,它可以随意使用它。这是一个很好的连续内存块(从应用程序的角度来看)。

然而,它并不是唯一运行的应用程序,操作系统必须在它们之间进行协调。在这个漂亮的连续模型下,需要进行大量映射来将逻辑地址转换为物理地址。

通过这种映射,操作系统和硬件(从这里开始我将它们称为较低层)可以自由地将应用程序页面放置在它想要的任何地方(无论是在物理内存中还是换出到辅助存储)。

当应用程序尝试访问逻辑地址 50 处的内存时,较低级别可以使用转换表将其转换为物理地址。而且,如果它尝试访问已换出到磁盘的逻辑内存,则会引发页面错误,并且较低级别可以将相关数据带回到内存中,无论它想要什么物理地址。

在过去的糟糕日子里,当你拥有物理地址时,代码必须是可重新定位的(或在加载时修复),因为它可以加载到任何地方。使用虚拟内存,该代码(和数据)可以同时位于十几个不同进程中的逻辑内存位置 50 - 然而,它的实际物理地址将有所不同。

它甚至可以被共享,以便在许多进程的地址空间中同时存在一个物理副本。这是共享代码(因此我们不会使用超出需要的物理内存)和共享内存以允许轻松的进程间通信的关键。

当然,它的效率低于纯物理地址环境,但 CPU 制造商试图使其尽可能高效,因为它被大量使用。优点远远超过缺点。

This answer is by no means exhaustive but it may explain it enough to make things click.

In virtual memory systems, there is a disconnect between logical and physical addresses.

An application can be given a virtual address space of (let's say) 4G. This is its usable memory and it's free to use it as it sees fit. It's a nice contiguous block of memory (from the point of view of the application).

However, it is not the only application running, and the OS has to mediate between them all. Underneath that nice contiguous model, there is a lot of mapping going on to convert logical to physical addresses.

With this mapping, the OS and hardware (I'll just call these the lower layers from here on in) is free to put the application pages anywhere it wants (either in physical memory or swapped out to secondary storage).

When the application tries to access memory at logical address 50, the lower levels can translate that to a physical address using translation tables. And, if it tries to access logical memory that's been swapped out to disk, a page fault is raised and the lower levels can bring the relevant data back into memory, at whatever physical address it wants.

In the bad old days when physical addresses were all you had, code had to be relocatable (or fixed up on load) since it could load anywhere. With virtual memory, that code (and data) can be at logical memory location 50 in a dozen different processes at the same time - it's actual physical address will be different however.

It can even be shared so that one physical copy exists in the address space of many processes at once. This is the crux of shared code (so we don't use more physical memory than we need) and shared memory to allow easy inter-process communication).

It is, of course, less efficient than a pure physical-address environment but the CPU manufacturers try to make it as insanely efficient as possible, since it's used heavily. The advantages far outweigh the disadvantages.

世俗缘 2024-09-26 01:57:27

逻辑地址是相对于程序的地址。它告诉了特定进程将占用多少内存,而不告诉进程的确切位置是什么,以及我们将通过使用某种映射生成的确切位置,称为物理地址。

logical address is address relative to program. It tells how much memory a particular process will take, not tell what will the exact location of the process and this exact location will we generated by using some mapping, and is known as physical address.

緦唸λ蓇 2024-09-26 01:57:27

逻辑地址:-由CPU生成的逻辑地址。当我们把问题交给计算机时,我们的计算机通过逻辑地址将问题传递给处理器,我们看不到的这个地址称为逻辑地址。

物理地址:-当我们的处理器创建进程并解决我们的问题时,我们通过称为物理地址的地址将数据存储在辅助内存中

Logical address:- Logical address generated by the CPU . when we are give the problem to the computer then our computer pass the problem to the processor through logical address , which we are not seen this address called logical address .

Physical address :- when our processor create process and solve our problem then we store data in secondary memory through address called physical address

生生漫 2024-09-26 01:57:27
  1. CPU生成的地址通常称为逻辑地址。程序生成的所有逻辑地址的集合称为逻辑地址空间。而内存单元看到的地址(即加载到内存的内存地址寄存器中的地址)通常称为物理地址。与逻辑地址对应的所有物理地址的集合称为物理地址空间。
  2. 编译时和加载时地址绑定方法生成相同的逻辑和物理地址。然而,在执行时地址绑定方案中,逻辑地址空间和物理地址空间不同。
  3. 用户程序永远看不到物理地址。该程序创建一个指向逻辑地址(例如 346)的指针,将其存储在内存中,对其进行操作,将其与其他逻辑地址进行比较 - 全部都是数字 346。
    仅当逻辑地址用作内存地址时,才会相对于基址/重定位寄存器进行重定位。称为内存管理单元 (MMU) 的内存映射硬件设备将逻辑地址转换为物理地址。
  4. 逻辑地址范围从 0 到最大。生成逻辑地址的用户程序认为该进程运行在0到max的位置。
    逻辑地址在使用之前必须映射到物理地址。对于基址/重定位寄存器值 R,物理地址范围从 (R+0) 到 (R + max)。
  5. 示例:
    输入图片此处描述
    使用内存管理单元 (MMU) 和重定位/基址寄存器从逻辑地址映射到物理地址
    重定位/基址寄存器中的值在发送到内存时与用户进程生成的每个逻辑地址相加,生成相应的物理地址。
    在上图中,base/relocation 值为 14000,则用户尝试访问位置 346 时将映射到 14346。
  1. An address generated by the CPU is commonly referred to as a logical address. The set of all logical addresses generated by a program is known as logical address space. Whereas, an address seen by the memory unit- that is, the one loaded into the memory-address register of the memory- is commonly referred to as physical address. The set of all physical addresses corresponding to the logical addresses is known as physical address space.
  2. The compile-time and load-time address-binding methods generate identical logical and physical addresses. However, in the execution-time address-binding scheme, the logical and physical-address spaces differ.
  3. The user program never sees the physical addresses. The program creates a pointer to a logical address, say 346, stores it in memory, manipulate it, compares it to other logical addresses- all as the number 346.
    Only when a logical address is used as memory address, it is relocated relative to the base/relocation register. The memory-mapping hardware device called the memory- management unit(MMU) converts logical addresses into physical addresses.
  4. Logical addresses range from 0 to max. User program that generates logical address thinks that the process runs in locations 0 to max.
    Logical addresses must be mapped to physical addresses before they are used. Physical addresses range from (R+0) to (R + max) for a base/relocation register value R.
  5. Example:
    enter image description here
    Mapping from logical to physical addresses using memory management unit (MMU) and relocation/base register
    The value in relocation/base register is added to every logical address generated by a user process, at the time it is sent to memory, to generate corresponding physical address.
    In the above figure, base/ relocation value is 14000, then an attempt by the user to access the location 346 is mapped to 14346.
℉服软 2024-09-26 01:57:27

逻辑地址与物理地址空间

CPU生成的地址通常称为逻辑地址,而内存单元看到的地址,即加载到内存的内存地址寄存器中的地址通常称为物理地址。加载时地址绑定生成相同的逻辑和物理地址。但是,执行时地址绑定方案会产生不同的逻辑和物理地址。

程序生成的所有逻辑地址的集合称为逻辑地址空间,而这些逻辑地址对应的所有物理地址的集合称为物理地址空间。现在,从虚拟地址到物理地址的运行时映射是通过称为内存管理单元的硬件设备。这里在映射的情况下,基址寄存器称为重定位寄存器。重定位寄存器中的值被添加到用户进程在发送到内存时生成的地址。让我们了解一下借助示例来说明这种情况:如果基址寄存器包含值 1000,则用户尝试对位置 0 进行寻址会动态重定位到位置 1000,对位置 346 的访问会映射到位置 1346。

用户程序永远看不到真实的物理地址空间,它总是处理逻辑地址。因为我们有两种不同类型的地址,逻辑地址在范围(0到最大)中,物理地址在范围(R到R+max)中,其中R是值用户只生成逻辑地址,并认为进程运行在0到max的位置。从上面的文字可以清楚地看出,用户程序只提供逻辑地址,这些逻辑地址必须先映射到物理地址,然后才能使用。被使用。

Logical Vs Physical Address space

An address generated by the CPU is commonly refereed as Logical Address,whereas the address seen by the memory unit,that is one loaded into the memory address register of the memory is commonly refereed as the Physical Address.The compile time and load time address binding generates the identical logical and physical addresses.However, the execution time address binding scheme results in differing logical and physical addresses.

The set of all logical addresses generated by a program is known as Logical Address Space,whereas the set of all physical addresses corresponding to these logical addresses is Physical Address Space.Now, the run time mapping from virtual address to physical address is done by a hardware device known as Memory Management Unit.Here in the case of mapping the base register is known as relocation register.The value in the relocation register is added to the address generated by a user process at the time it is sent to memory.Let's understand this situation with the help of example:If the base register contains the value 1000,then an attempt by the user to address location 0 is dynamically relocated to location 1000,an access to location 346 is mapped to location 1346.

The user program never sees the real physical address space,it always deals with the Logical addresses.As we have two different type of addresses Logical address in the range (0 to max) and Physical addresses in the range(R to R+max) where R is the value of relocation register.The user generates only logical addresses and thinks that the process runs in location to 0 to max.As it is clear from the above text that user program supplies only logical addresses,these logical addresses must be mapped to physical address before they are used.

╰沐子 2024-09-26 01:57:27

逻辑地址是对存储器位置的引用,与存储器的当前数据分配无关。
物理地址或绝对地址是主存储器中的实际位置。

这是《Stallings》第 7.2 章中的内容。

A logical address is a reference to memory location independent of the current assignment of data to memory.
A physical address or absolute address is an actual location in main memory.

It is in chapter 7.2 of Stallings.

南笙 2024-09-26 01:57:27

据我所知,物理地址是内存中明确的、固定的地址,而逻辑地址由基指针和偏移量组成。

原因基本如您所指定。它不仅允许将程序和进程分段为线程和数据,还允许动态加载此类程序,并至少允许伪并行性,而无需在内存中发生任何实际的指令交错。

To the best of my memory, a physical address is an explicit, set in stone address in memory, while a logical address consists of a base pointer and offset.

The reason is as you have basically specified. It allows for not only the segmentation of programs and processes into threads and data, but also for the dynamic loading of such programs, and the allowance for at least pseudo-parallelism, without any actual interlacing of instructions in memory needing to take place.

幻梦 2024-09-26 01:57:27

我找到了一篇关于逻辑地址与物理地址的文章在操作系统中,它清楚地解释了这一点。

逻辑地址是在程序运行时由CPU生成的。逻辑地址是虚拟地址,因为它物理上不存在,因此也称为虚拟地址。该地址用作 CPU 访问物理内存位置的参考。术语“逻辑地址空间”用于表示从程序角度生成的所有逻辑地址的集合。
称为内存管理单元的硬件设备用于将逻辑地址映射到其对应的物理地址。

物理地址标识存储器中所需数据的物理位置。用户并不直接处理物理地址,而是通过其对应的逻辑地址来访问。用户程序生成逻辑地址,并认为程序正在该逻辑地址中运行,但程序需要物理内存来执行,因此在使用逻辑地址之前必须将逻辑地址映射到物理地址bu MMU。术语“物理地址空间”用于与逻辑地址空间中的逻辑地址相对应的所有物理地址。

逻辑和物理地址比较

来源:www. geeksforgeeks.org

I found a article about Logical vs Physical Address in Operating System, which clearly explains about this.

Logical Address is generated by CPU while a program is running. The logical address is virtual address as it does not exist physically therefore it is also known as Virtual Address. This address is used as a reference to access the physical memory location by CPU. The term Logical Address Space is used for the set of all logical addresses generated by a programs perspective.
The hardware device called Memory-Management Unit is used for mapping logical address to its corresponding physical address.

Physical Address identifies a physical location of required data in a memory. The user never directly deals with the physical address but can access by its corresponding logical address. The user program generates the logical address and thinks that the program is running in this logical address but the program needs physical memory for its execution therefore the logical address must be mapped to the physical address bu MMU before they are used. The term Physical Address Space is used for all physical addresses corresponding to the logical addresses in a Logical address space.

Logical and Physical Address comparision

Source: www.geeksforgeeks.org

夜夜流光相皎洁 2024-09-26 01:57:27

简单来说,逻辑地址被处理器视为连续的可访问内存块,但在其下面是不连续的物理内存块。

底层有很多逻辑地址和物理地址之间的映射。从虚拟地址到物理地址的运行时映射是由称为内存管理单元(MMU)的硬件设备完成的。

In simple terms, the logical address is seen by the processor as a continuous block of accessible memory, but underneath it is discontinuous blocks of physical memory.

Underneath there is a lot of mapping between logical address and physical address. The runtime mapping from virtual to physical address is done by a hardware device called the memory-management unit(MMU).

遗心遗梦遗幸福 2024-09-26 01:57:27

物理地址是计算机内存中数据的精确位置,逻辑地址是计算机程序用来访问内存的虚拟地址。虽然较新的处理器可以无缝处理物理地址和逻辑地址,但较旧的处理器(例如 Intel 8080/8085)会直接生成物理地址。它没有单独的内存管理单元(MMU)或支持虚拟内存。

Physical address is the precise location of data in computer memory and logical address is a virtual address that a computer program uses to access memory. While newer processors seamlessly handle both physical and logical addresses, older ones like the Intel 8080/8085 directly generates physical addresses. It doesn't have a separate Memory Management Unit (MMU) or support virtual memory.

陌伤ぢ 2024-09-26 01:57:27

逻辑地址是从执行应用程序的角度来看项目(存储器单元、存储元件、网络主机)似乎驻留的地址。

A logical address is the address at which an item (memory cell, storage element, network host) appears to reside from the perspective of an executing application program.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文