Memfd Preservation via LUO¶
Overview¶
Memory file descriptors (memfd) can be preserved over a kexec using the Live Update Orchestrator (LUO) file preservation. This allows userspace to transfer its memory contents to the next kernel after a kexec.
The preservation is not intended to be transparent. Only select properties of the file are preserved. All others are reset to default. The preserved properties are described below.
Note
The LUO API is not stabilized yet, so the preserved properties of a memfd are also not stable and are subject to backwards incompatible changes.
Note
Currently a memfd backed by Hugetlb is not supported. Memfds created
with MFD_HUGETLB will be rejected.
Preserved Properties¶
The following properties of the memfd are preserved across kexec:
- File Contents
All data stored in the file is preserved.
- File Size
The size of the file is preserved. Holes in the file are filled by allocating pages for them during preservation.
- File Position
The current file position is preserved, allowing applications to continue reading/writing from their last position.
- File Status Flags
memfds are always opened with
O_RDWRandO_LARGEFILE. This property is maintained.
Non-Preserved Properties¶
All properties which are not preserved must be assumed to be reset to default. This section describes some of those properties which may be more of note.
FD_CLOEXECflagA memfd can be created with the
MFD_CLOEXECflag that sets theFD_CLOEXECon the file. This flag is not preserved and must be set again after restore viafcntl().- Seals
File seals are not preserved. The file is unsealed on restore and if needed, must be sealed again via
fcntl().
Memfd Preservation ABI¶
-
MEMFD_LUO_FOLIO_DIRTY¶
MEMFD_LUO_FOLIO_DIRTY
The folio is dirty.
Description
This flag indicates the folio contains data from user. A non-dirty folio is one that was allocated (say using fallocate(2)) but not written to.
-
MEMFD_LUO_FOLIO_UPTODATE¶
MEMFD_LUO_FOLIO_UPTODATE
The folio is up-to-date.
Description
An up-to-date folio has been zeroed out. shmem zeroes out folios on first use. This flag tracks which folios need zeroing.
-
struct memfd_luo_folio_ser¶
Serialized state of a single folio.
Definition:
struct memfd_luo_folio_ser {
u64 pfn:52;
u64 flags:12;
u64 index;
};
Members
pfnThe page frame number of the folio.
flagsFlags to describe the state of the folio.
indexThe page offset (pgoff_t) of the folio within the original file.
-
struct memfd_luo_ser¶
Main serialization structure for a memfd.
Definition:
struct memfd_luo_ser {
u64 pos;
u64 size;
u64 nr_folios;
struct kho_vmalloc folios;
};
Members
posThe file’s current position (f_pos).
sizeThe total size of the file in bytes (i_size).
nr_foliosNumber of folios in the folios array.
foliosKHO vmalloc descriptor pointing to the array of
struct memfd_luo_folio_ser.