libkmod-index: do not pre-populate mmap
If we tell mmap to populate all the indexes and they are big, this will
impact load time. Let them be mapped as they are used.
diff --git a/libkmod/libkmod-index.c b/libkmod/libkmod-index.c
index 1698d7f..e3850f6 100644
--- a/libkmod/libkmod-index.c
+++ b/libkmod/libkmod-index.c
@@ -771,10 +771,9 @@
}
struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename,
- bool populate, unsigned long long *stamp)
+ unsigned long long *stamp)
{
int fd;
- int flags;
struct stat st;
struct index_mm *idx;
struct {
@@ -798,14 +797,11 @@
}
fstat(fd, &st);
- flags = MAP_PRIVATE;
- if (populate)
- flags |= MAP_POPULATE;
- if ((idx->mm = mmap(0, st.st_size, PROT_READ, flags, fd, 0))
+ if ((idx->mm = mmap(0, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0))
== MAP_FAILED) {
- ERR(ctx, "mmap(0, %zd, PROT_READ, %d, %d, 0): %m\n",
- (size_t)st.st_size, flags, fd);
+ ERR(ctx, "mmap(0, %zd, PROT_READ, %d, MAP_PRIVATE, 0): %m\n",
+ st.st_size, fd);
goto fail;
}
diff --git a/libkmod/libkmod-index.h b/libkmod/libkmod-index.h
index 0134ac5..dd3a762 100644
--- a/libkmod/libkmod-index.h
+++ b/libkmod/libkmod-index.h
@@ -122,7 +122,7 @@
/* Implementation using mmap */
struct index_mm;
struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename,
- bool populate, unsigned long long *stamp);
+ unsigned long long *stamp);
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);
diff --git a/libkmod/libkmod.c b/libkmod/libkmod.c
index 6c3e0f8..02f3b14 100644
--- a/libkmod/libkmod.c
+++ b/libkmod/libkmod.c
@@ -807,7 +807,7 @@
snprintf(path, sizeof(path), "%s/%s.bin", ctx->dirname,
index_files[i].fn);
- ctx->indexes[i] = index_mm_open(ctx, path, true,
+ ctx->indexes[i] = index_mm_open(ctx, path,
&ctx->indexes_stamp[i]);
if (ctx->indexes[i] == NULL)
goto fail;