Commit 431f1fc
committed
fix(memory): use madvise(MADV_REMOVE) to discard memfd ranges
Replace fallocate(PUNCH_HOLE) with madvise(MADV_REMOVE) for the
memfd-backed (MAP_SHARED) memory discard path.
The critical difference is that madvise(MADV_REMOVE) calls
userfaultfd_remove() on the VMA before issuing the fallocate, which
delivers a UFFD_EVENT_REMOVE to any userfaultfd registered on that VMA.
fallocate(PUNCH_HOLE) called directly on the file descriptor does not go
through this path and produces no uffd event. Without the event, a uffd
handler cannot learn that the pages have been freed and may serve stale
data on subsequent faults in the discarded range.
Signed-off-by: Nikita Kalyazin <nikita.kalyazin@e2b.dev>1 parent 3a19026 commit 431f1fc
1 file changed
Lines changed: 18 additions & 22 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
22 | 22 | | |
23 | 23 | | |
24 | 24 | | |
25 | | - | |
26 | | - | |
| 25 | + | |
27 | 26 | | |
28 | 27 | | |
29 | 28 | | |
| |||
441 | 440 | | |
442 | 441 | | |
443 | 442 | | |
444 | | - | |
445 | | - | |
446 | | - | |
447 | | - | |
448 | | - | |
449 | | - | |
450 | | - | |
451 | | - | |
452 | | - | |
453 | | - | |
454 | | - | |
455 | | - | |
456 | | - | |
457 | | - | |
458 | | - | |
459 | | - | |
460 | | - | |
461 | | - | |
462 | | - | |
463 | | - | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
464 | 460 | | |
465 | 461 | | |
466 | 462 | | |
| |||
0 commit comments