Physical Memory Pools (a.k.a. PMPs) are a type of Dynamic Area introduced in RISC OS 5.23 that allow for full control over the logical to physical mapping of memory that is allocated to the PMP.
The key difference between a regular dynamic area and a PMP is that PMPs grant you the ability to alter the logical mapping of memory without affecting the content of the underlying physical pages – the pool of physical pages which constitutes the dynamic area is not affected by any changes which are made to the logical mapping of those pages. With a regular dynamic area, as soon as memory is removed from the logical mapping, the physical page and its content are lost to you. But with a PMP you can map pages in and out at will without them losing their content.
Because the logical address space of a RISC OS system is a limited resource, the ability to control the logical mapping of the physical pages within a PMP becomes a powerful tool for reducing the logical address space needed by some types of dynamic area. If you need to store a large amount of data in memory but only need to access a small amount of it at any one time, then you can create a PMP with a large physical size but only a small logical size, and use the logical area as a kind of window to peer into the physical pool beyond. For example, RAMFS makes use of this in order to allow the creation of RAM discs that are hundreds of megabytes in size, while only requiring a small amount (currently, 1MB) of logical address space in order to access the data. Another example is the free pool, which in previous versions of RISC OS used to have a logical mapping, but under PMP versions of RISC OS requires no logical mapping whatsoever, representing a mammoth saving of logical address space for systems with upwards of 1GB of RAM.
PMPs can have separate logical and physical sizes. The physical size is always measured in units of pages. Logical size may be measured in pages or bytes, depending on the specific API call. By specifying the physical size in units of pages this allows for greater compatibility with future systems that feature 4GB or more of RAM.
As with a regular dynamic area, the maximum logical size of a PMP is fixed at time of creation. However the maximum physical size is not fixed – you can increase or decrease it at will via OS_DynamicArea 23. This is important because PMPs incur additional memory overheads compared to regular dynamic areas – to keep track of which pages belong to the PMP the kernel needs to store an array which is N entries long, where N is the maximum physical size of the PMP. Currently each array entry is only 4 bytes, but these overheads can add up quickly if there are many large PMPs present in the system. Therefore it’s recommended that programs grow and shrink the physical size of their PMP as appropriate in order to help minimise the amount of memory that is lost to array entries which track unallocated physical pages.
The following terms are used to identify logical or physical pages associated with a PMP:
(address - DA_base_address) / page_size
. The highest valid logical page number for an area is (DA_max_logical_size - 1) / page_size
.OS_DynamicArea 21 is used to control the mapping of PMP page indices to physical page numbers – it allows you to add and remove physical pages from the PMP. OS_DynamicArea 22 is used to control the mapping of DA page numbers to PMP page indices – it allows you to control which page is mapped to any given logical address within the logical portion of the DA. OS_DynamicArea 22 will only allow you to specify PMP page indices which have a physical page associated with them, and OS_DynamicArea 21 will not allow you to free a physical page if it is currently mapped in.
Support for PMP DAs was introduced in RISC OS 5.23.