Skip to content

Conversation

neilalexander
Copy link
Member

@neilalexander neilalexander commented Aug 18, 2025

This PR modifies the write-through cache in the filestore to use elastic pointers. Elastic pointers are weak by default and can be reclaimed by the GC under pressure, but can be strengthened when there are pending writes for a block. Once the flush has completed, we weaken the cache again.

There are now two cache references within each msgBlock:

  • mb.ecache: The elastic pointer, populated when the cache is set up and only reset back to nil either by the GC or when clearCache is called
  • mb.cache: Left as nil by default, populated with a strong reference from mb.ecache when we need to use the cache, and then reset back to nil after we're done with it

This PR replaces and therefore closes #7097.

Signed-off-by: Neil Twigg [email protected]

@neilalexander neilalexander changed the title Elastic pointers in the filestore write-through cache (2.12) Elastic pointers in the filestore write-through cache Aug 18, 2025
@neilalexander neilalexander marked this pull request as ready for review August 18, 2025 15:57
@neilalexander neilalexander requested a review from a team as a code owner August 18, 2025 15:57
@neilalexander neilalexander marked this pull request as draft August 18, 2025 16:31
@neilalexander
Copy link
Member Author

Want to investigate some flaking tests first before review.

Copy link
Member

@derekcollison derekcollison left a comment

Choose a reason for hiding this comment

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

In general looking better. A few concerns around some logic.

// The reference mb.cache shouldn't have changed ordinarily, but
// stash it away into the weak pointer again just in case.
mb.ecache.Set(mb.cache)
mb.cache = nil
Copy link
Member

Choose a reason for hiding this comment

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

We have two levels in the cache, the indexing and the data itself. Both IIRC are under mb.cache but they have different lifetimes under normal operations. This seems to undo that?

Copy link
Member Author

Choose a reason for hiding this comment

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

They're still held in the ecache until it is GC'd (and for that there would need to be no strong references left too), but if that happens, we'll just reload the block and re-index it the next time we need to.

Copy link
Member

Choose a reason for hiding this comment

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

fss is held outside this scope. Not sure if we want this extended to that in a follow on PR or not.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yep, I can look into it as a follow-up for sure.

mbcache.wp = 0
}

mb.ecache.Weaken()
Copy link
Member

Choose a reason for hiding this comment

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

This a no-op if line 5557 excuted?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it would have no effect in that case.

@neilalexander neilalexander force-pushed the neil/fsweak2 branch 3 times, most recently from 55e5157 to ee49624 Compare August 19, 2025 17:19
@neilalexander neilalexander marked this pull request as ready for review August 20, 2025 07:57
"weak"
)

func Make[T any](ptr *T) *Pointer[T] {
Copy link
Member

Choose a reason for hiding this comment

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

Seems this is unused, can it be removed?

// can reuse.
if mb.cacheAlreadyLoaded() {
return
}
Copy link
Member

Choose a reason for hiding this comment

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

mb.cache is initialized below, but then mb.ecache is not set to it?
This would probably lead to the mb.ecache.Strengthen() call not actually doing work.

Copy link
Member

@MauriceVanVeen MauriceVanVeen left a comment

Choose a reason for hiding this comment

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

LGTM

@neilalexander neilalexander merged commit e1094a6 into main Aug 20, 2025
69 of 70 checks passed
@neilalexander neilalexander deleted the neil/fsweak2 branch August 20, 2025 09:03
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