]> git.proxmox.com Git - mirror_spl.git/blame - module/spl/spl-vmem.c
Add hooks for disabling direct reclaim
[mirror_spl.git] / module / spl / spl-vmem.c
CommitLineData
b34b9563 1/*
e5b9b344
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.
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/>.
b34b9563 23 */
e5b9b344
BB
24
25#include <sys/debug.h>
26#include <sys/vmem.h>
c3eabc75 27#include <linux/mm_compat.h>
e5b9b344
BB
28#include <linux/module.h>
29
30vmem_t *heap_arena = NULL;
31EXPORT_SYMBOL(heap_arena);
32
33vmem_t *zio_alloc_arena = NULL;
34EXPORT_SYMBOL(zio_alloc_arena);
35
36vmem_t *zio_arena = NULL;
37EXPORT_SYMBOL(zio_arena);
38
39size_t
40vmem_size(vmem_t *vmp, int typemask)
41{
42 ASSERT3P(vmp, ==, NULL);
43 ASSERT3S(typemask & VMEM_ALLOC, ==, VMEM_ALLOC);
44 ASSERT3S(typemask & VMEM_FREE, ==, VMEM_FREE);
45
46 return (VMALLOC_TOTAL);
47}
48EXPORT_SYMBOL(vmem_size);
49
50/*
c3eabc75 51 * Public vmem_alloc(), vmem_zalloc() and vmem_free() interfaces.
e5b9b344 52 */
e5b9b344 53void *
c3eabc75 54spl_vmem_alloc(size_t size, int flags, const char *func, int line)
e5b9b344 55{
c3eabc75 56 ASSERT0(flags & ~KM_PUBLIC_MASK);
e5b9b344 57
c3eabc75 58 flags |= KM_VMEM;
e5b9b344 59
c3eabc75
BB
60#if !defined(DEBUG_KMEM)
61 return (spl_kmem_alloc_impl(size, flags, NUMA_NO_NODE));
62#elif !defined(DEBUG_KMEM_TRACKING)
63 return (spl_kmem_alloc_debug(size, flags, NUMA_NO_NODE));
64#else
65 return (spl_kmem_alloc_track(size, flags, func, line, NUMA_NO_NODE));
66#endif
e5b9b344 67}
c3eabc75 68EXPORT_SYMBOL(spl_vmem_alloc);
e5b9b344
BB
69
70void *
c3eabc75 71spl_vmem_zalloc(size_t size, int flags, const char *func, int line)
e5b9b344 72{
c3eabc75 73 ASSERT0(flags & ~KM_PUBLIC_MASK);
e5b9b344 74
c3eabc75 75 flags |= (KM_VMEM | KM_ZERO);
e5b9b344 76
c3eabc75
BB
77#if !defined(DEBUG_KMEM)
78 return (spl_kmem_alloc_impl(size, flags, NUMA_NO_NODE));
79#elif !defined(DEBUG_KMEM_TRACKING)
80 return (spl_kmem_alloc_debug(size, flags, NUMA_NO_NODE));
81#else
82 return (spl_kmem_alloc_track(size, flags, func, line, NUMA_NO_NODE));
83#endif
e5b9b344 84}
c3eabc75 85EXPORT_SYMBOL(spl_vmem_zalloc);
e5b9b344
BB
86
87void
c3eabc75 88spl_vmem_free(const void *buf, size_t size)
e5b9b344 89{
c3eabc75
BB
90#if !defined(DEBUG_KMEM)
91 return (spl_kmem_free_impl(buf, size));
92#elif !defined(DEBUG_KMEM_TRACKING)
93 return (spl_kmem_free_debug(buf, size));
94#else
95 return (spl_kmem_free_track(buf, size));
96#endif
e5b9b344 97}
c3eabc75 98EXPORT_SYMBOL(spl_vmem_free);
e5b9b344 99
c2fa0945
RY
100/*
101 * Public vmalloc() interface designed to be safe to be called during I/O.
102 */
103void *
104spl_vmalloc(unsigned long size, gfp_t lflags, pgprot_t prot)
105{
106#if defined(PF_MEMALLOC_NOIO)
107 void *ptr;
108 unsigned noio_flag = 0;
109
110 if (spl_fstrans_check())
111 noio_flag = memalloc_noio_save();
112
113 ptr = __vmalloc(size, lflags, prot);
114
115 if (spl_fstrans_check())
116 memalloc_noio_restore(noio_flag);
117
118 return (ptr);
119#else
120 return (__vmalloc(size, lflags, prot));
121#endif
122}
123EXPORT_SYMBOL(spl_vmalloc);
124
e5b9b344
BB
125int
126spl_vmem_init(void)
127{
c3eabc75 128 return (0);
e5b9b344
BB
129}
130
131void
132spl_vmem_fini(void)
133{
e5b9b344 134}