make a default alloc hint that's not 0

set to 8 bytes initially, could be adjusted up or down.
This commit is contained in:
bunnie 2022-07-01 19:45:55 +08:00
parent 5ba62df98d
commit a1950a4c00
2 changed files with 15 additions and 7 deletions

View file

@ -196,6 +196,10 @@ pub(crate) const DK_PER_VPAGE: usize = VPAGE_SIZE / DK_STRIDE; // should be 32 -
pub(crate) const DICT_VSIZE: u64 = 0xFE_0000;
/// maximum number of dictionaries in a system
pub(crate) const DICT_MAXCOUNT: usize = 16383;
/// default alloc hint, if none is given (needs to be non-zero)
/// this would be the typical "minimum space" reserved for a key
/// users are of course allowed to specify something smaller, but it should be non-zero
pub(crate) const DEFAULT_ALLOC_HINT: usize = 8;
/// This is the format of the Basis as stored on disk
#[derive(PartialEq, Debug, Default)]
@ -583,10 +587,14 @@ impl BasisCache {
// mutate the page table to allocate data while we're accessing the page table. This huge gob of code
// computes the pages needed. :-/
let mut pages_needed = 2; // things go badly when no space is available so make sure there's always at least 1 spot
let reserved = if data.len() + offset.unwrap_or(0) > alloc_hint.unwrap_or(0) {
let reserved = if data.len() + offset.unwrap_or(0) > alloc_hint.unwrap_or(DEFAULT_ALLOC_HINT) {
data.len() + offset.unwrap_or(0)
} else {
alloc_hint.unwrap_or(0)
if alloc_hint.unwrap_or(DEFAULT_ALLOC_HINT) == 0 { // disallow 0-sized alloc hints, round up to the default size if someone tries 0
DEFAULT_ALLOC_HINT
} else {
alloc_hint.unwrap_or(DEFAULT_ALLOC_HINT)
}
};
let reserved_pages = if reserved % VPAGE_SIZE == 0 {
reserved / VPAGE_SIZE

View file

@ -570,7 +570,7 @@ impl DictCacheEntry {
} else {
// key does not exist (or was previously erased) -- create one or replace the erased one.
// try to fit the key in the small pool first
if ((data.len() + offset) < SMALL_CAPACITY) && (alloc_hint.unwrap_or(0) < SMALL_CAPACITY) {
if ((data.len() + offset) < SMALL_CAPACITY) && (alloc_hint.unwrap_or(DEFAULT_ALLOC_HINT) < SMALL_CAPACITY) {
log::debug!("creating small key {}", name);
// handle the case that we're a brand new dictionary and no small keys have ever been stored before.
if self.small_pool.len() == 0 {
@ -578,8 +578,8 @@ impl DictCacheEntry {
self.rebuild_free_pool();
}
let pool_candidate = self.small_pool_free.pop().expect("Free pool was allocated & rebuilt, but still empty.");
let mut reservation = if alloc_hint.unwrap_or(0) > data.len() + offset {
alloc_hint.unwrap_or(0)
let mut reservation = if alloc_hint.unwrap_or(DEFAULT_ALLOC_HINT) > data.len() + offset {
alloc_hint.unwrap_or(DEFAULT_ALLOC_HINT)
} else {
data.len() + offset
};
@ -647,8 +647,8 @@ impl DictCacheEntry {
log::debug!("creating large key");
// it didn't fit in the small pool, stick it in the big pool.
let reservation = PageAlignedVa::from(
if alloc_hint.unwrap_or(0) > data.len() + offset {
alloc_hint.unwrap_or(0)
if alloc_hint.unwrap_or(DEFAULT_ALLOC_HINT) > data.len() + offset {
alloc_hint.unwrap_or(DEFAULT_ALLOC_HINT)
} else {
data.len() + offset
});