free(node);
}
-struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename)
+struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename,
+ bool populate)
{
int fd;
+ int flags;
struct stat st;
struct index_mm *idx;
struct {
goto fail;
}
- if ((idx->mm = mmap(0, st.st_size, PROT_READ,
- MAP_PRIVATE | MAP_POPULATE,
- fd, 0)) == MAP_FAILED) {
+ flags = MAP_PRIVATE;
+ if (populate)
+ flags |= MAP_POPULATE;
+
+ if ((idx->mm = mmap(0, st.st_size, PROT_READ, flags, fd, 0))
+ == MAP_FAILED) {
ERR(ctx, "%m\n");
goto fail;
}
/* Implementation using mmap */
struct index_mm;
-struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename);
+struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename,
+ bool populate);
void index_mm_close(struct index_mm *index);
char *index_mm_search(struct index_mm *idx, const char *key);
struct index_value *index_mm_searchwild(struct index_mm *idx, const char *key);