logd: Limit ustream write buffer with configurable value
Gokulnathan Matta Raja
gokulmrt at gmail.com
Tue Jul 27 02:29:19 PDT 2021
If the "logread" process is blocked in write call or stopped by
pressing "CTRL+Z", the logd starts to buffer all the messages in
the write buffer. Since currently there is no limit in ustream
w.max_buffers, the logd consumes all the system memory and at a
point of time which triggers Out Of Memory.
The ustream write max_buffer of logd is limited with value 4096.
Similar ticket has been reported in,
https://github.com/openwrt/packages/issues/5604
Signed-off-by: Gokulnathan Matta Raja <gokulmrt at gmail.com>
---
log/logd.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/log/logd.c b/log/logd.c
index 5d6c458..6ca4a2b 100644
--- a/log/logd.c
+++ b/log/logd.c
@@ -130,6 +130,8 @@ read_log(struct ubus_context *ctx, struct ubus_object *obj,
cl->s.stream.notify_state = client_notify_state;
cl->fd = fds[1];
ustream_fd_init(&cl->s, cl->fd);
+ /* Limit the ustream write max_buffers to avoid infinite memory consumption when no logread happens */
+ cl->s.stream.w.max_buffers = 4096;
list_add(&cl->list, &clients);
while ((!tb[READ_LINES] || count) && l) {
blob_buf_init(&b, 0);
--
2.25.1
More information about the openwrt-devel
mailing list