]> git.ipfire.org Git - location/libloc.git/commitdiff
database: Call madvise() to tell the kernel that we will randomly access the data
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 23 Aug 2022 13:02:50 +0000 (13:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 23 Aug 2022 13:02:50 +0000 (13:02 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/database.c

index a76afadfc98aa40b73f6aaa0b2032d8a920cb827..311f4ab30aa8b422f3bdd3aeee7ee9108fbba77f 100644 (file)
@@ -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;
 }