Page/Swap/RAM File Implementation

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
devc1
Member
Member
Posts: 439
Joined: Fri Feb 11, 2022 4:55 am
Location: behind the keyboard

Page/Swap/RAM File Implementation

Post by devc1 »

As far as I know, the page file is used to extend the RAM by temporarely storing unused RAM to the disk. Marking each page as paged and loading it when a page fault occurs.

- How systems choose pages to be paged
- RAM extension using a Paging File doesn't seem to be safe and in a (brute force) case it will slow/freeze/panic the operating system.
- Memory Management Question : the FreePool() or free() function must search through a list of memory/heap segments, a (page table scheme) will be much faster but so ineffective.

- Unused memory is selected by going through the page tables and checking the accessed bit and the dirty bit to write new content to the page file
- Do you recommand loading page by page or loading the entire heap from the page file ?
Octocontrabass
Member
Member
Posts: 5563
Joined: Mon Mar 25, 2013 7:01 pm

Re: Page/Swap/RAM File Implementation

Post by Octocontrabass »

devc1 wrote:- How systems choose pages to be paged
The OS tracks how recently each page was accessed. Pages that haven't been accessed recently will be moved to the disk if the OS runs out of free RAM.
devc1 wrote:- RAM extension using a Paging File doesn't seem to be safe and in a (brute force) case it will slow/freeze/panic the operating system.
Out-of-memory conditions can cause a freeze or panic even without paging to disk. You're right about the disk being slower than RAM, though.
devc1 wrote:- Memory Management Question : the FreePool() or free() function must search through a list of memory/heap segments, a (page table scheme) will be much faster but so ineffective.
That's not a question.
devc1 wrote:- Unused memory is selected by going through the page tables and checking the accessed bit and the dirty bit to write new content to the page file
Correct. On architectures that don't provide these bits, you can emulate them by removing read or write permissions and waiting for page faults.
devc1 wrote:- Do you recommand loading page by page or loading the entire heap from the page file ?
You know you can swap any page to disk, not just pages that are part of the heap, right? Anyway, it's a trade: loading many pages means fewer disk accesses if the program accesses all of the pages you load, but it means extra time spent waiting for the disk if the program doesn't access the extra pages that you load.
sounds
Member
Member
Posts: 112
Joined: Sat Feb 04, 2012 5:03 pm

Re: Page/Swap/RAM File Implementation

Post by sounds »

Linux, Windows and macOS also compress memory. As in, "swap" it to a different part of RAM and compress it.

https://docs.kernel.org/admin-guide/blockdev/zram.html

https://superuser.com/questions/1383484 ... windows-10

https://support.apple.com/guide/activit ... tr1004/mac (search for "compressed memory")
devc1
Member
Member
Posts: 439
Joined: Fri Feb 11, 2022 4:55 am
Location: behind the keyboard

Re: Page/Swap/RAM File Implementation

Post by devc1 »

Nice idea, I will implement it too
Post Reply