]> git.ipfire.org Git - thirdparty/kmod.git/commitdiff
libkmod-index: do not pre-populate mmap
authorLucas De Marchi <lucas.demarchi@profusion.mobi>
Fri, 2 Mar 2012 23:33:26 +0000 (20:33 -0300)
committerLucas De Marchi <lucas.demarchi@profusion.mobi>
Fri, 2 Mar 2012 23:33:26 +0000 (20:33 -0300)
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.

libkmod/libkmod-index.c
libkmod/libkmod-index.h
libkmod/libkmod.c

index 1698d7fc96749f0eaa55d388ea6ffe2fbe8e56db..e3850f68c0a25280187f6e616dd9e26edea37d47 100644 (file)
@@ -771,10 +771,9 @@ static void index_mm_free_node(struct index_mm_node *node)
 }
 
 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 @@ struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename,
        }
 
        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;
        }
 
index 0134ac501bf697e0a7f36218e207a0ce9c793951..dd3a76265d2a4f7798fc938301eb421c83c329b8 100644 (file)
@@ -122,7 +122,7 @@ void index_values_free(struct index_value *values);
 /* 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);
index 6c3e0f84c5663df9d42ba80b72018fdb3f0f1bf6..02f3b14be5c6709d64540bebb1bf6eed5c6a19cf 100644 (file)
@@ -807,7 +807,7 @@ KMOD_EXPORT int kmod_load_resources(struct kmod_ctx *ctx)
 
                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;