From nobody Thu Nov 12 09:44:27 2026 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4jQFpg627fz70JbY for ; Thu, 12 Nov 2026 09:44:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (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 mx1.freebsd.org (Postfix) with ESMTPS id 4jQFpg5XyZz3Cqh for ; Thu, 12 Nov 2026 09:44:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794476667; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=wCq5mJeTP7XEgDwi06M9Xp9a+w67EEXGldf+CAGjddg=; b=mmAWz/3Exjkjz0mpIZ+kDWAjjGovL8WD2M5hTyigIUFKd1dBNkbKtuqMpN9mOIzqOD7WPb e1WNXCl4Yox49HU/3NSgSoEG0pUmc7Rwh6XEL8fCAFu6YOgdoYucc9bh4rmh+Zkqcx/Vor NNxKOOG6AmOqVR/YuRu5jyD1Z9OkcshuaGB0Zr84Uuv2mIzUDpo7yQxPFycGKzJ/SE8iGZ H3VjjBjvq1lJaFhjG9ScVwFCbbU5AUVRZcOMG8NMpaePg/hK0R1l6WauUNN0XHRGEQfLg0 3lL/xwadbDoQcLZY6KTHk/M2OGIA8/44gKVNMUJzSojkZzg6CH6/Zs0zvBqMsg== ARC-Seal: i=1; a=rsa-sha256; d=freebsd.org; s=dkim; cv=none; t=1794476667; b=l3LdMcohN0EbbhLEo4dB2TxSY2t2ipm3vG0fTA7jr1OdThOxJj0Z/hCXJB0EjlmogoQVe4 1D/0JDPps9nfCLntFZVbdd65x/zBLYxCqqNsc5ByYfN+sm54LaGcTElthHIuPFqVV5mbog /rDRZNqTgXWdjVKaM8IIKNiy6a1IE4eH539QOddGLw8+WZEfMmibPJOHueekZdNgb2tQ8V UOkl0PNEiy8+FN+gk9Y4Unex2PDOri+Q/dx/ZD9vA1wDa7709EibBypB8TkdLhrC2Ewosy 0F54BuOJZdnVZ3tEWMEpWkEybcF+WVE2w3KKRVAs9yLGUTyfyZFTE9iTb805ug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1794476667; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=wCq5mJeTP7XEgDwi06M9Xp9a+w67EEXGldf+CAGjddg=; b=fZGeGwvOXizop76+CAiILtt/P5+erXcD8+ZlDuE7CFE4IO3gosxEqjviS/pcEnxe6YZY6T mifEHR0BL8fG/ZiQAxV/h47/JgLO/BMToCYEhxvQ+Tum7Jle4/G8s1e4LRAyXyfDhXzoDl mZ9pTpijcpKvOPuXe0Trq+V0uLO/o2SGwRtqs8cbGcM11VCqnUzi3MB9gix0yWKjoXL06Y dE2WMhTXdxouhih/DjaL2MVcqAvIAI0wi6iulbCXzJfG7+/jrkqkqgz4JsD9SW33f9kNz7 uG3s9dw3HhVPWMlk6ToZrmXF/WIcmQMOaIgWknuwwAXf/+Ljvbf0vOm8HuNRyw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) by mxrelay.nyi.freebsd.org (Postfix) with ESMTP id 4jQFpg5C5nzxf3 for ; Thu, 12 Nov 2026 09:44:27 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from git (uid 1279) (envelope-from git@FreeBSD.org) id 1fe35 by gitrepo.freebsd.org (DragonFly Mail Agent v0.13+ on gitrepo.freebsd.org); Thu, 12 Nov 2026 09:44:27 +0000 To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Olivier Cochard Subject: git: a2adf568cdfe - main - loader.efi: Free the unused tail of the memdisk buffer List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all X-BeenThere: dev-commits-src-all@freebsd.org List-Id: Commit messages for all branches of the src repository List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: olivier X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a2adf568cdfe83d8aca49f9eb9ba7891e88ff3cd Auto-Submitted: auto-generated Date: Thu, 12 Nov 2026 09:44:27 +0000 Message-Id: <6af58a7b.1fe35.167aaa74@gitrepo.freebsd.org> The branch main has been updated by olivier: URL: https://cgit.FreeBSD.org/src/commit/?id=a2adf568cdfe83d8aca49f9eb9ba7891e88ff3cd commit a2adf568cdfe83d8aca49f9eb9ba7891e88ff3cd Author: Olivier Cochard AuthorDate: 2026-11-08 22:14:52 +0000 Commit: Olivier Cochard CommitDate: 2026-11-12 09:38:56 +0000 loader.efi: Free the unused tail of the memdisk buffer The buffer is sized from a guess, 4x the compressed size for most formats, so free the pages past the image once it is complete. Reviewed by: imp Sponsored by: Netflix Differential Revision: https://ron-dev.freebsd.org/FreeBSD/src/pulls/100 --- stand/efi/loader/decompress.c | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/stand/efi/loader/decompress.c b/stand/efi/loader/decompress.c index 11199e1ed3bc..c90634037260 100644 --- a/stand/efi/loader/decompress.c +++ b/stand/efi/loader/decompress.c @@ -129,6 +129,28 @@ free_buffer(decomp_state *dctx) dctx->buf = 0; } +/* + * The buffer size is a guess, so once the image is complete, give the pages + * past its end back to the firmware. + */ +static void +trim_buffer(decomp_state *dctx) +{ + size_t used = roundup2((uintptr_t)dctx->buf_cur - (uintptr_t)dctx->buf, + EFI_PAGE_SIZE); + size_t pages = used / EFI_PAGE_SIZE; + + if (dctx->buf == 0 || pages == 0 || pages >= dctx->pages) + return; + if (EFI_ERROR(BS->FreePages(dctx->buf + used, dctx->pages - pages))) + return; + printf("Freed %llu unused bytes of the decompression buffer\n", + ULL(dctx->alloc_size - used)); + dctx->pages = pages; + dctx->alloc_size = used; + dctx->buf_end = (uint8_t *)(uintptr_t)dctx->buf + used; +} + /* * zlib supprot */ @@ -504,7 +526,9 @@ decomp_step(decomp_state *dctx, uint8_t *buf, size_t len, size_t offset) void decomp_fini(decomp_state *dctx, bool flush) { - return (dctx->fini(dctx, flush)); + dctx->fini(dctx, flush); + if (!flush) + trim_buffer(dctx); } EFI_PHYSICAL_ADDRESS