From patchwork Mon Apr 1 10:25:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Petr_=C5=A0tetiar?= X-Patchwork-Id: 1918443 X-Patchwork-Delegate: ynezz@true.cz Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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=KffpAw/b; dkim=fail reason="key not found in DNS" header.d=true.cz header.i=@true.cz header.a=rsa-sha256 header.s=xnet header.b=Br8fqnCg; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4V7RyJ6lG2z1yYB for ; Mon, 1 Apr 2024 21:26:47 +1100 (AEDT) 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: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:In-Reply-To:References: List-Owner; bh=9zm0fke+OZqSLUkTjFATg4AuGQLDpYQCmtJBXb850HU=; b=KffpAw/b6QKAbM Q9zRsFFeILDWBKd6pX8J0kjajlyw7taAVahjDBVZy+Nd0+JB3iJdQr56lfTZSYB61WbFnLlWGCr78 xdndsBioZoyeSe0Kqkrd39+5VoV0rYBpd5xDZaQUdYp1hX50VemXM8lujhLO3D50o0ZlpuF2Wb64R 6ZAP9SGQrrHefbZuJAqAPQ+hplz50Eq5RJckuivX2pOCiKiokn5SBNfxZHEWMkejgXuYyZ/vDQaQO liuHjTk1prfAVSRKwQIZJ+V5D1wRwHrcZkumsIjjV3B4EyeQrsbjH3QXig8nuwRxXIqGaOzgvqNol FUkLbCqEjslivc1SUhjA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rrEr8-00000007SMh-3DDO; Mon, 01 Apr 2024 10:25:34 +0000 Received: from smtp-out.xnet.cz ([178.217.244.18]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rrEr4-00000007SLl-0upH for openwrt-devel@lists.openwrt.org; Mon, 01 Apr 2024 10:25:32 +0000 Received: from meh.true.cz (meh.true.cz [108.61.167.218]) (Authenticated sender: petr@true.cz) by smtp-out.xnet.cz (Postfix) with ESMTPSA id 95A8C1874E; Mon, 1 Apr 2024 12:25:21 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=true.cz; s=xnet; t=1711967121; bh=mTeb6kA9CXJMl06ibzdLtLCqtaOJtprlAIiW7YYQ3Dc=; h=From:To:Cc:Subject:Date; b=Br8fqnCgIBq0q2TqWYhW638pAzZPZhBTdAo/XKAkFJzhbPaOhSFyLNxVHleFWNIpL 9pDL9ohKEbm7NJluia6FGmnKMX8gxFKeqT2VdIq6tq4BJ1iZR0aroZpiL9cnyYhi8S UNy//Ke2bRXkFuRV8BbT8OTUG9X972/75jHXXzaY= Received: by meh.true.cz (OpenSMTPD) with ESMTP id e1339e62; Mon, 1 Apr 2024 12:08:22 +0200 (CEST) From: =?utf-8?q?Petr_=C5=A0tetiar?= To: openwrt-devel@lists.openwrt.org Cc: =?utf-8?q?Petr_=C5=A0tetiar?= , Nishant Sharma , shir474 Subject: [PATCH] image.mk: fix dd memory exhaustion during padding of large images Date: Mon, 1 Apr 2024 10:25:11 +0000 Message-Id: <20240401102511.495791-1-ynezz@true.cz> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240401_032530_772115_4D59CEFB X-CRM114-Status: UNSURE ( 8.36 ) X-CRM114-Notice: Please train this message. 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: This commit adjusts the Image/pad-to function within image.mk to improve memory management when padding large images. Previously, the dd command was used with a block size (bs) directly derived from t [...] Content analysis details: (0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.1 DKIM_INVALID DKIM or DK signature exists, but is not valid 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 This commit adjusts the Image/pad-to function within image.mk to improve memory management when padding large images. Previously, the dd command was used with a block size (bs) directly derived from the target padding size. This could lead to inefficiencies or memory exhaustion issues when dealing with very large images. To address this, a conditional has been introduced: If the desired padding size exceeds 1MiB (1048576 bytes), dd now operates with a block size of 1MiB and calculates the necessary count to achieve the desired padding. This approach aims to balance memory usage and performance by avoiding excessively large block sizes in memory-intensive operations. For padding sizes of 1MiB or less, the original behavior is preserved, using the specified padding size as the block size. This change ensures more reliable and efficient image padding, particularly in environments with limited memory resources. References: https://github.com/openwrt/openwrt/pull/2862 Reported-by: Nishant Sharma Suggested-by: shir474 Signed-off-by: Petr Štetiar --- include/image.mk | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/image.mk b/include/image.mk index 4b6acbe1aad6..2586f29160f6 100644 --- a/include/image.mk +++ b/include/image.mk @@ -163,7 +163,13 @@ DTC_FLAGS += $(DTC_WARN_FLAGS) DTCO_FLAGS += $(DTC_WARN_FLAGS) define Image/pad-to - dd if=$(1) of=$(1).new bs=$(2) conv=sync + if [ $(2) -gt 1048576 ]; then \ + dd if=$(1) of=$(1).new \ + bs=1048576 count=$(shell expr $(2) / 1048576) \ + conv=sync ; \ + else \ + dd if=$(1) of=$(1).new bs=$(2) conv=sync ; \ + fi mv $(1).new $(1) endef