Dividing Addresses into Pages and Offsets

Paging groups addresses into fixed-size ranges. A page number identifies the range, while an offset identifies a position inside it.

Source
Anbloq
Language
English
Created
Updated
Chapters
4
Reading time
1 min
In this article4 chapters
  1. Work a small calculation
  2. Resolve the page before reading its contents
  3. Compute page index and offset from one address
  4. Check accesses spanning a page boundary

Work a small calculation

With pages of 4096 bytes, virtual address 4100 has page number one and offset four. This follows quotient and remainder with divisor 4096.

Resolve the page before reading its contents

A mapping translates the page identity under permission and availability rules. The offset locates the byte within the mapped page. See virtual memory translation for a full lookup model.[1]

Compute page index and offset from one address

With pages of size 4096 bytes, address 8195 lies on virtual page two with offset three. The page ends at address 12287, and 12288 starts page three. These positions follow from quotient and remainder. See quotient and remainder.

8195 = 2×4096 + 3
Page 2 covers [8192,12288)
Address 12287 has offset 4095
Address 12288 has offset 0 on page 3

Check accesses spanning a page boundary

A multi-byte read can touch two pages even when its first byte is valid. Permission or mapping status can differ across them. Validate the whole access under the target page model and test the last byte of a page.

References

  1. Remzi H. Arpaci-Dusseau and Andrea C. Arpaci-Dusseau, Operating Systems: Three Easy Pieces ↩