pub struct Allocator { /* private fields */ }
Implementations§
Source§impl Allocator
impl Allocator
pub fn new(filesystem: Arc<FxFilesystem>, object_id: u64) -> Allocator
pub fn tree(&self) -> &LSMTree<AllocatorKey, AllocatorValue>
Sourcepub async fn filter(
&self,
iter: impl LayerIterator<AllocatorKey, AllocatorValue>,
committed_marked_for_deletion: bool,
) -> Result<impl LayerIterator<AllocatorKey, AllocatorValue>, Error>
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.
Sourcepub fn allocation_size_histogram(&self) -> [u64; 64]
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.
Sourcepub async fn create(
&self,
transaction: &mut Transaction<'_>,
) -> Result<(), Error>
pub async fn create( &self, transaction: &mut Transaction<'_>, ) -> Result<(), Error>
Creates a new (empty) allocator.
pub async fn open(self: &Arc<Self>) -> Result<(), Error>
pub async fn on_replay_complete(self: &Arc<Self>) -> Result<(), Error>
Sourcepub async fn take_for_trimming(
&self,
offset: u64,
max_extent_size: usize,
extents_per_batch: usize,
) -> Result<TrimmableExtents<'_>, Error>
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.
Sourcepub fn parent_objects(&self) -> Vec<u64>
pub fn parent_objects(&self) -> Vec<u64>
Returns all objects that exist in the parent store that pertain to this allocator.
Sourcepub fn owner_byte_limits(&self) -> Vec<(u64, u64)>
pub fn owner_byte_limits(&self) -> Vec<(u64, u64)>
Returns all the current owner byte limits (in pairs of (owner_object_id, bytes)
).
Sourcepub fn owner_allocation_info(&self, owner_object_id: u64) -> (u64, Option<u64>)
pub fn owner_allocation_info(&self, owner_object_id: u64) -> (u64, Option<u64>)
Returns (allocated_bytes, byte_limit) for the given owner.
Sourcepub fn owner_bytes_debug(&self) -> String
pub fn owner_bytes_debug(&self) -> String
Returns owner bytes debug information.
Sourcepub fn disown_reservation(&self, old_owner_object_id: Option<u64>, amount: u64)
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.
Sourcepub fn track_statistics(self: &Arc<Self>, parent: &Node, name: &str)
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.
Sourcepub fn maximum_offset(&self) -> u64
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
impl Allocator
Sourcepub fn info(&self) -> AllocatorInfo
pub fn info(&self) -> AllocatorInfo
Returns information about the allocator such as the layer files storing persisted allocations.
Sourcepub async fn allocate(
self: &Arc<Self>,
transaction: &mut Transaction<'_>,
owner_object_id: u64,
len: u64,
) -> Result<Range<u64>, Error>
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.
Sourcepub async fn mark_allocated(
&self,
transaction: &mut Transaction<'_>,
owner_object_id: u64,
device_range: Range<u64>,
) -> Result<(), Error>
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.
Sourcepub async fn set_bytes_limit(
&self,
transaction: &mut Transaction<'_>,
owner_object_id: u64,
bytes: u64,
) -> Result<(), Error>
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.
Sourcepub async fn get_bytes_limit(&self, owner_object_id: u64) -> Option<u64>
pub async fn get_bytes_limit(&self, owner_object_id: u64) -> Option<u64>
Gets the bytes limit for an owner object.
Sourcepub async fn deallocate(
&self,
transaction: &mut Transaction<'_>,
owner_object_id: u64,
dealloc_range: Range<u64>,
) -> Result<u64, Error>
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.
Sourcepub async fn mark_for_deletion(
&self,
transaction: &mut Transaction<'_>,
owner_object_id: u64,
)
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
.
Sourcepub async fn did_flush_device(&self, flush_log_offset: u64)
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.
Sourcepub fn reserve(
self: Arc<Self>,
owner_object_id: Option<u64>,
amount: u64,
) -> Option<Reservation>
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.
Sourcepub fn reserve_with(
self: Arc<Self>,
owner_object_id: Option<u64>,
amount: impl FnOnce(u64) -> u64,
) -> Reservation
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.
Sourcepub fn get_allocated_bytes(&self) -> u64
pub fn get_allocated_bytes(&self) -> u64
Returns the total number of allocated bytes.
Sourcepub fn get_disk_bytes(&self) -> u64
pub fn get_disk_bytes(&self) -> u64
Returns the size of bytes available to allocate.
Sourcepub fn get_owner_allocated_bytes(&self) -> BTreeMap<u64, u64>
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.
Sourcepub fn get_used_bytes(&self) -> Saturating<u64>
pub fn get_used_bytes(&self) -> Saturating<u64>
Returns the number of allocated and reserved bytes.
Trait Implementations§
Source§impl JournalingObject for Allocator
impl JournalingObject for Allocator
Source§fn apply_mutation(
&self,
mutation: Mutation,
context: &ApplyContext<'_, '_>,
_assoc_obj: AssocObj<'_>,
) -> Result<(), Error>
fn apply_mutation( &self, mutation: Mutation, context: &ApplyContext<'_, '_>, _assoc_obj: AssocObj<'_>, ) -> Result<(), Error>
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<'_>)
fn drop_mutation(&self, mutation: Mutation, transaction: &Transaction<'_>)
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,
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,
Source§fn write_mutation(&self, mutation: &Mutation, writer: Writer<'_>)
fn write_mutation(&self, mutation: &Mutation, writer: Writer<'_>)
Source§impl ReservationOwner for Allocator
impl ReservationOwner for Allocator
Auto Trait Implementations§
impl !Freeze for Allocator
impl !RefUnwindSafe for Allocator
impl Send for Allocator
impl Sync for Allocator
impl Unpin for Allocator
impl !UnwindSafe for Allocator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous1, D> for Twhere
D: ResourceDialect,
Source§impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
impl<T, D> Encode<Ambiguous2, D> for Twhere
D: ResourceDialect,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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