index: mm: Add flag to open call to populate buffer

This commit is contained in:
Lucas De Marchi 2011-12-08 15:10:55 -02:00
parent a4a750297d
commit 5109f2b422
2 changed files with 11 additions and 5 deletions

View File

@ -654,9 +654,11 @@ static void index_mm_free_node(struct index_mm_node *node)
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 {
@ -681,9 +683,12 @@ struct index_mm *index_mm_open(struct kmod_ctx *ctx, const char *filename)
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;
}

View File

@ -167,7 +167,8 @@ 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);
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);