Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/sys/contrib/openzfs/module/os/linux/spl/spl-shrinker.c
48775 views
1
// SPDX-License-Identifier: GPL-2.0-or-later
2
/*
3
* Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
4
* Copyright (C) 2007 The Regents of the University of California.
5
* Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
6
* Written by Brian Behlendorf <[email protected]>.
7
* UCRL-CODE-235197
8
*
9
* This file is part of the SPL, Solaris Porting Layer.
10
*
11
* The SPL is free software; you can redistribute it and/or modify it
12
* under the terms of the GNU General Public License as published by the
13
* Free Software Foundation; either version 2 of the License, or (at your
14
* option) any later version.
15
*
16
* The SPL is distributed in the hope that it will be useful, but WITHOUT
17
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19
* for more details.
20
*
21
* You should have received a copy of the GNU General Public License along
22
* with the SPL. If not, see <http://www.gnu.org/licenses/>.
23
*
24
* Solaris Porting Layer (SPL) Shrinker Implementation.
25
*/
26
27
#include <sys/kmem.h>
28
#include <sys/shrinker.h>
29
30
struct shrinker *
31
spl_register_shrinker(const char *name, spl_shrinker_cb countfunc,
32
spl_shrinker_cb scanfunc, int seek_cost)
33
{
34
struct shrinker *shrinker;
35
36
/* allocate shrinker */
37
#ifdef HAVE_SHRINKER_REGISTER
38
/* 6.7: kernel will allocate the shrinker for us */
39
shrinker = shrinker_alloc(0, name);
40
#else
41
/* 4.4-6.6: we allocate the shrinker */
42
shrinker = kmem_zalloc(sizeof (struct shrinker), KM_SLEEP);
43
#endif
44
45
if (shrinker == NULL)
46
return (NULL);
47
48
/* set callbacks */
49
shrinker->count_objects = countfunc;
50
shrinker->scan_objects = scanfunc;
51
52
/* set params */
53
shrinker->seeks = seek_cost;
54
55
/* register with kernel */
56
#if defined(HAVE_SHRINKER_REGISTER)
57
shrinker_register(shrinker);
58
#elif defined(HAVE_REGISTER_SHRINKER_VARARG)
59
register_shrinker(shrinker, name);
60
#else
61
register_shrinker(shrinker);
62
#endif
63
64
return (shrinker);
65
}
66
EXPORT_SYMBOL(spl_register_shrinker);
67
68
void
69
spl_unregister_shrinker(struct shrinker *shrinker)
70
{
71
#if defined(HAVE_SHRINKER_REGISTER)
72
shrinker_free(shrinker);
73
#else
74
unregister_shrinker(shrinker);
75
kmem_free(shrinker, sizeof (struct shrinker));
76
#endif
77
}
78
EXPORT_SYMBOL(spl_unregister_shrinker);
79
80