Skip to content

Commit

Permalink
Added a test of Arena dependencies and destruction when using the new…
Browse files Browse the repository at this point in the history
… aligned buffer feature.
  • Loading branch information
sfc-gh-satherton committed May 6, 2021
1 parent e0e3cd3 commit 16f9f6e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
21 changes: 21 additions & 0 deletions fdbserver/VersionedBTree.actor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7820,6 +7820,27 @@ TEST_CASE(":/redwood/performance/mutationBuffer") {
return Void();
}

// This test is only useful with Arena debug statements which show when aligned buffers are allocated and freed.
TEST_CASE(":/redwood/pager/ArenaPage") {
Arena x;
printf("Making p\n");
Reference<ArenaPage> p(new ArenaPage(4096, 4096));
printf("Made p=%p\n", p->begin());
printf("Clearing p\n");
p.clear();
printf("Making p\n");
p = Reference<ArenaPage>(new ArenaPage(4096, 4096));
printf("Made p=%p\n", p->begin());
printf("Making x depend on p\n");
x.dependsOn(p->getArena());
printf("Clearing p\n");
p.clear();
printf("Clearing x\n");
x = Arena();
printf("Pointer should be freed\n");
return Void();
}

TEST_CASE("/redwood/correctness/btree") {
g_redwoodMetricsActor = Void(); // Prevent trace event metrics from starting
g_redwoodMetrics.clear();
Expand Down
2 changes: 2 additions & 0 deletions flow/Arena.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ void* ArenaBlock::makeAlignedBuffer(size_t alignment, size_t size) {
makeDefined(r, sizeof(ArenaBlockRef));
r->alignedBufferSize = size;
r->alignedBuffer = aligned_alloc(alignment, size);
// printf("Arena::alignedBuffer alloc %p\n", r->alignedBuffer);
r->nextBlockOffset = nextBlockOffset;
makeNoAccess(r, sizeof(ArenaBlockRef));
nextBlockOffset = bigUsed;
Expand Down Expand Up @@ -397,6 +398,7 @@ void ArenaBlock::destroy() {

// If alignedBuffer is valid, free it
if (br->alignedBufferSize != 0) {
// printf("Arena::alignedBuffer free %p\n", br->alignedBuffer);
aligned_free(br->alignedBuffer);
} else {
allowAccess(br->next);
Expand Down

0 comments on commit 16f9f6e

Please sign in to comment.