From e63d76be69e6be4704a9925300f0055148e7a41d Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 23 Aug 2022 13:02:50 +0000 Subject: [PATCH] database: Call madvise() to tell the kernel that we will randomly access the data Signed-off-by: Michael Tremer --- src/database.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/database.c b/src/database.c index a76afad..311f4ab 100644 --- a/src/database.c +++ b/src/database.c @@ -243,6 +243,9 @@ ERROR: Maps the entire database into memory */ static int loc_database_mmap(struct loc_database* db) { + int r; + + // Get file descriptor int fd = fileno(db->f); // Determine the length of the database @@ -264,6 +267,13 @@ static int loc_database_mmap(struct loc_database* db) { DEBUG(db->ctx, "Mapped database of %zu byte(s) at %p\n", db->length, db->data); + // Tell the system that we expect to read data randomly + r = madvise(db->data, db->length, MADV_RANDOM); + if (r) { + ERROR(db->ctx, "madvise() failed: %m\n"); + return r; + } + return 0; } -- 2.39.5