Path: blob/main/sys/contrib/openzfs/module/os/linux/spl/spl-shrinker.c
48775 views
// SPDX-License-Identifier: GPL-2.0-or-later1/*2* Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.3* Copyright (C) 2007 The Regents of the University of California.4* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).5* Written by Brian Behlendorf <[email protected]>.6* UCRL-CODE-2351977*8* This file is part of the SPL, Solaris Porting Layer.9*10* The SPL is free software; you can redistribute it and/or modify it11* under the terms of the GNU General Public License as published by the12* Free Software Foundation; either version 2 of the License, or (at your13* option) any later version.14*15* The SPL is distributed in the hope that it will be useful, but WITHOUT16* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or17* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License18* for more details.19*20* You should have received a copy of the GNU General Public License along21* with the SPL. If not, see <http://www.gnu.org/licenses/>.22*23* Solaris Porting Layer (SPL) Shrinker Implementation.24*/2526#include <sys/kmem.h>27#include <sys/shrinker.h>2829struct shrinker *30spl_register_shrinker(const char *name, spl_shrinker_cb countfunc,31spl_shrinker_cb scanfunc, int seek_cost)32{33struct shrinker *shrinker;3435/* allocate shrinker */36#ifdef HAVE_SHRINKER_REGISTER37/* 6.7: kernel will allocate the shrinker for us */38shrinker = shrinker_alloc(0, name);39#else40/* 4.4-6.6: we allocate the shrinker */41shrinker = kmem_zalloc(sizeof (struct shrinker), KM_SLEEP);42#endif4344if (shrinker == NULL)45return (NULL);4647/* set callbacks */48shrinker->count_objects = countfunc;49shrinker->scan_objects = scanfunc;5051/* set params */52shrinker->seeks = seek_cost;5354/* register with kernel */55#if defined(HAVE_SHRINKER_REGISTER)56shrinker_register(shrinker);57#elif defined(HAVE_REGISTER_SHRINKER_VARARG)58register_shrinker(shrinker, name);59#else60register_shrinker(shrinker);61#endif6263return (shrinker);64}65EXPORT_SYMBOL(spl_register_shrinker);6667void68spl_unregister_shrinker(struct shrinker *shrinker)69{70#if defined(HAVE_SHRINKER_REGISTER)71shrinker_free(shrinker);72#else73unregister_shrinker(shrinker);74kmem_free(shrinker, sizeof (struct shrinker));75#endif76}77EXPORT_SYMBOL(spl_unregister_shrinker);787980