Also advise when unmapping pages

This commit is contained in:
Eric Fischer 2016-04-04 16:14:26 -07:00
parent b1d3849889
commit 72e485f285
2 changed files with 14 additions and 0 deletions

View File

@ -916,6 +916,7 @@ void *run_sort(void *v) {
memcpy(map2, map, end - start);
// No madvise, since caller will want the sorted data
munmap(map, end - start);
munmap(map2, end - start);
}
@ -1036,6 +1037,7 @@ void *run_read_parallel(void *v) {
do_read_parallel(map, a->len, a->offset, a->reading, a->reader, a->progress_seq, a->exclude, a->include, a->exclude_all, a->fname, a->basezoom, a->source, a->nlayers, a->droprate, a->initialized, a->initial_x, a->initial_y);
madvise(map, a->len, MADV_FREE);
if (munmap(map, a->len) != 0) {
perror("munmap source file");
}
@ -1190,10 +1192,12 @@ void radix1(int *geomfds_in, int *indexfds_in, int inputs, int prefix, int split
fwrite_check(&ix, sizeof(struct index), 1, indexfiles[which], "index");
}
madvise(indexmap, indexst.st_size, MADV_FREE);
if (munmap(indexmap, indexst.st_size) < 0) {
perror("unmap index");
exit(EXIT_FAILURE);
}
madvise(geommap, geomst.st_size, MADV_FREE);
if (munmap(geommap, geomst.st_size) < 0) {
perror("unmap geom");
exit(EXIT_FAILURE);
@ -1295,10 +1299,12 @@ void radix1(int *geomfds_in, int *indexfds_in, int inputs, int prefix, int split
merge(merges, nmerges, (unsigned char *) indexmap, indexfile, bytes, indexpos / bytes, geommap, geomfile, geompos_out, progress, progress_max, progress_reported);
madvise(indexmap, indexst.st_size, MADV_FREE);
if (munmap(indexmap, indexst.st_size) < 0) {
perror("unmap index");
exit(EXIT_FAILURE);
}
madvise(geommap, geomst.st_size, MADV_FREE);
if (munmap(geommap, geomst.st_size) < 0) {
perror("unmap geom");
exit(EXIT_FAILURE);
@ -1333,10 +1339,12 @@ void radix1(int *geomfds_in, int *indexfds_in, int inputs, int prefix, int split
fwrite_check(&ix, sizeof(struct index), 1, indexfile, "index");
}
madvise(indexmap, indexst.st_size, MADV_FREE);
if (munmap(indexmap, indexst.st_size) < 0) {
perror("unmap index");
exit(EXIT_FAILURE);
}
madvise(geommap, geomst.st_size, MADV_FREE);
if (munmap(geommap, geomst.st_size) < 0) {
perror("unmap geom");
exit(EXIT_FAILURE);
@ -1606,6 +1614,7 @@ int read_json(int argc, struct source **sourcelist, char *fname, const char *lay
overall_offset += st.st_size - off;
if (munmap(map, st.st_size - off) != 0) {
madvise(map, st.st_size, MADV_FREE);
perror("munmap source file");
}
} else {
@ -1852,6 +1861,7 @@ int read_json(int argc, struct source **sourcelist, char *fname, const char *lay
perror("Reunify meta");
exit(EXIT_FAILURE);
}
madvise(map, reader[i].metapos, MADV_FREE);
if (munmap(map, reader[i].metapos) != 0) {
perror("unmap unmerged meta");
}
@ -2122,6 +2132,7 @@ int read_json(int argc, struct source **sourcelist, char *fname, const char *lay
}
}
madvise(map, indexpos, MADV_FREE);
munmap(map, indexpos);
}
@ -2163,6 +2174,7 @@ int read_json(int argc, struct source **sourcelist, char *fname, const char *lay
ret = EXIT_FAILURE;
}
madvise(meta, metapos, MADV_FREE);
if (munmap(meta, metapos) != 0) {
perror("munmap meta");
}
@ -2171,6 +2183,7 @@ int read_json(int argc, struct source **sourcelist, char *fname, const char *lay
}
if (poolpos > 0) {
madvise(pool, poolpos, MADV_FREE);
if (munmap(stringpool, poolpos) != 0) {
perror("munmap stringpool");
}

View File

@ -1152,6 +1152,7 @@ void *run_thread(void *vargs) {
}
}
madvise(geomstart, arg->geom_size[j], MADV_FREE);
if (munmap(geomstart, arg->geom_size[j]) != 0) {
perror("munmap geom");
}