-
Notifications
You must be signed in to change notification settings - Fork 263
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
Add combined locking support for MMContainer #182
Conversation
f507394
to
212094a
Compare
I was reading your comment in #172 (comment). In single-tier version, without the further change, would using combined_locking for iterator cause reduction in eviction success rate and why? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall this looks good. Once you address the qestions I will import it for internal review.
cachelib/allocator/MM2Q.h
Outdated
@@ -68,6 +68,7 @@ class MM2Q { | |||
enum LruType { Warm, WarmTail, Hot, Cold, ColdTail, NumTypes }; | |||
|
|||
// Config class for MM2Q | |||
// TODO: implement support for useCombinedLockForIterators |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the code you have, implementing this for 2Q is just adding the if statement you have for MMLRU right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding the if statement + extending the MM2Q config
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. I just realized that TinyLFU uses a spin lock, which does not support combined locking, so there is no option to enable it.
@@ -343,5 +348,26 @@ size_t MMTypeTest<MMType>::getListSize(const Container& c, | |||
} | |||
throw std::invalid_argument("LruType not existing"); | |||
} | |||
|
|||
template <typename MMType> | |||
void MMTypeTest<MMType>::verifyIterationVariants(Container& c) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment on this function.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
There are two issues with using
The second issue is actually what started our efforts to optimize Lower eviction rate in PR 132 was due to higher chance of collision: after we marked the item and exited the critical section, someone else could have increased the ref count on that item causing us to fail. In the new design, this cannot happen because after item is marked, it's inaccessible by others. |
212094a
to
8b6acff
Compare
@haowu14 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
cachelib/allocator/MMLru.h
Outdated
@@ -195,6 +200,9 @@ class MMLru { | |||
// lruInsertionPointSpec = 2, we insert at a point 1/4th from tail | |||
uint8_t lruInsertionPointSpec{0}; | |||
|
|||
// Whether to use combined locking for withEvictionIterator. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move this after mmReconfigureIntervalSecs
. Meta internal build failed on the initialization order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
8b6acff
to
5ade8c0
Compare
@igchor has updated the pull request. You must reimport the pull request before landing. |
@haowu14 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@@ -213,7 +216,8 @@ class MM2Q { | |||
bool rebalanceOnRecordAccs, | |||
size_t hotPercent, | |||
size_t coldPercent, | |||
uint32_t mmReconfigureInterval) | |||
uint32_t mmReconfigureInterval, | |||
bool useCombinedLockForIterators) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make this optional.
The way we typically do is create a new constructor with all the parameters while keeping the constructor of Config(uint32_t time, double ratio, bool updateOnW, bool updateOnR, bool tryLockU, bool rebalanceOnRecordAccs, size_t hotPercent, size_t coldPercent, uint32_t mmReconfigureInterval)
And have it call the constructor with all the parameters with default value.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, done.
} | ||
|
||
size_t i = 0; | ||
c.withEvictionIterator([&c, &nodes, &i](auto&& iter) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't have to capture c
here since it is not used inside.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
5ade8c0
to
0e9cbdf
Compare
@igchor has updated the pull request. You must reimport the pull request before landing. |
@haowu14 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
through withEvictionIterator function. Also, expose config option to enable and disable combined locking. withEvictionIterator is implemented as en extra function, getEvictionIterator() is still there and it's behavior hasn't changed.
cachelib/allocator/MMTinyLFU.h
Outdated
@@ -456,6 +444,40 @@ class MMTinyLFU { | |||
// Tiny and main cache iterators | |||
ListIterator tIter_; | |||
ListIterator mIter_; | |||
}; | |||
|
|||
class LockedIterator : public Iterator { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@igchor: is this necessary? TinyLFU doesn't support combined locking. It seems like we can just rename Iterator to LockIterator and avoid introducing this new code here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, you are right, I forgot to revert these changes after realizing TinyLFU does not support combined locking. Done.
0e9cbdf
to
3ad50fa
Compare
@igchor has updated the pull request. You must reimport the pull request before landing. |
@haowu14 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
@haowu14 has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
through withEvictionIterator function.
Also, expose the config option to enable and disable combined locking.
withEvictionIterator is implemented as an extra function, getEvictionIterator() is still there and it's behavior hasn't changed.
This is a subset of changes from: #172