xref: /freebsd/sys/contrib/openzfs/lib/libzpool/arc_os.c (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
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 }
88