Memory Pages: Difference between revisions

From COMP15212 Wiki
gravatar Yuron [userbureaucratinterface-adminsysopPHRhYmxlIGNsYXNzPSJ0d3BvcHVwIj48dHI+PHRkIGNsYXNzPSJ0d3BvcHVwLWVudHJ5dGl0bGUiPkdyb3Vwczo8L3RkPjx0ZD51c2VyPGJyIC8+YnVyZWF1Y3JhdDxiciAvPmludGVyZmFjZS1hZG1pbjxiciAvPnN5c29wPGJyIC8+PC90ZD48L3RyPjwvdGFibGU+] (talk | contribs)
m (1 revision imported)
pc>Yuron
No edit summary
Line 1: Line 1:
{{#set: Priority=4 | Summary=Dividing memory into pages - standard-size, interchangeable blocks - makes memory management practical.}}<!--
{{#set: Priority=4 | Summary=Dividing memory into pages - standard-size, interchangeable blocks - makes memory management practical.}}<!--
-->{{#invoke:Dependencies|add|Virtual Memory,3|Memory Sizes,3}}
-->{{#invoke:Dependencies|add|Virtual Memory,3|Memory Sizes,3}}
A page is a division of a virtual memory system.  The whole address
A page is a division of a virtual memory system.  The whole address space is sliced into pages which – for implementation purposes – will each contain 2<sup>N</sup> locations.
space is sliced into pages which – for implementation purposes –
will each contain 2<sup>N</sup> locations.


What ‘N’ is may be debated; for the moment let us <em>assume</em>
What ‘N’ is may be debated; for the moment let us <em>assume</em> a value of 12, as this is typically <em>representative</em> of the sort of sizes used practically.
a value of 12, as this is typically <em>representative</em> of the sort of
sizes used practically.


This gives a page size of 4 KiB (“4 KB”) if we
This gives a page size of 4 KiB (“4 KB”) if we assume each <em>byte</em> has a separate address.  (Again this is normal in
assume each <em>byte</em> has a separate address.  (Again this is normal in
almost every modern system.)
almost every modern system.)


The page is an indivisible block.  The operating system will assign
The page is an indivisible block.  The operating system will assign memory to a process in pages: thus a program which has (say) 14 KiB of code will have four pages in which that code will be stored.
memory to a process in pages: thus a program which has (say)
14 KiB of code will have four pages in which that code will be
stored.
<blockquote>
<blockquote>
*3 pages x 4 KiB = 12 KiB: Insufficient.
*3 pages x 4 KiB = 12 KiB: Insufficient.
*4 pages x 4 KiB = 16 KiB: Minimum feasible for 14 KiB requirement.
*4 pages x 4 KiB = 16 KiB: Minimum feasible for 14 KiB requirement.
The choice of page size is such that there is not too much memory
The choice of page size is such that there is not too much memory ‘wasted’ when this occurs (so pages should be small) but
‘wasted’ when this occurs (so pages should be small) but
there are not too many separate pages to manage (so pages should be large). It’s all a compromise.
there are not too many separate pages to manage (so pages should be
large).
It’s all a compromise.
</blockquote>
</blockquote>
If we use this memory with a 32-bit address, the <em>least significant</em>
If we use this memory with a 32-bit address, the <em>least significant</em> 12 bits of the address will act as an offset (like an array index) into the page.  These bits are used because programs must (and data tends to) be at contiguous addresses.  There is are illustrations of this process in the [[Memory_Mapping|memory mapping]] articles.
12 bits of the address will act as an offset (like an array index)
into the page.  These bits are used because programs must (and data
tends to) be at contiguous addresses.  There is are illustrations of
this process in the [[Memory_Mapping|memory mapping]] articles.


Because pages are the same size, in a [[Virtual_Memory|virtual memory]]
Because pages are the same size, in a [[Virtual_Memory|virtual memory]] system they can be mapped arbitrarily and interchangeably.  This is called “[[paging]]” – or, sometimes “swapping”; there is an interactive illustration under
system they can be mapped arbitrarily and interchangeably.  This is
called “[[paging]]” – or, sometimes
“swapping”; there is an interactive illustration under
that article.
that article.


With the system described here there are still 20 address bits which
With the system described here there are still 20 address bits which select the page, thus 2<sup>20</sup> (~ “a million”) pages
select the page, thus 2<sup>20</sup> (~ “a million”) pages
to manage in the virtual space.
to manage in the virtual space.
----
----
Line 47: Line 28:


==== Different page sizes ====
==== Different page sizes ====
If you delve into specific implementations you may discover that a few
If you delve into specific implementations you may discover that a few discrete sizes of pages may be possible.  However these will always be 2<sup>N</sup> bytes long and so will ‘fit together’.
discrete sizes of pages may be possible.  However these will always be
2<sup>N</sup> bytes long and so will ‘fit together’.


If you want a commercial example, the [http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.subset.architecture.reference/index.html ARM Architecture Reference Manual]
If you want a commercial example, the [http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.subset.architecture.reference/index.html ARM Architecture Reference Manual] (Section B) is on line.
(Section B) is on line.
(You’ll need to register for the official download.)
(You’ll need to register for the official download.)


This allows a mixture of 1 MiB ‘sections’ with 64 KiB, 4
This allows a mixture of 1 MiB ‘sections’ with 64 KiB, 4 KiB and (formerly) 1 KiB pages … and maybe some newer variants. That’s probably as much as (or more than) you want to know.
KiB and (formerly) 1 KiB pages … and maybe some newer variants.
That’s probably as much as (or more than) you want to know.
----
----
 
{{BookChapter|9.3|360-371}}
{{PageGraph}}
{{PageGraph}}
{{Category|Virtual Memory}}
{{Category|Virtual Memory}}
{{Category|Memory}}
{{Category|Memory}}

Revision as of 14:54, 2 August 2019

Depends on Virtual MemoryMemory Sizes

A page is a division of a virtual memory system. The whole address space is sliced into pages which – for implementation purposes – will each contain 2N locations.

What ‘N’ is may be debated; for the moment let us assume a value of 12, as this is typically representative of the sort of sizes used practically.

This gives a page size of 4 KiB (“4 KB”) if we assume each byte has a separate address. (Again this is normal in almost every modern system.)

The page is an indivisible block. The operating system will assign memory to a process in pages: thus a program which has (say) 14 KiB of code will have four pages in which that code will be stored.

  • 3 pages x 4 KiB = 12 KiB: Insufficient.
  • 4 pages x 4 KiB = 16 KiB: Minimum feasible for 14 KiB requirement.

The choice of page size is such that there is not too much memory ‘wasted’ when this occurs (so pages should be small) but there are not too many separate pages to manage (so pages should be large). It’s all a compromise.

If we use this memory with a 32-bit address, the least significant 12 bits of the address will act as an offset (like an array index) into the page. These bits are used because programs must (and data tends to) be at contiguous addresses. There is are illustrations of this process in the memory mapping articles.

Because pages are the same size, in a virtual memory system they can be mapped arbitrarily and interchangeably. This is called “paging” – or, sometimes “swapping”; there is an interactive illustration under that article.

With the system described here there are still 20 address bits which select the page, thus 220 (~ “a million”) pages to manage in the virtual space.


Bonus bit: (don’t worry too much about this).

Different page sizes

If you delve into specific implementations you may discover that a few discrete sizes of pages may be possible. However these will always be 2N bytes long and so will ‘fit together’.

If you want a commercial example, the ARM Architecture Reference Manual (Section B) is on line. (You’ll need to register for the official download.)

This allows a mixture of 1 MiB ‘sections’ with 64 KiB, 4 KiB and (formerly) 1 KiB pages … and maybe some newer variants. That’s probably as much as (or more than) you want to know.


Also refer to: Operating System Concepts, 10th Edition: Chapter 9.3, pages 360-371