Skip to content

Conversation

nqd
Copy link
Collaborator

@nqd nqd commented Aug 11, 2025

This PR provides a buffer pool as an alternative to mmap for page management.

Benchmark shows that writing is 3 - 4 times faster than the current mmap. Run example/insert to insert 20 million EOA + storage result:

➜  time ./insert-mmap ./mmap/db20m 10000 1000 100 10
./insert-mmap ./mmap/db20m 10000 1000 100 10  157.05s user 600.80s system 73% cpu 17:14.41 total

➜  time ./insert-buffer-pool ./buffer_pool/db20m 10000 1000 100 10
./insert-buffer-pool ./buffer_pool/db20m 10000 1000 100 10  182.79s user 9.79s system 76% cpu 4:11.19 total

The current cache eviction is just a proof of concept and is not efficient. Another PR will be raised to provide a better eviction policy.

@cb-heimdall
Copy link
Collaborator

cb-heimdall commented Aug 11, 2025

🟡 Heimdall Review Status

Requirement Status More Info
Reviews 🟡 0/1
Denominator calculation
Show calculation
1 if user is bot 0
1 if user is external 0
2 if repo is sensitive 0
From .codeflow.yml 1
Additional review requirements
Show calculation
Max 0
0
From CODEOWNERS 0
Global minimum 0
Max 1
1
1 if commit is unverified 1
Sum 2

@nqd nqd force-pushed the page-manager-with-buffer-pool branch 3 times, most recently from dc1f170 to b35459b Compare September 12, 2025 08:36
}

/// Retrieves a page from the memory mapped file.
pub fn get(&self, _snapshot_id: SnapshotId, page_id: PageId) -> Result<Page<'_>, PageError> {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unused snapshot_id

@nqd nqd changed the title [WIP][Dont review] Page manager with buffer pool Page manager with buffer pool Sep 18, 2025
@nqd nqd marked this pull request as ready for review September 18, 2025 06:33

// TODO: Temporarily use LruReplacer as the eviction policy, replace with a better eviction policy
pub(crate) struct CacheEvict {
lru_replacer: LruReplacer<PageId>,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A new cache eviction policy will be in the nextPR

.map_err(|_| PageError::InvalidValue)?;
// Use O_DIRECT on Linux for better performance, but not available on macOS
#[cfg(target_os = "linux")]
let flags = libc::O_RDWR | libc::O_CREAT | libc::O_DIRECT;
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

O_DIRECT to bypass OS page cache, hence avoid double caching

@nqd nqd requested a review from and-cb September 18, 2025 13:58
@nqd nqd force-pushed the page-manager-with-buffer-pool branch from 266f484 to c820e65 Compare October 1, 2025 13:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants