[QUEUED scylladb next] utils/logalloc: introduce segment_store_backend

3 views
Skip to first unread message

Commit Bot

<bot@cloudius-systems.com>
unread,
Sep 20, 2022, 5:59:51 AM9/20/22
to scylladb-dev@googlegroups.com, Botond Dénes
From: Botond Dénes <bde...@scylladb.com>
Committer: Botond Dénes <bde...@scylladb.com>
Branch: next

utils/logalloc: introduce segment_store_backend

We want to make it possible to select the segment-store to be used for
LSA -- the seastar allocator based one or the standard allocator based
on -- at runtime. Currently this choice is made at compile time via
preprocessor switches.
The current standard memory based store is specialized for debug build,
we want something more similar to the seastar standard memory allocator
based one. So we introduce a segment store backend for the current
seastar allocator based store, which abstracts how the backing memory
for all segments is allocated/freed, while keeping the segment <-> index
mapping common. In the next patches we will rebase the current seastar
allocator based segment store on this backend and later introduce
another backend for standard allocator, targeted for release builds.

---
diff --git a/utils/logalloc.cc b/utils/logalloc.cc
--- a/utils/logalloc.cc
+++ b/utils/logalloc.cc
@@ -693,6 +693,53 @@ struct segment_descriptor : public log_heap_hook<segment_descriptor_hist_options

using segment_descriptor_hist = log_heap<segment_descriptor, segment_descriptor_hist_options>;

+class segment_store_backend {
+protected:
+ memory::memory_layout _layout;
+ // Whether freeing segments actually increases availability of non-lsa memory.
+ bool _freed_segment_increases_general_memory_availability;
+ // Aligned (to segment::size) address of the first segment.
+ uintptr_t _segments_base;
+
+public:
+ explicit segment_store_backend(memory::memory_layout layout, bool freed_segment_increases_general_memory_availability) noexcept
+ : _layout(layout)
+ , _freed_segment_increases_general_memory_availability(freed_segment_increases_general_memory_availability)
+ , _segments_base(align_up(_layout.start, static_cast<uintptr_t>(segment::size)))
+ { }
+ memory::memory_layout memory_layout() const noexcept { return _layout; }
+ uintptr_t segments_base() const noexcept { return _segments_base; }
+ virtual void* alloc_segment_memory() noexcept = 0;
+ virtual void free_segment_memory(void* seg) noexcept = 0;
+ virtual size_t free_memory() const noexcept = 0;
+ bool can_allocate_more_segments(size_t non_lsa_reserve) const noexcept {
+ if (_freed_segment_increases_general_memory_availability) {
+ return free_memory() >= non_lsa_reserve + segment::size;
+ } else {
+ return free_memory() >= segment::size;
+ }
+ }
+};
+
+// Segments are allocated from the seastar allocator.
+// The entire memory area of the local shard is used as a segment store, i.e.
+// segments are allocated from the same memory area regular objeces are.
+class seastar_memory_segment_store_backend : public segment_store_backend {
+public:
+ seastar_memory_segment_store_backend()
+ : segment_store_backend(memory::get_memory_layout(), true)
+ { }
+ virtual void* alloc_segment_memory() noexcept override {
+ return aligned_alloc(segment::size, segment::size);
+ }
+ virtual void free_segment_memory(void* seg) noexcept override {
+ ::free(seg);
+ }
+ virtual size_t free_memory() const noexcept override {
+ return memory::stats().free_memory();
+ }
+};
+
#ifndef SEASTAR_DEFAULT_ALLOCATOR
class segment_store {
memory::memory_layout _layout;

Commit Bot

<bot@cloudius-systems.com>
unread,
Sep 21, 2022, 12:25:05 PM9/21/22
to scylladb-dev@googlegroups.com, Botond Dénes
From: Botond Dénes <bde...@scylladb.com>
Committer: Botond Dénes <bde...@scylladb.com>
Branch: master
Reply all
Reply to author
Forward
0 new messages