xref: /freebsd/sys/contrib/openzfs/module/os/linux/spl/spl-vmem.c (revision a67cc943273ba7cba2f78e33fc5897e1fbecd462)
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  *  For details, see <http://zfsonlinux.org/>.
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 
25 #include <linux/percpu_compat.h>
26 #include <sys/debug.h>
27 #include <sys/vmem.h>
28 #include <sys/kmem_cache.h>
29 #include <sys/shrinker.h>
30 #include <linux/module.h>
31 
32 /*
33  * Public vmem_alloc(), vmem_zalloc() and vmem_free() interfaces.
34  */
35 void *
36 spl_vmem_alloc(size_t size, int flags, const char *func, int line)
37 {
38 	ASSERT0(flags & ~KM_PUBLIC_MASK);
39 
40 	flags |= KM_VMEM;
41 
42 #if !defined(DEBUG_KMEM)
43 	return (spl_kmem_alloc_impl(size, flags, NUMA_NO_NODE));
44 #elif !defined(DEBUG_KMEM_TRACKING)
45 	return (spl_kmem_alloc_debug(size, flags, NUMA_NO_NODE));
46 #else
47 	return (spl_kmem_alloc_track(size, flags, func, line, NUMA_NO_NODE));
48 #endif
49 }
50 EXPORT_SYMBOL(spl_vmem_alloc);
51 
52 void *
53 spl_vmem_zalloc(size_t size, int flags, const char *func, int line)
54 {
55 	ASSERT0(flags & ~KM_PUBLIC_MASK);
56 
57 	flags |= (KM_VMEM | KM_ZERO);
58 
59 #if !defined(DEBUG_KMEM)
60 	return (spl_kmem_alloc_impl(size, flags, NUMA_NO_NODE));
61 #elif !defined(DEBUG_KMEM_TRACKING)
62 	return (spl_kmem_alloc_debug(size, flags, NUMA_NO_NODE));
63 #else
64 	return (spl_kmem_alloc_track(size, flags, func, line, NUMA_NO_NODE));
65 #endif
66 }
67 EXPORT_SYMBOL(spl_vmem_zalloc);
68 
69 void
70 spl_vmem_free(const void *buf, size_t size)
71 {
72 #if !defined(DEBUG_KMEM)
73 	return (spl_kmem_free_impl(buf, size));
74 #elif !defined(DEBUG_KMEM_TRACKING)
75 	return (spl_kmem_free_debug(buf, size));
76 #else
77 	return (spl_kmem_free_track(buf, size));
78 #endif
79 }
80 EXPORT_SYMBOL(spl_vmem_free);
81 
82 int
83 spl_vmem_init(void)
84 {
85 	return (0);
86 }
87 
88 void
89 spl_vmem_fini(void)
90 {
91 }
92