mm/memfd_luo.c
Source file repositories/reference/linux-study-clean/mm/memfd_luo.c
File Facts
- System
- Linux kernel
- Corpus path
mm/memfd_luo.c- Extension
.c- Size
- 15390 bytes
- Lines
- 623
- Domain
- Core OS
- Bucket
- Memory Management
- Inferred role
- Core OS: implementation source
- Status
- source implementation candidate
Why This File Exists
Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Core operating-system implementation surface: boot, tasks, memory, VFS, syscall-facing interfaces, synchronization, credentials, and isolation.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/bits.hlinux/err.hlinux/file.hlinux/io.hlinux/kexec_handover.hlinux/kho/abi/memfd.hlinux/liveupdate.hlinux/shmem_fs.hlinux/vmalloc.hlinux/memfd.huapi/linux/memfd.hinternal.h
Detected Declarations
function memfd_luo_preserve_foliosfunction memfd_luo_unpreserve_foliosfunction memfd_luo_preservefunction memfd_luo_freezefunction memfd_luo_unpreservefunction memfd_luo_discard_foliosfunction memfd_luo_finishfunction memfd_luo_retrieve_foliosfunction memfd_luo_retrievefunction memfd_luo_can_preservefunction memfd_luo_get_idfunction memfd_luo_init
Annotated Snippet
if (!folio_test_uptodate(folio)) {
folio_zero_range(folio, 0, folio_size(folio));
flush_dcache_folio(folio);
folio_mark_uptodate(folio);
}
folio_unlock(folio);
pfolio->pfn = folio_pfn(folio);
pfolio->flags = MEMFD_LUO_FOLIO_DIRTY | MEMFD_LUO_FOLIO_UPTODATE;
pfolio->index = folio->index;
}
err = kho_preserve_vmalloc(folios_ser, kho_vmalloc);
if (err)
goto err_unpreserve;
kvfree(folios);
*nr_foliosp = nr_folios;
*out_folios_ser = folios_ser;
/*
* Note: folios_ser is purposely not freed here. It is preserved
* memory (via KHO). In the 'unpreserve' path, we use the vmap pointer
* that is passed via private_data.
*/
return 0;
err_unpreserve:
for (i = i - 1; i >= 0; i--)
kho_unpreserve_folio(folios[i]);
vfree(folios_ser);
err_unpin:
unpin_folios(folios, nr_folios);
err_free_folios:
kvfree(folios);
return err;
}
static void memfd_luo_unpreserve_folios(struct kho_vmalloc *kho_vmalloc,
struct memfd_luo_folio_ser *folios_ser,
u64 nr_folios)
{
long i;
if (!nr_folios)
return;
kho_unpreserve_vmalloc(kho_vmalloc);
for (i = 0; i < nr_folios; i++) {
const struct memfd_luo_folio_ser *pfolio = &folios_ser[i];
struct folio *folio;
if (!pfolio->pfn)
continue;
folio = pfn_folio(pfolio->pfn);
kho_unpreserve_folio(folio);
unpin_folio(folio);
}
vfree(folios_ser);
}
static int memfd_luo_preserve(struct liveupdate_file_op_args *args)
{
struct inode *inode = file_inode(args->file);
struct memfd_luo_folio_ser *folios_ser;
struct memfd_luo_ser *ser;
u64 nr_folios, inode_size;
int err = 0, seals;
inode_lock(inode);
shmem_freeze(inode, true);
/* Allocate the main serialization structure in preserved memory */
ser = kho_alloc_preserve(sizeof(*ser));
if (IS_ERR(ser)) {
err = PTR_ERR(ser);
goto err_unlock;
}
seals = memfd_get_seals(args->file);
if (seals < 0) {
err = seals;
goto err_free_ser;
}
Annotation
- Immediate include surface: `linux/bits.h`, `linux/err.h`, `linux/file.h`, `linux/io.h`, `linux/kexec_handover.h`, `linux/kho/abi/memfd.h`, `linux/liveupdate.h`, `linux/shmem_fs.h`.
- Detected declarations: `function memfd_luo_preserve_folios`, `function memfd_luo_unpreserve_folios`, `function memfd_luo_preserve`, `function memfd_luo_freeze`, `function memfd_luo_unpreserve`, `function memfd_luo_discard_folios`, `function memfd_luo_finish`, `function memfd_luo_retrieve_folios`, `function memfd_luo_retrieve`, `function memfd_luo_can_preserve`.
- Atlas domain: Core OS / Memory Management.
- Implementation status: source implementation candidate.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.