mirror of
https://github.com/AuxXxilium/kmod.git
synced 2025-01-27 09:15:01 +07:00
index: mm: Add flag to open call to populate buffer
This commit is contained in:
parent
a4a750297d
commit
5109f2b422
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user