From: Vito Caputo Date: Fri, 14 Jul 2017 17:26:01 +0000 (-0700) Subject: journal: elide fd matching from window_matches() (#6340) X-Git-Tag: v235~336 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8c3d9662ed998451a833af611e92b25e570b00c0;p=platform%2Fupstream%2Fsystemd.git journal: elide fd matching from window_matches() (#6340) 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. --- diff --git a/src/journal/mmap-cache.c b/src/journal/mmap-cache.c index 89f4a1d..3e076f8 100644 --- a/src/journal/mmap-cache.c +++ b/src/journal/mmap-cache.c @@ -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)