Skip to content

Commit f70dc4e

Browse files
committed
MemoryStore now uses fixed memory pool per store
MemoryStore now pre-allocates max_bytes from the eviction policy, then installs a custom allocator in that pool that the store will use. In testing, memory fragmentation appears to have dropped significantly, significantly decreased the number of sys-calls managing memory and slightly reduced user time. In addition, we remove two full copies of our data when we store it in the memory store. This PR also adds two new crates (likely to be published). "Heap Allocator" Fixed heap allocator based on the TLSF (Two-Level Segregated Fit) algorithm. TLSF is a fast, constant-time memory allocation algorithm designed for real-time applications. It organizes free memory into segregated lists based on block sizes, allowing for quick allocation and deallocation with minimal fragmentation. "Alloc Bytes" Provides custom byte buffers allocated using a user-provided allocator. It offers both mutable and immutable byte buffers, enabling efficient memory allocation strategies in systems with custom memory requirements. closes: #289
1 parent fc85156 commit f70dc4e

File tree

16 files changed

+1378
-157
lines changed

16 files changed

+1378
-157
lines changed

Cargo.lock

Lines changed: 117 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ nativelink-util = { path = "nativelink-util" }
4646
nativelink-worker = { path = "nativelink-worker" }
4747
nativelink-metric = { path = "nativelink-metric" }
4848
nativelink-metric-collector = { path = "nativelink-metric-collector" }
49+
alloc-bytes = { path = "external-crates/alloc-bytes" }
50+
heap-allocator = { path = "external-crates/heap-allocator" }
4951
async-lock = { version = "3.4.0", features = ["std"], default-features = false }
5052
axum = { version = "0.7.9", default-features = false }
5153
clap = { version = "4.5.26", features = ["derive"] }

MODULE.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ crate.from_cargo(
3636
cargo_lockfile = "//:Cargo.lock",
3737
manifests = [
3838
"//:Cargo.toml",
39+
"//external-crates/alloc-bytes:Cargo.toml",
40+
"//external-crates/heap-allocator:Cargo.toml",
3941
"//nativelink-config:Cargo.toml",
4042
"//nativelink-error:Cargo.toml",
4143
"//nativelink-macro:Cargo.toml",
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
load(
2+
"@rules_rust//rust:defs.bzl",
3+
"rust_doc",
4+
"rust_doc_test",
5+
"rust_library",
6+
)
7+
8+
rust_library(
9+
name = "alloc-bytes",
10+
srcs = [
11+
"src/lib.rs",
12+
],
13+
crate_features = ["bytes"],
14+
visibility = ["//visibility:public"],
15+
deps = [
16+
"//external-crates/heap-allocator",
17+
"@crates//:bytes",
18+
],
19+
)
20+
21+
rust_doc(
22+
name = "docs",
23+
crate = ":alloc-bytes",
24+
visibility = ["//visibility:public"],
25+
)
26+
27+
rust_doc_test(
28+
name = "doc_test",
29+
timeout = "short",
30+
crate = ":alloc-bytes",
31+
)
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
[package]
2+
name = "alloc-bytes"
3+
version = "0.0.1"
4+
edition = "2018"
5+
authors = [
6+
"Nativelink Authors",
7+
"Nathan (Blaise) Bruer <[email protected]>"
8+
]
9+
license = "Apache-2.0"
10+
repository = "https://github.com/TraceMachina/nativelink/external-crates/alloc-bytes"
11+
description = "A lightweight crate offering custom-allocated byte buffers with user-specified allocators for efficient, fine-tuned memory management."
12+
keywords = ["bytes", "allocator", "buffers"]
13+
categories = ["network-programming", "data-structures"]
14+
15+
[lib]
16+
crate-type = ["rlib"]
17+
18+
[dependencies]
19+
bytes = { version = "1.10.0", optional = true, default-features = false }
20+
heap-allocator = { path = "../heap-allocator", optional = true }
21+
22+
[features]
23+
default = []
24+
25+
bytes = ["dep:bytes"]

0 commit comments

Comments
 (0)