Skip to content

Conversation

@ValentaTomas
Copy link
Member

@ValentaTomas ValentaTomas commented Oct 27, 2025

This should be only a refactor now—I tried to minimize all changes.

The serving loop should be the same too.

The biggest problem I encountered is that there are seems to be performance limits of UFFD that we probably also can encounter in prod now. There are illustrated by the parallel missing and missing write tests (there is a TODO there).
I'm not sure how we can resolve these—from the debugging I did it seems we won't even reach our code and it gets stuck before.


Note

Refactors UFFD to an object-based userfaultfd type and adds a dedicated memory mapping module with tests, updating UFFD wiring and tests accordingly.

  • UFFD refactor:
    • Extracts UFFD logic into userfaultfd package with Userfaultfd type (Serve, Register, Close, internal copy/configure helpers).
    • Replaces procedural Serve in uffd with instance-based userfaultfd.Userfaultfd.Serve; updates uffd.Uffd to construct and manage handler via NewUserfaultfdFromFd.
    • Simplifies constants and flags, removes unused WP-related constants; adjusts pagefault address handling to uintptr.
  • Memory mapping:
    • Adds memory package with Region and Mapping (new GetOffset logic); deletes old mapping package and Firecracker-specific types.
    • Introduces comprehensive tests for mapping (mapping_test.go).
  • Tests updates:
    • Migrates UFFD tests to new userfaultfd API; centralizes missing request tracking via Userfaultfd.
  • Misc:
    • Minor renames and buffer size constants (regionMappingsSize), plumbing of fd-exit and logging through the new API.

Written by Cursor Bugbot for commit 30fbc35. This will update automatically on new commits. Configure here.

}

func TestParallelMissingWrite(t *testing.T) {
// TODO: At around 10k+ parallel operations the test often freezes.
Copy link
Member Author

@ValentaTomas ValentaTomas Oct 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as for the parallel missing.

@ValentaTomas ValentaTomas changed the base branch from main to uffd-tests October 30, 2025 02:19
@ValentaTomas ValentaTomas marked this pull request as draft November 1, 2025 00:12
@ValentaTomas ValentaTomas marked this pull request as ready for review November 4, 2025 00:27
cursor[bot]

This comment was marked as outdated.

Base automatically changed from uffd-tests to main November 4, 2025 00:30
cursor[bot]

This comment was marked as outdated.

Comment on lines +33 to +35
hostVirtAddr: 0x1500,
expectedOffset: 0x5500, // 0x5000 + (0x1500 - 0x1000)
expectedSize: 4096,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we're going to use hex, can we be consistent?

Suggested change
hostVirtAddr: 0x1500,
expectedOffset: 0x5500, // 0x5000 + (0x1500 - 0x1000)
expectedSize: 4096,
hostVirtAddr: 0x1500,
expectedOffset: 0x5500, // 0x5000 + (0x1500 - 0x1000)
expectedSize: 0x1000,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same for below

{
name: "address in gap between regions",
hostVirtAddr: 0x4000,
expectError: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we verify what the error was, and not just that there's an error and it's not nil?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, we don't return a specific error if the address cannot be resolved; the whole FC is essentially unrecoverable anyway.


var _ MemoryBackend = (*Uffd)(nil)

func New(memfile block.ReadonlyDevice, socketPath string, blockSize int64) (*Uffd, error) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we get some tests covering this struct?

Copy link
Member Author

@ValentaTomas ValentaTomas Nov 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theoretically, yes, but this whole interaction is FC-specific (essentially passing fd + their struct), so not sure if that is worth it.

@ValentaTomas
Copy link
Member Author

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Another round soon, please!

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@ValentaTomas ValentaTomas changed the base branch from main to cross-process-uffd-tests November 7, 2025 02:25
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.

3 participants