Skip to content

Commit c07f9a2

Browse files
robntonyhutter
authored andcommitted
arc_os: split userspace and Linux kernel code
The Linux arc_os.c carries userspace and kernel code, with very little overlap between the two. This lifts the userspace parts out into a separate arc_os.c for libzpool and removes it from the Linux side. Reviewed by: Brian Behlendorf <[email protected]> Reviewed-by: Alexander Motin <[email protected]> Signed-off-by: Rob Norris <[email protected]> Sponsored-by: https://despairlabs.com/sponsor/ Closes openzfs#16492
1 parent 0dee309 commit c07f9a2

File tree

3 files changed

+88
-46
lines changed

3 files changed

+88
-46
lines changed

lib/libzpool/Makefile.am

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ CPPCHECKTARGETS += libzpool.la
1212

1313
dist_libzpool_la_SOURCES = \
1414
%D%/abd_os.c \
15+
%D%/arc_os.c \
1516
%D%/kernel.c \
1617
%D%/taskq.c \
1718
%D%/util.c
@@ -42,7 +43,6 @@ nodist_libzpool_la_SOURCES = \
4243
module/lua/lvm.c \
4344
module/lua/lzio.c \
4445
\
45-
module/os/linux/zfs/arc_os.c \
4646
module/os/linux/zfs/trace.c \
4747
module/os/linux/zfs/vdev_file.c \
4848
module/os/linux/zfs/zfs_debug.c \

lib/libzpool/arc_os.c

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
* CDDL HEADER START
3+
*
4+
* The contents of this file are subject to the terms of the
5+
* Common Development and Distribution License (the "License").
6+
* You may not use this file except in compliance with the License.
7+
*
8+
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9+
* or https://opensource.org/licenses/CDDL-1.0.
10+
* See the License for the specific language governing permissions
11+
* and limitations under the License.
12+
*
13+
* When distributing Covered Code, include this CDDL HEADER in each
14+
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15+
* If applicable, add the following below this CDDL HEADER, with the
16+
* fields enclosed by brackets "[]" replaced with your own identifying
17+
* information: Portions Copyright [yyyy] [name of copyright owner]
18+
*
19+
* CDDL HEADER END
20+
*/
21+
/*
22+
* Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
23+
* Copyright (c) 2018, Joyent, Inc.
24+
* Copyright (c) 2011, 2019 by Delphix. All rights reserved.
25+
* Copyright (c) 2014 by Saso Kiselkov. All rights reserved.
26+
* Copyright 2017 Nexenta Systems, Inc. All rights reserved.
27+
*/
28+
29+
#include <sys/zfs_context.h>
30+
#include <sys/arc_impl.h>
31+
32+
/*
33+
* Return a default max arc size based on the amount of physical memory.
34+
* This may be overridden by tuning the zfs_arc_max module parameter.
35+
*/
36+
uint64_t
37+
arc_default_max(uint64_t min, uint64_t allmem)
38+
{
39+
uint64_t size;
40+
41+
if (allmem >= 1 << 30)
42+
size = allmem - (1 << 30);
43+
else
44+
size = min;
45+
return (MAX(allmem * 5 / 8, size));
46+
}
47+
48+
int64_t
49+
arc_available_memory(void)
50+
{
51+
int64_t lowest = INT64_MAX;
52+
53+
/* Every 100 calls, free a small amount */
54+
if (random_in_range(100) == 0)
55+
lowest = -1024;
56+
57+
return (lowest);
58+
}
59+
60+
int
61+
arc_memory_throttle(spa_t *spa, uint64_t reserve, uint64_t txg)
62+
{
63+
(void) spa, (void) reserve, (void) txg;
64+
return (0);
65+
}
66+
67+
uint64_t
68+
arc_all_memory(void)
69+
{
70+
return (ptob(physmem) / 2);
71+
}
72+
73+
uint64_t
74+
arc_free_memory(void)
75+
{
76+
return (random_in_range(arc_all_memory() * 20 / 100));
77+
}
78+
79+
void
80+
arc_register_hotplug(void)
81+
{
82+
}
83+
84+
void
85+
arc_unregister_hotplug(void)
86+
{
87+
}

module/os/linux/zfs/arc_os.c

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,12 @@
4242
#include <sys/abd.h>
4343
#include <sys/zil.h>
4444
#include <sys/fm/fs/zfs.h>
45-
#ifdef _KERNEL
4645
#include <sys/shrinker.h>
4746
#include <sys/vmsystm.h>
4847
#include <sys/zpl.h>
4948
#include <linux/page_compat.h>
5049
#include <linux/notifier.h>
5150
#include <linux/memory.h>
52-
#endif
5351
#include <sys/callb.h>
5452
#include <sys/kstat.h>
5553
#include <sys/zthr.h>
@@ -88,7 +86,6 @@ arc_default_max(uint64_t min, uint64_t allmem)
8886
return (MAX(allmem / 2, min));
8987
}
9088

91-
#ifdef _KERNEL
9289
/*
9390
* Return maximum amount of memory that we could possibly use. Reduced
9491
* to half of all memory in user space which is primarily used for testing.
@@ -449,48 +446,6 @@ arc_unregister_hotplug(void)
449446
unregister_memory_notifier(&arc_hotplug_callback_mem_nb);
450447
#endif
451448
}
452-
#else /* _KERNEL */
453-
int64_t
454-
arc_available_memory(void)
455-
{
456-
int64_t lowest = INT64_MAX;
457-
458-
/* Every 100 calls, free a small amount */
459-
if (random_in_range(100) == 0)
460-
lowest = -1024;
461-
462-
return (lowest);
463-
}
464-
465-
int
466-
arc_memory_throttle(spa_t *spa, uint64_t reserve, uint64_t txg)
467-
{
468-
(void) spa, (void) reserve, (void) txg;
469-
return (0);
470-
}
471-
472-
uint64_t
473-
arc_all_memory(void)
474-
{
475-
return (ptob(physmem) / 2);
476-
}
477-
478-
uint64_t
479-
arc_free_memory(void)
480-
{
481-
return (random_in_range(arc_all_memory() * 20 / 100));
482-
}
483-
484-
void
485-
arc_register_hotplug(void)
486-
{
487-
}
488-
489-
void
490-
arc_unregister_hotplug(void)
491-
{
492-
}
493-
#endif /* _KERNEL */
494449

495450
ZFS_MODULE_PARAM(zfs_arc, zfs_arc_, shrinker_limit, INT, ZMOD_RW,
496451
"Limit on number of pages that ARC shrinker can reclaim at once");

0 commit comments

Comments
 (0)