1*61145dc2SMartin Matuska // SPDX-License-Identifier: GPL-2.0-or-later
2eda14cbcSMatt Macy /*
3eda14cbcSMatt Macy * Copyright (C) 2007-2010 Lawrence Livermore National Security, LLC.
4eda14cbcSMatt Macy * Copyright (C) 2007 The Regents of the University of California.
5eda14cbcSMatt Macy * Produced at Lawrence Livermore National Laboratory (cf, DISCLAIMER).
6eda14cbcSMatt Macy * Written by Brian Behlendorf <behlendorf1@llnl.gov>.
7eda14cbcSMatt Macy * UCRL-CODE-235197
8eda14cbcSMatt Macy *
9eda14cbcSMatt Macy * This file is part of the SPL, Solaris Porting Layer.
10eda14cbcSMatt Macy *
11eda14cbcSMatt Macy * The SPL is free software; you can redistribute it and/or modify it
12eda14cbcSMatt Macy * under the terms of the GNU General Public License as published by the
13eda14cbcSMatt Macy * Free Software Foundation; either version 2 of the License, or (at your
14eda14cbcSMatt Macy * option) any later version.
15eda14cbcSMatt Macy *
16eda14cbcSMatt Macy * The SPL is distributed in the hope that it will be useful, but WITHOUT
17eda14cbcSMatt Macy * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18eda14cbcSMatt Macy * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19eda14cbcSMatt Macy * for more details.
20eda14cbcSMatt Macy *
21eda14cbcSMatt Macy * You should have received a copy of the GNU General Public License along
22eda14cbcSMatt Macy * with the SPL. If not, see <http://www.gnu.org/licenses/>.
23eda14cbcSMatt Macy */
24eda14cbcSMatt Macy
25eda14cbcSMatt Macy #include <sys/debug.h>
26eda14cbcSMatt Macy #include <sys/vmem.h>
27eda14cbcSMatt Macy #include <sys/kmem_cache.h>
28eda14cbcSMatt Macy #include <sys/shrinker.h>
29eda14cbcSMatt Macy #include <linux/module.h>
30eda14cbcSMatt Macy
31eda14cbcSMatt Macy /*
32eda14cbcSMatt Macy * Public vmem_alloc(), vmem_zalloc() and vmem_free() interfaces.
33eda14cbcSMatt Macy */
34eda14cbcSMatt Macy void *
spl_vmem_alloc(size_t size,int flags,const char * func,int line)35eda14cbcSMatt Macy spl_vmem_alloc(size_t size, int flags, const char *func, int line)
36eda14cbcSMatt Macy {
37eda14cbcSMatt Macy ASSERT0(flags & ~KM_PUBLIC_MASK);
38eda14cbcSMatt Macy
39eda14cbcSMatt Macy flags |= KM_VMEM;
40eda14cbcSMatt Macy
41eda14cbcSMatt Macy #if !defined(DEBUG_KMEM)
42eda14cbcSMatt Macy return (spl_kmem_alloc_impl(size, flags, NUMA_NO_NODE));
43eda14cbcSMatt Macy #elif !defined(DEBUG_KMEM_TRACKING)
44eda14cbcSMatt Macy return (spl_kmem_alloc_debug(size, flags, NUMA_NO_NODE));
45eda14cbcSMatt Macy #else
46eda14cbcSMatt Macy return (spl_kmem_alloc_track(size, flags, func, line, NUMA_NO_NODE));
47eda14cbcSMatt Macy #endif
48eda14cbcSMatt Macy }
49eda14cbcSMatt Macy EXPORT_SYMBOL(spl_vmem_alloc);
50eda14cbcSMatt Macy
51eda14cbcSMatt Macy void *
spl_vmem_zalloc(size_t size,int flags,const char * func,int line)52eda14cbcSMatt Macy spl_vmem_zalloc(size_t size, int flags, const char *func, int line)
53eda14cbcSMatt Macy {
54eda14cbcSMatt Macy ASSERT0(flags & ~KM_PUBLIC_MASK);
55eda14cbcSMatt Macy
56eda14cbcSMatt Macy flags |= (KM_VMEM | KM_ZERO);
57eda14cbcSMatt Macy
58eda14cbcSMatt Macy #if !defined(DEBUG_KMEM)
59eda14cbcSMatt Macy return (spl_kmem_alloc_impl(size, flags, NUMA_NO_NODE));
60eda14cbcSMatt Macy #elif !defined(DEBUG_KMEM_TRACKING)
61eda14cbcSMatt Macy return (spl_kmem_alloc_debug(size, flags, NUMA_NO_NODE));
62eda14cbcSMatt Macy #else
63eda14cbcSMatt Macy return (spl_kmem_alloc_track(size, flags, func, line, NUMA_NO_NODE));
64eda14cbcSMatt Macy #endif
65eda14cbcSMatt Macy }
66eda14cbcSMatt Macy EXPORT_SYMBOL(spl_vmem_zalloc);
67eda14cbcSMatt Macy
68eda14cbcSMatt Macy void
spl_vmem_free(const void * buf,size_t size)69eda14cbcSMatt Macy spl_vmem_free(const void *buf, size_t size)
70eda14cbcSMatt Macy {
71eda14cbcSMatt Macy #if !defined(DEBUG_KMEM)
72eda14cbcSMatt Macy return (spl_kmem_free_impl(buf, size));
73eda14cbcSMatt Macy #elif !defined(DEBUG_KMEM_TRACKING)
74eda14cbcSMatt Macy return (spl_kmem_free_debug(buf, size));
75eda14cbcSMatt Macy #else
76eda14cbcSMatt Macy return (spl_kmem_free_track(buf, size));
77eda14cbcSMatt Macy #endif
78eda14cbcSMatt Macy }
79eda14cbcSMatt Macy EXPORT_SYMBOL(spl_vmem_free);
80eda14cbcSMatt Macy
81eda14cbcSMatt Macy int
spl_vmem_init(void)82eda14cbcSMatt Macy spl_vmem_init(void)
83eda14cbcSMatt Macy {
84eda14cbcSMatt Macy return (0);
85eda14cbcSMatt Macy }
86eda14cbcSMatt Macy
87eda14cbcSMatt Macy void
spl_vmem_fini(void)88eda14cbcSMatt Macy spl_vmem_fini(void)
89eda14cbcSMatt Macy {
90eda14cbcSMatt Macy }
91