git: 13e15ac4990c - stable/13 - smp_topo(): correct allocation sizes for trivial topologies

From: Konstantin Belousov <kib_at_FreeBSD.org>
Date: Tue, 16 May 2023 04:11:03 UTC
The branch stable/13 has been updated by kib:

URL: https://cgit.FreeBSD.org/src/commit/?id=13e15ac4990ca2f725ea10c1d9f74398b737ccc9

commit 13e15ac4990ca2f725ea10c1d9f74398b737ccc9
Author:     Konstantin Belousov <kib@FreeBSD.org>
AuthorDate: 2023-05-09 15:08:22 +0000
Commit:     Konstantin Belousov <kib@FreeBSD.org>
CommitDate: 2023-05-16 04:03:38 +0000

    smp_topo(): correct allocation sizes for trivial topologies
    
    (cherry picked from commit 361c8f75a61832d9aa3dd4c589a0220f3467466f)
---
 sys/kern/subr_smp.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/sys/kern/subr_smp.c b/sys/kern/subr_smp.c
index 8d3e398d6b54..fafdc5b65cab 100644
--- a/sys/kern/subr_smp.c
+++ b/sys/kern/subr_smp.c
@@ -790,8 +790,8 @@ smp_topo_1level(int share, int count, int flags)
 	int i;
 
 	cpu = 0;
-	top = smp_topo_alloc(1);
 	packages = mp_ncpus / count;
+	top = smp_topo_alloc(1 + packages);
 	top->cg_child = child = top + 1;
 	top->cg_level = CG_SHARE_NONE;
 	for (i = 0; i < packages; i++, child++)
@@ -811,7 +811,8 @@ smp_topo_2level(int l2share, int l2count, int l1share, int l1count,
 	int j;
 
 	cpu = 0;
-	top = smp_topo_alloc(1);
+	top = smp_topo_alloc(1 + mp_ncpus / (l2count * l1count) +
+	    mp_ncpus / l1count);
 	l2g = top + 1;
 	top->cg_child = l2g;
 	top->cg_level = CG_SHARE_NONE;