1 /*
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 <behlendorf1@llnl.gov>.
6  *  UCRL-CODE-235197
7  *
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 it
11  *  under the terms of the GNU General Public License as published by the
12  *  Free Software Foundation; either version 2 of the License, or (at your
13  *  option) any later version.
14  *
15  *  The SPL is distributed in the hope that it will be useful, but WITHOUT
16  *  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17  *  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
18  *  for more details.
19  *
20  *  You should have received a copy of the GNU General Public License along
21  *  with the SPL.  If not, see <http://www.gnu.org/licenses/>.
22  */
23 
24 #ifndef _SPL_SHRINKER_H
25 #define	_SPL_SHRINKER_H
26 
27 #include <linux/mm.h>
28 #include <linux/fs.h>
29 
30 /*
31  * Due to frequent changes in the shrinker API the following
32  * compatibility wrapper should be used.
33  *
34  *   shrinker = spl_register_shrinker(name, countfunc, scanfunc, seek_cost);
35  *   spl_unregister_shrinker(shrinker);
36  *
37  * spl_register_shrinker is used to create and register a shrinker with the
38  * given name.
39  * The countfunc returns the number of free-able objects.
40  * The scanfunc returns the number of objects that were freed.
41  * The callbacks can return SHRINK_STOP if further calls can't make any more
42  * progress.  Note that a return value of SHRINK_EMPTY is currently not
43  * supported.
44  *
45  * Example:
46  *
47  * static unsigned long
48  * my_count(struct shrinker *shrink, struct shrink_control *sc)
49  * {
50  *	...calculate number of objects in the cache...
51  *
52  *	return (number of objects in the cache);
53  * }
54  *
55  * static unsigned long
56  * my_scan(struct shrinker *shrink, struct shrink_control *sc)
57  * {
58  *	...scan objects in the cache and reclaim them...
59  * }
60  *
61  * static struct shrinker *my_shrinker;
62  *
63  * void my_init_func(void) {
64  *	my_shrinker = spl_register_shrinker("my-shrinker",
65  *	    my_count, my_scan, DEFAULT_SEEKS);
66  * }
67  *
68  * void my_fini_func(void) {
69  *	spl_unregister_shrinker(my_shrinker);
70  * }
71  */
72 
73 typedef unsigned long (*spl_shrinker_cb)
74 	(struct shrinker *, struct shrink_control *);
75 
76 struct shrinker *spl_register_shrinker(const char *name,
77     spl_shrinker_cb countfunc, spl_shrinker_cb scanfunc, int seek_cost);
78 void spl_unregister_shrinker(struct shrinker *);
79 
80 #ifndef SHRINK_STOP
81 /* 3.0-3.11 compatibility */
82 #define	SHRINK_STOP	(-1)
83 #endif
84 
85 #endif /* SPL_SHRINKER_H */
86