10
$\begingroup$

I'm learning about paging. My book says that the logical addresses generated by the CPU are in the form |p|d|(page number, page offset) and the physical addresses are in the form |f|d|(frame number, frame offset). It is also specifically mentioned that d i.e. the offset is copied directly to generate the physical address from the logical ones.

Now, commonsense says that if the offset is copied directly, the page size HAS to be equal to the frame size (otherwise, offsets wouldn't correspond). But unfortunately my book doesn't say anything about that.

So, is page size always equal to frame size?

Please enable images ;)

$\endgroup$

3 Answers 3

10
$\begingroup$

A page is a region of virtual address space, and a page frame is a region of physical memory. A page which maps a region of physical memory must have the same size as that piece of physical memory, otherwise there's no point.

They also typically must be aligned correctly. If you try to map, say, a 2Mb page frame into virtual memory, both the virtual address and physical address must both be 2Mb aligned.

Many modern CPUs support more than one page size, and some can support different page sizes in the same address space. Current Intel x86-64, for example, supports 4kb, 2Mb and 1Gb page sizes. These numbers are not arbitrary; they represent the address space covered by different "levels" in the multilevel page table. Similarly, modern ARM supports 4kb, 64kb, and 1Mb pages, though ARM does not refer to the 1Mb pages as "pages" (they are "sections"). ARMv4 and ARMv5 supported splitting pages further into so-called "subpages"; these are no longer available in ARMv7.

Interestingly, there are a few other things that are often the same size as the page size. Obviously a TLB entry is the same size as a page or frame, since it's conceptually a cache for page table entries. However, L1 cache size is often determined by the page size, too.

Suppose the L1 cache is set-associative (a direct-mapped cache is really just a 1-way set associative cache, so you can think of this as a limiting case), then it's often convenient to make one "set" the size of a physical page. So suppose that the page size is 4kb, and the L1 cache is a 4-way set-associative cache, then the "best" size for the L1 cache is 16kb (which is four times 4kb). See if you can work out for yourself this might be the case.

$\endgroup$
1
$\begingroup$

yes page size must be equal to frame size in order to minimize the internal fragmentation of main memory.

$\endgroup$
4
  • 3
    $\begingroup$ Note that some architectures support several page sizes simultaneously. $\endgroup$
    – Grabul
    Commented Sep 25, 2015 at 19:27
  • $\begingroup$ Can you elaborate? We prefer detailed answers that provide explanation, justification, or analysis. If the page size were not equal to the frame size, how would this cause increased internal fragmentation of main memory? Can you edit the answer to add an explanation of this? $\endgroup$
    – D.W.
    Commented Sep 26, 2015 at 5:17
  • $\begingroup$ The above answer with 1 upvote is absolutely wrong. Paging uses constant-size blocks of memory, and thus minimizes external fragmentation at the expense of internal, if the memory allocated is less than a page. So, I concluded that your O.S will be happier if you choose pageSize=frameSize. $\endgroup$ Commented Apr 20, 2018 at 19:56
  • $\begingroup$ @JigneshKumar, please don't use the 'Your Answer' box to comment on existing answers. Instead, focus on questions where you can provide a complete answer of your own, or asking useful new questions. Thank you! $\endgroup$
    – D.W.
    Commented Apr 20, 2018 at 22:00
1
$\begingroup$

The page frame can't be smaller than the page, because then the offset could overflow the page frame. What about the reverse -- the page frame being bigger than the page? Unlike the former scenario, this would work, but it would be wasteful because there would be parts of the page frame that were never used (these are the parts that are beyond the maximum offset).

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.