Skip to content

Make the new buffer impl's reserve/commit semantics match libevent#7079

Merged
mattklein123 merged 3 commits intoenvoyproxy:masterfrom
brian-pane:buffer_reuse
May 28, 2019
Merged

Make the new buffer impl's reserve/commit semantics match libevent#7079
mattklein123 merged 3 commits intoenvoyproxy:masterfrom
brian-pane:buffer_reuse

Conversation

@brian-pane
Copy link
Copy Markdown
Contributor

Description:

  • On OwnedImpl::reserve, if any slices at the end of the buffer
    have reservations, clear the reservations so the space can be
    used for the new reservation.
  • Add tests for the two cases where this is important: calling
    reserve and never committing the buffers before the next reserve
    call; and calling reserve, getting back N slices, and only committing
    the first M of those slices (where M < N) before the next reserve
    call.

Risk Level: medium
Testing: new unit tests included
Docs Changes: N/A
Release Notes: N/A

Signed-off-by: Brian Pane brianp+github@brianp.net

* On OwnedImpl::reserve, if any slices at the end of the buffer
  have reservations, clear the reservations so the space can be
  used for the new reservation.
* Add tests for the two cases where this is important: calling
  reserve and never committing the buffers before the next reserve
  call; and calling reserve, getting back N slices, and only committing
  the first M of those slices (where M < N) before the next reserve
  call.

Signed-off-by: Brian Pane <brianp+github@brianp.net>
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks for working on this. Quick question.

/wait-any

size_t first_reservable_slice = slices_.size();
while (first_reservable_slice > 0) {
// Reclaim any space that was previously reserved but never committed.
slices_[first_reservable_slice - 1]->clearReservation();
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Probably stupid question: Why do we need to keep track of reservation state at all if we have these semantics? Can't you just return allocated but not used chain space if the user asks for it again?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah, with the new semantics, we probably can stop tracking the reservation state. I'll try making that change (which should simplify the implementation) later today.

… replaces the last.

Signed-off-by: Brian Pane <brianp+github@brianp.net>
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks, LGTM with a small nit and question.

/wait

}
return capacity_ - reservable_;
}
uint64_t reservableSize() const { return capacity_ - reservable_; }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: ASSERT(capacity_ >= reservable_); ?

if (size == 0) {
return {nullptr, 0};
}
if (data_ != 0 && data_ == reservable_) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Q: Why would this branch happen vs. being reset in the drain path? Should this be an assert instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

For a while, I couldn't decide whether to reset the offsets in the drain path or the reserve path, so it ended up in both. I'll replace this one with an assert.

Signed-off-by: Brian Pane <brianp+github@brianp.net>
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Nice, thanks.

@mattklein123 mattklein123 merged commit 2f498c9 into envoyproxy:master May 28, 2019
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