1

I'm watching these series and I don't understand what is the 12 bits page offset (I only raise 2^12-1 and got 4Kb and I though it is the size of the page itself but I'm not sure it's correct). Also I don't understand what is the virtual page number. I've watched all the series 1-6 from the guy, and did understand what he presented. I also enjoy the explanation with the houses and streets but I still don't get it.

This is the picture he explains: enter image description here

Cătălina Sîrbu
  • 1,253
  • 9
  • 30
  • Your program uses [virtual addresses](https://en.wikipedia.org/wiki/Virtual_address_space). In this example, 32-bit virtual addresses. Virtual addresses ultimately map to physical addresses. Page tables facilitate mapping virtual to physical addresses. The size and layout of physical pages *NEED NOT* map exactly to virtual pages - they can be *different*. Q: Does that help? – paulsm4 Dec 01 '20 at 21:42
  • I would like to understand what are the virtual page number and page offsets and how to calculate them and what they represent – Cătălina Sîrbu Dec 01 '20 at 22:17
  • 1
    In this example: 1) Your application has a 32-bit address. 2) The 20 high order bits of that 32-bit VA point to a "page #", in the "page table". 3) The address translation mechanism fetches that entry in the page table. 4) The entry in the page table points to the physical page. 5) The OS loads the physical page. 6) The physical page + page offset = physical address. 7) Your application can now access the data at that address. – paulsm4 Dec 02 '20 at 00:09
  • what does the page offset? – Cătălina Sîrbu Dec 02 '20 at 07:24

1 Answers1

2

OK - the diagram you posted is a very good description of "virtual memory".

With regard to your most recent question:

Q: What does the page offset?

  1. When your program wants to access memory, it uses a "Virtual Address".

  2. "Virtual addresses" map to "Physical addresses".

    The mapping involves a combination of "page #" (what "page" does the data we're interested in reside in?) and an "offset".

  3. The "offset" is simply the location within a page where our data resides.

    Offset "0" is the first byte in the page.

    Offset "9" is the 10th byte in the page.

    Etc. Etc.

Perhaps part of your confusion is:

Q: Why do we need "virtual memory" (and pages and address mappings) in the first place???

Consider an operating system like DOS. There is no virtual addressing, there are no "pages". Everything is just "physical memory".

In DOS, a 16-bit address IS the physical address. It points directly to a specific location - a specific byte - in physical memory. The "address" IS the "offset", from physical memory location "0". (Strictly speaking, a DOS "address" is actually the 16-bit offset into the current "segment", which is in the Intel 8086 "segment register". But we digress...)

One of the problems with a simple, non-paged system like DOS is RAM limits. Another problem is that any DOS application can access - and potentially corrupt - the memory used by any other active DOS application (including DOS TSRs).

Virtual Memory solves these - and many other - problems. Even though "paging" introduces extra complexity, systems that support virtual memory can be much more powerful, robust and secure.

Q: Does that help?

paulsm4
  • 114,292
  • 17
  • 138
  • 190
  • Yes, actually It took me so much to understand that the actual "pages" needs to be numbered (and therefore more bits needed) along with the page offset (which is a well known size and therefore can occupy less memory - 12 bits for e.g) – Cătălina Sîrbu Dec 02 '20 at 20:41