Skip to content

Commit 98b603e

Browse files
committed
map_populate on linux; fall back to mlock/memset otherwise
1 parent ce90ef4 commit 98b603e

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

cpp/src/plasma/malloc.cc

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,11 +133,28 @@ void* fake_mmap(size_t size) {
133133

134134
int fd = create_buffer(size);
135135
ARROW_CHECK(fd >= 0) << "Failed to create buffer during mmap";
136+
#ifdef __linux__
137+
void *pointer = mmap(NULL, size, PROT_READ | PROT_WRITE,
138+
MAP_SHARED | MAP_POPULATE, fd, 0);
139+
if (pointer == MAP_FAILED) {
140+
ARROW_LOG(ERROR) << "mmap failed with error : " << std::strerror(errno);
141+
return pointer;
142+
}
143+
#else
136144
void *pointer = mmap(NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
137145
if (pointer == MAP_FAILED) {
138146
ARROW_LOG(ERROR) << "mmap failed with error : " << std::strerror(errno);
139147
return pointer;
140148
}
149+
// Attempt to mlock the mmaped region of memory (best effort).
150+
int rv = mlock(pointer, size);
151+
if (rv != 0) {
152+
ARROW_LOG(WARNING) << "(best effort) mlock failed";
153+
// Attempt to memset the mmaped region of memory (best effort).
154+
memset(pointer, 0xff, size);
155+
}
156+
#endif
157+
ARROW_LOG(INFO) << "mmaping pointer " << pointer << " size " << size;
141158

142159
/* Increase dlmalloc's allocation granularity directly. */
143160
mparams.granularity *= GRANULARITY_MULTIPLIER;

0 commit comments

Comments
 (0)