]> git.proxmox.com Git - mirror_zfs.git/blame - include/os/linux/spl/sys/shrinker.h
FreeBSD: Add zfs_link_create() error handling
[mirror_zfs.git] / include / os / linux / spl / sys / shrinker.h
CommitLineData
4b393c50 1/*
716154c5
BB
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.
716154c5
BB
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/>.
4b393c50 22 */
716154c5 23
a9125891
BB
24#ifndef _SPL_SHRINKER_H
25#define _SPL_SHRINKER_H
baf2979e
BB
26
27#include <linux/mm.h>
914b0631 28#include <linux/fs.h>
baf2979e 29
a55bcaad 30/*
c3d9c0df 31 * Due to frequent changes in the shrinker API the following
957dc103 32 * compatibility wrapper should be used.
c3d9c0df 33 *
957dc103
RN
34 * shrinker = spl_register_shrinker(name, countfunc, scanfunc, seek_cost);
35 * spl_unregister_shrinker(shrinker);
c3d9c0df 36 *
957dc103
RN
37 * spl_register_shrinker is used to create and register a shrinker with the
38 * given name.
270ece24
MA
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.
c3d9c0df
RY
44 *
45 * Example:
46 *
270ece24
MA
47 * static unsigned long
48 * my_count(struct shrinker *shrink, struct shrink_control *sc)
c3d9c0df 49 * {
c3d9c0df
RY
50 * ...calculate number of objects in the cache...
51 *
52 * return (number of objects in the cache);
53 * }
270ece24
MA
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 *
957dc103 61 * static struct shrinker *my_shrinker;
270ece24
MA
62 *
63 * void my_init_func(void) {
957dc103
RN
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);
270ece24 70 * }
a55bcaad 71 */
495bd532 72
957dc103
RN
73typedef unsigned long (*spl_shrinker_cb)
74 (struct shrinker *, struct shrink_control *);
495bd532 75
957dc103
RN
76struct shrinker *spl_register_shrinker(const char *name,
77 spl_shrinker_cb countfunc, spl_shrinker_cb scanfunc, int seek_cost);
78void spl_unregister_shrinker(struct shrinker *);
a55bcaad 79
957dc103
RN
80#ifndef SHRINK_STOP
81/* 3.0-3.11 compatibility */
270ece24 82#define SHRINK_STOP (-1)
c3d9c0df 83#endif
495bd532 84
a9125891 85#endif /* SPL_SHRINKER_H */