Frame Allocator: update `GLOBAL_POOL_SIZE` when dropping `OnDemandGlobalLock`

This commit is contained in:
Wang Siyuan 2025-11-25 14:03:06 +00:00 committed by Tate, Hongliang Tian
parent 44c3ffa4e2
commit bd412dd388
1 changed files with 9 additions and 13 deletions

View File

@ -89,8 +89,6 @@ pub(super) fn alloc(guard: &DisabledLocalIrqGuard, layout: Layout) -> Option<Pad
balancing::balance(local_pool.deref_mut(), &mut global_pool);
global_pool.update_global_size_if_locked();
chunk_addr
}
@ -105,8 +103,6 @@ pub(super) fn dealloc(
do_dealloc(&mut local_pool, &mut global_pool, segments);
balancing::balance(local_pool.deref_mut(), &mut global_pool);
global_pool.update_global_size_if_locked();
}
pub(super) fn add_free_memory(_guard: &DisabledLocalIrqGuard, addr: Paddr, size: usize) {
@ -115,8 +111,6 @@ pub(super) fn add_free_memory(_guard: &DisabledLocalIrqGuard, addr: Paddr, size:
split_to_chunks(addr, size).for_each(|(addr, order)| {
global_pool.get().insert_chunk(addr, order);
});
global_pool.update_global_size_if_locked();
}
fn do_dealloc(
@ -154,13 +148,6 @@ impl OnDemandGlobalLock {
self.guard.get_or_insert_with(|| GLOBAL_POOL.lock())
}
/// Updates [`GLOBAL_POOL_SIZE`] if the global pool is locked.
fn update_global_size_if_locked(&self) {
if let Some(guard) = self.guard.as_ref() {
GLOBAL_POOL_SIZE.store(guard.total_size(), Ordering::Relaxed);
}
}
/// Returns the size of the global pool.
///
/// If the global pool is locked, returns the actual size of the global pool.
@ -174,3 +161,12 @@ impl OnDemandGlobalLock {
}
}
}
impl Drop for OnDemandGlobalLock {
fn drop(&mut self) {
// Updates [`GLOBAL_POOL_SIZE`] if the global pool is locked.
if let Some(guard) = self.guard.as_ref() {
GLOBAL_POOL_SIZE.store(guard.total_size(), Ordering::Relaxed);
}
}
}