Skip to content

Commit e05cd7f

Browse files
committed
CR and CI changes
1 parent 3a54e81 commit e05cd7f

File tree

5 files changed

+42
-34
lines changed

5 files changed

+42
-34
lines changed

src/snmalloc/backend_helpers/statsrange.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,15 @@ namespace snmalloc
2828

2929
constexpr Type() = default;
3030

31-
capptr::Arena<void> alloc_range(size_t size)
31+
CapPtr<void, ChunkBounds> alloc_range(size_t size)
3232
{
3333
auto r = parent.alloc_range(size);
3434
if (r != nullptr)
3535
usage += size;
3636
return r;
3737
}
3838

39-
void dealloc_range(capptr::Arena<void> base, size_t size)
39+
void dealloc_range(CapPtr<void, ChunkBounds> base, size_t size)
4040
{
4141
usage -= size;
4242
parent.dealloc_range(base, size);

src/snmalloc/ds_core/stats.h

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,8 @@ namespace snmalloc
2929
void decrease(size_t amount)
3030
{
3131
size_t prev = curr.fetch_sub(amount);
32-
// TODO Fix this to be true.
33-
// SNMALLOC_ASSERT_MSG(prev >= amount, "prev = {}, amount = {}",
34-
// prev, amount);
32+
SNMALLOC_ASSERT_MSG(
33+
prev >= amount, "prev = {}, amount = {}", prev, amount);
3534
UNUSED(prev);
3635
}
3736

@@ -65,4 +64,28 @@ namespace snmalloc
6564
decrease(1);
6665
}
6766
};
67+
68+
/**
69+
* Very basic statistic that can only grow. Not thread-safe.
70+
*/
71+
class MonotoneLocalStat
72+
{
73+
size_t value{0};
74+
75+
public:
76+
void operator++(int)
77+
{
78+
value++;
79+
}
80+
81+
void operator+=(const MonotoneLocalStat& other)
82+
{
83+
value += other.value;
84+
}
85+
86+
size_t operator*()
87+
{
88+
return value;
89+
}
90+
};
6891
} // namespace snmalloc

src/snmalloc/mem/allocstats.h

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,12 @@
55

66
namespace snmalloc
77
{
8-
class MonotoneStat
9-
{
10-
size_t value{0};
11-
12-
public:
13-
void operator++(int)
14-
{
15-
value++;
16-
}
17-
18-
void operator+=(const MonotoneStat& other)
19-
{
20-
value += other.value;
21-
}
22-
23-
size_t operator*()
24-
{
25-
return value;
26-
}
27-
};
28-
298
struct AllocStat
309
{
31-
MonotoneStat objects_allocated{};
32-
MonotoneStat objects_deallocated{};
33-
MonotoneStat slabs_allocated{};
34-
MonotoneStat slabs_deallocated{};
10+
MonotoneLocalStat objects_allocated{};
11+
MonotoneLocalStat objects_deallocated{};
12+
MonotoneLocalStat slabs_allocated{};
13+
MonotoneLocalStat slabs_deallocated{};
3514
};
3615

3716
class AllocStats

src/snmalloc/mem/corealloc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -558,7 +558,7 @@ namespace snmalloc
558558
}
559559
else
560560
{
561-
need_post = attached_cache->remote_dealloc_cache.reserve_space(entry);
561+
need_post |= attached_cache->remote_dealloc_cache.reserve_space(entry);
562562
attached_cache->remote_dealloc_cache
563563
.template dealloc<sizeof(CoreAllocator)>(
564564
entry.get_remote()->trunc_id(), p.as_void());

src/test/perf/churn/churn.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,13 @@ int main()
99
std::vector<std::thread> threads;
1010
std::atomic<size_t> running;
1111
snmalloc::Stat requests;
12+
std::atomic<bool> done{false};
1213

1314
for (size_t i = 0; i < 16; i++)
1415
{
15-
std::thread([&running, &requests]() {
16+
threads.push_back(std::thread([&running, &requests, &done]() {
1617
std::queue<size_t*> q;
17-
while (true)
18+
while (!done)
1819
{
1920
snmalloc::ScopedAllocator alloc;
2021
running++;
@@ -54,7 +55,7 @@ int main()
5455
running--;
5556
std::this_thread::sleep_for(std::chrono::microseconds(rand() % 2000));
5657
}
57-
}).detach();
58+
}));
5859
}
5960

6061
std::thread([&requests]() {
@@ -84,5 +85,10 @@ int main()
8485
}
8586
}).join();
8687

88+
done = true;
89+
90+
for (auto& t : threads)
91+
t.join();
92+
8793
return 0;
8894
}

0 commit comments

Comments
 (0)