Struct Allocator

Source
pub struct Allocator { /* private fields */ }

Implementations§

Source§

impl Allocator

Source

pub fn new(filesystem: Arc<FxFilesystem>, object_id: u64) -> Allocator

Source

pub fn tree(&self) -> &LSMTree<AllocatorKey, AllocatorValue>

Source

pub async fn filter( &self, iter: impl LayerIterator<AllocatorKey, AllocatorValue>, committed_marked_for_deletion: bool, ) -> Result<impl LayerIterator<AllocatorKey, AllocatorValue>, Error>

Returns an iterator that yields all allocations, filtering out tombstones and any owner_object_id that have been marked as deleted. If committed_marked_for_deletion is true, then filter using the committed volumes marked for deletion rather than the in-memory copy which excludes volumes that have been deleted but there hasn’t been a sync yet.

Source

pub fn allocation_size_histogram(&self) -> [u64; 64]

A histogram of allocation request sizes. The index into the array is ‘number of blocks’. The last bucket is a catch-all for larger allocation requests.

Source

pub async fn create( &self, transaction: &mut Transaction<'_>, ) -> Result<(), Error>

Creates a new (empty) allocator.

Source

pub async fn open(self: &Arc<Self>) -> Result<(), Error>

Source

pub async fn on_replay_complete(self: &Arc<Self>) -> Result<(), Error>

Source

pub async fn take_for_trimming( &self, offset: u64, max_extent_size: usize, extents_per_batch: usize, ) -> Result<TrimmableExtents<'_>, Error>

Collects up to extents_per_batch free extents of size up to max_extent_size from offset. The extents will be reserved. Note that only one FreeExtents can exist for the allocator at any time.

Source

pub fn parent_objects(&self) -> Vec<u64>

Returns all objects that exist in the parent store that pertain to this allocator.

Source

pub fn owner_byte_limits(&self) -> Vec<(u64, u64)>

Returns all the current owner byte limits (in pairs of (owner_object_id, bytes)).

Source

pub fn owner_allocation_info(&self, owner_object_id: u64) -> (u64, Option<u64>)

Returns (allocated_bytes, byte_limit) for the given owner.

Source

pub fn owner_bytes_debug(&self) -> String

Returns owner bytes debug information.

Source

pub fn disown_reservation(&self, old_owner_object_id: Option<u64>, amount: u64)

Updates the accounting to track that a byte reservation has been moved out of an owner to the unattributed pool.

Source

pub fn track_statistics(self: &Arc<Self>, parent: &Node, name: &str)

Creates a lazy inspect node named str under parent which will yield statistics for the allocator when queried.

Source

pub fn maximum_offset(&self) -> u64

Returns the offset of the first byte which has not been used by the allocator since its creation. NB: This does not take into account existing allocations. This is only reliable when the allocator was created from scratch, without any pre-existing allocations.

Source§

impl Allocator

Source

pub fn object_id(&self) -> u64

Returns the object ID for the allocator.

Source

pub fn info(&self) -> AllocatorInfo

Returns information about the allocator such as the layer files storing persisted allocations.

Source

pub async fn allocate( self: &Arc<Self>, transaction: &mut Transaction<'_>, owner_object_id: u64, len: u64, ) -> Result<Range<u64>, Error>

Tries to allocate enough space for |object_range| in the specified object and returns the device range allocated. The allocated range may be short (e.g. due to fragmentation), in which case the caller can simply call allocate again until they have enough blocks.

We also store the object store ID of the store that the allocation should be assigned to so that we have a means to delete encrypted stores without needing the encryption key.

Source

pub async fn mark_allocated( &self, transaction: &mut Transaction<'_>, owner_object_id: u64, device_range: Range<u64>, ) -> Result<(), Error>

Marks the given device range as allocated. The main use case for this at this time is for the super-block which needs to be at a fixed location on the device.

Source

pub async fn set_bytes_limit( &self, transaction: &mut Transaction<'_>, owner_object_id: u64, bytes: u64, ) -> Result<(), Error>

Sets the limits for an owner object in terms of usage.

Source

pub async fn get_bytes_limit(&self, owner_object_id: u64) -> Option<u64>

Gets the bytes limit for an owner object.

Source

pub async fn deallocate( &self, transaction: &mut Transaction<'_>, owner_object_id: u64, dealloc_range: Range<u64>, ) -> Result<u64, Error>

Deallocates the given device range for the specified object.

Source

pub async fn mark_for_deletion( &self, transaction: &mut Transaction<'_>, owner_object_id: u64, )

Marks allocations associated with a given |owner_object_id| for deletion.

This is used as part of deleting encrypted volumes (ObjectStore) without having the keys.

MarkForDeletion mutations eventually manipulates allocator metadata (AllocatorInfo) instead of the mutable layer but we must be careful not to do this too early and risk premature reuse of extents.

Replay is not guaranteed until the device gets flushed, so we cannot reuse the deleted extents until we’ve flushed the device.

TODO(b/316827348): Consider removing the use of mark_for_deletion in AllocatorInfo and just compacting?

After an allocator.flush() (i.e. a major compaction), we know that there is no data left in the layer files for this owner_object_id and we are able to clear marked_for_deletion.

Source

pub async fn did_flush_device(&self, flush_log_offset: u64)

Called when the device has been flush and indicates what the journal log offset was when that happened.

Source

pub fn reserve( self: Arc<Self>, owner_object_id: Option<u64>, amount: u64, ) -> Option<Reservation>

Returns a reservation that can be used later, or None if there is insufficient space. The |owner_object_id| indicates which object in the root object store the reservation is for.

Source

pub fn reserve_with( self: Arc<Self>, owner_object_id: Option<u64>, amount: impl FnOnce(u64) -> u64, ) -> Reservation

Like reserve, but takes a callback is passed the |limit| and should return the amount, which can be zero.

Source

pub fn get_allocated_bytes(&self) -> u64

Returns the total number of allocated bytes.

Source

pub fn get_disk_bytes(&self) -> u64

Returns the size of bytes available to allocate.

Source

pub fn get_owner_allocated_bytes(&self) -> BTreeMap<u64, u64>

Returns the total number of allocated bytes per owner_object_id. Note that this is quite an expensive operation as it copies the collection. This is intended for use in fsck() and friends, not general use code.

Source

pub fn get_used_bytes(&self) -> Saturating<u64>

Returns the number of allocated and reserved bytes.

Trait Implementations§

Source§

impl Drop for Allocator

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl JournalingObject for Allocator

Source§

fn apply_mutation( &self, mutation: Mutation, context: &ApplyContext<'_, '_>, _assoc_obj: AssocObj<'_>, ) -> Result<(), Error>

This method get called when the transaction commits, which can either be during live operation (See ObjectManager::apply_mutation) or during journal replay, in which case transaction will be None (See super_block::read).
Source§

fn drop_mutation(&self, mutation: Mutation, transaction: &Transaction<'_>)

Called when a transaction fails to commit.
Source§

fn flush<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Version, Error>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Flushes in-memory changes to the device (to allow journal space to be freed). Read more
Source§

fn write_mutation(&self, mutation: &Mutation, writer: Writer<'_>)

Writes a mutation to the journal. This allows objects to encrypt or otherwise modify what gets written to the journal.
Source§

impl ReservationOwner for Allocator

Source§

fn release_reservation(&self, owner_object_id: Option<u64>, amount: u64)

Report that bytes are being released from the reservation back to the the |ReservationOwner| where |owner_object_id| is the owner under the root object store associated with the reservation.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T, D> Encode<Ambiguous1, D> for T
where D: ResourceDialect,

Source§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
Source§

impl<T, D> Encode<Ambiguous2, D> for T
where D: ResourceDialect,

Source§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V