Skip to content

Commit b49a42d

Browse files
authored
Code Quality - inlining (#792)
* Inline lambdas for better codegen * Disable PreventFork in the freelist queue
1 parent 71e205f commit b49a42d

File tree

3 files changed

+18
-14
lines changed

3 files changed

+18
-14
lines changed

src/snmalloc/mem/corealloc.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -642,7 +642,7 @@ namespace snmalloc
642642
Allocator* alloc,
643643
smallsizeclass_t sizeclass,
644644
freelist::Iter<>* fl,
645-
size_t size) -> void* {
645+
size_t size) SNMALLOC_FAST_PATH_LAMBDA {
646646
return alloc->small_refill<Conts, CheckInit>(sizeclass, *fl, size);
647647
},
648648
this,
@@ -673,9 +673,9 @@ namespace snmalloc
673673
}
674674

675675
return self->handle_message_queue(
676-
[](Allocator* self, size_t size) -> void* {
676+
[](Allocator* self, size_t size) SNMALLOC_FAST_PATH_LAMBDA {
677677
return CheckInit::check_init(
678-
[self, size]() {
678+
[self, size]() SNMALLOC_FAST_PATH_LAMBDA {
679679
if (size > bits::one_at_bit(bits::BITS - 1))
680680
{
681681
// Cannot allocate something that is more that half the size of
@@ -728,7 +728,7 @@ namespace snmalloc
728728

729729
return Conts::failure(size);
730730
},
731-
[](Allocator* a, size_t size) {
731+
[](Allocator* a, size_t size) SNMALLOC_FAST_PATH_LAMBDA {
732732
return alloc_not_small<Conts, CheckInitNoOp>(size, a);
733733
},
734734
size);
@@ -812,7 +812,7 @@ namespace snmalloc
812812
smallsizeclass_t sizeclass, freelist::Iter<>& fast_free_list, size_t size)
813813
{
814814
return CheckInit::check_init(
815-
[this, size, sizeclass, &fast_free_list]() -> void* {
815+
[this, size, sizeclass, &fast_free_list]() SNMALLOC_FAST_PATH_LAMBDA {
816816
size_t rsize = sizeclass_to_size(sizeclass);
817817

818818
// No existing free list get a new slab.
@@ -862,7 +862,7 @@ namespace snmalloc
862862
auto r = finish_alloc<Conts>(p, size);
863863
return ticker.check_tick(r);
864864
},
865-
[](Allocator* a, size_t size) {
865+
[](Allocator* a, size_t size) SNMALLOC_FAST_PATH_LAMBDA {
866866
return a->small_alloc<Conts, CheckInitNoOp>(size);
867867
},
868868
size);

src/snmalloc/mem/freelist_queue.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,17 @@ namespace snmalloc
104104
invariant();
105105
freelist::Object::atomic_store_null(last, Key, Key_tweak);
106106

107-
// The following non-linearisable effect is normally benign,
108-
// but could lead to a remote list become completely detached
109-
// during a fork in a multi-threaded process. This would lead
110-
// to a memory leak, which is probably the least of your problems
111-
// if you forked in during a deallocation.
112-
PreventFork pf;
113-
snmalloc::UNUSED(pf);
107+
// // The following non-linearisable effect is normally benign,
108+
// // but could lead to a remote list become completely detached
109+
// // during a fork in a multi-threaded process. This would lead
110+
// // to a memory leak, which is probably the least of your problems
111+
// // if you forked in during a deallocation. We can prevent this
112+
// // with the following code, but it is not currently enabled as it
113+
// // has negative performance impact.
114+
// // An alternative would be to reset the queue on the child postfork
115+
// // handler to ensure that the queue has not been blackholed.
116+
// PreventFork pf;
117+
// snmalloc::UNUSED(pf);
114118

115119
// Exchange needs to be acq_rel.
116120
// * It needs to be a release, so nullptr in next is visible.

src/snmalloc/mem/remotecache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ namespace snmalloc
268268
entropy,
269269
[this](
270270
RemoteAllocator::alloc_id_t target_id,
271-
capptr::Alloc<RemoteMessage> msg) {
271+
capptr::Alloc<RemoteMessage> msg) SNMALLOC_FAST_PATH_LAMBDA {
272272
forward<allocator_size>(target_id, msg);
273273
});
274274
}

0 commit comments

Comments
 (0)