Skip to content
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

cephfs: potential adjust failure in lru_expire #19277

Merged
merged 1 commit into from Dec 18, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/include/lru.h
Expand Up @@ -157,14 +157,14 @@ class LRU {

// expire -- expire a single item
LRUObject *lru_get_next_expire() {
adjust();
// look through tail of bot
while (bottom.size()) {
LRUObject *p = bottom.back();
if (!p->lru_pinned) return p;

// move to pintail
pintail.push_front(&p->lru_link);
adjust();
Copy link
Member

Choose a reason for hiding this comment

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

I believe this adjust() is necessary because the size of bottom is changing so it may be necessary to move objects from top to bottom.

}

// ok, try head then
Expand All @@ -174,7 +174,6 @@ class LRU {

// move to pintail
pintail.push_front(&p->lru_link);
adjust();
Copy link
Member

Choose a reason for hiding this comment

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

This loop probably isn't well tested because bottom will be empty if we are in this loop. I think you're right it may be possible for adjust() to crash if we remove an item from top here. Is that the problem you found originally? If that's the case, then we should fix adjust() to handle bottom.size() == 0, not remove this call here.

Copy link
Contributor

Choose a reason for hiding this comment

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

int adjust():
uint64_t toplen = top.size();
uint64_t topwant = (midpoint * (double)(lru_get_size() - num_pinned));

both lru_get_size() and num_pinned do not change when moving item to pintail

Copy link
Member

Choose a reason for hiding this comment

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

Great point. Thanks Zheng.

}

// no luck!
Expand Down