Commit 23bc29b8 authored by Lucian Grijincu's avatar Lucian Grijincu Committed by Noam Lerner

folly: MemoryMapping: madvise: round the end to lower bound

Test Plan: n/a

Reviewed By: ott@fb.com

Subscribers: ott, folly-diffs@, yfeldblum, tudort, chalfant

FB internal diff: D2100535

Tasks: 4421175

Signature: t1:2100535:1432674713:6f5f40a8462851b2b8972c68d34ae23aaf1e9340
parent 328dda4b
...@@ -300,19 +300,20 @@ void MemoryMapping::advise(int advice, size_t offset, size_t length) const { ...@@ -300,19 +300,20 @@ void MemoryMapping::advise(int advice, size_t offset, size_t length) const {
<< " length: " << length << " length: " << length
<< " mapLength_: " << mapLength_; << " mapLength_: " << mapLength_;
if (length == 0) { // Include the entire start page: round down to page boundary.
return; const auto offMisalign = offset % options_.pageSize;
offset -= offMisalign;
length += offMisalign;
// Round the last page down to page boundary.
if (offset + length != size_t(mapLength_)) {
length -= length % options_.pageSize;
} }
auto offMisalign = offset % options_.pageSize; if (length == 0) {
if (offMisalign != 0) { return;
offset -= offMisalign;
length += offMisalign;
} }
length = (length + options_.pageSize - 1) & ~(options_.pageSize - 1);
length = std::min<size_t>(length, mapLength_ - offset);
char* mapStart = static_cast<char*>(mapStart_) + offset; char* mapStart = static_cast<char*>(mapStart_) + offset;
PLOG_IF(WARNING, ::madvise(mapStart, length, advice)) << "madvise"; PLOG_IF(WARNING, ::madvise(mapStart, length, advice)) << "madvise";
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment