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¶
-
struct memfd_luo_folio_ser¶
Serialized state of a single folio.
Definition:
struct memfd_luo_folio_ser {
u64 foliodesc;
u64 index;
};
Members
foliodescA packed 64-bit value containing both the PFN and status flags of the preserved folio. The upper 52 bits store the PFN, and the lower 12 bits are reserved for flags (e.g., dirty, uptodate).
indexThe page offset (pgoff_t) of the folio within the original file’s address space. This is used to correctly position the folio during restoration.
Description
This structure represents the minimal information required to restore a single folio in the new kernel. An array of these structs forms the binary data for the “folios” property in the handover FDT.