93 lines
2.9 KiB
Diff
93 lines
2.9 KiB
Diff
|
From dd186998dd408c54ffe30df1cc35422e645e0ca2 Mon Sep 17 00:00:00 2001
|
||
|
From: Lennart Poettering <lennart@poettering.net>
|
||
|
Date: Tue, 26 Nov 2013 18:58:44 +0100
|
||
|
Subject: [PATCH] journald: keep statistics on how of we hit/miss the mmap
|
||
|
cache
|
||
|
|
||
|
(cherry picked from commit bf807d4dbf27c783db8dfd7f4eca321ae4be5b00)
|
||
|
---
|
||
|
src/journal/mmap-cache.c | 25 +++++++++++++++++++++++--
|
||
|
src/journal/mmap-cache.h | 3 +++
|
||
|
src/journal/sd-journal.c | 4 +++-
|
||
|
3 files changed, 29 insertions(+), 3 deletions(-)
|
||
|
|
||
|
diff --git a/src/journal/mmap-cache.c b/src/journal/mmap-cache.c
|
||
|
index 03b57be..42a8a7d 100644
|
||
|
--- a/src/journal/mmap-cache.c
|
||
|
+++ b/src/journal/mmap-cache.c
|
||
|
@@ -72,6 +72,9 @@ struct MMapCache {
|
||
|
int n_ref;
|
||
|
unsigned n_windows;
|
||
|
|
||
|
+ unsigned n_hit, n_missed;
|
||
|
+
|
||
|
+
|
||
|
Hashmap *fds;
|
||
|
Hashmap *contexts;
|
||
|
|
||
|
@@ -542,13 +545,19 @@ int mmap_cache_get(
|
||
|
|
||
|
/* Check whether the current context is the right one already */
|
||
|
r = try_context(m, fd, prot, context, keep_always, offset, size, ret);
|
||
|
- if (r != 0)
|
||
|
+ if (r != 0) {
|
||
|
+ m->n_hit ++;
|
||
|
return r;
|
||
|
+ }
|
||
|
|
||
|
/* Search for a matching mmap */
|
||
|
r = find_mmap(m, fd, prot, context, keep_always, offset, size, ret);
|
||
|
- if (r != 0)
|
||
|
+ if (r != 0) {
|
||
|
+ m->n_hit ++;
|
||
|
return r;
|
||
|
+ }
|
||
|
+
|
||
|
+ m->n_missed++;
|
||
|
|
||
|
/* Create a new mmap */
|
||
|
return add_mmap(m, fd, prot, context, keep_always, offset, size, st, ret);
|
||
|
@@ -578,3 +587,15 @@ void mmap_cache_close_context(MMapCache *m, unsigned context) {
|
||
|
|
||
|
context_free(c);
|
||
|
}
|
||
|
+
|
||
|
+unsigned mmap_cache_get_hit(MMapCache *m) {
|
||
|
+ assert(m);
|
||
|
+
|
||
|
+ return m->n_hit;
|
||
|
+}
|
||
|
+
|
||
|
+unsigned mmap_cache_get_missed(MMapCache *m) {
|
||
|
+ assert(m);
|
||
|
+
|
||
|
+ return m->n_missed;
|
||
|
+}
|
||
|
diff --git a/src/journal/mmap-cache.h b/src/journal/mmap-cache.h
|
||
|
index 0c42fb8..912336d 100644
|
||
|
--- a/src/journal/mmap-cache.h
|
||
|
+++ b/src/journal/mmap-cache.h
|
||
|
@@ -34,3 +34,6 @@ MMapCache* mmap_cache_unref(MMapCache *m);
|
||
|
int mmap_cache_get(MMapCache *m, int fd, int prot, unsigned context, bool keep_always, uint64_t offset, size_t size, struct stat *st, void **ret);
|
||
|
void mmap_cache_close_fd(MMapCache *m, int fd);
|
||
|
void mmap_cache_close_context(MMapCache *m, unsigned context);
|
||
|
+
|
||
|
+unsigned mmap_cache_get_hit(MMapCache *m);
|
||
|
+unsigned mmap_cache_get_missed(MMapCache *m);
|
||
|
diff --git a/src/journal/sd-journal.c b/src/journal/sd-journal.c
|
||
|
index 9676f0f..52abbe9 100644
|
||
|
--- a/src/journal/sd-journal.c
|
||
|
+++ b/src/journal/sd-journal.c
|
||
|
@@ -1831,8 +1831,10 @@ _public_ void sd_journal_close(sd_journal *j) {
|
||
|
if (j->inotify_fd >= 0)
|
||
|
close_nointr_nofail(j->inotify_fd);
|
||
|
|
||
|
- if (j->mmap)
|
||
|
+ if (j->mmap) {
|
||
|
+ log_debug("mmap cache statistics: %u hit, %u miss", mmap_cache_get_hit(j->mmap), mmap_cache_get_missed(j->mmap));
|
||
|
mmap_cache_unref(j->mmap);
|
||
|
+ }
|
||
|
|
||
|
free(j->path);
|
||
|
free(j->unique_field);
|