Skip to content

Combined locking with exclusive bit #38

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Dec 2, 2022
Merged

Conversation

byrnedj
Copy link

@byrnedj byrnedj commented Nov 21, 2022

For leader and follower - I see about 20% performance improvement in throughput, for follower it is about 10% improvement.


This change is Reviewable

igchor and others added 4 commits November 7, 2022 11:12
(findEviction and evictForSlabRelease) but not for
item movement. moveForSlabRelease relies on markMoving().

Only allow to mark item as exclusive if ref count
is 0. This ensures that after item is marked eviction
cannot fail. This makes it possible to return NULL handle
immediately from find if item is marked as exclusive.

markMoving() does have those restrictions and still allows
readers to obtain a handle to a moving item.

Also, add option to use combined locking for MMContainer
iteration.

Pass item ref to NavyCache::put
and just return the actual ref count
@byrnedj byrnedj requested a review from igchor November 21, 2022 12:54
@igchor igchor force-pushed the cs_part_2 branch 2 times, most recently from 8e33d00 to d351b6d Compare November 22, 2022 00:36
This simplifies moving code a lot.
We don't need to worry about any failure other
than allocation failure since item is protected
from any readers (and by extension, removes).
@igchor igchor force-pushed the cs_part_2 branch 2 times, most recently from 3e6ec39 to a30f2ac Compare November 22, 2022 17:21
Copy link
Member

@igchor igchor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 20 files at r2.
Reviewable status: 0 of 29 files reviewed, 2 unresolved discussions (waiting on @byrnedj)


cachelib/allocator/CacheAllocator.h line 1968 at r3 (raw file):

  // exposed for the background evictor to iterate through the memory and evict
  // in batch. This should improve insertion path for tiered memory config
  size_t traverseAndEvictItems(unsigned int tid, unsigned int pid, unsigned int cid, size_t batch) {

this (and promotion function) should be adjusted and use similar logic as in findEviction (mark moving first, then exclusive if needed)


cachelib/allocator/CacheAllocator-inl.h line 3260 at r3 (raw file):

      token = createPutToken(*evicted);
      if (evicted->markExclusiveWhenMoving()) {
        unlinkItemExclusive(*evicted);

I think we need to wakeUp any waiters here as well (similarly to findEviction).
We should probably do this only for mutli-tier case. And for single-tier we might allow readers for moving items (pass false to incRef() call in acquire for single tier)

Copy link
Author

@byrnedj byrnedj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 29 files reviewed, 2 unresolved discussions (waiting on @igchor)


cachelib/allocator/CacheAllocator.h line 1968 at r3 (raw file):

Previously, igchor (Igor Chorążewicz) wrote…

this (and promotion function) should be adjusted and use similar logic as in findEviction (mark moving first, then exclusive if needed)

Done.


cachelib/allocator/CacheAllocator-inl.h line 3260 at r3 (raw file):

Previously, igchor (Igor Chorążewicz) wrote…

I think we need to wakeUp any waiters here as well (similarly to findEviction).
We should probably do this only for mutli-tier case. And for single-tier we might allow readers for moving items (pass false to incRef() call in acquire for single tier)

Done

Copy link
Member

@igchor igchor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 2 of 2 files at r4.
Reviewable status: 2 of 29 files reviewed, 2 unresolved discussions (waiting on @byrnedj)


cachelib/allocator/CacheAllocator-inl.h line 3260 at r3 (raw file):

Previously, byrnedj (Daniel Byrne) wrote…

Done

How about chained items? Will you wakeUpWaiters for them then? Perhpas just add some TODO now?


cachelib/allocator/CacheAllocator-inl.h line 1040 at r4 (raw file):

  SCOPE_FAIL { stats_.numRefcountOverflow.inc(); };

  auto failIfMoving = getNumTiers() > 1 ? true : false;

nit: you can drop the ? true : false part ;d


cachelib/allocator/CacheAllocator-inl.h line 1362 at r4 (raw file):

  // Adding the item to mmContainer has to succeed since no one can remove the item
  auto& newContainer = getMMContainer(*newItemHdl);
  auto mmContainerAdded = newContainer.add(*newItemHdl);

Hm, I think this should still be replace after all. Then, you don't nee to call removeFromMMContainer in traverseAndPromoteItems

…during

eviction:
-if marked moving, then another thread can still acquire handle to the item
(because in single tier we don't have wait context, an item can acquire handle)
-then we will later fail to markExclusiveWhenMoving during the eviction process
 because there is an outstanding handle

-> made it so that in single tier (or when evicting from last tier) we always just
   mark it as exclusive so that there will be no threads that can get a valid handle.
Copy link
Author

@byrnedj byrnedj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 of 29 files reviewed, 2 unresolved discussions (waiting on @igchor)


cachelib/allocator/CacheAllocator-inl.h line 3260 at r3 (raw file):

Previously, igchor (Igor Chorążewicz) wrote…

How about chained items? Will you wakeUpWaiters for them then? Perhpas just add some TODO now?

Added for now - chained item PR will address any additional logic.


cachelib/allocator/CacheAllocator-inl.h line 1040 at r4 (raw file):

Previously, igchor (Igor Chorążewicz) wrote…

nit: you can drop the ? true : false part ;d

done


cachelib/allocator/CacheAllocator-inl.h line 1362 at r4 (raw file):

Previously, igchor (Igor Chorążewicz) wrote…

Hm, I think this should still be replace after all. Then, you don't nee to call removeFromMMContainer in traverseAndPromoteItems

I am not sure because replaceInMMContainer will only replace if oldItem exists in mmContainer due to the short circuit evaluation. But here we have already removed the oldItem from mmContainer in most cases (expect for promotion case).

Copy link
Member

@igchor igchor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 1 of 29 files reviewed, 1 unresolved discussion (waiting on @byrnedj)


cachelib/allocator/CacheAllocator.h line 2083 at r6 (raw file):

      } else {
	 //we failed to allocate a new item, this item is no  longer moving
	candidate->unmarkMoving();

I think you need to handle possible ref==0 case here as well.


cachelib/allocator/CacheAllocator-inl.h line 1362 at r4 (raw file):

Previously, byrnedj (Daniel Byrne) wrote…

I am not sure because replaceInMMContainer will only replace if oldItem exists in mmContainer due to the short circuit evaluation. But here we have already removed the oldItem from mmContainer in most cases (expect for promotion case).

Ok, I see, but we still need to make sure the oldItem is removed from the MMContainer. Perhaps some assert in findEviction and BGEvciction then? And I'm not sure if ChainedItem support won't require any changes

Copy link
Author

@byrnedj byrnedj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewable status: 0 of 30 files reviewed, 1 unresolved discussion (waiting on @igchor)


cachelib/allocator/CacheAllocator.h line 2083 at r6 (raw file):

Previously, igchor (Igor Chorążewicz) wrote…

I think you need to handle possible ref==0 case here as well.

Done.


cachelib/allocator/CacheAllocator-inl.h line 1362 at r4 (raw file):

Previously, igchor (Igor Chorążewicz) wrote…

Ok, I see, but we still need to make sure the oldItem is removed from the MMContainer. Perhaps some assert in findEviction and BGEvciction then? And I'm not sure if ChainedItem support won't require any changes

remove with the iterator returns void - removedLock in mmContainer does not fail so I think we can assume that it succeeded.

Copy link
Member

@igchor igchor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewable status: 0 of 30 files reviewed, all discussions resolved

@igchor igchor merged commit 7aed493 into intel:develop Dec 2, 2022
byrnedj added a commit that referenced this pull request Mar 3, 2023
- transparent item movement
- multi-tier combined locking with exclusive bit (#38)
with refactored incRef to support returning the result of
markMoving (fail if already moving or exclusvie bit is set) option.
- add tests (updated for numa bindings - post combined locking)
for transparent item movement
vinser52 pushed a commit that referenced this pull request Jul 17, 2023
- transparent item movement
- multi-tier combined locking with exclusive bit (#38)
with refactored incRef to support returning the result of
markMoving (fail if already moving or exclusvie bit is set) option.
- add tests (updated for numa bindings - post combined locking)
for transparent item movement
byrnedj pushed a commit that referenced this pull request Jul 23, 2023
Return a sum of sizes of each tier instead of just 1st tier's size.
byrnedj pushed a commit that referenced this pull request Jul 23, 2023
Return a sum of sizes of each tier instead of just 1st tier's size.
byrnedj added a commit that referenced this pull request Jul 23, 2023
- transparent item movement
- multi-tier combined locking with exclusive bit (#38)
with refactored incRef to support returning the result of
markMoving (fail if already moving or exclusvie bit is set) option.
- add tests (updated for numa bindings - post combined locking)
for transparent item movement
vinser52 pushed a commit that referenced this pull request Feb 29, 2024
- transparent item movement
- multi-tier combined locking with exclusive bit (#38)
with refactored incRef to support returning the result of
markMoving (fail if already moving or exclusvie bit is set) option.
- add tests (updated for numa bindings - post combined locking)
for transparent item movement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants