Skip to content

Commit 6cf6f09

Browse files
robnbehlendorf
authored andcommitted
libspl: move physmem to sys/systm.h; initialise at libspl_init()
Sponsored-by: https://despairlabs.com/sponsor/ Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Rob Norris <[email protected]> Closes #17861
1 parent d02ea51 commit 6cf6f09

File tree

5 files changed

+47
-4
lines changed

5 files changed

+47
-4
lines changed

include/sys/zfs_context.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ extern "C" {
127127
#include <sys/kmem.h>
128128
#include <sys/zfs_delay.h>
129129
#include <sys/vnode.h>
130+
#include <sys/random.h>
131+
#include <sys/callb.h>
132+
#include <sys/trace.h>
133+
#include <sys/systm.h>
130134

131135
#include <sys/zfs_context_os.h>
132136

@@ -206,7 +210,6 @@ extern char *vn_dumpdir;
206210
#define NN_DIVISOR_1000 (1U << 0)
207211
#define NN_NUMBUF_SZ (6)
208212

209-
extern uint64_t physmem;
210213
extern const char *random_path;
211214
extern const char *urandom_path;
212215

lib/libspl/include/Makefile.am

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ libspl_sys_HEADERS = \
5959
%D%/sys/string.h \
6060
%D%/sys/sunddi.h \
6161
%D%/sys/systeminfo.h \
62+
%D%/sys/systm.h \
6263
%D%/sys/thread.h \
6364
%D%/sys/taskq.h \
6465
%D%/sys/time.h \

lib/libspl/include/sys/systm.h

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// SPDX-License-Identifier: CDDL-1.0
2+
/*
3+
* CDDL HEADER START
4+
*
5+
* The contents of this file are subject to the terms of the
6+
* Common Development and Distribution License (the "License").
7+
* You may not use this file except in compliance with the License.
8+
*
9+
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10+
* or https://opensource.org/licenses/CDDL-1.0.
11+
* See the License for the specific language governing permissions
12+
* and limitations under the License.
13+
*
14+
* When distributing Covered Code, include this CDDL HEADER in each
15+
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16+
* If applicable, add the following below this CDDL HEADER, with the
17+
* fields enclosed by brackets "[]" replaced with your own identifying
18+
* information: Portions Copyright [yyyy] [name of copyright owner]
19+
*
20+
* CDDL HEADER END
21+
*/
22+
/*
23+
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24+
* Copyright 2011 Nexenta Systems, Inc. All rights reserved.
25+
* Copyright (c) 2012, 2018 by Delphix. All rights reserved.
26+
* Copyright (c) 2012, Joyent, Inc. All rights reserved.
27+
*/
28+
29+
#ifndef _LIBSPL_SYS_SYSTM_H
30+
#define _LIBSPL_SYS_SYSTM_H
31+
32+
extern uint64_t physmem;
33+
34+
#endif

lib/libspl/libspl.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,22 @@
2020
* CDDL HEADER END
2121
*/
2222
/*
23+
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
24+
* Copyright (c) 2012, 2018 by Delphix. All rights reserved.
25+
* Copyright (c) 2016 Actifio, Inc. All rights reserved.
26+
* Copyright (c) 2025, Klara, Inc.
2327
* Copyright (c) 2025, Rob Norris <[email protected]>
2428
*/
2529

2630
#include <libspl.h>
31+
#include <unistd.h>
32+
33+
uint64_t physmem;
2734

2835
void
2936
libspl_init(void)
3037
{
38+
physmem = sysconf(_SC_PHYS_PAGES);
3139
}
3240

3341
void

lib/libzpool/kernel.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,6 @@
6060
* Emulation of kernel services in userland.
6161
*/
6262

63-
uint64_t physmem;
6463
uint32_t hostid;
6564
struct utsname hw_utsname;
6665

@@ -509,8 +508,6 @@ kernel_init(int mode)
509508

510509
umem_nofail_callback(umem_out_of_memory);
511510

512-
physmem = sysconf(_SC_PHYS_PAGES);
513-
514511
dprintf("physmem = %llu pages (%.2f GB)\n", (u_longlong_t)physmem,
515512
(double)physmem * sysconf(_SC_PAGE_SIZE) / (1ULL << 30));
516513

0 commit comments

Comments
 (0)