Skip to content

Commit f6254d6

Browse files
committed
Fixes
1 parent 30fcc22 commit f6254d6

File tree

3 files changed

+50
-9
lines changed

3 files changed

+50
-9
lines changed

src/backend/backend.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ namespace snmalloc
129129
#if defined(OPEN_ENCLAVE)
130130
// Single global buddy allocator is used on open enclave due to
131131
// the limited address space.
132-
using GlobalR = GlobalRange<StatsR<SmallBuddyRange<
133-
LargeBuddyRange<EmptyRange, bits::BITS - 1, bits::BITS - 1, Pagemap>>>>;
132+
using StatsR = StatsR<SmallBuddyRange<
133+
LargeBuddyRange<EmptyRange, bits::BITS - 1, bits::BITS - 1, Pagemap>>>;
134+
using GlobalR = GlobalRange<StatsR>;
134135
using ObjectRange = GlobalR;
135136
using GlobalMetaRange = ObjectRange;
136137
#else
@@ -280,16 +281,15 @@ namespace snmalloc
280281
auto p = local_state.object_range->alloc_range(size);
281282

282283
#ifdef SNMALLOC_TRACING
283-
std::cout << "Alloc chunk: " << p.unsafe_ptr() << " (" << size << ")"
284-
<< std::endl;
284+
message<1024>("Alloc chunk: {} ({})", p.unsafe_ptr(), size);
285285
#endif
286286
if (p == nullptr)
287287
{
288288
local_state.get_meta_range()->dealloc_range(
289289
meta_cap, PAGEMAP_METADATA_STRUCT_SIZE);
290290
errno = ENOMEM;
291291
#ifdef SNMALLOC_TRACING
292-
std::cout << "Out of memory" << std::endl;
292+
message<1024>("Out of memory");
293293
#endif
294294
return {p, nullptr};
295295
}

src/backend/decayrange.h

+34-3
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ namespace snmalloc
4848
auto curr = *this;
4949
while (!curr.is_empty())
5050
{
51-
auto next = get_next();
51+
auto next = curr.get_next();
5252

5353
f(curr.get_capability());
5454

@@ -183,8 +183,7 @@ namespace snmalloc
183183
ParentRange::ConcurrencySafe,
184184
"Parent must be concurrency safe, as dealloc_range is called here on "
185185
"potentially another thread's state.");
186-
auto new_epoch =
187-
(epoch + 1) % NUM_EPOCHS;
186+
auto new_epoch = (epoch + 1) % NUM_EPOCHS;
188187
// Flush old index for all threads.
189188
auto curr = all_local.load(std::memory_order_acquire);
190189
while (curr != nullptr)
@@ -211,6 +210,9 @@ namespace snmalloc
211210
*/
212211
static void process(PalTimerObject*)
213212
{
213+
#ifdef SNMALLOC_TRACING
214+
message<1024>("DecayRange::handle_decay_tick timer");
215+
#endif
214216
handle_decay_tick();
215217
}
216218

@@ -256,7 +258,14 @@ namespace snmalloc
256258
auto p = chunk_stack[slab_sizeclass][(epoch - e) % NUM_EPOCHS].pop();
257259

258260
if (p != nullptr)
261+
{
262+
#ifdef SNMALLOC_TRACING
263+
message<1024>(
264+
"DecayRange::alloc_range: returning from local cache: {} on {}",
265+
address_cast(p), this);
266+
#endif
259267
return p;
268+
}
260269
}
261270
}
262271

@@ -272,14 +281,31 @@ namespace snmalloc
272281
result = parent->alloc_range(size);
273282
if (result != nullptr)
274283
{
284+
#ifdef SNMALLOC_TRACING
285+
message<1024>(
286+
"DecayRange::alloc_range: returning from parent: {} on {}",
287+
address_cast(result), this);
288+
#endif
275289
return result;
276290
}
277291

278292
// We have run out of memory.
279293
// Try to free some memory to the parent.
294+
#ifdef SNMALLOC_TRACING
295+
message<1024>("DecayRange::handle_decay_tick OOM");
296+
#endif
280297
handle_decay_tick();
281298
}
282299

300+
// Last try.
301+
result = parent->alloc_range(size);
302+
303+
#ifdef SNMALLOC_TRACING
304+
message<1024>(
305+
"DecayRange::alloc_range: returning from parent last try: {} on {}",
306+
address_cast(result), this);
307+
#endif
308+
283309
return result;
284310
}
285311

@@ -310,6 +336,11 @@ namespace snmalloc
310336

311337
auto slab_sizeclass = bits::next_pow2_bits(size) - MIN_CHUNK_BITS;
312338
// Add to local cache.
339+
#ifdef SNMALLOC_TRACING
340+
message<1024>(
341+
"DecayRange::dealloc_range: returning to local cache: {} on {}",
342+
address_cast(base), this);
343+
#endif
313344
chunk_stack[slab_sizeclass][epoch].push(base);
314345
}
315346
};

src/pal/pal.h

+11-1
Original file line numberDiff line numberDiff line change
@@ -168,10 +168,20 @@ namespace snmalloc
168168
Pal::error(msg.get_message());
169169
}
170170

171+
static inline thread_local size_t tid {0};
172+
static inline std::atomic<size_t> tid_source {1};
173+
171174
template<size_t BufferSize, typename... Args>
172175
inline void message(Args... args)
173176
{
177+
if (tid == 0)
178+
{
179+
tid = tid_source++;
180+
}
181+
174182
MessageBuilder<BufferSize> msg{std::forward<Args>(args)...};
175-
Pal::message(msg.get_message());
183+
MessageBuilder<BufferSize> msg_tid{"{}: {}", tid, msg.get_message()};
184+
185+
Pal::message(msg_tid.get_message());
176186
}
177187
} // namespace snmalloc

0 commit comments

Comments
 (0)