Skip to content

Implement constrained direct memory writes#25

Merged
fwsGonzo merged 1 commit intomasterfrom
constrained_direct_memory_writes
Mar 28, 2025
Merged

Implement constrained direct memory writes#25
fwsGonzo merged 1 commit intomasterfrom
constrained_direct_memory_writes

Conversation

@fwsGonzo
Copy link
Member

@fwsGonzo fwsGonzo commented Mar 28, 2025

After two days of hammering the keyboard and getting increasingly annoyed, I've finally made constrained working memory for main VM work. It turned out better than I thought because it has some nice properties. Here's a short explanation:

  • The main VM is turned entirely copy-on-write but importantly with no other pagetable changes. That is, every writable page is turned into read-only + cloneable. The equivalent of iterating the page table and toggling bits.
  • The main VM has a property called "direct main memory writes" enabled.
  • When a read-only page is being written to, a page fault happens that enters paging. Paging sees that it's a VM with direct memory writes, and just unlocks the page by making it writable again. No other change, making it very fast. It also counts the pages that are unlocked. And if the number of unlocked pages exceeds the set working memory, it throws an out of memory exception.

When the VM has been loaded, it is again made copy-on-write and any forks will see the pagetables in the same way as before (without this feature). So, bottom line is: Not a single extra page is used, but we can still constrain pages used.

@fwsGonzo fwsGonzo merged commit 0f0265d into master Mar 28, 2025
4 checks passed
@fwsGonzo fwsGonzo deleted the constrained_direct_memory_writes branch March 28, 2025 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant