From nobody Wed Feb 19 14:14:26 2025 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 4YydgR5x37z5pQB8; Wed, 19 Feb 2025 14:14: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 "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4YydgR0hm8z3nC9; Wed, 19 Feb 2025 14:14:27 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1739974467; 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=sK8sPWJdHmnOBGLbysbJ6U1QurIDeDpzjhc/iDhn350=; b=Xi9iPBFhK4QclME4nl9XcDIzhBUuzq7WlPCNIoSMdlP59X4+7ziYqPcgEmlRbQzJofGfh0 9as0V3i+jhpHoYtJ4kphQk2LX9PrHwRv1EI51zzGKxvq3rtvqmmaVq/j5g6/l9GVY/vOqG 5O6hpk3crs2huQZciaQeo4J9Vyt4Yi8rsccJ1sXl2D5/7f4OtxYTJtbBoI4g12CGxZWmn5 ot6nOqayzE/4C334dkOuxQ+1e9siZhyeeMn4WoI4LDqHOR8bu/aowUoGTvJmnPBeA3yXPM sNNDeEhb39L4yNa+lV+CspeYE8ZA6bwrgbK50Xo/ugQdRGFrNiM3HV4Zxt5bLg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1739974467; a=rsa-sha256; cv=none; b=kpJmPZtcUBVgiBToXNGGqOzq7V8eZNOkuLmvuUc8jfo96VNRMhOZs/X7GRC9UvATixPR7I 4PTD1soBJkrlbke7saY+HgfVKA40mMUuSP1mYqKTfafsfNOFJTN+m+KFyIxaGGhH9Q1Urq chhr4K0QaaaH+CHWyEjBOG+SfsAY4XHrJmosiRAk5I3a99lJwfkUKBOCquqOtQqj20PzVK +xaT7xgSqty5VK9PagtUrKNTqeVTVAlMdPDog5hNRF521mwURqob17C4qSr3Mfe0rV9/eS R0jCsDMVplAdNafX2J66QM2da9wqUdWhq/IAj8u8cnh+4aDRHmCM4dNUjFcvpw== 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=1739974467; 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=sK8sPWJdHmnOBGLbysbJ6U1QurIDeDpzjhc/iDhn350=; b=QGiHPbmfxBw+eZQFML5Xo9e//oNbV7yswDQIjjciJvzkRo7Vx1eEuEJyYTxkjRKIDH46Pl 2lHNVb1Rp17f1zxyIjMExmu+pAUdyuKQEHLjNbi8z5psfUMn96qm8a3ezHNE5W94GUpywo vwaaw2VGJjRHeMy2Tjnjb1Qv3EXyUA7AATupbLoACCSDcJRgMMjLaMuevVy3rluPMDCVZ9 ZV1JUvEjIBaqTI+RZMpctjay6/h/gA7v/JQSUzssFdG23nCWmkiVYq22glipsgKPh3ZsV9 7ttVQVUOG5rYTWev55r3JnXd9pbdEO40nJNTknfX3HL/HQ55UaTGRU6G5vO0dg== 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 4YydgR0F0Vz181t; Wed, 19 Feb 2025 14:14:27 +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 51JEEQuQ038265; Wed, 19 Feb 2025 14:14:26 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 51JEEQpR038262; Wed, 19 Feb 2025 14:14:26 GMT (envelope-from git) Date: Wed, 19 Feb 2025 14:14:26 GMT Message-Id: <202502191414.51JEEQpR038262@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Olivier Certner Subject: git: 16317a174a52 - main - vm_page_startup(): Clarify memory lowest, highest and size computation 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@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/main X-Git-Reftype: branch X-Git-Commit: 16317a174a5288f0377f8d40421b5c7821d57ac2 Auto-Submitted: auto-generated The branch main has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=16317a174a5288f0377f8d40421b5c7821d57ac2 commit 16317a174a5288f0377f8d40421b5c7821d57ac2 Author: Olivier Certner AuthorDate: 2024-10-29 10:41:47 +0000 Commit: Olivier Certner CommitDate: 2025-02-19 14:13:27 +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 --- 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 06965633ee07..c105aafca40f 100644 --- a/sys/vm/vm_page.c +++ b/sys/vm/vm_page.c @@ -655,40 +655,39 @@ vm_page_startup(vm_offset_t vaddr) #else (void)pa; #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