summaryrefslogtreecommitdiff
path: root/src/journal
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2011-12-27 23:18:09 +0100
committerLennart Poettering <lennart@poettering.net>2011-12-27 23:18:09 +0100
commit9cfb57c989b62d11c073c77179df4bb7fa19f35d (patch)
treee8d1255f1c70a16fc77bccfb55462407e2ca45f4 /src/journal
parent85a131e8d8aa9fe3c2115e281569bed64a4200f1 (diff)
journald: when checking available disk space for rate limiting, cache the results temporarily
Diffstat (limited to 'src/journal')
-rw-r--r--src/journal/journald.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/journal/journald.c b/src/journal/journald.c
index 9f753013a0..c216b78790 100644
--- a/src/journal/journald.c
+++ b/src/journal/journald.c
@@ -44,6 +44,8 @@
#define USER_JOURNALS_MAX 1024
#define STDOUT_STREAMS_MAX 4096
+#define RECHECK_AVAILABLE_SPACE_USEC (30*USEC_PER_SEC)
+
typedef struct StdoutStream StdoutStream;
typedef struct Server {
@@ -68,6 +70,9 @@ typedef struct Server {
uint64_t max_use;
bool compress;
+ uint64_t cached_available_space;
+ usec_t cached_available_space_timestamp;
+
LIST_HEAD(StdoutStream, stdout_streams);
unsigned n_stdout_streams;
} Server;
@@ -108,6 +113,10 @@ static uint64_t available_space(Server *s) {
uint64_t sum = 0, avail = 0, ss_avail = 0;
int r;
DIR *d;
+ usec_t ts = now(CLOCK_MONOTONIC);
+
+ if (s->cached_available_space_timestamp + RECHECK_AVAILABLE_SPACE_USEC > ts)
+ return s->cached_available_space;
r = sd_id128_get_machine(&machine);
if (r < 0)
@@ -163,6 +172,9 @@ static uint64_t available_space(Server *s) {
if (ss_avail < avail)
avail = ss_avail;
+ s->cached_available_space = avail;
+ s->cached_available_space_timestamp = ts;
+
finish:
closedir(d);
@@ -326,6 +338,8 @@ static void server_vacuum(Server *s) {
if (r < 0 && r != -ENOENT)
log_error("Failed to vacuum %s: %s", p, strerror(-r));
free(p);
+
+ s->cached_available_space_timestamp = 0;
}
static char *shortened_cgroup_path(pid_t pid) {