Commit Graph

43 Commits

Author SHA1 Message Date
Tomasz Grabiec
53caf5ecca lsa: Fix segment heap corruption
The segment heap is a max-heap, with sparser segments on the top. When
we free from a segment its occupancy is decreased, but its position in
the heap increases.

This bug caused that we picked up segments for compaction in the wrong
order. In extreme cases this can lead to a livelock, in some cases may
just increase compaction latency.
2015-09-10 17:20:04 +03:00
Avi Kivity
6d0a2b5075 logalloc: don't invalidate merged region
A region being merged can still be in use; but after merging, compaction_lock
and the reclaim counter will no longer work.  This can lead to
use-after-compact-without-re-lookup errors.

Fix by making the source region be the same as the target region; they
will share compaction locks and reclaim counters, so lookup avoidance
will still work correctly.

Fixes #286.
2015-09-08 08:55:44 +02:00
Tomasz Grabiec
fecc87e601 lsa: stub allocation_section with default allocator
memory::stats() always returns 0 as free memory which confuses
guard::enter().
2015-09-07 17:23:02 +02:00
Paweł Dziepak
03f5827570 logalloc: add missing methods to DEFAULT_ALLOCATOR version
Signed-off-by: Paweł Dziepak <pdziepak@cloudius-systems.com>
2015-09-07 16:59:27 +02:00
Tomasz Grabiec
3b441416fa lsa: Make segment size publicly accessible
Some tests depend on segment size.
2015-09-06 21:25:44 +02:00
Tomasz Grabiec
c82325a76c lsa: Make region evictor signal forward progress
In some cases region may be in a state where it is not empty and
nothing could be evicted from it. For example when creating the first
entry, reclaimer may get invoked during creation before it gets
linked. We therefore can't rely on emptiness as a stop condition for
reclamation, the evction function shall signal us if it made forward
progress.
2015-09-06 21:25:44 +02:00
Tomasz Grabiec
94f0db933f lsa: Fix typo in the word 'emergency' 2015-09-06 21:24:59 +02:00
Tomasz Grabiec
200562abe7 lsa: Reclaim over-max segments from segment pool reserve 2015-09-06 21:24:59 +02:00
Tomasz Grabiec
d022a1a4a3 lsa: Introduce allocating_section
Related to #259. In some cases we need to allocate memory and hold
reclaim lock at the same time. If that region holds most of the
reclaimable memory, allocations inside that code section may
fail. allocating_section is a work-around of the problem. It learns
how big reserves shold be from past execution of critical section and
tries to ensure proper reserves before entering the section.
2015-09-06 21:24:59 +02:00
Tomasz Grabiec
3caad2294b lsa: Tolerate empty segments when region is destroyed
Some times we may close an empty active segment, if all data in it was
evicted. Normally segments are removed as soon as the last object in
it is freed, but if the segment is already empty when closed, noone is
supposed to call free on it. Such segments would be quickly reclaimed
during compaction, but it's possible that we will destroy the region
before they're reclaimed by compaction. Currently we would fail on an
assertion which checks that there are no segments. This change fixes
the problem by handling empty closed segments when region is
destroyed.
2015-09-06 21:24:59 +02:00
Tomasz Grabiec
c37aa73051 lsa: Drop alignment requirement from segment 2015-09-06 21:24:59 +02:00
Tomasz Grabiec
2c1536b5a7 lsa: Make free() path noexcept
Memory releasing is invoked from destructors so should not throw. As a
consequence it should not allocate memory, so emergency segment pool
was switched from std::deque<> to an alloc-free intrusive stack.
2015-09-06 21:24:59 +02:00
Tomasz Grabiec
fa8d530cc2 lsa: Add ability to trace reclaiming latency 2015-09-06 21:24:58 +02:00
Tomasz Grabiec
870e9e5729 lsa: Replace compaction_lock with broader reclaim_lock
Disabling compaction of a region is currently done in order to keep
the references valid. But disabling only compaction is not enough, we
also need to disable eviction, as it also invalidates
references. Rather than introducing another type of lock, compaction
and eviction are controlled together, generalized as "reclaiming"
(hence the reclaim_lock).
2015-09-01 17:29:04 +03:00
Tomasz Grabiec
48569651ea lsa: Fix calculation of bytes.non_lsa_used_space 2015-09-01 17:29:03 +03:00
Tomasz Grabiec
d20fae96a2 lsa: Make reclaimer run synchronously with allocations
The goal is to make allocation less likely to fail. With async
reclaimer there is an implicit bound on the amount of memory that can
be allocated between deferring points. This bound is difficult to
enforce though. Sync reclaimer lifts this limitation off.

Also, allocations which could not be satisfied before because of
fragmentation now will have higher chances of succeeding, although
depending on how much memory is fragmented, that could involve
evicting a lot of segments from cache, so we should still avoid them.

Downside of sync reclaiming is that now references into regions may be
invalidated not only across deferring points but at any allocation
site. compaction_lock can be used to pin data, preferably just
temporarily.
2015-08-31 21:50:18 +02:00
Tomasz Grabiec
42dce17c82 lsa: Fix documentation for eviction functions 2015-08-31 21:50:17 +02:00
Avi Kivity
203b349722 Merge seastar upstream
* seastar 5176352...68fee6c (1):
  > Merge "Memory reclamation infrastructure follow-up" from Tomasz

Adjusted logalloc::tracker's reclaimer to fit new API
2015-08-31 20:01:07 +03:00
Tomasz Grabiec
110a55886c lsa: Introduce region::compaction_counter() 2015-08-31 13:58:42 +02:00
Tomasz Grabiec
9ad3dbe592 lsa: Add region::compaction_enabled() 2015-08-31 13:58:42 +02:00
Tomasz Grabiec
048387782a lsa: Rename region::set_compactible() to set_compaction_enabled()
To avoid confusion with region_impl::is_compactible() when the getter
is added.
2015-08-31 13:58:42 +02:00
Avi Kivity
0617aecb62 lsa: downgrade "no compactible pool" warning to trace
It's a fairly standard condition.
2015-08-24 17:26:48 +02:00
Avi Kivity
77b3212c88 lsa: provide a fallback during normal allocation
Instead of failing normal allocations when the seastar allocator cannot
allocate a segment, provide a generous reserve.  An allocation failure
will now be satisified from the reserve, but it will still trigger a
reclaim.  This allows hiding low-memory conditions from the user.
2015-08-23 16:38:04 +03:00
Avi Kivity
f531f36a44 lsa: fix types in logs 2015-08-20 15:29:08 +03:00
Avi Kivity
9012f991bf logalloc: really allow dipping into the emergency pool during reclaim
The RAII wrapper for the emergency pool was invoked without an object,
and so had no effect.
2015-08-20 12:10:03 +03:00
Avi Kivity
9ed2bbb25c lsa: introduce region_group
A region_group is a nestable group of regions, for cumulative statistics
purposes.
2015-08-19 19:36:40 +03:00
Avi Kivity
71aad57ca8 lsa: make region::impl a top-level class
Makes using forward declarations possible.
2015-08-19 14:43:17 +03:00
Avi Kivity
932ddc328c logalloc: optimize current_allocation_strategy()
This heavily used function shows up in many places in the profile (as part
of other functions), so it's worth optimizing by eliminating the special
case for the standard allocator.  Use a statically allocated object instead.

(a non-thread-local object is fine since it has no data members).
2015-08-17 16:51:10 +03:00
Avi Kivity
5a061fe66e lsa: increase segment size
While #152 is still open, we need to allow for moderately sized allocations
to succeed.  Extend the segment size to 256k, which allows for threads to
be allocated.

Fixes #151.
2015-08-16 19:26:59 +03:00
Avi Kivity
ecc3ccc716 lsa: emergency segment reserve for compaction
To free memory, we need to allocate memory.  In lsa compaction, we convert
N segments with average occupancy of (N-1)/N into N-1 new segments.  However,
to do that, we need to allocate segments, which we may not be able to do
due to the low memory condition which caused us to compact anyway.

Fix by introducing a segment reserve, which we normally try to ensure is
full.  During low memory conditions, we temporarily allow allocating from
the emergency reserve.
2015-08-12 11:29:09 +03:00
Tomasz Grabiec
ef549ae5a5 lsa: Reclaim space from evictable regions incrementally
When LSA reclaimer cannot reclaim more space by compaction, it
will reclaim data by evicting from evictable regions.

Currently the only evictable region is the one owned by the row cache.
2015-08-08 09:59:24 +02:00
Tomasz Grabiec
a095b39091 lsa: Don't leak empty _active segment in merge() 2015-08-08 09:59:24 +02:00
Tomasz Grabiec
5b5c0038e6 lsa: Don't allocate aligned segments
Requiring alignment means that there must be 64K of contiguous space
to allocate each 32K segment. When memory is fragmented, we may fail
to allocate such segment, even though there's plenty of free space.

This especially hurts forward progress of compaction, which frees
segments randomly and relies on the fact that freeing a segment will
make it available to the next segment request.
2015-08-07 22:13:17 +02:00
Tomasz Grabiec
64bd4bee94 lsa: Log segment closing and releasing on trace level 2015-08-07 22:06:15 +02:00
Tomasz Grabiec
02ff31b815 lsa: Reduce amount of calls to descriptor() in free() 2015-08-07 22:05:53 +02:00
Tomasz Grabiec
7b7b6dd301 lsa: Don't initialize segments 2015-08-06 18:56:48 +02:00
Tomasz Grabiec
d60c04542a lsa: Consistently use segment::at() to access data 2015-08-06 18:56:48 +02:00
Tomasz Grabiec
112385455e lsa: Drop unnecessary use of __int128_t in reclaim() 2015-08-06 18:56:48 +02:00
Tomasz Grabiec
6ae0747fe5 lsa: Use size_t for sizes 2015-08-06 18:40:06 +02:00
Tomasz Grabiec
f5fdaa61a2 lsa: Avoid overflow in reclaim() 2015-08-06 16:50:15 +02:00
Tomasz Grabiec
4389bc748e lsa: Fix target calculation in reclaim() 2015-08-06 16:19:48 +02:00
Tomasz Grabiec
df6f0c35df utils: lsa: Add reclaimer hook which compacts regions 2015-08-06 14:05:15 +02:00
Tomasz Grabiec
5a9e296803 utils: lsa: Introduce log-structured allocator 2015-08-06 14:05:15 +02:00