Page 1 of 1

Page/Swap/RAM File Implementation

Posted: Tue Aug 23, 2022 7:08 pm
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 ?

Re: Page/Swap/RAM File Implementation

Posted: Mon Aug 29, 2022 3:35 pm
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.

Re: Page/Swap/RAM File Implementation

Posted: Mon Aug 29, 2022 6:00 pm
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")

Re: Page/Swap/RAM File Implementation

Posted: Mon Aug 29, 2022 7:23 pm
by devc1
Nice idea, I will implement it too