]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal: elide fd matching from window_matches() (#6340)
authorVito Caputo <vcaputo@pengaru.com>
Fri, 14 Jul 2017 17:26:01 +0000 (10:26 -0700)
committerLennart Poettering <lennart@poettering.net>
Fri, 14 Jul 2017 17:26:01 +0000 (19:26 +0200)
Introduces window_matches_fd() for the fd matching case in try_context(),

In find_mmap() we're already walking a list of windows by fd, checking
this is pointless work in a potentially hot loop with many windows.

src/journal/mmap-cache.c

index 89f4a1df64c2c04b37230c1c7552328702879dac..3e076f8fea31ed2d0191271b13ded0aa09062b0e 100644 (file)
@@ -157,19 +157,26 @@ static void window_free(Window *w) {
         free(w);
 }
 
-_pure_ static bool window_matches(Window *w, MMapFileDescriptor *f, int prot, uint64_t offset, size_t size) {
+_pure_ static inline bool window_matches(Window *w, int prot, uint64_t offset, size_t size) {
         assert(w);
-        assert(f);
         assert(size > 0);
 
         return
-                w->fd &&
-                f->fd == w->fd->fd &&
                 prot == w->prot &&
                 offset >= w->offset &&
                 offset + size <= w->offset + w->size;
 }
 
+_pure_ static bool window_matches_fd(Window *w, MMapFileDescriptor *f, int prot, uint64_t offset, size_t size) {
+        assert(w);
+        assert(f);
+
+        return
+                w->fd &&
+                f->fd == w->fd->fd &&
+                window_matches(w, prot, offset, size);
+}
+
 static Window *window_add(MMapCache *m, MMapFileDescriptor *f, int prot, bool keep_always, uint64_t offset, size_t size, void *ptr) {
         Window *w;
 
@@ -357,7 +364,7 @@ static int try_context(
         if (!c->window)
                 return 0;
 
-        if (!window_matches(c->window, f, prot, offset, size)) {
+        if (!window_matches_fd(c->window, f, prot, offset, size)) {
 
                 /* Drop the reference to the window, since it's unnecessary now */
                 context_detach_window(c);
@@ -395,7 +402,7 @@ static int find_mmap(
                 return -EIO;
 
         LIST_FOREACH(by_fd, w, f->windows)
-                if (window_matches(w, f, prot, offset, size))
+                if (window_matches(w, prot, offset, size))
                         break;
 
         if (!w)