Skip to content

Commit

Permalink
add except, move graphs into package
Browse files Browse the repository at this point in the history
  • Loading branch information
SFBdragon committed Apr 23, 2024
1 parent 0594436 commit 8a6d18b
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 11 deletions.
2 changes: 1 addition & 1 deletion graph_microbench.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import os

BENCHMARK_RESULTS_DIR = 'benchmark_results/micro/'
BENCHMARK_RESULT_GRAPHS_DIR = 'benchmark_graphs/'
BENCHMARK_RESULT_GRAPHS_DIR = 'talc/benchmark_graphs/'

def get_benchmark_data(filename):
print("reading", filename)
Expand Down
2 changes: 1 addition & 1 deletion graph_random_actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import os

BENCHMARK_RESULTS_DIR = 'benchmark_results/'
BENCHMARK_RESULT_GRAPHS_DIR = 'benchmark_graphs/'
BENCHMARK_RESULT_GRAPHS_DIR = 'talc/benchmark_graphs/'

def get_benchmark_data(filename):
with open(filename, 'r') as f:
Expand Down
2 changes: 1 addition & 1 deletion talc/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "talc"
version = "4.4.0"
version = "4.4.1"
rust-version = "1.67.1"
edition = "2021"
readme = "README.md"
Expand Down
11 changes: 8 additions & 3 deletions talc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,15 @@ The number of successful allocations, deallocations, and reallocations within th

#### 1 Thread

![Random Actions Benchmark Results](/benchmark_graphs/random_actions.png)
![Random Actions Benchmark Results](./benchmark_graphs/random_actions.png)

#### 4 Threads

![Random Actions Multi Benchmark Results](/benchmark_graphs/random_actions_multi.png)
![Random Actions Multi Benchmark Results](./benchmark_graphs/random_actions_multi.png)

## Allocations & Deallocations Microbenchmark

![Microbenchmark Results](/benchmark_graphs/microbench.png)
![Microbenchmark Results](./benchmark_graphs/microbench.png)

Label indicates the maximum within 50 standard deviations from the median. Max allocation size is 0x10000.

Expand All @@ -117,6 +117,7 @@ Here is the list of important `Talc` methods:
* `new`
* Information:
* `get_allocated_span` - returns the minimum heap span containing all allocated memory in an established heap
* `get_counters` - if feature `"counters"` is enabled, this returns a struct with allocation statistics
* Management:
* `claim` - claim memory to establishing a new heap
* `extend` - extend an established heap
Expand Down Expand Up @@ -213,6 +214,10 @@ Additionally, the layout of chunk metadata is rearranged to allow for smaller mi

## Changelog

#### v4.4.1

- Added utility function `except` to `Span`, which takes the set difference, potentially splitting the `Span`. Thanks [bjorn3](https://github.com/bjorn3) for the suggestion!

#### v4.4.0

- Added feature `allocator-api2` which allows using the `Allocator` trait on stable via the [`allocator-api2`](https://github.com/zakarumych/allocator-api2) crate. Thanks [jess-sol](https://github.com/jess-sol)!
Expand Down
File renamed without changes
File renamed without changes
File renamed without changes
37 changes: 32 additions & 5 deletions talc/src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,19 @@ impl Span {
pub fn below(self, max: *mut u8) -> Self {
Self { base: self.base, acme: if max < self.acme { max } else { self.acme } }
}

/// Returns the [`Span`]s of `self` below and above the `exclude` span, respectively.
/// Alternatively worded, the set difference `self`\\`exclude`.
///
/// If `exclude` is empty, `self` and an empty `Span` are returned.
#[inline]
pub fn except(self, exclude: Span) -> (Self, Self) {
match exclude.get_base_acme() {
Some((base, acme)) => (self.below(base), self.above(acme)),
None => (self, Span::empty()),
}
}

/// Returns a span that `other` contains by raising `base` or lowering `acme`.
///
/// If `other` is empty, returns `other`.
Expand Down Expand Up @@ -374,11 +387,25 @@ mod test {
)
);

assert!(span.above(ptr(2345)) == Span::new(ptr(2345), aptr));
assert!(span.below(ptr(7890)) == Span::new(bptr, aptr));
assert!(span.below(ptr(3456)) == Span::new(bptr, ptr(3456)));
assert!(span.below(ptr(0123)).is_empty());
assert!(span.above(ptr(7890)).is_empty());
assert_eq!(span.above(ptr(2345)), Span::new(ptr(2345), aptr));
assert_eq!(span.below(ptr(7890)), Span::new(bptr, aptr));
assert_eq!(span.below(ptr(3456)), Span::new(bptr, ptr(3456)));
assert_eq!(span.below(ptr(0123)), Span::empty());
assert_eq!(span.above(ptr(7890)), Span::empty());

assert_eq!(
span.except(Span::new(ptr(base + 1111), ptr(acme - 1111))),
(Span::new(bptr, ptr(base + 1111)), Span::new(ptr(acme - 1111), aptr))
);
assert_eq!(
span.except(Span::new(ptr(base + 1111), ptr(acme + 1111))),
(Span::new(bptr, ptr(base + 1111)), Span::empty())
);
assert_eq!(
span.except(Span::new(ptr(base - 1111), ptr(acme + 1111))),
(Span::empty(), Span::empty())
);
assert_eq!(span.except(Span::empty()), (span, Span::empty()));

assert!(span.fit_over(Span::empty()) == span);
assert!(span.fit_within(Span::empty()).is_empty());
Expand Down

0 comments on commit 8a6d18b

Please sign in to comment.