From nobody Fri Feb 03 15:50:57 2023 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 4P7g9Z4Ql4z3kRrf; Fri, 3 Feb 2023 15:50:58 +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 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4P7g9Y47z5z3JGh; Fri, 3 Feb 2023 15:50:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675439457; 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=sxktI946gHplmt2XXTwl7W+QxNL7B49XS21eQskE818=; b=aXaCGwBnPOCGbvkMy4X3v04m/EdIjLtAjPg6gIOArrTz/pXJQoY/XqZgg8cPtGH5ixoHHz JMnE2j35rhRw4E+NpED84xCrK8xp1Y/u6qjdpUtDw0lm/tDMJrGkUyfYn+dvUk+fIAoAu4 ih/QR9XiFJng9plY00Z3vuUYnp7OUnooSjlUJEYX/HKO9+fY5E0YXq6UdHansex9jq9lIA AbrM/SFYVrjRK7kH4DTXAncMrEnoXBDzUPONUxi6/lcWYRBf93VIMgvZerjnn/HXnuXjd0 /6ITIKdj5Y3oEL6b1TCKkAzGXIm6448Su3ay037U7kEx2+XuuCHPSGLliIclxw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675439457; 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=sxktI946gHplmt2XXTwl7W+QxNL7B49XS21eQskE818=; b=W/KzVPb4S2ct9u8tJYkJUPdgmiM8mtc861Dr2SPuf8GOAaFqvAV0J0o5JwxWM/hu1GmhdB EN0z/96r315tlV+oc8HUpMiEfKcDDgqjwi91283W1cDtMGXZhkvpf8ViT8daCkgOLS9ATS FTlcmbkiM9nQpaXKtY1K7OEHa6sZWq7gBNfFlgyQSjju/Z+R/PHCMYkfGbNQiXVTblhoLE v4KZz/EsbM+ygf2hU0lnTxqUyW3hAHN2Wuz+5psXr5pWp32DGcSQOpCamYqXHn4N6l+GDG I5yk0QLX2EzeUEphEH2tS+t5IUD3eXWJ6Dg/EoG/kYkQixwrQP4CXXlm2wqBwA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675439457; a=rsa-sha256; cv=none; b=j2+D3xd/vDzhCQrDemElXNVc9fGxdnXJGpa1HxFWmIsanEF3eAI8FOTS1e5jPXxWdX2Of/ igwC5f7BBoMbKlQDaEmlaONhgXOpLx2iHAWyeU71F0en0Nr10zfOWKrLUrz+CE/Td40gVp eJi4oSuQutvZjYWFpOTxbB3C8WUVklyHfClBt1mM6k8XvOzKoL4uaoCc93GF9sb3j9VIty PbMxY+G+EahBfwmP/I5fFJeeWGf4GnJYkQfVfqxSGSbk+7WzYNoWibgD0L7lLI/MYDsPuU mCJpzuLV4+eXO92fJd9/CXf6eaRTkbaGWdGnWrU1Q4WCbTq4avksvKmzgnkfCg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (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) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4P7g9Y2yZVzgQv; Fri, 3 Feb 2023 15:50:57 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 313Fovxe024210; Fri, 3 Feb 2023 15:50:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 313FovSe024209; Fri, 3 Feb 2023 15:50:57 GMT (envelope-from git) Date: Fri, 3 Feb 2023 15:50:57 GMT Message-Id: <202302031550.313FovSe024209@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Warner Losh Subject: git: db8d0c0cd998 - main - kboot: Allocate a really big first segment List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: imp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: db8d0c0cd998722535f984c017acafbd78be2ba7 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=db8d0c0cd998722535f984c017acafbd78be2ba7 commit db8d0c0cd998722535f984c017acafbd78be2ba7 Author: Warner Losh AuthorDate: 2023-02-03 15:41:03 +0000 Commit: Warner Losh CommitDate: 2023-02-03 15:41:41 +0000 kboot: Allocate a really big first segment Allocate a huge segment for the first kexec_load segments. We limit the lessor of: allocation to the size of the remaining memory segment 45% of available memory 95% of the memory we can allocate This allows us to have really large RAM disks. We likely need to limit this to the amount we actually used, though, since this can be a lot of memory. We have to do this complicated calculation for a few reasons: First, we need 2 copies of the loaded kernel in the memory: The kernel can copy everything to a temporary buffer. Next, malloc (via mmap) is limited to a certain amount due to over commit, so we have to not allocate all we can (only most of what we can). Sponsored by: Netflix Reviewed by: tsoome Differential Revision: https://reviews.freebsd.org/D38314 --- stand/kboot/main.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/stand/kboot/main.c b/stand/kboot/main.c index 75c2d55c3f39..450934b72777 100644 --- a/stand/kboot/main.c +++ b/stand/kboot/main.c @@ -322,6 +322,7 @@ get_phys_buffer(vm_offset_t dest, const size_t len, void **buf) { int i = 0; const size_t segsize = 64*1024*1024; + size_t sz; if (nkexec_segments == HOST_KEXEC_SEGMENT_MAX) panic("Tried to load too many kexec segments"); @@ -332,10 +333,22 @@ get_phys_buffer(vm_offset_t dest, const size_t len, void **buf) goto out; } - loaded_segments[nkexec_segments].buf = host_getmem(segsize); - loaded_segments[nkexec_segments].bufsz = segsize; + sz = segsize; + if (nkexec_segments == 0) { + /* how much space does this segment have */ + sz = space_avail(dest); + /* Clip to 45% of available memory (need 2 copies) */ + sz = min(sz, rounddown2(mem_avail * 45 / 100, SEGALIGN)); + /* And only use 95% of what we can allocate */ + sz = min(sz, rounddown2( + (commit_limit - committed_as) * 95 / 100, SEGALIGN)); + printf("Allocating %zd MB for first segment\n", sz >> 20); + } + + loaded_segments[nkexec_segments].buf = host_getmem(sz); + loaded_segments[nkexec_segments].bufsz = sz; loaded_segments[nkexec_segments].mem = (void *)rounddown2(dest,SEGALIGN); - loaded_segments[nkexec_segments].memsz = segsize; + loaded_segments[nkexec_segments].memsz = sz; i = nkexec_segments; nkexec_segments++;