File: kmem.h

package info (click to toggle)
xfsprogs 6.18.0-4
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 11,304 kB
  • sloc: ansic: 167,330; sh: 4,604; makefile: 1,337; python: 835; cpp: 5
file content (91 lines) | stat: -rw-r--r-- 2,061 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// SPDX-License-Identifier: GPL-2.0
/*
 * Copyright (c) 2008 Silicon Graphics, Inc.
 * All Rights Reserved.
 */
#ifndef __KMEM_H__
#define __KMEM_H__

#define KM_NOFS		0x0004u
#define KM_MAYFAIL	0x0008u
#define KM_LARGE	0x0010u
#define KM_NOLOCKDEP	0x0020u

struct kmem_cache {
	int		cache_unitsize;	/* Size in bytes of cache unit */
	int		allocated;	/* debug: How many allocated? */
	unsigned int	align;
	const char	*cache_name;	/* tag name */
	void		(*ctor)(void *);
};

typedef unsigned int __bitwise gfp_t;

#define GFP_KERNEL	((__force gfp_t)0)
#define GFP_NOFS	((__force gfp_t)0)
#define __GFP_NOFAIL	((__force gfp_t)0)
#define __GFP_NOLOCKDEP	((__force gfp_t)0)
#define __GFP_RETRY_MAYFAIL	((__force gfp_t)0)

#define __GFP_ZERO	((__force gfp_t)1)

struct kmem_cache * kmem_cache_create(const char *name, unsigned int size,
		unsigned int align, unsigned int slab_flags,
		void (*ctor)(void *));

static inline struct kmem_cache *
kmem_cache_init(unsigned int size, const char *name)
{
	return kmem_cache_create(name, size, 0, 0, NULL);
}

extern void	*kmem_cache_alloc(struct kmem_cache *, gfp_t);
extern void	*kmem_cache_zalloc(struct kmem_cache *, gfp_t);
extern int	kmem_cache_destroy(struct kmem_cache *);

static inline void
kmem_cache_free(struct kmem_cache *cache, void *ptr)
{
	cache->allocated--;
	free(ptr);
}

extern void	*kvmalloc(size_t, gfp_t);
extern void	*krealloc(void *, size_t, int);

static inline void *kmalloc(size_t size, gfp_t flags)
{
	return kvmalloc(size, flags);
}

#define kzalloc(size, gfp)	kvmalloc((size), (gfp) | __GFP_ZERO)
#define kvzalloc(size, gfp)	kzalloc((size), (gfp))

static inline void kfree(const void *ptr)
{
	free((void *)ptr);
}

static inline void kvfree(const void *ptr)
{
	kfree(ptr);
}

static inline void kfree_rcu_mightsleep(const void *ptr)
{
	kfree(ptr);
}

__attribute__((format(printf,2,3)))
char *kasprintf(gfp_t gfp, const char *fmt, ...);

static inline void *kmemdup(const void *src, size_t len, gfp_t gfp)
{
	void *p = kmalloc(len, gfp);

	if (p)
		memcpy(p, src, len);
	return p;
}

#endif