From patchwork Tue Jul 27 08:21:30 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: 1510603 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=wAznkHjK; 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=sn2aidoC; 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 4GZ3fG4Nhtz9sWS for ; Wed, 28 Jul 2021 03:28:05 +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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=nzUWo/93wd5lcWMaB8vlpsShENiKnd0WJ6P9fYfePkc=; b=wAznkHjKVJ4cez T6IUuatyGsN1p+54Cjftbu2oXbKQhSp4Tou+QB3Hx2GpD5xWsdivvPsCdosxYhPauS1z/tDX2O2Jp rVlnbI/wUzvSuLKAVua09qfv1QriaD/kNPktGoGLDXQt2sSWdHgrskfBucKpKx9wIZNy1GMuUI3PK IO+Vn7TO8c+HAdViOnPEZMaXT+NG1iyxWzcwC912MC2gSzamzSZ9ghgTAKp8nOBnLbENRNMr5YE3x 1XMp5Vah3i1dnFADTrrRHQwZiqXEovRGaMuVIynx/ZejLJ6ouujMN/AwWPnHBYq7iJ61sfI9rao76 LdxPSfMPaqFpp4uMKzmg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1m8QpB-00FZJX-3q; Tue, 27 Jul 2021 17:25:01 +0000 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1m8Qp4-00FZJ0-QH for openwrt-devel@lists.openwrt.org; Tue, 27 Jul 2021 17:24:56 +0000 Received: by mail-pl1-x635.google.com with SMTP id d17so16509114plh.10 for ; Tue, 27 Jul 2021 10:24:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ogdswZx3XL8XeJ9238hRumUxlPXS1yW7Nv7gGRt1r4o=; b=sn2aidoC+j2vUyANl977JyaH6KMHfT6M1YPYvESvH2DZPrLtCNyt+Wix5K9vlCsR0L +9VL8+7zQ5UC1+FIEh0ur9N6GCvDw9wn+poAFZEUi9dQ7ZBV4wUvkvKEAM03kHc3jTAy fnCvN2kmzLx0dvbH3gUnKozJEKI2p0sOFpykDyoJEWm07MLRNMQODXNPwFniD8dAph39 ulYVRH0AzZszCIjXunTDGUQlLTwHj28LAAaTRpM0hVhaK2mH6a8fISPea5DmnE2e+IOS VsNGOLI9D8UouUzzaaW1BxVpLNivcyuMTVZsSQXPJqTY0h4IlynbvOdqOoI8NDtgdY/G C2Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ogdswZx3XL8XeJ9238hRumUxlPXS1yW7Nv7gGRt1r4o=; b=IhV6Lkc8JDRMTnq5S2GjQa56iMT4eTNI/kznWTPklGaKgyD/qqiay5Z2AFBSel7Af9 0QVuel9dYnJiotLEW2sAu7cESDYPgL0b8M2L3mFIY8z/cxDAiOfkj+H6eSXp5bxA+PRC ix1CafMRBIbEXw7tVQ0NrNBcf32lDL4bkSf1laTDltqvScjvF76nXNeZpwBUgqbMlTmS e7dtV0t4HXsBm8ui6+eWMsQrs354JhmY+tr8SytAsmMk1xm+nGDahRm5a/8d7Xp+hmEb EMhrRUe/I3bEf9WxjU+BtyPKKM57d4V78GEY82aAHEqqAPISiHm2i3TK2djQnXlzFZW1 0fEg== X-Gm-Message-State: AOAM531FrLxOnh911iA/IEO72YDUC6Vb4Z2PIfoiFnyEgPdxln3bbrJS P62/tCtCq0BATK7iJgNuL9NlXvwcmYc= X-Google-Smtp-Source: ABdhPJx+UiB33N6kee4f58fS/81SNFyoWFQxKwuigrECUg2Ki0NapKIGduE1+H+jYYaeJW3FbssM1w== X-Received: by 2002:a65:490b:: with SMTP id p11mr24152400pgs.313.1627406691859; Tue, 27 Jul 2021 10:24:51 -0700 (PDT) Received: from localhost.localdomain ([115.96.11.188]) by smtp.googlemail.com with ESMTPSA id x10sm4634529pgj.73.2021.07.27.10.24.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Jul 2021 10:24:51 -0700 (PDT) From: Gokulnathan Matta Raja To: openwrt-devel@lists.openwrt.org Cc: Gokulnathan Matta Raja Subject: [PATCH] logd: Limit ustream write max buffer with the limit of 4096 Date: Tue, 27 Jul 2021 08:21:30 +0000 Message-Id: <20210727082130.26322-1-gokulmrt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210727_102454_910008_AA5B0D4B X-CRM114-Status: GOOD ( 10.27 ) X-Spam-Score: 0.9 (/) 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 currently there is no limit in ustream w.max_bu [...] Content analysis details: (0.9 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:635 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] 1.1 DATE_IN_PAST_06_12 Date: is 6 to 12 hours before Received: date -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 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 --- 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);