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.
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 #
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 #
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
;
Members
pfn: The page frame number of the folio.flags: Flags to describe the state of the folio.index: The page offset (pgoff_t) of the folio within the original file.
struct memfd_luo_ser #
Main serialization structure for a memfd.
Definition
;
Members
pos: The file's current position (f_pos).size: The total size of the file in bytes (i_size).nr_folios: Number of folios in the folios array.folios: KHO vmalloc descriptor pointing to the array of struct memfd_luo_folio_ser.