Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
289 commits
Select commit Hold shift + click to select a range
c5e55e3
Clarify comment
ValentaTomas Oct 5, 2025
b04e552
Remove yet non-relevant diagram
ValentaTomas Oct 5, 2025
9607180
Remove comment
ValentaTomas Oct 5, 2025
3cf3bec
Remove write protection field
ValentaTomas Oct 5, 2025
ac9bfdf
Add explicit mmap cleanup
ValentaTomas Oct 6, 2025
3ab7848
Merge branch 'main' into uffd-extract
ValentaTomas Oct 6, 2025
69954c5
Improve test names
ValentaTomas Oct 6, 2025
4ce39ab
Fix test error message
ValentaTomas Oct 6, 2025
e8b9330
Cleanup tests
ValentaTomas Oct 6, 2025
e366753
Merge branch 'main' into uffd-extract
ValentaTomas Oct 6, 2025
5ef4373
Fix lint error
ValentaTomas Oct 6, 2025
bb951ba
Add uffd write protect constants
ValentaTomas Oct 5, 2025
8906575
Add UFFD write protection event diagram
ValentaTomas Oct 5, 2025
d89b81f
Add userfaultfd write protection methods
ValentaTomas Oct 5, 2025
f2a012a
Add tests todo
ValentaTomas Oct 5, 2025
e522612
[WIP] Add dirty tracking via WP
ValentaTomas Oct 6, 2025
64e2b13
Clarify WP flow
ValentaTomas Oct 7, 2025
bd8988e
[WIP] Add WP to the serve loop
ValentaTomas Oct 7, 2025
0dadb58
Wrap uffd fd in a struct with corresponding methods; Move the low lev…
ValentaTomas Aug 7, 2025
34ccfc5
Unify receiver name
ValentaTomas Aug 7, 2025
7312bca
[WIP] Add uffd tests
ValentaTomas Aug 7, 2025
3c75576
Add disabled wp
ValentaTomas Aug 7, 2025
b67f0f2
[WIP] WP
ValentaTomas Aug 8, 2025
9f1708c
[WIP] Check multicopy
ValentaTomas Aug 10, 2025
b07e13d
[WIP] Multicopy
ValentaTomas Aug 12, 2025
ff23f18
Remove experiments
ValentaTomas Aug 19, 2025
389862e
Add the page alignment check (only in method)
ValentaTomas Aug 19, 2025
a8ec1bf
Remove commented out part
ValentaTomas Aug 19, 2025
5632f63
Remove unused return field
ValentaTomas Aug 19, 2025
ef33099
Cleanup
ValentaTomas Aug 19, 2025
5384bec
Remove WP parts
ValentaTomas Aug 19, 2025
f26cc5c
Cleanup
ValentaTomas Aug 19, 2025
47e14b0
Fix compile errors
ValentaTomas Oct 3, 2025
7ba06e7
Cleanup
ValentaTomas Oct 4, 2025
e91945f
Simplify offset check
ValentaTomas Oct 4, 2025
d4c2ea0
Clarify comment
ValentaTomas Oct 4, 2025
091607e
Add test constant
ValentaTomas Oct 4, 2025
7ae5f70
Fix incorrect log
ValentaTomas Oct 4, 2025
f9f95c5
Fix format
ValentaTomas Oct 4, 2025
708d54b
Remove conversion
ValentaTomas Oct 4, 2025
2aa9449
Make method public
ValentaTomas Oct 4, 2025
dc7dc60
Add command context
ValentaTomas Oct 4, 2025
6331bd2
Fix error formatting
ValentaTomas Oct 4, 2025
97ee756
Fix error formatting
ValentaTomas Oct 4, 2025
03b0c46
Improve error comparison
ValentaTomas Oct 4, 2025
a331214
Fix error formatting
ValentaTomas Oct 4, 2025
6855c56
Change process exit
ValentaTomas Oct 4, 2025
359c17d
Trigger build
ValentaTomas Oct 4, 2025
835a32d
Enable unpriviledged uffd mode in GH PR tests
ValentaTomas Oct 4, 2025
76c3bf3
Fix uffd unpriviledged enable
ValentaTomas Oct 4, 2025
0ba2a14
Use 4k pages in uffd cross process test
ValentaTomas Oct 4, 2025
52d2fc7
Add access checks to tests
ValentaTomas Oct 5, 2025
f092687
Cleanup
ValentaTomas Oct 5, 2025
3f7216a
Remove unused constants for now
ValentaTomas Oct 5, 2025
7fb669e
Fix lint issue
ValentaTomas Oct 5, 2025
052b09f
Clarify naming
ValentaTomas Oct 5, 2025
1066947
Clarify comment
ValentaTomas Oct 5, 2025
d06985c
Remove yet non-relevant diagram
ValentaTomas Oct 5, 2025
179ba74
Remove comment
ValentaTomas Oct 5, 2025
bacedce
Remove write protection field
ValentaTomas Oct 5, 2025
5d4c576
Add explicit mmap cleanup
ValentaTomas Oct 6, 2025
fe1f562
Improve test names
ValentaTomas Oct 6, 2025
70015bd
Fix test error message
ValentaTomas Oct 6, 2025
6920876
Cleanup tests
ValentaTomas Oct 6, 2025
cb5cfdb
Fix lint error
ValentaTomas Oct 6, 2025
ac77fe5
Put back offset log on uffd panic
ValentaTomas Oct 7, 2025
c11e5ef
Fix lint errors
ValentaTomas Oct 8, 2025
dcea5f1
Merge branch 'main' into uffd-extract
djeebus Oct 10, 2025
43f7daa
Merge branch 'main' into uffd-extract
ValentaTomas Oct 11, 2025
6e6e073
Fix diagram flags
ValentaTomas Oct 13, 2025
1ec8b01
Add uffd write handling
ValentaTomas Oct 14, 2025
f0247a0
Fix test errors
ValentaTomas Oct 14, 2025
131b801
Merge branch 'uffd-extract' into use-uffd-wp-to-only-save-dirty-pages…
ValentaTomas Oct 14, 2025
c283d0c
Make offsetmap thread safe
ValentaTomas Oct 14, 2025
7e78473
Fix merge problems; [WIP] Add triggerable uffd copy
ValentaTomas Oct 14, 2025
bc50b15
Fix refactor bug
ValentaTomas Oct 16, 2025
96f546c
Fix compile error
ValentaTomas Oct 16, 2025
edb1c4c
[WIP] Refactor memory access
ValentaTomas Oct 17, 2025
ec4421f
Fix test after refactor
ValentaTomas Oct 17, 2025
f916358
Cleanup mapping
ValentaTomas Oct 17, 2025
6838b66
Improve naming
ValentaTomas Oct 17, 2025
0d4dc64
[WIP] Cleanup
ValentaTomas Oct 18, 2025
65cf118
Fix test bugs
ValentaTomas Oct 18, 2025
0505ab3
Add testing case
ValentaTomas Oct 18, 2025
a388c74
Cleanup
ValentaTomas Oct 18, 2025
4f89a59
[WIP] Add overlay layer
ValentaTomas Oct 20, 2025
2051bd6
Configure mise
ValentaTomas Oct 20, 2025
8fc2164
Exclude mise tools from git
ValentaTomas Oct 20, 2025
8995e6d
Extend tracker
ValentaTomas Oct 20, 2025
7ac927b
[WIP] Add masked overlay
ValentaTomas Oct 20, 2025
64be117
[WIP] Update masked overlay
ValentaTomas Oct 20, 2025
20c0766
Remove files that will be added later
ValentaTomas Oct 20, 2025
ae57cb4
Cleanup
ValentaTomas Oct 20, 2025
9783690
Remove files that will be added later
ValentaTomas Oct 20, 2025
aea1db4
Remove unnecessary change
ValentaTomas Oct 20, 2025
d9db61a
Cleanup
ValentaTomas Oct 20, 2025
12911de
Remove files that will be added later
ValentaTomas Oct 20, 2025
3b9249c
Add mapping tests
ValentaTomas Oct 20, 2025
06a82ba
Add invalid event log
ValentaTomas Oct 20, 2025
446c935
Remove files that will be added later
ValentaTomas Oct 20, 2025
1bd8700
Remove methods that will be added later
ValentaTomas Oct 20, 2025
345b335
Merge branch 'main' into refactor-uffd-add-wp
ValentaTomas Oct 20, 2025
51ccb5e
Minimize changes
ValentaTomas Oct 20, 2025
bc3e626
Add settle counter tests
ValentaTomas Oct 20, 2025
ae02a32
Minimize changes
ValentaTomas Oct 20, 2025
38e57f7
Cleanup
ValentaTomas Oct 20, 2025
2055343
Fix lint issues
ValentaTomas Oct 20, 2025
4d44340
Revert noop memory change
ValentaTomas Oct 21, 2025
71103ec
Fix formatting
ValentaTomas Oct 21, 2025
7ccc6fb
Add fc snapshot via proc mem
ValentaTomas Oct 21, 2025
4f663ce
Fix lint
ValentaTomas Oct 21, 2025
c7db6b3
Merge branch 'main' into refactor-uffd-add-wp
ValentaTomas Oct 21, 2025
eb9bcfa
Merge branch 'refactor-uffd-add-wp' into proc-mem-access
ValentaTomas Oct 21, 2025
98dfa4f
Fix uninitialized handler
ValentaTomas Oct 21, 2025
b5a632f
Fix lint errors
ValentaTomas Oct 21, 2025
8614b7b
Test disabling dedup
ValentaTomas Oct 21, 2025
031b7c9
Synchronize test
ValentaTomas Oct 21, 2025
83566b0
Add wp dedup
ValentaTomas Oct 21, 2025
a716af2
Test removing only wp dedup
ValentaTomas Oct 21, 2025
7c3cb44
Cleanup
ValentaTomas Oct 21, 2025
41908a0
Fix linter errors
ValentaTomas Oct 21, 2025
2fa17bc
Clarify uffd behavior
ValentaTomas Oct 21, 2025
0237c08
Add tests for parallel uffd; [WIP] testing non-ready uffd
ValentaTomas Oct 22, 2025
23836ca
[WIP] Add parallel test
ValentaTomas Oct 22, 2025
de1219d
Fix settle counter test
ValentaTomas Oct 23, 2025
8018841
Cleanup
ValentaTomas Oct 24, 2025
4b0ce69
Minimize changes
ValentaTomas Oct 27, 2025
32fdc01
Minimize changes
ValentaTomas Oct 27, 2025
db1543a
Minimize changes
ValentaTomas Oct 27, 2025
57c4f53
Minimize changes
ValentaTomas Oct 27, 2025
450f278
Merge branch 'main' into uffd-refactor
ValentaTomas Oct 27, 2025
2150035
Fix fmt
ValentaTomas Oct 27, 2025
29dbcd3
Tweak tests
ValentaTomas Oct 27, 2025
7ed0a49
Fix lint
ValentaTomas Oct 27, 2025
680dcf5
Minimize changes
ValentaTomas Oct 27, 2025
6bdfaa6
Remove log file
ValentaTomas Oct 27, 2025
81238c0
[WIP] Add tests to current implementation
ValentaTomas Oct 29, 2025
5b60d98
Refactor tracking; Add unregister on pause
ValentaTomas Nov 3, 2025
087e05b
Fix lint errors
ValentaTomas Nov 3, 2025
007420d
Cleanup
ValentaTomas Nov 3, 2025
169a666
Fix test race
ValentaTomas Nov 3, 2025
81fe1c7
Merge branch 'main' into uffd-tests
ValentaTomas Nov 3, 2025
20f7757
Fix test operation
ValentaTomas Nov 3, 2025
e2b11e6
Cleanup tests
ValentaTomas Nov 3, 2025
bb5d630
Merge branch 'uffd-tests' into uffd-refactor
ValentaTomas Nov 4, 2025
1bc2b21
Merge
ValentaTomas Nov 4, 2025
ed4516f
Fix map passing
ValentaTomas Nov 4, 2025
4bf8fbd
Merge branch 'uffd-refactor' into add-tracker
ValentaTomas Nov 4, 2025
6c46c07
Fix serve
ValentaTomas Nov 4, 2025
d08a2f9
Put back eagain increase
ValentaTomas Nov 4, 2025
026471d
Remove log
ValentaTomas Nov 4, 2025
c1f8966
Remove unused var
ValentaTomas Nov 4, 2025
1789c88
Merge branch 'main' into uffd-refactor
ValentaTomas Nov 4, 2025
be8c768
Merge
ValentaTomas Nov 4, 2025
30fbc35
Fix map passing
ValentaTomas Nov 4, 2025
1ff8982
Merge branch 'uffd-refactor' into add-tracker
ValentaTomas Nov 4, 2025
116062b
Cleanup
ValentaTomas Nov 4, 2025
bdc15de
Merge branch 'main' into uffd-refactor
ValentaTomas Nov 7, 2025
d6dbdd5
Merge branch 'main' into uffd-refactor
ValentaTomas Nov 7, 2025
e33692c
Merge
ValentaTomas Nov 7, 2025
f04dcfa
Fix tests
ValentaTomas Nov 7, 2025
73be91e
Cleanup
ValentaTomas Nov 7, 2025
888bc66
Cleanup
ValentaTomas Nov 7, 2025
c505ed7
Cleanup
ValentaTomas Nov 7, 2025
9ec00dd
Merge branch 'uffd-refactor' into add-tracker
ValentaTomas Nov 7, 2025
21ff568
Cleanup
ValentaTomas Nov 7, 2025
e80a760
Remove unused sync.Map function from cross_process_helpers_test.go
ValentaTomas Nov 7, 2025
fe4f0a0
Refactor constant formatting in userfaultfd fd.go for improved readab…
ValentaTomas Nov 7, 2025
0782fc4
Refactor Dirty method in Userfaultfd to accept context and update rel…
ValentaTomas Nov 7, 2025
e2b4ea4
Enhance SettleCounter functionality by improving context handling in …
ValentaTomas Nov 7, 2025
9c6c60f
Refactor Wait method in SettleCounter to improve atomic checks and re…
ValentaTomas Nov 7, 2025
40e4d5f
Refactor Dirty method in Userfaultfd to remove context parameter and …
ValentaTomas Nov 8, 2025
642bf68
Refactor Pause method in Sandbox to improve error handling by reorder…
ValentaTomas Nov 8, 2025
b225692
Add Disable and update comments in Userfaultfd for improved clarity o…
ValentaTomas Nov 8, 2025
6a49d5a
Refactor Userfaultfd to replace settle struct with sync.RWMutex for i…
ValentaTomas Nov 8, 2025
520574f
Refactor Tracker's Add method to remove return value and simplify log…
ValentaTomas Nov 8, 2025
df33f90
Add write protection handling in Userfaultfd and enhance memory regio…
ValentaTomas Nov 8, 2025
4fc3aa2
[WIP] Add WP tests
ValentaTomas Nov 8, 2025
b55be74
Refactor Userfaultfd methods to use uintptr for size parameters and e…
ValentaTomas Nov 8, 2025
121c00b
Use constructor
ValentaTomas Nov 10, 2025
05fb2ca
Refactor slice
ValentaTomas Nov 10, 2025
896d177
Cleanup comments
ValentaTomas Nov 10, 2025
320b26c
Add comments
ValentaTomas Nov 10, 2025
e630223
Improve tests
ValentaTomas Nov 10, 2025
5897b18
Improve tracker tests
ValentaTomas Nov 10, 2025
cdfb109
Cleanup
ValentaTomas Nov 10, 2025
4429aaf
Tweak the lock
ValentaTomas Nov 10, 2025
070ddb6
Merge branch 'main' into add-tracker
ValentaTomas Nov 10, 2025
c43a4e0
Merge branch 'add-tracker' into refactor-uffd-add-wp
ValentaTomas Nov 11, 2025
5899e59
Refactor newUffdioWriteProtect to use newUffdioRange constructor for …
ValentaTomas Nov 11, 2025
febd7e4
Update comments in userfaultfd.go for clarity on memory handling and …
ValentaTomas Nov 11, 2025
050b187
Rename handleWriteProtection to handleWriteProtected for consistency …
ValentaTomas Nov 11, 2025
b7b5329
Add explicit dirty reset
ValentaTomas Nov 11, 2025
2ea1261
Cleanup
ValentaTomas Nov 11, 2025
4f13b7c
Merge branch 'add-tracker' into refactor-uffd-add-wp
ValentaTomas Nov 11, 2025
d282652
WIP: Add tests
ValentaTomas Nov 11, 2025
b6a0c3a
Merge branch 'main' into add-tracker
ValentaTomas Nov 11, 2025
41da606
Refactor Userfaultfd to register memory regions with write protection…
ValentaTomas Nov 11, 2025
b5ffe46
Update memory mapping tests to use uintptr for expected size and repl…
ValentaTomas Nov 11, 2025
c897737
Merge branch 'refactor-uffd-add-wp' into proc-mem-access
ValentaTomas Nov 11, 2025
4226213
Add helpers
ValentaTomas Nov 11, 2025
45029a1
Refactor error handling in memory mapping: Introduce OffsetNotFoundEr…
ValentaTomas Nov 11, 2025
d409985
Refactor memory mapping: Rename variable 's' to 'remainingSize' for i…
ValentaTomas Nov 11, 2025
7da216e
Remove outdated comments in uffd.go regarding the Disable method and …
ValentaTomas Nov 11, 2025
c9127db
Add tests for various read/write operations in userfaultfd, including…
ValentaTomas Nov 12, 2025
7e6cd7f
[WIP] Refactor tests to allow testing locking
ValentaTomas Nov 12, 2025
2f3cd2d
Add uffd event handler tests
ValentaTomas Nov 12, 2025
e9d6311
Fix event testing
ValentaTomas Nov 12, 2025
185b242
Rename channel in TestUffdSettleRequests to better reflect its purpos…
ValentaTomas Nov 12, 2025
a5d81f7
Improve tests
ValentaTomas Nov 12, 2025
e5e5666
Merge branch 'add-tracker' into refactor-uffd-add-wp
ValentaTomas Nov 12, 2025
6258ce4
Merge branch 'refactor-uffd-add-wp' into proc-mem-access
ValentaTomas Nov 12, 2025
40029a2
Fix incorrect test label
ValentaTomas Nov 12, 2025
90259f8
Improve comments
ValentaTomas Nov 13, 2025
13bf3cc
Merge branch 'refactor-uffd-add-wp' into proc-mem-access
ValentaTomas Nov 13, 2025
9f069df
Add MemoryNotFaultedError type and related tests; remove obsolete mem…
ValentaTomas Nov 13, 2025
9705772
Enhance error handling in NewUserfaultfdFromFd by including the origi…
ValentaTomas Nov 13, 2025
252b8f0
Merge branch 'refactor-uffd-add-wp' into proc-mem-access
ValentaTomas Nov 13, 2025
8d5195b
Clarify comment
ValentaTomas Nov 13, 2025
3de2466
Merge branch 'refactor-uffd-add-wp' into proc-mem-access
ValentaTomas Nov 13, 2025
d94e0be
Refactor userfaultfd_memory_view_test to improve read assertions and …
ValentaTomas Nov 13, 2025
518d5da
Update comment to clarify that passing 0 as the mode removes write pr…
ValentaTomas Nov 13, 2025
de60520
Cleanup
ValentaTomas Nov 13, 2025
97d6267
Fix host mapping
ValentaTomas Nov 13, 2025
15ffaef
Add tests
ValentaTomas Nov 13, 2025
62df6c5
Improve tests
ValentaTomas Nov 14, 2025
a5a38b6
Fix diff test order
ValentaTomas Nov 14, 2025
7901cbb
Improve tests
ValentaTomas Nov 14, 2025
176f283
Improve tests
ValentaTomas Nov 14, 2025
09a5315
Update assertions in view tests to use pagesize and improve error rep…
ValentaTomas Nov 14, 2025
e5504c5
Fix tests
ValentaTomas Nov 14, 2025
7d148a0
Merge branch 'refactor-uffd-add-wp' into proc-mem-access
ValentaTomas Nov 14, 2025
b11d70b
Merge branch 'main' into refactor-uffd-add-wp
ValentaTomas Dec 2, 2025
734a9e2
Fix merge bugs
ValentaTomas Dec 2, 2025
3fdd24a
Merge branch 'refactor-uffd-add-wp' into proc-mem-access
ValentaTomas Dec 2, 2025
f00ce48
Merge branch 'main' into add-tracker
ValentaTomas Dec 3, 2025
16eaf89
Merge branch 'main' into add-tracker
ValentaTomas Dec 3, 2025
0f2ad5c
Add comment
ValentaTomas Dec 3, 2025
8dc51d0
Merge branch 'add-tracker' of https://github.com/e2b-dev/infra into a…
ValentaTomas Dec 3, 2025
770c3a3
Merge branch 'main' into refactor-uffd-add-wp
ValentaTomas Dec 3, 2025
baa5ec3
Merge branch 'add-tracker' into refactor-uffd-add-wp
ValentaTomas Dec 3, 2025
137d8bf
WIP
ValentaTomas Dec 5, 2025
b8c3e60
Merge branch 'refactor-uffd-add-wp' into proc-mem-access
ValentaTomas Dec 5, 2025
be2c9e3
Merge branch 'proc-mem-access' into proc-only
ValentaTomas Dec 5, 2025
2e95a19
Merge
ValentaTomas Dec 5, 2025
55df11d
Improve err return
ValentaTomas Dec 5, 2025
94266b3
Incorporate custom fc changes
ValentaTomas Dec 6, 2025
1e048cb
Remove unused parts
ValentaTomas Dec 6, 2025
3e04c57
Cleanup
ValentaTomas Dec 6, 2025
8d94828
Fix missing hook
ValentaTomas Dec 6, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .github/actions/start-services/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ runs:
STORAGE_PROVIDER: "Local"
ENVIRONMENT: "local"
OTEL_COLLECTOR_GRPC_ENDPOINT: "localhost:4317"
MAX_PARALLEL_MEMFILE_SNAPSHOTTING: "2"
SHARED_CHUNK_CACHE_PATH: "./.e2b-chunk-cache"
EDGE_TOKEN: "abdcdefghijklmnop"
run: |
Expand Down
2 changes: 1 addition & 1 deletion packages/api/internal/cfg/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const (
DefaultKernelVersion = "vmlinux-6.1.158"
// The Firecracker version the last tag + the short SHA (so we can build our dev previews)
// TODO: The short tag here has only 7 characters — the one from our build pipeline will likely have exactly 8 so this will break.
DefaultFirecrackerVersion = "v1.12.1_d990331"
DefaultFirecrackerVersion = "v1.12.1_g8769de7cf"
)

type Config struct {
Expand Down
1 change: 0 additions & 1 deletion packages/orchestrator/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ run-debug:
GCP_DOCKER_REPOSITORY_NAME=$(GCP_DOCKER_REPOSITORY_NAME) \
GOOGLE_SERVICE_ACCOUNT_BASE64=$(GOOGLE_SERVICE_ACCOUNT_BASE64) \
OTEL_COLLECTOR_GRPC_ENDPOINT=$(OTEL_COLLECTOR_GRPC_ENDPOINT) \
MAX_PARALLEL_MEMFILE_SNAPSHOTTING=$(MAX_PARALLEL_MEMFILE_SNAPSHOTTING) \
./bin/orchestrator

define setup_local_env
Expand Down
21 changes: 7 additions & 14 deletions packages/orchestrator/internal/sandbox/diffcreator.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,11 @@ package sandbox
import (
"context"
"errors"
"fmt"
"io"
"os"

"github.com/bits-and-blooms/bitset"

"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/rootfs"
"github.com/e2b-dev/infra/packages/shared/pkg/storage"
"github.com/e2b-dev/infra/packages/shared/pkg/storage/header"
)

Expand All @@ -28,29 +25,25 @@ func (r *RootfsDiffCreator) process(ctx context.Context, out io.Writer) (*header
}

type MemoryDiffCreator struct {
memfile *storage.TemporaryMemfile
memory io.ReaderAt
dirtyPages *bitset.BitSet
blockSize int64
doneHook func(context.Context) error
}

func (r *MemoryDiffCreator) process(ctx context.Context, out io.Writer) (h *header.DiffMetadata, e error) {
defer func() {
err := r.doneHook(ctx)
if err != nil {
e = errors.Join(e, err)
if r.doneHook != nil {
err := r.doneHook(ctx)
if err != nil {
e = errors.Join(e, err)
}
}
}()

memfileSource, err := os.Open(r.memfile.Path())
if err != nil {
return nil, fmt.Errorf("failed to open memfile: %w", err)
}
defer memfileSource.Close()

return header.WriteDiffWithTrace(
ctx,
memfileSource,
r.memory,
r.blockSize,
r.dirtyPages,
out,
Expand Down
16 changes: 14 additions & 2 deletions packages/orchestrator/internal/sandbox/fc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,13 +126,11 @@ func (c *apiClient) pauseVM(ctx context.Context) error {
func (c *apiClient) createSnapshot(
ctx context.Context,
snapfilePath string,
memfilePath string,
) error {
snapshotConfig := operations.CreateSnapshotParams{
Context: ctx,
Body: &models.SnapshotCreateParams{
SnapshotType: models.SnapshotCreateParamsSnapshotTypeFull,
MemFilePath: &memfilePath,
SnapshotPath: &snapfilePath,
},
}
Expand Down Expand Up @@ -301,3 +299,17 @@ func (c *apiClient) startVM(ctx context.Context) error {

return nil
}

// vmInfo retrieves general information about an instance from the Firecracker API.
func (c *apiClient) instanceInfo(ctx context.Context) (*models.InstanceInfo, error) {
req := operations.DescribeInstanceParams{
Context: ctx,
}

resp, err := c.client.Operations.DescribeInstance(&req)
if err != nil {
return nil, fmt.Errorf("error retrieving vm info: %w", err)
}

return resp.Payload, nil
}
32 changes: 32 additions & 0 deletions packages/orchestrator/internal/sandbox/fc/memory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package fc

import (
"context"
"fmt"

"github.com/e2b-dev/infra/packages/orchestrator/internal/sandbox/uffd/memory"
)

func (p *Process) Memory(ctx context.Context) (*memory.View, error) {
pid, err := p.Pid()
if err != nil {
return nil, fmt.Errorf("failed to get process pid: %w", err)
}

info, err := p.client.instanceInfo(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get instance info: %w", err)
}

mapping, err := memory.NewMappingFromFCInfo(info.MemoryRegions)
if err != nil {
return nil, fmt.Errorf("failed to create memory mapping: %w", err)
}

view, err := memory.NewView(pid, mapping)
if err != nil {
return nil, fmt.Errorf("failed to create memory view: %w", err)
}

return view, nil
}
4 changes: 2 additions & 2 deletions packages/orchestrator/internal/sandbox/fc/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -487,9 +487,9 @@ func (p *Process) Pause(ctx context.Context) error {
}

// CreateSnapshot VM needs to be paused before creating a snapshot.
func (p *Process) CreateSnapshot(ctx context.Context, snapfilePath string, memfilePath string) error {
func (p *Process) CreateSnapshot(ctx context.Context, snapfilePath string) error {
ctx, childSpan := tracer.Start(ctx, "create-snapshot-fc")
defer childSpan.End()

return p.client.createSnapshot(ctx, snapfilePath, memfilePath)
return p.client.createSnapshot(ctx, snapfilePath)
}
67 changes: 16 additions & 51 deletions packages/orchestrator/internal/sandbox/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -673,10 +673,6 @@ func (s *Sandbox) Shutdown(ctx context.Context) error {
return fmt.Errorf("failed to pause VM: %w", err)
}

if _, err := s.memory.Disable(ctx); err != nil {
return fmt.Errorf("failed to disable uffd: %w", err)
}

// This is required because the FC API doesn't support passing /dev/null
tf, err := storage.TemplateFiles{
BuildID: uuid.New().String(),
Expand All @@ -688,32 +684,17 @@ func (s *Sandbox) Shutdown(ctx context.Context) error {
}
defer tf.Close()

// The snapfile is required only because the FC API doesn't support passing /dev/null
snapfile := template.NewLocalFileLink(tf.CacheSnapfilePath())
defer snapfile.Close()

// The memfile is required only because the FC API doesn't support passing /dev/null
memfile, err := storage.AcquireTmpMemfile(ctx, s.config, tf.BuildID)
if err != nil {
return fmt.Errorf("failed to acquire memfile snapshot: %w", err)
}
defer memfile.Close()

err = s.process.CreateSnapshot(
ctx,
snapfile.Path(),
memfile.Path(),
)
if err != nil {
return fmt.Errorf("error creating snapshot: %w", err)
}

// Close the memfile right after the snapshot to release the lock.
err = memfile.Close()
if err != nil {
return fmt.Errorf("error closing memfile: %w", err)
}

// This should properly flush rootfs to the underlying device.
err = s.Close(ctx)
if err != nil {
Expand Down Expand Up @@ -753,41 +734,16 @@ func (s *Sandbox) Pause(
// Stop the health check before pausing the VM
s.Checks.Stop()

if err := s.process.Pause(ctx); err != nil {
return nil, fmt.Errorf("failed to pause VM: %w", err)
}

// This disables the uffd and returns the dirty pages.
// With FC async io engine, there can be some further writes to the memory during the actual create snapshot process,
// but as we are still including even read pages as dirty so this should not introduce more bugs right now.
dirty, err := s.memory.Disable(ctx)
err = s.process.Pause(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get dirty pages: %w", err)
return nil, fmt.Errorf("failed to pause VM: %w", err)
}

// Snapfile is not closed as it's returned and cached for later use (like resume)
snapfile := template.NewLocalFileLink(snapshotTemplateFiles.CacheSnapfilePath())
cleanup.AddNoContext(ctx, snapfile.Close)
// Memfile is also closed on diff creation processing
/* The process of snapshotting memory is as follows:
1. Pause FC via API
2. Snapshot FC via API—memory dump to “file on disk” that is actually tmpfs, because it is too slow
3. Create the diff - copy the diff pages from tmpfs to normal disk file
4. Delete tmpfs file
5. Unlock so another snapshot can use tmpfs space
*/
memfile, err := storage.AcquireTmpMemfile(ctx, s.config, buildID.String())
if err != nil {
return nil, fmt.Errorf("failed to acquire memfile snapshot: %w", err)
}
// Close the file even if an error occurs
defer memfile.Close()

err = s.process.CreateSnapshot(
ctx,
snapfile.Path(),
memfile.Path(),
)
err = s.process.CreateSnapshot(ctx, snapfile.Path())
if err != nil {
return nil, fmt.Errorf("error creating snapshot: %w", err)
}
Expand All @@ -797,23 +753,32 @@ func (s *Sandbox) Pause(
if err != nil {
return nil, fmt.Errorf("failed to get original memfile: %w", err)
}

originalRootfs, err := s.Template.Rootfs()
if err != nil {
return nil, fmt.Errorf("failed to get original rootfs: %w", err)
}

dirty, err := s.memory.Dirty(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get dirty pages: %w", err)
}

memoryView, err := s.process.Memory(ctx)
if err != nil {
return nil, fmt.Errorf("failed to get memory view: %w", err)
}
defer memoryView.Close()

// Start POSTPROCESSING
memfileDiff, memfileDiffHeader, err := pauseProcessMemory(
ctx,
buildID,
originalMemfile.Header(),
&MemoryDiffCreator{
memfile: memfile,
memory: memoryView,
dirtyPages: dirty.BitSet(),
blockSize: originalMemfile.BlockSize(),
doneHook: func(context.Context) error {
return memfile.Close()
},
},
s.config.DefaultCacheDir,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"sync"
)

var ErrFdExit = errors.New("fd exit signal")

// FdExit is a wrapper around a pipe that allows to signal the exit of the uffd.
type FdExit struct {
r *os.File
Expand Down
48 changes: 44 additions & 4 deletions packages/orchestrator/internal/sandbox/uffd/memory/mapping.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,24 @@ package memory

import (
"fmt"

"github.com/e2b-dev/infra/packages/shared/pkg/fc/models"
)

type AddressNotFoundError struct {
hostVirtAddr uintptr
}

func (e AddressNotFoundError) Error() string {
return fmt.Sprintf("address %d not found in any mapping", e.hostVirtAddr)
return fmt.Sprintf("host virtual address %d not found in any mapping", e.hostVirtAddr)
}

type OffsetNotFoundError struct {
offset int64
}

func (e OffsetNotFoundError) Error() string {
return fmt.Sprintf("offset %d not found in any mapping", e.offset)
}

type Mapping struct {
Expand All @@ -20,13 +30,43 @@ func NewMapping(regions []Region) *Mapping {
return &Mapping{Regions: regions}
}

// GetOffset returns the relative offset and the page size of the mapped range for a given address.
func (m *Mapping) GetOffset(hostVirtAddr uintptr) (int64, uint64, error) {
func NewMappingFromFCInfo(regions []*models.GuestMemoryRegionMapping) (*Mapping, error) {
r := make([]Region, len(regions))

for i, infoRegion := range regions {
if infoRegion.BaseHostVirtAddr == nil || infoRegion.Size == nil || infoRegion.Offset == nil || infoRegion.PageSize == nil {
return nil, fmt.Errorf("missing required fields for memory region %d", i)
}

r[i] = Region{
BaseHostVirtAddr: uintptr(*infoRegion.BaseHostVirtAddr),
Size: uintptr(*infoRegion.Size),
Offset: uintptr(*infoRegion.Offset),
PageSize: uintptr(*infoRegion.PageSize),
}
}

return NewMapping(r), nil
}

// GetOffset returns the relative offset and the pagesize of the mapped range for a given address.
func (m *Mapping) GetOffset(hostVirtAddr uintptr) (int64, uintptr, error) {
for _, r := range m.Regions {
if hostVirtAddr >= r.BaseHostVirtAddr && hostVirtAddr < r.endHostVirtAddr() {
return r.shiftedOffset(hostVirtAddr), uint64(r.PageSize), nil
return r.shiftedOffset(hostVirtAddr), r.PageSize, nil
}
}

return 0, 0, AddressNotFoundError{hostVirtAddr: hostVirtAddr}
}

// GetHostVirtAddr returns the host virtual address and size of the remaining contiguous mapped host range for the given offset.
func (m *Mapping) GetHostVirtAddr(off int64) (uintptr, int64, error) {
for _, r := range m.Regions {
if off >= int64(r.Offset) && off < r.endOffset() {
return r.shiftedHostVirtAddr(off), r.endOffset() - off, nil
}
}

return 0, 0, OffsetNotFoundError{offset: off}
}
Loading
Loading