Skip to content

Eviction - #9

Open
SapphireHue wants to merge 52 commits into
mainfrom
eviction
Open

Eviction#9
SapphireHue wants to merge 52 commits into
mainfrom
eviction

Conversation

@SapphireHue

@SapphireHue SapphireHue commented Apr 25, 2026

Copy link
Copy Markdown
Collaborator

Provides the mechanism to safely evict a page.

  • Currently only applies to pages which are managed by the page cache (i.e. those that are file-backed)

Adds the physical memory map, a flat array of metadata for physical frames (0x800000 - 0x7FB7FFF). Each page's metadata contains a lock, a reverse mapping, and flags.
Each time a page managed by the page cache is mapped or unmapped, it's reverse mapping is updated.

Splits the TLB miss handler into a TLB miss handler (walks the page table and updates the TLB value if the page table value is satisfactory) and a page fault handler (traditional page fault handling because the PTE value is insufficient).

Performs dirty bit tracking on first write (instead of conservatively when mapped with write permissions)

Adds a function to perform synchronous TLB shootdown across all cores

On eviction:

  • The entry is removed from the page cache
  • The reverse mapping is used to invalidate all PTEs and shootdown TLB entries
  • The page is written back to disk if it is dirty
  • The cache entry is freed (decrementing the cached inode's refcount)
  • The frame is freed, releasing it back to the physical memory allocator

Tests have been added to ensure that the code is safe and correct.

SapphireHue and others added 9 commits April 17, 2026 01:02
- AI-generated
- Hopefully doesn't break anything :D
- Mostly AI generated
- Reviewed & edited by me though
- Initialization takes ~1-2 seconds per run instead of 40 :D

Co-authored-by: Brooks Bryant <brooks.bryant@icloud.com>
Comment thread kernel/physmem.c Outdated
SapphireHue and others added 11 commits April 25, 2026 18:48
- Do dirty bit tracking in the Page struct instead
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
- need to think about allll the race conditions. Yippee!
SapphireHue and others added 7 commits April 28, 2026 19:06
- This passes even without doing lock ordering, which makes sense, I guess

Co-authored-by: Copilot <copilot@github.com>
- Pulling from the PTE to the TLB must be "atomic" (can't have eviction happen)
- Revalidate PTE value before modifying
- when tearing down another thread, we should removeRef based on the pid of the thread being destructed, not based on the running thread
Locks must be acquired in order:
1. Page lock
2. INode lock
3. Page cache lock

Remaining:
- Accessing invalid frame indices sometimes? (Probably concurrency issues)
- God the output of the file is not what we want (but that's a problem of releasing the cache lock before acquiring the page lock during IO)
- The goal is to get lots of eviction As threads are writing, and for writes to be reasonably balanced between threads. That's not Really happening? But fuck it we ball
- The physmem bug still exists :(
- And the incoherence race condition is getting exposed super rarely
- spamming debug prints I guess
- In case: thread A finds a cache entry and blocks on the page, the cache entry is freed (eviction) by another thread, and then faulted back in by another thread (so it's an equivalent entry but at a different address), and then thread A wakes back up
- "maybe" is because I'm not 100% certain this is a bug
- for a page cache page, "PINNED" = it's still being read in, which means both that it's not evictable AND that the data isn't stable yet
- We kiiind of want the page a cache entry points to to be a promise, but we want to be able to free the cache entry without having to deal with waking up or waiting on the waiters, so for now we just use the flag
- Since IPI now sends to all cores, instead of excluding the one that sent it
@SapphireHue
SapphireHue marked this pull request as ready for review May 7, 2026 22:01
- Allows us to maintain a correct rounded tail size
- Previously, truncate tests were failing because changing the inode size had no effect if relevant pages were still in the cache
- Now, we remove pages from the cache when truncating
- Someone should definitely make sure nothing sketchy is happening...
- Enlarge text section and shrink data section
- Allows ext_delete to build correctly
- Future section overflows will error during build
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.

2 participants