Page MenuHomeFreeBSD

Add support to demote and promote pages

Authored by andrew on Jun 27 2016, 5:15 PM.
Referenced Files
Unknown Object (File)
Sat, Sep 16, 12:56 AM
Unknown Object (File)
Sun, Sep 10, 9:01 PM
Unknown Object (File)
Sat, Sep 2, 3:58 AM
Unknown Object (File)
Tue, Aug 29, 2:14 AM
Unknown Object (File)
Sat, Aug 26, 11:26 AM
Unknown Object (File)
Jul 15 2023, 12:30 PM
Unknown Object (File)
Jul 8 2023, 6:34 PM
Unknown Object (File)
Jul 5 2023, 9:57 PM



We will promote a full set of level 3 pages to a single level 2 page
in pmap_enter.

We demote pages when changing attributes, or removing pages that have
been promoted. The former will happen if we are asked to map a page with
attributes different than what the DMAP page contains. In this case
we need to demote the DMAP page and set the new attribute. For the latter
we need to handle the reverse of the pmap_enter case to split the page
when needed.

Test Plan

Tested on a ThunderX while forcing all DMA mappings to be uncached as
this will call pmap_page_set_memattr and pmap_change_attr.

Diff Detail

rS FreeBSD src repository - subversion
Lint Passed
No Test Coverage
Build Status
Buildable 4675
Build 4729: arc lint + arc unit

Event Timeline

andrew retitled this revision from to Add initial support to change page attributes.
andrew updated this object.
andrew edited the test plan for this revision. (Show Details)
andrew added reviewers: arm64, kib.
andrew added a subscriber: emaste.

In pmap_demote_<foo>, you must temporary unmap relative large portion of DMAP.
How is ensured that this memory is not accessed by other threads on different CPUs.
You can umap vital kernel data (kernel stack, loaded modules code...) by this, no?


The given page can be mapped by multiple times, but attributes are changed only in DMAP. ARM doesn't allows multiple mapping with different page attributes.


Why idcache ?


Isn't tmpva just unmapped?


New entries are not synced.


This invalidate is superfluous, unmapped TLB entries cannot be cached.


How would this happen? My understanding is the VM code will only call this with unmapped pages.


No, it is the virtual address we are currently changing. It will have been mapped in pmap_demote_l2.

Update to handle both promotion and demotion

andrew retitled this revision from Add initial support to change page attributes to Add support to demote and promote pages.Aug 1 2016, 6:26 PM
andrew updated this object.
andrew updated this object.

On amd64/i386, the same knob is called vm.pmap.pg_ps_enabled. Not sure if it is required to have consistent name there, but at least this is something to consider.


I remember that I asked the same question when reviewing the similar arm changes (break-before-make).

Could transient page fault occur recursively ? In other words, could you get the fault while the thread owns pmap lock ? E.g., might it happen that interrupt handler accesses the DMAP mapping which is being promoted or demoted by the same CPU and interrupted ?


It looked like this was named after the flag in the pagetables. On armv6 is seems to be vm.pmap.sp_enabled. I don't have an opinion on the correct name.


I can change the critical section to a spin lock to disable interrupts. I don't expect any other exception to be triggered within the break-before-make section, and any that do would indicate a bug in the break-before-make section.

andrew updated this object.

Use spinlocks to disable interrupts in the break-before-make section

spinlock_enter() is not a general-purpose KPI to disable interrupts. MD code uses machine-specific primitives to disable interrupts.

Did you measured whether the promotions and demotions with your patch occur at all ? As I understand, you do not operate on userspace mappings, de-facto limiting the pmap to kernel mappings. x86s have basic counters for promotions and demotions events available always.

andrew edited edge metadata.

Use intr_disable to disable interrupts.
Stop promoting unmanaged pages, until all needed demotions are ready

Demote when entering a new va with pmap_enter.
Add pmap_demote_l2_locked. It doesn't lock, but will in later revisions.

I have seen promotions & demotions, but as part of a larger patch that still needs testing. I'd like to get this in so we can allocate uncached memory, e.g. for DMA.

kib edited edge metadata.
This revision is now accepted and ready to land.Aug 11 2016, 4:48 PM
This revision was automatically updated to reflect the committed changes.