Skip to content

[upstream] transparent Item movement #92

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

vinser52
Copy link

@vinser52 vinser52 commented Jul 28, 2023

I was able to extract code changes related to transparent data movements.
No testing was done yet. I just make sure that the code is compiled.

I extracted code almost as-is from develop branch. I will use this PR to discuss possible refactoring - I will put comments to the appropriate code lines.


This change is Reviewable

@vinser52 vinser52 requested review from byrnedj and igchor July 28, 2023 17:41
@vinser52 vinser52 force-pushed the upstream_transparent_move branch from e33e0fb to 14b6829 Compare July 28, 2023 17:45
Copy link
Author

@vinser52 vinser52 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 11 files reviewed, 1 unresolved discussion (waiting on @byrnedj and @igchor)


cachelib/common/Mutex.h line 344 at r1 (raw file):

  using ReadLockHolder = ReadLockHolderType;
  using WriteLockHolder = WriteLockHolderType;
  using LockHolder = std::unique_lock<Lock>;

It looks like a workaround because WriteLockHolderType does not support try_lock.

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.

It would be nice to have some high-level overview of the algorithm in the commit description.

// we rely on moving flag being set (it should block all readers)
XDCHECK_EQ(item.getRefCount(),0);
XDCHECK(item.isMoving());
return item.isMoving();
Copy link
Member

Choose a reason for hiding this comment

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

we can probably just return true here, right? no need to check the isMoving in Release

Copy link
Author

Choose a reason for hiding this comment

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

Yeah. My strategy was to extract code from develop as is and use this PR to discuss excessive XDCHECK. I believe Daniel added them when investigated data race issues.
In that particular case there are two possible simplifications:

  • remove checks and just return item.isMoving();
  • hardcode to always return true and keep checks.


size_t wakeUpWaitersLocked(folly::StringPiece key, WriteHandle&& handle);

class MoveCtx {
Copy link
Member

Choose a reason for hiding this comment

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

nit: This class can probably be implemented in CacheALlocator-inl.h

XDCHECK(item->isChainedItem()
? item->asChainedItem().getParentItem(compressor_).isMoving()
: item->isMoving()) << item->toString() << "\n" << syncItem->toString();
if ( ( item->isChainedItem() &&
Copy link
Member

Choose a reason for hiding this comment

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

When can this happen?

Copy link
Author

@vinser52 vinser52 Aug 16, 2023

Choose a reason for hiding this comment

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

I think just XDCHECK(syncItem->isMoving()); is enough. All other checks are just duplications.

XDCHECK(oldItem.isChainedItem() && oldItem.getRefCount() == 1);
XDCHECK_EQ(0, parentItem->getRefCount());
newItemHdl =
allocateChainedItemInternal(*parentItem, oldItem.getSize());
Copy link
Author

Choose a reason for hiding this comment

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

I think we need to call allocateNewItemForOldItem function for chained items as well. And modify allocateNewItemForOldItem function to work correctly with chained items.

@vinser52 vinser52 force-pushed the upstream_transparent_move branch 2 times, most recently from dcce4be to 955fbe7 Compare August 4, 2023 22:09
@vinser52 vinser52 force-pushed the upstream_transparent_move branch from 3824795 to ba3f5b5 Compare August 14, 2023 12:49
@@ -4841,7 +4841,7 @@ class BaseAllocatorTest : public AllocatorTest<AllocatorT> {

std::memcpy(newItem.getMemory(), oldItem.getMemory(), oldItem.getSize());
++numMoves;
}, {}, 1000000 /* lots of moving tries */);
Copy link
Member

Choose a reason for hiding this comment

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

why change this?

Copy link
Author

Choose a reason for hiding this comment

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

This change just returns the test to the initial state (like in main branch).
@byrnedj increased the number of tries, but after various fixes looks like it is not required anymore.

@vinser52 vinser52 force-pushed the upstream_transparent_move branch 5 times, most recently from c0ecd6d to ab70b7d Compare August 18, 2023 12:49
@vinser52 vinser52 force-pushed the upstream_transparent_move branch 3 times, most recently from 635eb22 to bada673 Compare October 27, 2023 14:15
The new algorithm relies on the moving bit and does not require external
synchronization. Data movement happens transparently for the client: if
the client thread attempts to get a handle for the item being moved it
will get a handle with wait context to wait till the movement is
completed.
@vinser52 vinser52 force-pushed the upstream_transparent_move branch from bada673 to 807dbda Compare October 27, 2023 14:46
@vinser52 vinser52 force-pushed the upstream_transparent_move branch from 807dbda to 3d73cfe Compare November 8, 2023 13:42
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.

3 participants