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 (c) 2018, Joyent, Inc. 25 * Copyright (c) 2011, 2019 by Delphix. All rights reserved. 26 * Copyright (c) 2014 by Saso Kiselkov. All rights reserved. 27 * Copyright 2017 Nexenta Systems, Inc. All rights reserved. 28 */ 29 30 #include <sys/zfs_context.h> 31 #include <sys/arc_impl.h> 32 33 /* 34 * Return a default max arc size based on the amount of physical memory. 35 * This may be overridden by tuning the zfs_arc_max module parameter. 36 */ 37 uint64_t 38 arc_default_max(uint64_t min, uint64_t allmem) 39 { 40 uint64_t size; 41 42 if (allmem >= 1 << 30) 43 size = allmem - (1 << 30); 44 else 45 size = min; 46 return (MAX(allmem * 5 / 8, size)); 47 } 48 49 int64_t 50 arc_available_memory(void) 51 { 52 int64_t lowest = INT64_MAX; 53 54 /* Every 100 calls, free a small amount */ 55 if (random_in_range(100) == 0) 56 lowest = -1024; 57 58 return (lowest); 59 } 60 61 int 62 arc_memory_throttle(spa_t *spa, uint64_t reserve, uint64_t txg) 63 { 64 (void) spa, (void) reserve, (void) txg; 65 return (0); 66 } 67 68 uint64_t 69 arc_all_memory(void) 70 { 71 return (ptob(physmem) / 2); 72 } 73 74 uint64_t 75 arc_free_memory(void) 76 { 77 return (random_in_range(arc_all_memory() * 20 / 100)); 78 } 79 80 void 81 arc_register_hotplug(void) 82 { 83 } 84 85 void 86 arc_unregister_hotplug(void) 87 { 88 } 89