Also use pread instead of mapping to read in the data to sort

This commit is contained in:
Erica Fischer
2023-01-12 18:21:46 -08:00
parent 966fdb63d4
commit 2695db5ebf
+3 -8
View File
@@ -392,15 +392,10 @@ void *run_sort(void *v) {
std::string s;
s.resize(end - start);
void *map = mmap(NULL, end - start, PROT_READ, MAP_PRIVATE, a->indexfd, start);
if (map == MAP_FAILED) {
perror("mmap in run_sort");
exit(EXIT_MEMORY);
if (pread(a->indexfd, (void *) s.c_str(), end - start, start) != end - start) {
fprintf(stderr, "pread(index): %s\n", strerror(errno));
exit(EXIT_READ);
}
madvise(map, end - start, MADV_SEQUENTIAL);
madvise(map, end - start, MADV_WILLNEED);
memcpy((void *) s.c_str(), map, end - start);
munmap(map, end - start);
qsort((void *) s.c_str(), (end - start) / a->bytes, a->bytes, indexcmp);