class VmCompressedStorage
Defined at line 24 of file ../../zircon/kernel/vm/include/vm/compression.h
Defines an allocator like interface for adding, removing and accessing compressed data.
Instances of this class may be accessed concurrently.
Public Methods
ktl::pair<ktl::optional<CompressedRef>, vm_page_t *> Store (vm_page_t * page, size_t len)
Attempts to store the data in |page| of size |len|. The data is assumed to start at offset 0 in
the page, and |len| cannot exceed kPageSize. The |page| becomes owned by this
VmCompressedStorage instance, although ownership may be returned via the return result.
The return value is an optional reference to compressed data, as well as an optional vm_page_t,
with a nullptr for the vm_page_t being used to indicate absence. If a vm_page_t is returned the
caller owns it, and is responsible for freeing it.
If the data is stored successfully then a valid CompressedRef will be returned and will be
retained until that reference is passed to |Free|. Otherwise a nullopt is returned.
Regardless of the success or failure of the storage, a vm_page_t might be returned, and if one
is returned it may or may not be the same as the |page| passed in. The returned vm_page_t has
undefined content and is now freely owned by the caller and can be used as the caller likes, or
returned to the pmm.
The expected usage of this is that a compressor puts data in a buffer page and passes it here
as |page|, then takes any returned vm_page_t as its next buffer page, or if none was returned
allocates a new one. This provides the storage implementation with the freedom to either copy
the data out of |page| and return it, or take the page to add to its storage instead of going
to the PMM (and then returning a nullptr).
void Free (CompressedRef ref)
Free the data referenced by a |CompressedRef| that was returned from |Store|. After calling
this the reference is no longer valid and must not be passed to |CompressedData|, and any
previous result of |CompressedData| must not be used.
ktl::tuple<const void *, uint32_t, size_t> CompressedData (CompressedRef ref)
Retrieve a reference to original data that was stored. The metadata and length of the data are
also returned, alleviating the need to retain them separately.
The return address remains valid as long as this specific reference is not freed, and otherwise
any other calls to |Store| or |Free| do not invalidate.
TODO(https://fxbug.dev/42138396): Restrict this if de-fragmentation of the compressed storage
becomes necessary.
No guarantee on alignment of the data is provided, and callers must tolerate arbitrary byte
alignment.
TODO(https://fxbug.dev/42138396): Consider providing an alignment guarantee if needed by
decompressors.
uint32_t GetMetadata (CompressedRef ref)
Retrieve the metadata for the original page referred to by ref.
void SetMetadata (CompressedRef ref, uint32_t metadata)
Set the metadata for the original page referred to by ref.
void Dump ()
Perform an information dump of the internal state to the debuglog.
MemoryUsage GetMemoryUsage ()
void VmCompressedStorage ()
Defined at line 26 of file ../../zircon/kernel/vm/include/vm/compression.h
void ~VmCompressedStorage ()
Defined at line 27 of file ../../zircon/kernel/vm/include/vm/compression.h