From nobody Tue Apr 8 13:40:44 2025 X-Original-To: dev-commits-src-branches@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 4ZX6fN6FYzz5sQ6t; Tue, 08 Apr 2025 13:40:44 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4ZX6fN3y7Wz3CZV; Tue, 08 Apr 2025 13:40:44 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1744119644; 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=V1iajTtH9+W+F/bOxwryp0oVKLQzxzF+mAQJt8HbNb8=; b=MyWcYsT3R6PxLROEuPasvhDu9k5ckD4Nefi4jOKvIvSTHv+4OZYx//T7g+sGshm9A6P8sZ VZVaZrYA4CRZrCvJZ5XXtOVjisEq+OnDFepHwaBFTKPZlwAH74RpWyPf9ypdtZa5NlxpdZ HlfaMMIfflVfNYlK+iiOuZBYwZ0M5G5ifzVnfNzxsNq14RbJ1q8yzM2v0VOVEzZ3SDWVYA 7nyMeoEPWUaopGLtQzEnQvZrpKlYdg/DHDgVGuj4/IaoIi3xeUsXw/56xTYzsKqohbdvsX ZP0y9Ez+vpCvuKz/c4GxYGVCTsY/CFsa7m3Vo2alANuQU5Fy9I14+YuuRHtQXQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1744119644; a=rsa-sha256; cv=none; b=IVmiqn1JOz7kAfOAfyklcvXF4Yv868Wz9A6PEbEKQ62tdJMw0p8cDvcciE27BVSyJ1jW/h T7GZiCdYRoLceJgCRZl4w6wQjCScnSaUpEEr/rlmVRbhumJMCE2BfvHThRAIf3WBg7w7+c 99es+bx/gcU8YnYIiB06RfCII75+czc6fitxhtsKryG6da7X487fHFK6hoLWGjMa0aa8V/ uWd3AKRn0gEja4iaiGezSKt9fO4vrYx6Qx6ZHZsHZJ9mqze5JLzFyiopU/MQZX0ygQpWqA RdU3TrUfATO7z1NxR7F5aW5TU/IQ18lIpDDpsuHxPoMY6RLs2VgN/p1oLdDtRQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1744119644; 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=V1iajTtH9+W+F/bOxwryp0oVKLQzxzF+mAQJt8HbNb8=; b=oEULCh47ven0oy60s2JI6mE3+q0KTRbkpglN1qB5MSwN+EHisnM7LYGRg/Dnh7C/5Rb13c lWNhPj+qp75vEnCaR0JGDmS8bbBTxG+wSb+vO28PbtJ3Q6+fHP9lN9LLBInUp5dozuxlrO t7GhCV18AwjWUHwPl3AL7rYmsvt4Rpdg8ycT3SCTgn2ZXCCSio4yuVELduzwz8iZQl7Ha5 /P4YgoijT9kGihZqUIaYJhzBDzkXO1ohtkGSlYH0wuvRf20LY0q1PX8SraCOr2NojdhJlI oZVzXuWXPk1hW+pJ6jFEQOVRe4g6Oueb25be1zAwE21W5bZ62X5OwwJiommeRA== 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 4ZX6fN3KSJzZrT; Tue, 08 Apr 2025 13:40:44 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 538DeiNm030794; Tue, 8 Apr 2025 13:40:44 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 538DeiAk030791; Tue, 8 Apr 2025 13:40:44 GMT (envelope-from git) Date: Tue, 8 Apr 2025 13:40:44 GMT Message-Id: <202504081340.538DeiAk030791@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: f3983aeb6284 - stable/14 - vm_page_startup(): Clarify memory lowest, highest and size computation List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-branches@freebsd.org Sender: owner-dev-commits-src-branches@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: olce X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: f3983aeb628460085f4fc0d9ab65aa8c36077de8 Auto-Submitted: auto-generated The branch stable/14 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=f3983aeb628460085f4fc0d9ab65aa8c36077de8 commit f3983aeb628460085f4fc0d9ab65aa8c36077de8 Author: Olivier Certner AuthorDate: 2024-10-29 10:41:47 +0000 Commit: Olivier Certner CommitDate: 2025-04-08 13:38:22 +0000 vm_page_startup(): Clarify memory lowest, highest and size computation Change the comment before this block of code, and separate the latter from the preceding one by an empty line. Move the loop on phys_avail[] to compute the minimum and maximum memory physical addresses closer to the initialization of 'low_avail' and 'high_avail', so that it's immediately clear why the loop starts at 2 (and remove the related comment). While here, fuse the additional loop in the VM_PHYSSEG_DENSE case that is used to compute the exact physical memory size. This change suppresses one occurence of detecting whether at least one of VM_PHYSSEG_DENSE or VM_PHYSSEG_SPARSE is defined at compile time, but there is still another one in PHYS_TO_VM_PAGE(). Reviewed by: markj MFC after: 1 week Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D48632 (cherry picked from commit 16317a174a5288f0377f8d40421b5c7821d57ac2) --- sys/vm/vm_page.c | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/sys/vm/vm_page.c b/sys/vm/vm_page.c index 49628b94b12b..979a4b7b07fb 100644 --- a/sys/vm/vm_page.c +++ b/sys/vm/vm_page.c @@ -650,40 +650,39 @@ vm_page_startup(vm_offset_t vaddr) pa += PAGE_SIZE; } #endif + /* - * Compute the number of pages of memory that will be available for - * use, taking into account the overhead of a page structure per page. - * In other words, solve - * "available physical memory" - round_page(page_range * - * sizeof(struct vm_page)) = page_range * PAGE_SIZE - * for page_range. + * Determine the lowest and highest physical addresses and, in the case + * of VM_PHYSSEG_SPARSE, the exact size of the available physical + * memory. vm_phys_early_startup() already checked that phys_avail[] + * has at least one element. */ +#ifdef VM_PHYSSEG_SPARSE + size = phys_avail[1] - phys_avail[0]; +#endif low_avail = phys_avail[0]; high_avail = phys_avail[1]; - for (i = 0; i < vm_phys_nsegs; i++) { - if (vm_phys_segs[i].start < low_avail) - low_avail = vm_phys_segs[i].start; - if (vm_phys_segs[i].end > high_avail) - high_avail = vm_phys_segs[i].end; - } - /* Skip the first chunk. It is already accounted for. */ for (i = 2; phys_avail[i + 1] != 0; i += 2) { +#ifdef VM_PHYSSEG_SPARSE + size += phys_avail[i + 1] - phys_avail[i]; +#endif if (phys_avail[i] < low_avail) low_avail = phys_avail[i]; if (phys_avail[i + 1] > high_avail) high_avail = phys_avail[i + 1]; } - first_page = low_avail / PAGE_SIZE; + for (i = 0; i < vm_phys_nsegs; i++) { #ifdef VM_PHYSSEG_SPARSE - size = 0; - for (i = 0; i < vm_phys_nsegs; i++) size += vm_phys_segs[i].end - vm_phys_segs[i].start; - for (i = 0; phys_avail[i + 1] != 0; i += 2) - size += phys_avail[i + 1] - phys_avail[i]; -#elif defined(VM_PHYSSEG_DENSE) +#endif + if (vm_phys_segs[i].start < low_avail) + low_avail = vm_phys_segs[i].start; + if (vm_phys_segs[i].end > high_avail) + high_avail = vm_phys_segs[i].end; + } + first_page = low_avail / PAGE_SIZE; +#ifdef VM_PHYSSEG_DENSE size = high_avail - low_avail; -#else -#error "Either VM_PHYSSEG_DENSE or VM_PHYSSEG_SPARSE must be defined." #endif #ifdef PMAP_HAS_PAGE_ARRAY