Path: blob/main/sys/contrib/openzfs/module/os/linux/spl/spl-vmem.c
48775 views
// SPDX-License-Identifier: GPL-2.0-or-later1/*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 <[email protected]>.6* UCRL-CODE-2351977*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 it11* under the terms of the GNU General Public License as published by the12* Free Software Foundation; either version 2 of the License, or (at your13* option) any later version.14*15* The SPL is distributed in the hope that it will be useful, but WITHOUT16* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or17* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License18* for more details.19*20* You should have received a copy of the GNU General Public License along21* with the SPL. If not, see <http://www.gnu.org/licenses/>.22*/2324#include <sys/debug.h>25#include <sys/vmem.h>26#include <sys/kmem_cache.h>27#include <sys/shrinker.h>28#include <linux/module.h>2930/*31* Public vmem_alloc(), vmem_zalloc() and vmem_free() interfaces.32*/33void *34spl_vmem_alloc(size_t size, int flags, const char *func, int line)35{36ASSERT0(flags & ~KM_PUBLIC_MASK);3738flags |= KM_VMEM;3940#if !defined(DEBUG_KMEM)41return (spl_kmem_alloc_impl(size, flags, NUMA_NO_NODE));42#elif !defined(DEBUG_KMEM_TRACKING)43return (spl_kmem_alloc_debug(size, flags, NUMA_NO_NODE));44#else45return (spl_kmem_alloc_track(size, flags, func, line, NUMA_NO_NODE));46#endif47}48EXPORT_SYMBOL(spl_vmem_alloc);4950void *51spl_vmem_zalloc(size_t size, int flags, const char *func, int line)52{53ASSERT0(flags & ~KM_PUBLIC_MASK);5455flags |= (KM_VMEM | KM_ZERO);5657#if !defined(DEBUG_KMEM)58return (spl_kmem_alloc_impl(size, flags, NUMA_NO_NODE));59#elif !defined(DEBUG_KMEM_TRACKING)60return (spl_kmem_alloc_debug(size, flags, NUMA_NO_NODE));61#else62return (spl_kmem_alloc_track(size, flags, func, line, NUMA_NO_NODE));63#endif64}65EXPORT_SYMBOL(spl_vmem_zalloc);6667void68spl_vmem_free(const void *buf, size_t size)69{70#if !defined(DEBUG_KMEM)71return (spl_kmem_free_impl(buf, size));72#elif !defined(DEBUG_KMEM_TRACKING)73return (spl_kmem_free_debug(buf, size));74#else75return (spl_kmem_free_track(buf, size));76#endif77}78EXPORT_SYMBOL(spl_vmem_free);7980int81spl_vmem_init(void)82{83return (0);84}8586void87spl_vmem_fini(void)88{89}909192