From nobody Thu Feb 02 20:16:27 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 4P796M3VCsz3kXPY; Thu, 2 Feb 2023 20:16: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 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 4P796M2zq5z4KNm; Thu, 2 Feb 2023 20:16:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675368987; 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=3KrIAXjmIaBKP0soxwlMga0U+vHOQkeNbA25zLEXVng=; b=hs5hGvBrloRdwhRN4XbpHGBZXL3BTdgvkmOiPlsBY0bI4maBDls4t04BralXI+leq4zwZq v3KV9I71jAENw+TXT7+zDrWOYOW15PQVGVqv0HjJyHQ86iHtSj8xjGSmep6Its5YBsUwkV RB0j1+pH9K/8weEo0iOYMvXILbNBOSOOn4RagL/H85wrQoXxVS9/V7fH/wJZcq1fLb07KO vnFuVOKm/aokNLgnh44AbDgxq9V6vK4smaUaypaMc5K5AWgbhSHUBPu1ZWdeanDQAmWRGU 4Wx1tH8++h5rdSrRhjIErfZh/0gXRqQelj3LjxKJHtjYD72zGXSn6Hvaeqi5mg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675368987; 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=3KrIAXjmIaBKP0soxwlMga0U+vHOQkeNbA25zLEXVng=; b=SpwzkjEFHBc5/QTisXm9B2qOSgADX2D9138KW9wIor2FDznRQ+anelVzWT+IFk9wxUGzCe t0xdC3HwAtK1mq3nlcjzcMCtufTnhI0taMmMV5lu0nqqTMuteIqLoSUw1ffe7DggMnFw6T Kklq34/qKToqZ3NydU/jRbwik4hrQr46sBmhu8pCnrGuXxW443FyAtBo+xrAQuDDM236uU vCdaeliMGXUDJhwkQYK4uIE5rUaBcUulImdtIUjBw3Jp4PHaoT5/+Wm7XPOy6YViPjOLOP VBLhmCGp2w++greU5udfcLaNuSWzg9CunKUbYDP00mAPPUNq30wtC2qA7UQrIw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675368987; a=rsa-sha256; cv=none; b=XQv+U4uVLlyler84Qs6lWiPirK99KOlvPGLQ6zJrNCeGCeeWIg6H87ebvOERDZOmTrP/3g J5Xx7RrEQoNFnmeZ7CvfFWIYgteelru/G1NmuYIjEmitkyk7aASMjXvSb3eKvp2B4bHZZj edVuUSdZBPpz/raI4yc59zH1kNG0MZ46p79s3uAua2+IVomZs3TL9HNhDKsOknlNCesstd hLlgnIl8MouM5rFUbBdpZ6cMD2XxPNxXjwZ4130Ra5RN8BwiEBlDZdCcixmYy4PU2rF8Se eM8xCNfupYi2wJaAS0OF+v+l7o2xPkYkiaXFAqj4jzCzUFWUoQanVAOpwIDYEw== 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 4P796M1xqPz16w0; Thu, 2 Feb 2023 20:16:27 +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 312KGRwx049881; Thu, 2 Feb 2023 20:16:27 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 312KGRRU049880; Thu, 2 Feb 2023 20:16:27 GMT (envelope-from git) Date: Thu, 2 Feb 2023 20:16:27 GMT Message-Id: <202302022016.312KGRRU049880@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: 7da605ec03c1 - main - kboot: Parse memory usage 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: 7da605ec03c14362c3e957989b59b3084e28697b Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by imp: URL: https://cgit.FreeBSD.org/src/commit/?id=7da605ec03c14362c3e957989b59b3084e28697b commit 7da605ec03c14362c3e957989b59b3084e28697b Author: Warner Losh AuthorDate: 2023-02-02 20:11:57 +0000 Commit: Warner Losh CommitDate: 2023-02-02 20:11:57 +0000 kboot: Parse memory usage To properly size segments, we have to know how much memory we have in the system, as well as how much this process can allocate. Due to our inability to overcommit, we need to know how much memory is available. commit_limit is the grand total allowed. committed_as is the current memory used. mem_avail is what Linux tells us is available. Find these from /proc/meminfo. We'll use them later to allocate the biggest possible segment sizes, but for now print the raw numbers. Sponsored by: Netflix Reviewed by: kevans (earlier version) Differential Revision: https://reviews.freebsd.org/D38267 --- stand/kboot/main.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/stand/kboot/main.c b/stand/kboot/main.c index 7144f081e4dd..0076db13b589 100644 --- a/stand/kboot/main.c +++ b/stand/kboot/main.c @@ -50,6 +50,45 @@ static void kboot_zfs_probe(void); extern int command_fdt_internal(int argc, char *argv[]); +static uint64_t commit_limit; +static uint64_t committed_as; +static uint64_t mem_avail; + +static void +memory_limits(void) +{ + int fd; + char buf[128]; + + /* + * To properly size the slabs, we need to find how much memory we can + * commit to using. commit_limit is the max, while commited_as is the + * current total. We can use these later to allocate the largetst amount + * of memory possible so we can support larger ram disks than we could + * by using fixed segment sizes. We also grab the memory available so + * we don't use more than 49% of that. + */ + fd = open("host:/proc/meminfo", O_RDONLY); + if (fd != -1) { + while (fgetstr(buf, sizeof(buf), fd) > 0) { + if (strncmp(buf, "MemAvailable:", 13) == 0) { + mem_avail = strtoll(buf + 13, NULL, 0); + mem_avail <<= 10; /* Units are kB */ + } else if (strncmp(buf, "CommitLimit:", 12) == 0) { + commit_limit = strtoll(buf + 13, NULL, 0); + commit_limit <<= 10; /* Units are kB */ + } else if (strncmp(buf, "Committed_AS:", 13) == 0) { + committed_as = strtoll(buf + 14, NULL, 0); + committed_as <<= 10; /* Units are kB */ + } + } + } + printf("Commit limit: %lld Committed bytes %lld Available %lld\n", + (long long)commit_limit, (long long)committed_as, + (long long)mem_avail); + close(fd); +} + /* * NB: getdev should likely be identical to this most places, except maybe * we should move to storing the length of the platform devdesc. @@ -217,6 +256,8 @@ main(int argc, const char **argv) setenv("LINES", "24", 1); setenv("usefdt", "1", 1); + memory_limits(); + /* * Find acpi, if it exists */