From patchwork Tue Jul 20 09:51:32 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gokulnathan Matta Raja X-Patchwork-Id: 1507448 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=fcnesEZj; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=N5IZTQk6; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GTYvc1ZKvz9sRN for ; Tue, 20 Jul 2021 19:54:03 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:Subject:Message-ID:Date:From: MIME-Version:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=3PtSSYRXnx/+cnGgqmkuB673PmxVElzDd+HIPID04J8=; b=fcnesEZjrCIYjb 7H6KWk+Be2tz2dTVE617KNvNZRhV81GY9hG9Vjewl7L4h028+k8KIBRTSdm+GNcsI3RugobZlbGJ3 LSlz37l1opWA/qJ2iwYuuQfOLdHsG1ANQMtcterMhlBBS9r9CQAxMisTMwT8KryPB74cEJj/5LOwB mnH+UNxX4f8e7OXmHArFlUqtGK5GYmNFyJVgDLZqwjiaxCyddETUsiuYNrjmmHwM9cBpERRGp357c uZVgZjdULhOHukTcOlt3ugJd4o1gWHPKYadC407wL82mAh9mojdozeNHz3zYetyJlFoHqK1Od2VIU PdXt4z4wcQavIfGiI1TA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m5mPa-00CR37-E3; Tue, 20 Jul 2021 09:51:38 +0000 Received: from mail-ej1-x62d.google.com ([2a00:1450:4864:20::62d]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m5mPW-00CR2l-Pi for openwrt-devel@lists.openwrt.org; Tue, 20 Jul 2021 09:51:36 +0000 Received: by mail-ej1-x62d.google.com with SMTP id hc15so33459161ejc.4 for ; Tue, 20 Jul 2021 02:51:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to:cc; bh=OMiVDjoCqW5Y7s4lIliqA3PlTphodGALGzD64cS8LL4=; b=N5IZTQk6BXrfdxf7AEfmiEy7VLl1aIm7Cu4OeJb1U1s34nYLwfKrcy6QsUhHL0e2nz Lwml+nC4Ovs5GilAwjK/PIs7E4QvMV+LAGSBhClxxI/rs4d26+FpTzJYaX24y3HBcLOj lqpcy1R9QNr8ot2TBYmauiEfkZZzezKlQO2yH7tyWE+SCnODqFrcHg3qEexRE8Z9DsfM bHXLnKPmVGulk8XUltyuXM5Q+sPBpswl1gQU/fnq8TBVbe5IWB1kLocCm7hn2CZJFBBn r6+6oiwslQT34RHGANdstg2oeDgUOQ0p3EpF2XXhVQyzWJKWZOLOTOGCsSGxnMpjLuhb vHiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to:cc; bh=OMiVDjoCqW5Y7s4lIliqA3PlTphodGALGzD64cS8LL4=; b=qyOfkbX1RkqDxOQ7cWm8hwz5gZmVr/fuD9FcIRDfurPqCfa6Jqq5VkJO5ybd0YWsC2 TWfmGu2paVqeXvNaBPQwHQXOPH1cjINn13brw5NWfEaDJhfwnD+jwlPAMgE1bH2AJdLs +SNjrHcy4iE1ZVlKfwdFgumJvYvA4RnskWQDMZY/Ax1IRyRyt8j3Z3JEworn4IVGwHG9 w9n0DUhRk/okrl1DFTVDwqE9u117p5HQwhgOgZs64Liul4Xc89O7/JhjiXrIBU0VvPiH k61KXTlw6/Oo4upHhOwuqFBA0mk7nh5zaRfhzGVmIVW37+4GBDjyekQgYdfrJd+rmS39 nzUQ== X-Gm-Message-State: AOAM531ddOr3JwGcKfndjDIjugGd2CkDyVy5ihuU6GxC0TiI3FjrUumj rG+kboCYTW5tnDZBWmJibGXdYNHW+y//1+mi+zpF8BQgbNaYdQ== X-Google-Smtp-Source: ABdhPJyJkAjBsO/jbc8O89k/TEe1LQZsdQMTBNxwqC9zdRS4f80bi7LkcWuGhMBjw+d6Fx0VlWdtNrGui5c89rrPFeQ= X-Received: by 2002:a17:907:62a1:: with SMTP id nd33mr31925414ejc.303.1626774692892; Tue, 20 Jul 2021 02:51:32 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a17:906:b1d9:0:0:0:0 with HTTP; Tue, 20 Jul 2021 02:51:32 -0700 (PDT) From: "Gocool.." Date: Tue, 20 Jul 2021 15:21:32 +0530 Message-ID: Subject: logd: Limit ustream write buffer with configurable value To: openwrt-devel@lists.openwrt.org Cc: gokulmrt@gmail.com X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210720_025134_877480_9D7AD50C X-CRM114-Status: GOOD ( 11.38 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: 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 there is no limit in w.max_buffers, the logd co [...] Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:62d listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [gokulmrt[at]gmail.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org 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 there is no limit in w.max_buffers, the logd consumes all the system memory at a point of time which triggers Out Of Memory. The ustream write max_buffer is limited with a configurable value parsed through logd with option "-W" and unlimited if value is '0'. Similar ticket has been reported in, https://github.com/openwrt/packages/issues/5604 Signed-off-by: gokulnathan blob_buf_init(&b, 0); @@ -243,13 +250,18 @@ main(int argc, char **argv) struct passwd *p = NULL; signal(SIGPIPE, SIG_IGN); - while ((ch = getopt(argc, argv, "S:")) != -1) { + while ((ch = getopt(argc, argv, "S:W:")) != -1) { switch (ch) { case 'S': log_size = atoi(optarg); if (log_size < 1) log_size = 16; break; + case 'W': + log_ustream_max_buffers = atoi(optarg); + if (log_ustream_max_buffers < 1) + log_ustream_max_buffers = 0; + break; } } log_size *= 1024; diff --git a/log/logd.c b/log/logd.c index 5d6c458..7e52820 100644 --- a/log/logd.c +++ b/log/logd.c @@ -33,6 +33,8 @@ static struct blob_buf b; static struct ubus_auto_conn conn; static LIST_HEAD(clients); +static unsigned int log_ustream_max_buffers = 0; + enum { READ_LINES, READ_STREAM, @@ -130,6 +132,11 @@ 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 */ + if (0 != log_ustream_max_buffers) + { + cl->s.stream.w.max_buffers = log_ustream_max_buffers; + } list_add(&cl->list, &clients); while ((!tb[READ_LINES] || count) && l) {