Data Structures

A technical reference for the key C structs used in USM policy development, including usm_event, page, and to_swap.

Understanding the data structures passed between the USM framework and your policy is critical for correct implementation. This page details the most important structs.

struct usm_event

This is the primary communication struct, passed to nearly all policy functions. It carries information about the memory event that occurred. Defined in APIv/include/com/event.h.

FieldTypeDescription
typeenum evt_typeThe type of event. Can be ALLOC, FREE, NEW_PROC, etc.
vaddrunsigned longThe virtual address that triggered the event, typically a page fault.
paddrunsigned longThe physical address (PFN). For usm_alloc, this is an output field you must set. For usm_pindex_free, this is an input field.
lengthunsigned longFor batch operations. In an allocation event, it indicates how many additional contiguous pages the application is likely to fault on soon.
offstunsigned longFor swap-in (UFFD_PAGEFAULT_FLAG_SWAP) faults, this contains the encoded swap entry information (device number and offset).
flagsunsigned longKernel flags from the fault, such as UFFD_PAGEFAULT_FLAG_WRITE or UFFD_PAGEFAULT_FLAG_SHARED.
originunsigned intThe unique ID (a userfaultfd file descriptor) for the process that generated the event.
usmmemchar *For the high-performance uThread path, this is a pointer to the shared memory communication page for the faulting thread.
procNamechar *The name of the process, available for NEW_PROC events.

struct page

This struct is USM's internal representation of a physical page within your managed memory pool. Defined in APIv/include/usm/usm.h.

FieldTypeDescription
dataintptr_tThe virtual address of the page's content within the InstanceUSM process. Allows your policy to directly read or write page data (e.g., before swapping out).
virtualAddressunsigned longThe virtual address this page is mapped to within the managed application's address space. 0 if the page is free.
physicalAddressunsigned longThe physical address (Page Frame Number, or PFN) of this page. This is the value you pass back in event->paddr.
processintThe origin ID of the process that currently owns this page. 0 if the page is free.
usedListPositionPointervoid *Crucial Link: A generic pointer for you to store a reference back to your policy's wrapper struct (e.g., a pointer to the optEludeList that contains this page). This enables O(1) lookups.

struct to_swap

This is a helper struct used by eviction and swapping policies to bundle all necessary information for a swap operation. Defined in APIv/include/policies/evict/swap.h.

FieldTypeDescription
swapDevicestruct usm_swap_dev *A pointer to the target swap device where the page will be written.
pagestruct page *A pointer to the USM struct page that is the victim for this swap-out operation.
swapped_addressunsigned longThe virtual address within the application that is being unmapped and swapped out.
snodestruct swap_node *A pointer to a node representing a free slot on the swap device.
procintThe ID of the process owning the page.
globliststruct list_headA list head for linking this struct into a global list of all swapped-out pages.
iuliststruct list_headA list head for linking this struct into a per-process list of swapped-out pages.

Performance Insight: Why these structures matter:

The combination of usedListPositionPointer in the page struct and the paddr index in usm_event allows USM to bypass the standard kernel's expensive list-scanning (LRU) overhead.

By using the physical address as a direct index and maintaining a direct link to your policy's wrapper structures, you achieve O(1) complexity for critical path operations. This architecture is precisely why USM can outperform the standard Linux Memory Manager (LMM) in memory-intensive workloads like Redis or PageRank.