From 6cf6f091cf9f0e7d9a9c21bf7db40916bb8c2d50 Mon Sep 17 00:00:00 2001 From: Rob Norris Date: Fri, 24 Oct 2025 23:19:53 +1100 Subject: [PATCH] libspl: move physmem to sys/systm.h; initialise at libspl_init() Sponsored-by: https://despairlabs.com/sponsor/ Reviewed-by: Brian Behlendorf Signed-off-by: Rob Norris Closes #17861 --- include/sys/zfs_context.h | 5 ++++- lib/libspl/include/Makefile.am | 1 + lib/libspl/include/sys/systm.h | 34 ++++++++++++++++++++++++++++++++++ lib/libspl/libspl.c | 8 ++++++++ lib/libzpool/kernel.c | 3 --- 5 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 lib/libspl/include/sys/systm.h diff --git a/include/sys/zfs_context.h b/include/sys/zfs_context.h index ef5899b11..d9eb64b1c 100644 --- a/include/sys/zfs_context.h +++ b/include/sys/zfs_context.h @@ -127,6 +127,10 @@ extern "C" { #include #include #include +#include +#include +#include +#include #include @@ -206,7 +210,6 @@ extern char *vn_dumpdir; #define NN_DIVISOR_1000 (1U << 0) #define NN_NUMBUF_SZ (6) -extern uint64_t physmem; extern const char *random_path; extern const char *urandom_path; diff --git a/lib/libspl/include/Makefile.am b/lib/libspl/include/Makefile.am index 41139d33e..8c5bb7b72 100644 --- a/lib/libspl/include/Makefile.am +++ b/lib/libspl/include/Makefile.am @@ -59,6 +59,7 @@ libspl_sys_HEADERS = \ %D%/sys/string.h \ %D%/sys/sunddi.h \ %D%/sys/systeminfo.h \ + %D%/sys/systm.h \ %D%/sys/thread.h \ %D%/sys/taskq.h \ %D%/sys/time.h \ diff --git a/lib/libspl/include/sys/systm.h b/lib/libspl/include/sys/systm.h new file mode 100644 index 000000000..94fcfdd2a --- /dev/null +++ b/lib/libspl/include/sys/systm.h @@ -0,0 +1,34 @@ +// SPDX-License-Identifier: CDDL-1.0 +/* + * CDDL HEADER START + * + * The contents of this file are subject to the terms of the + * Common Development and Distribution License (the "License"). + * You may not use this file except in compliance with the License. + * + * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE + * or https://opensource.org/licenses/CDDL-1.0. + * See the License for the specific language governing permissions + * and limitations under the License. + * + * When distributing Covered Code, include this CDDL HEADER in each + * file and include the License file at usr/src/OPENSOLARIS.LICENSE. + * If applicable, add the following below this CDDL HEADER, with the + * fields enclosed by brackets "[]" replaced with your own identifying + * information: Portions Copyright [yyyy] [name of copyright owner] + * + * CDDL HEADER END + */ +/* + * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright 2011 Nexenta Systems, Inc. All rights reserved. + * Copyright (c) 2012, 2018 by Delphix. All rights reserved. + * Copyright (c) 2012, Joyent, Inc. All rights reserved. + */ + +#ifndef _LIBSPL_SYS_SYSTM_H +#define _LIBSPL_SYS_SYSTM_H + +extern uint64_t physmem; + +#endif diff --git a/lib/libspl/libspl.c b/lib/libspl/libspl.c index 7c24f5cc0..d189357a1 100644 --- a/lib/libspl/libspl.c +++ b/lib/libspl/libspl.c @@ -20,14 +20,22 @@ * CDDL HEADER END */ /* + * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2012, 2018 by Delphix. All rights reserved. + * Copyright (c) 2016 Actifio, Inc. All rights reserved. + * Copyright (c) 2025, Klara, Inc. * Copyright (c) 2025, Rob Norris */ #include +#include + +uint64_t physmem; void libspl_init(void) { + physmem = sysconf(_SC_PHYS_PAGES); } void diff --git a/lib/libzpool/kernel.c b/lib/libzpool/kernel.c index 24d6fada3..25663882b 100644 --- a/lib/libzpool/kernel.c +++ b/lib/libzpool/kernel.c @@ -60,7 +60,6 @@ * Emulation of kernel services in userland. */ -uint64_t physmem; uint32_t hostid; struct utsname hw_utsname; @@ -509,8 +508,6 @@ kernel_init(int mode) umem_nofail_callback(umem_out_of_memory); - physmem = sysconf(_SC_PHYS_PAGES); - dprintf("physmem = %llu pages (%.2f GB)\n", (u_longlong_t)physmem, (double)physmem * sysconf(_SC_PAGE_SIZE) / (1ULL << 30));