0

In Computer Systems - A Programmer's Perspective, the authors discuss virtual memory in Chapter 9. They talk about N=2^n as the number of addresses in virtual address space, M=2^m as the number of addresses in physical address space and P=2^p as the page size (in bytes).

You can also refer to pages 9 and 10 of this pdf which is based on that chapter.

My question is, for any given machine, whether it runs windows or linux, how do I find the values of n, m and p ?

Tryer
  • 3,580
  • 1
  • 26
  • 49
  • 2
    For any given ISA, the number of virt and phys address bits are usually fixed constants, although for some (like x86-64) the number of physical address bits any given CPU implements can be queried (with CPUID). Similarly the number of page-offset bits is usually a fixed constant, or a couple fixed page sizes may be supports (like x86-64's 4k normal pages, and 2M and 1G hugepage sizes). So if you're writing in asm, you just look up the value in the vendor's manual. Obviously for any fixed page size, p = log2(P), like p=12 for x86. Linux defines that as `PAGE_SHIFT` in asm-generic/page.h – Peter Cordes Aug 09 '20 at 04:17
  • 1
    [how is page size determined in virtual address space?](https://unix.stackexchange.com/q/128213) shows how to query it from the command line. – Peter Cordes Aug 09 '20 at 04:17
  • When a machine has "16 GB RAM (Installed Memory)", that refers to `M`? So, `m=34`? One can upgrade or install more RAM. Doesn't that then change `m` ? For a given CPU and version of OS, whether more RAM is added or not, `p` and `n` would remain the same. Is this correct ? – Tryer Aug 09 '20 at 04:33
  • 1
    Depends if you mean `m` as in the *usable* / populated part of physical address space, then yes it would go up as you add more RAM and/or devices like GPUs with device memory that's part of physical address space. Or if you just mean the number of physical address bits the ISA supports in theory (e.g. width of a field in the page table format) or in practice (width of cache tags / TLB entries). See [Why in x86-64 the virtual address are 4 bits short (48bit long) compared with the physical address (52 bit long)?](https://stackoverflow.com/q/46509152) for an example. – Peter Cordes Aug 09 '20 at 04:38
  • 2
    Yes, `p` and `n` are fixed for a given CPU, regardless of OS. (Unless you want to get into semantics about a 32-bit OS leaving an x86-64 CPU in legacy mode for 32-bit virtual addresses instead of 64-bit pointer size, but actually 48 or 57-bit virtual addresses.) – Peter Cordes Aug 09 '20 at 04:43
  • 1
    `M` and `m` are also fixed, since `m` is referring to the number of bits the hardware uses for physical addressing on the address bus interface to memory (modulo LSBs that are omitted as they are always zero); `m` also goes to the width of the PPN field in the page table (`m-p`). `M` and `m` cannot be expanded, and these limit the maximum memory that can be installed. The amount of RAM actually installed is a 4th number, beyond m, n, and p. (The board may also further limit maximum memory.) – Erik Eidt Aug 09 '20 at 15:02

0 Answers0