From: Michael Tremer Date: Tue, 23 Aug 2022 13:02:50 +0000 (+0000) Subject: database: Call madvise() to tell the kernel that we will randomly access the data X-Git-Tag: 0.9.15~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e63d76be69e6be4704a9925300f0055148e7a41d;p=location%2Flibloc.git database: Call madvise() to tell the kernel that we will randomly access the data Signed-off-by: Michael Tremer --- 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; }