页码和偏移量 [英] Page number and offset

查看:163
本文介绍了页码和偏移量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习不同类型的内存管理.我不明白在虚拟地址中有偏移位的意义.还有为什么页面大小是 2 的幂?

I am learning the different types of memory management. I don't understand the point of having an offset bits in a virtual address. And also why page sizes are made power of 2?

  • 我的主要困惑是:给我一个在指令中用于访问某个虚拟地址的偏移量的例子?

  • My primary confusion is: give me an example of an offset being used in instruction to access a certain virtual address?

我的第二个困惑是:通常的说法是,如果逻辑地址的大小为2^m,页面大小为2^n,那么逻辑地址的高位 mn 位指定页码.

My second confusion is: The usual statement is that if the size of logical address is 2^m and page size is 2^n, then the high-order m-n bits of a logical address designate the page number.

推荐答案

我认为您的主要和次要混淆是由于对该主题的普遍混淆造成的 :)

让我谈谈这个问题,希望我可以提供一些帮助.首先,打个比方 - 假设您正在尝试在城市中找到一所房子.想象一下,每个房子都有一个唯一的编号——你可以想象房子的数量很快就会变得非常庞大和混乱.现在想象一下你引入了街道的概念——门牌号现在变得更易于管理,因为你已经将它们分组为漂亮的块.所以:街道 = 页码,门牌号 = 偏移地址.

拥有虚拟内存页面的全部意义在于允许计算机将内存分割成可管理的块,而不是浪费太多.将它分割成块(页面)允许对访问、分页和其他类似的好东西进行精细控制.你的页面越小,你浪费的内存就越少(如果进程 A 需要 32k 的内存,而你的页面大小是 64k,你最终会得到一些没有使用的),但是越高系统开销.

至于为什么页面大小是 2 的幂,这是地址内不浪费空间的原因.由于计算机基于二进制(目前),因此一切都倾向于归结为 2 的幂.想象一下,如果您有基于 10 的因数.二进制中的 10 是 1010 - 您必须使用 4 位来保存它,那么为什么不选择可以从 4 位中获得的所有值范围:0000 - 1111(0 到 15 = 16 个值).

抱歉,我有点胡思乱想了 - 我希望这会推动您朝着正确的方向发展!

I think your primary and secondary confusions are due to general confusion on the subject :)

Let me talk around this a bit and hopefully I can be of some help. First, an analogy - imagine that you're trying to locate a house in a city. Imagine that each house was given a unique number - you can imagine that the number of houses would soon get very large and confusing. Now imagine that you introduce the concept of streets - the house numbers now become a bit more managable as you've grouped them into nice chunks. So: Streets = Page number, house number = offset address.

The whole point of having virtual memory pages is to allow the computer to carve memory up into managable chunks and not waste too much of it. Carving it into chunks (pages) allows granular control of access, paging and other nice things like that. The smaller your pages, the less memory you're going to waste (if process A requires 32k of memory, and your page size is 64k, you're going to end up with some which isn't used), but the higher the overhead on the system.

As to why page sizes are powers of 2, this is down the not wasting space within the address. As computers are based on binary (at the moment), everything tends to boil down to powers of 2. Imagine if you have stuff based on factors of 10. 10 in binary is 1010 - you've got to use 4 bits to hold it, so why not go for the full range of values you can get out of 4 bits: 0000 - 1111 (0 to 15 = 16 values).

Sorry I've waffled on a bit - I hope this nudges you in the right direction!

这篇关于页码和偏移量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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