Skip to content

Commit

Permalink
memory: fix trimming of allocated spans
Browse files Browse the repository at this point in the history
Trimmers may request buffers smaller than n_pages, the original value
passed to allocate_large_and_trim(). That's why t.nr_page should be
used as a final size of the allocated span.

Another issue with the handling of span trimming is the order of operations
when pages from the beginning of the buffer are trimmed. In such case
span is updated to point to the actual beginning of the requested buffer,
but afterwards it is used to retrieve span->span_size value which is expected
to be the size of the originally allocated page span. Because the span
pointer was changed the value is invalid and the trimming doesn't free
all trimmed pages.

Signed-off-by: Paweł Dziepak <[email protected]>
  • Loading branch information
pdziepak authored and avikivity committed Mar 30, 2015
1 parent 7cf25ce commit d3504f9
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions core/memory.cc
Original file line number Diff line number Diff line change
Expand Up @@ -404,13 +404,13 @@ cpu_pages::allocate_large_and_trim(unsigned n_pages, Trimmer trimmer) {
span = &pages[span_idx];

}
if (t.nr_pages < span->span_size) {
if (t.nr_pages < span_size) {
free_span_no_merge(span_idx + t.nr_pages, span_size - t.nr_pages);
span_size = t.nr_pages;
}
auto span_end = &pages[span_idx + n_pages - 1];
auto span_end = &pages[span_idx + t.nr_pages - 1];
span->free = span_end->free = false;
span->span_size = span_end->span_size = n_pages;
span->span_size = span_end->span_size = t.nr_pages;
span->pool = nullptr;
if (nr_free_pages < current_min_free_pages) {
drain_cross_cpu_freelist();
Expand Down

0 comments on commit d3504f9

Please sign in to comment.