Date: Wed, 19 Feb 2025 14:14:26 GMT From: Olivier Certner <olce@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org Subject: git: 16317a174a52 - main - vm_page_startup(): Clarify memory lowest, highest and size computation Message-ID: <202502191414.51JEEQpR038262@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch main has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=16317a174a5288f0377f8d40421b5c7821d57ac2 commit 16317a174a5288f0377f8d40421b5c7821d57ac2 Author: Olivier Certner <olce@FreeBSD.org> AuthorDate: 2024-10-29 10:41:47 +0000 Commit: Olivier Certner <olce@FreeBSD.org> 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202502191414.51JEEQpR038262>