niyue commented on a change in pull request #11588:
URL: https://github.com/apache/arrow/pull/11588#discussion_r740770892
##########
File path: cpp/src/arrow/io/file.cc
##########
@@ -719,27 +719,38 @@ Future<std::shared_ptr<Buffer>>
MemoryMappedFile::ReadAsync(const IOContext&,
return Future<std::shared_ptr<Buffer>>::MakeFinished(ReadAt(position,
nbytes));
}
-Status MemoryMappedFile::WillNeed(const std::vector<ReadRange>& ranges) {
- using ::arrow::internal::MemoryRegion;
-
- RETURN_NOT_OK(memory_map_->CheckClosed());
- auto guard_resize = memory_map_->writable()
- ?
std::unique_lock<std::mutex>(memory_map_->resize_lock())
+Status MemoryMappedFile::ReadRangesToMemoryRegions(
+ const std::vector<ReadRange>& ranges,
+ std::shared_ptr<MemoryMappedFile::MemoryMap>& memory_map,
+ std::vector<MemoryRegion>& regions) {
+ RETURN_NOT_OK(memory_map->CheckClosed());
+ auto guard_resize = memory_map->writable()
+ ?
std::unique_lock<std::mutex>(memory_map->resize_lock())
: std::unique_lock<std::mutex>();
- std::vector<MemoryRegion> regions(ranges.size());
for (size_t i = 0; i < ranges.size(); ++i) {
const auto& range = ranges[i];
- ARROW_ASSIGN_OR_RAISE(
- auto size,
- internal::ValidateReadRange(range.offset, range.length,
memory_map_->size()));
- DCHECK_NE(memory_map_->data(), nullptr);
- regions[i] = {const_cast<uint8_t*>(memory_map_->data() + range.offset),
+ ARROW_ASSIGN_OR_RAISE(auto size, internal::ValidateReadRange(
+ range.offset, range.length,
memory_map->size()));
+ DCHECK_NE(memory_map->data(), nullptr);
+ regions[i] = {const_cast<uint8_t*>(memory_map->data() + range.offset),
static_cast<size_t>(size)};
}
+ return Status::OK();
+}
+
+Status MemoryMappedFile::WillNeed(const std::vector<ReadRange>& ranges) {
+ std::vector<MemoryRegion> regions(ranges.size());
+ RETURN_NOT_OK(ReadRangesToMemoryRegions(ranges, memory_map_, regions));
return ::arrow::internal::MemoryAdviseWillNeed(regions);
Review comment:
Previously we already have `WillNeed` API in `MemoryMappedFile` to
advise OS about the needed ranges, I add an `AdviseRandom` API similarly to
indicate the random access pattern. Initially, I would like to make this API
consistent with `WillNeed` and simply call it `Random` but I think this may be
slightly confusing as well, so I name it `AdviseRandom` currently. Let me know
if you have other naming suggestion for this API.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]