Skip to content

Commit

Permalink
No more MIN_FREE_CHUNK_SIZE limitation (#1555)
Browse files Browse the repository at this point in the history
* Do not use MIN_FREE_CHUNK_SIZE limitation - the provider's alignment will do the trick!

* Do not leave empty free chunks
  • Loading branch information
yellowhatter authored Oct 23, 2024
1 parent 5cc7464 commit 6a7c6ea
Showing 1 changed file with 3 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,6 @@ use crate::api::{
},
};

// TODO: MIN_FREE_CHUNK_SIZE limitation is made to reduce memory fragmentation and lower
// the CPU time needed to defragment() - that's reasonable, and there is additional thing here:
// our SHM\zerocopy functionality outperforms common buffer transmission only starting from 1K
// buffer size. In other words, there should be some minimal size threshold reasonable to use with
// SHM - and it would be good to synchronize this threshold with MIN_FREE_CHUNK_SIZE limitation!
const MIN_FREE_CHUNK_SIZE: usize = 1_024;

#[derive(Eq, Copy, Clone, Debug)]
struct Chunk {
offset: ChunkID,
Expand Down Expand Up @@ -181,7 +174,8 @@ impl ShmProviderBackend for PosixShmProviderBackend {
Some(mut chunk) if chunk.size >= required_len => {
// NOTE: don't loose any chunks here, as it will lead to memory leak
tracing::trace!("Allocator selected Chunk ({:?})", &chunk);
if chunk.size.get() - required_len.get() >= MIN_FREE_CHUNK_SIZE {

if chunk.size > required_len {
let free_chunk = Chunk {
offset: chunk.offset + required_len.get() as ChunkID,
// SAFETY: this is safe because we always operate on a leftover, which is checked above!
Expand All @@ -193,6 +187,7 @@ impl ShmProviderBackend for PosixShmProviderBackend {
guard.push(free_chunk);
chunk.size = required_len;
}

self.available
.fetch_sub(chunk.size.get(), Ordering::Relaxed);

Expand Down

0 comments on commit 6a7c6ea

Please sign in to comment.