From bb99a35a873c35e80b0b47fe045081022660374d Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Fri, 27 Jan 2012 18:57:37 +0100 Subject: [PATCH] log: increase socket buffers for logging by default --- src/journal/journal-send.c | 8 +++++++- src/log.c | 4 ++++ src/util.c | 36 +++++++++++++++++++++++++++++++++++ src/util.h | 3 +++ units/syslog.socket | 1 + units/systemd-journald.socket | 1 + 6 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/journal/journal-send.c b/src/journal/journal-send.c index 00029fe0b..b5b4fbfa0 100644 --- a/src/journal/journal-send.c +++ b/src/journal/journal-send.c @@ -30,6 +30,8 @@ #include "util.h" #include "socket-util.h" +#define SNDBUF_SIZE (8*1024*1024) + /* We open a single fd, and we'll share it with the current process, * all its threads, and all its subprocesses. This means we need to * initialize it atomically, and need to operate on it atomically @@ -47,6 +49,8 @@ retry: if (fd < 0) return -errno; + fd_inc_sndbuf(fd, SNDBUF_SIZE); + if (!__sync_bool_compare_and_swap(&fd_plus_one, 0, fd+1)) { close_nointr_nofail(fd); goto retry; @@ -219,7 +223,7 @@ _public_ int sd_journal_sendv(const struct iovec *iov, int n) { if (k >= 0) return 0; - if (errno != EMSGSIZE) + if (errno != EMSGSIZE && errno != ENOBUFS) return -errno; /* Message doesn't fit... Let's dump the data in a temporary @@ -294,6 +298,8 @@ _public_ int sd_journal_stream_fd(const char *identifier, int priority, int leve return -errno; } + fd_inc_sndbuf(fd, SNDBUF_SIZE); + if (!identifier) identifier = ""; diff --git a/src/log.c b/src/log.c index 0594f7fde..c37ab2264 100644 --- a/src/log.c +++ b/src/log.c @@ -33,6 +33,8 @@ #include "macro.h" #include "socket-util.h" +#define SNDBUF_SIZE (8*1024*1024) + static LogTarget log_target = LOG_TARGET_CONSOLE; static int log_max_level = LOG_INFO; @@ -127,6 +129,8 @@ static int create_log_socket(int type) { if (fd < 0) return -errno; + fd_inc_sndbuf(fd, SNDBUF_SIZE); + return fd; } diff --git a/src/util.c b/src/util.c index c9ad831c6..5fe22d2e5 100644 --- a/src/util.c +++ b/src/util.c @@ -6279,3 +6279,39 @@ void* memdup(const void *p, size_t l) { memcpy(r, p, l); return r; } + +int fd_inc_sndbuf(int fd, size_t n) { + int r, value; + socklen_t l = sizeof(value); + + r = getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &value, &l); + if (r >= 0 && + l == sizeof(value) && + (size_t) value >= n*2) + return 0; + + value = (int) n; + r = setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &value, sizeof(value)); + if (r < 0) + return -errno; + + return 1; +} + +int fd_inc_rcvbuf(int fd, size_t n) { + int r, value; + socklen_t l = sizeof(value); + + r = getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &value, &l); + if (r >= 0 && + l == sizeof(value) && + (size_t) value >= n*2) + return 0; + + value = (int) n; + r = setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &value, sizeof(value)); + if (r < 0) + return -errno; + + return 1; +} diff --git a/src/util.h b/src/util.h index 202d07a85..dcfc16d46 100644 --- a/src/util.h +++ b/src/util.h @@ -536,4 +536,7 @@ int rtc_open(int flags); int is_kernel_thread(pid_t pid); +int fd_inc_sndbuf(int fd, size_t n); +int fd_inc_rcvbuf(int fd, size_t n); + #endif diff --git a/units/syslog.socket b/units/syslog.socket index 657e7913e..1c5485776 100644 --- a/units/syslog.socket +++ b/units/syslog.socket @@ -21,6 +21,7 @@ Wants=syslog.target ListenDatagram=/run/systemd/journal/syslog SocketMode=0666 PassCredentials=yes +ReceiveBuffer=8M # The default syslog implementation should make syslog.service a # symlink to itself, so that this socket activates the right actual diff --git a/units/systemd-journald.socket b/units/systemd-journald.socket index 1062390ff..c752505d9 100644 --- a/units/systemd-journald.socket +++ b/units/systemd-journald.socket @@ -23,3 +23,4 @@ ListenDatagram=/run/systemd/journal/socket ListenDatagram=/dev/log SocketMode=0666 PassCredentials=yes +ReceiveBuffer=8M -- 2.30.2