Skip to content

Commit

Permalink
Allow configuring max chunk size
Browse files Browse the repository at this point in the history
Changes the magic since it breaks existing on-disk format
  • Loading branch information
lulf committed Apr 24, 2024
1 parent f121681 commit b91351a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -189,4 +189,10 @@ branching-factor-2 = [] # Default
branching-factor-3 = []
branching-factor-4 = []

max-chunk-size-256 = []
max-chunk-size-512 = []
max-chunk-size-1024 = []
max-chunk-size-2048 = []
max-chunk-size-4096 = [] # Default

# END AUTOGENERATED CONFIG FEATURES
1 change: 1 addition & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ static CONFIGS: &[(&str, usize)] = &[
("MAX_VALUE_SIZE", 1024),
("SCRATCH_PAGE_COUNT", 4),
("BRANCHING_FACTOR", 2),
("MAX_CHUNK_SIZE", 4096),
// END AUTOGENERATED CONFIG FEATURES
];

Expand Down
1 change: 1 addition & 0 deletions gen_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def feature(name, default, min=None, max=None, pow2=None, vals=None, factors=[])

feature("scratch_page_count", default=4, min=0, max=65536, pow2=True)
feature("branching_factor", default=2, min=2, max=4)
feature("max_chunk_size", default=4096, vals=[256, 512, 1024, 2048, 4096])

# ========= Update Cargo.toml

Expand Down
8 changes: 8 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,14 @@ pub const ERASE_VALUE: u8 = match raw::ERASE_VALUE {
_ => core::panic!("invalid ERASE_VALUE"),
};

/// Maximum chunk size supported.
///
/// The chunk size controls how big chunks of data is read and written from/to flash. A low
/// value reduces the memory usage of EKV at the expense of more reads/writes.
///
/// Default: 4096
pub const MAX_CHUNK_SIZE: usize = raw::MAX_CHUNK_SIZE;

pub(crate) const MAX_HEADER_SIZE: usize = {
let a = size_of::<MetaHeader>();
let b = size_of::<DataHeader>();
Expand Down
4 changes: 1 addition & 3 deletions src/page.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::errors::Error;
use crate::flash::Flash;
use crate::types::PageID;

const CHUNK_MAGIC: u16 = 0x58A4;
const CHUNK_MAGIC: u16 = 0x59B4;

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[repr(C)]
Expand Down Expand Up @@ -53,8 +53,6 @@ pub unsafe trait Header: Sized {
const MAGIC: u32;
}

pub const MAX_CHUNK_SIZE: usize = PAGE_SIZE - PageHeader::SIZE - ChunkHeader::SIZE;

async fn write_header<F: Flash, H: Header>(flash: &mut F, page_id: PageID, header: H) -> Result<(), F::Error> {
assert!(size_of::<H>() <= MAX_HEADER_SIZE);
let mut buf = [0u8; PageHeader::SIZE + MAX_HEADER_SIZE];
Expand Down

0 comments on commit b91351a

Please sign in to comment.