2018-06-05 19:42:14 -07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-16 15:20:36 -07:00
|
|
|
/*
|
2005-11-02 14:58:39 +11:00
|
|
|
* Copyright (c) 2000-2005 Silicon Graphics, Inc.
|
|
|
|
* All Rights Reserved.
|
2005-04-16 15:20:36 -07:00
|
|
|
*/
|
|
|
|
#ifndef __XFS_SUPPORT_KMEM_H__
|
|
|
|
#define __XFS_SUPPORT_KMEM_H__
|
|
|
|
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/mm.h>
|
2010-01-20 21:55:30 +00:00
|
|
|
#include <linux/vmalloc.h>
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2006-03-14 13:18:19 +11:00
|
|
|
/*
|
|
|
|
* General memory allocation interfaces
|
|
|
|
*/
|
|
|
|
|
2012-04-02 06:24:04 -04:00
|
|
|
typedef unsigned __bitwise xfs_km_flags_t;
|
|
|
|
#define KM_NOFS ((__force xfs_km_flags_t)0x0004u)
|
|
|
|
#define KM_MAYFAIL ((__force xfs_km_flags_t)0x0008u)
|
2013-11-04 18:21:05 +08:00
|
|
|
#define KM_ZERO ((__force xfs_km_flags_t)0x0010u)
|
2006-03-14 13:18:19 +11:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We use a special process flag to avoid recursive callbacks into
|
|
|
|
* the filesystem during transactions. We will also issue our own
|
|
|
|
* warnings, so we explicitly skip any generic ones (silly of us).
|
|
|
|
*/
|
|
|
|
static inline gfp_t
|
2012-04-02 06:24:04 -04:00
|
|
|
kmem_flags_convert(xfs_km_flags_t flags)
|
2005-04-16 15:20:36 -07:00
|
|
|
{
|
2006-03-14 13:18:19 +11:00
|
|
|
gfp_t lflags;
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2019-08-26 12:06:22 -07:00
|
|
|
BUG_ON(flags & ~(KM_NOFS|KM_MAYFAIL|KM_ZERO));
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2019-08-26 12:06:22 -07:00
|
|
|
lflags = GFP_KERNEL | __GFP_NOWARN;
|
|
|
|
if (flags & KM_NOFS)
|
|
|
|
lflags &= ~__GFP_FS;
|
2013-11-04 18:21:05 +08:00
|
|
|
|
2017-07-12 14:36:49 -07:00
|
|
|
/*
|
|
|
|
* Default page/slab allocator behavior is to retry for ever
|
|
|
|
* for small allocations. We can override this behavior by using
|
|
|
|
* __GFP_RETRY_MAYFAIL which will tell the allocator to retry as long
|
|
|
|
* as it is feasible but rather fail than retry forever for all
|
|
|
|
* request sizes.
|
|
|
|
*/
|
|
|
|
if (flags & KM_MAYFAIL)
|
|
|
|
lflags |= __GFP_RETRY_MAYFAIL;
|
|
|
|
|
2013-11-04 18:21:05 +08:00
|
|
|
if (flags & KM_ZERO)
|
|
|
|
lflags |= __GFP_ZERO;
|
|
|
|
|
2006-03-14 13:18:19 +11:00
|
|
|
return lflags;
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2012-04-02 06:24:04 -04:00
|
|
|
extern void *kmem_alloc(size_t, xfs_km_flags_t);
|
2018-03-06 17:03:28 -08:00
|
|
|
extern void *kmem_alloc_large(size_t size, xfs_km_flags_t);
|
2016-04-06 09:47:01 +10:00
|
|
|
extern void *kmem_realloc(const void *, size_t, xfs_km_flags_t);
|
2015-02-02 09:54:18 +11:00
|
|
|
static inline void kmem_free(const void *ptr)
|
|
|
|
{
|
|
|
|
kvfree(ptr);
|
|
|
|
}
|
2006-03-14 13:18:19 +11:00
|
|
|
|
2010-01-20 21:55:30 +00:00
|
|
|
|
2013-11-04 18:21:05 +08:00
|
|
|
static inline void *
|
|
|
|
kmem_zalloc(size_t size, xfs_km_flags_t flags)
|
|
|
|
{
|
|
|
|
return kmem_alloc(size, flags | KM_ZERO);
|
2018-03-06 17:03:28 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void *
|
|
|
|
kmem_zalloc_large(size_t size, xfs_km_flags_t flags)
|
|
|
|
{
|
|
|
|
return kmem_alloc_large(size, flags | KM_ZERO);
|
2013-11-04 18:21:05 +08:00
|
|
|
}
|
|
|
|
|
2006-03-14 13:18:19 +11:00
|
|
|
/*
|
|
|
|
* Zone interfaces
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define KM_ZONE_HWALIGN SLAB_HWCACHE_ALIGN
|
|
|
|
#define KM_ZONE_RECLAIM SLAB_RECLAIM_ACCOUNT
|
2006-03-24 03:16:09 -08:00
|
|
|
#define KM_ZONE_SPREAD SLAB_MEM_SPREAD
|
2016-01-14 15:18:21 -08:00
|
|
|
#define KM_ZONE_ACCOUNT SLAB_ACCOUNT
|
2006-03-14 13:18:19 +11:00
|
|
|
|
|
|
|
#define kmem_zone kmem_cache
|
|
|
|
#define kmem_zone_t struct kmem_cache
|
|
|
|
|
|
|
|
static inline kmem_zone_t *
|
2005-04-16 15:20:36 -07:00
|
|
|
kmem_zone_init(int size, char *zone_name)
|
|
|
|
{
|
2007-07-20 10:11:58 +09:00
|
|
|
return kmem_cache_create(zone_name, size, 0, 0, NULL);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2006-03-14 13:18:19 +11:00
|
|
|
static inline kmem_zone_t *
|
2017-11-15 17:32:18 -08:00
|
|
|
kmem_zone_init_flags(int size, char *zone_name, slab_flags_t flags,
|
2008-07-25 19:45:34 -07:00
|
|
|
void (*construct)(void *))
|
2006-03-14 13:18:19 +11:00
|
|
|
{
|
2007-07-20 10:11:58 +09:00
|
|
|
return kmem_cache_create(zone_name, size, 0, flags, construct);
|
2006-03-14 13:18:19 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
2005-04-16 15:20:36 -07:00
|
|
|
kmem_zone_free(kmem_zone_t *zone, void *ptr)
|
|
|
|
{
|
|
|
|
kmem_cache_free(zone, ptr);
|
|
|
|
}
|
|
|
|
|
2006-03-14 13:18:19 +11:00
|
|
|
static inline void
|
2005-04-16 15:20:36 -07:00
|
|
|
kmem_zone_destroy(kmem_zone_t *zone)
|
|
|
|
{
|
2017-11-08 12:00:40 -08:00
|
|
|
kmem_cache_destroy(zone);
|
2005-04-16 15:20:36 -07:00
|
|
|
}
|
|
|
|
|
2012-04-02 06:24:04 -04:00
|
|
|
extern void *kmem_zone_alloc(kmem_zone_t *, xfs_km_flags_t);
|
2013-11-04 18:21:05 +08:00
|
|
|
|
|
|
|
static inline void *
|
|
|
|
kmem_zone_zalloc(kmem_zone_t *zone, xfs_km_flags_t flags)
|
|
|
|
{
|
|
|
|
return kmem_zone_alloc(zone, flags | KM_ZERO);
|
|
|
|
}
|
2005-04-16 15:20:36 -07:00
|
|
|
|
2019-06-28 19:27:19 -07:00
|
|
|
static inline struct page *
|
|
|
|
kmem_to_page(void *addr)
|
|
|
|
{
|
|
|
|
if (is_vmalloc_addr(addr))
|
|
|
|
return vmalloc_to_page(addr);
|
|
|
|
return virt_to_page(addr);
|
|
|
|
}
|
|
|
|
|
2005-04-16 15:20:36 -07:00
|
|
|
#endif /* __XFS_SUPPORT_KMEM_H__ */
|