Blame view

fs/xfs/kmem.h 3.22 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
  /*
7b7187698   Nathan Scott   [XFS] Update lice...
2
3
   * Copyright (c) 2000-2005 Silicon Graphics, Inc.
   * All Rights Reserved.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
   *
7b7187698   Nathan Scott   [XFS] Update lice...
5
6
   * This program is free software; you can redistribute it and/or
   * modify it under the terms of the GNU General Public License as
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
7
8
   * published by the Free Software Foundation.
   *
7b7187698   Nathan Scott   [XFS] Update lice...
9
10
11
12
   * This program is distributed in the hope that it would be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   * GNU General Public License for more details.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
   *
7b7187698   Nathan Scott   [XFS] Update lice...
14
15
16
   * You should have received a copy of the GNU General Public License
   * along with this program; if not, write the Free Software Foundation,
   * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
17
18
19
20
21
22
23
   */
  #ifndef __XFS_SUPPORT_KMEM_H__
  #define __XFS_SUPPORT_KMEM_H__
  
  #include <linux/slab.h>
  #include <linux/sched.h>
  #include <linux/mm.h>
bdfb04301   Christoph Hellwig   xfs: replace KM_L...
24
  #include <linux/vmalloc.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
25
26
  
  /*
8758280fc   Nathan Scott   [XFS] Cleanup the...
27
28
   * General memory allocation interfaces
   */
77ba78776   Al Viro   xfs: switch to pr...
29
30
31
32
33
  typedef unsigned __bitwise xfs_km_flags_t;
  #define KM_SLEEP	((__force xfs_km_flags_t)0x0001u)
  #define KM_NOSLEEP	((__force xfs_km_flags_t)0x0002u)
  #define KM_NOFS		((__force xfs_km_flags_t)0x0004u)
  #define KM_MAYFAIL	((__force xfs_km_flags_t)0x0008u)
359d992bc   Gu Zheng   xfs: simplify kme...
34
  #define KM_ZERO		((__force xfs_km_flags_t)0x0010u)
8758280fc   Nathan Scott   [XFS] Cleanup the...
35
36
37
38
39
40
41
  
  /*
   * 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
77ba78776   Al Viro   xfs: switch to pr...
42
  kmem_flags_convert(xfs_km_flags_t flags)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
43
  {
8758280fc   Nathan Scott   [XFS] Cleanup the...
44
  	gfp_t	lflags;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
45

359d992bc   Gu Zheng   xfs: simplify kme...
46
  	BUG_ON(flags & ~(KM_SLEEP|KM_NOSLEEP|KM_NOFS|KM_MAYFAIL|KM_ZERO));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
47
48
  
  	if (flags & KM_NOSLEEP) {
8758280fc   Nathan Scott   [XFS] Cleanup the...
49
  		lflags = GFP_ATOMIC | __GFP_NOWARN;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
50
  	} else {
8758280fc   Nathan Scott   [XFS] Cleanup the...
51
  		lflags = GFP_KERNEL | __GFP_NOWARN;
59c1b082f   Nathan Scott   [XFS] Make the pf...
52
  		if ((current->flags & PF_FSTRANS) || (flags & KM_NOFS))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
53
54
  			lflags &= ~__GFP_FS;
  	}
359d992bc   Gu Zheng   xfs: simplify kme...
55
56
57
  
  	if (flags & KM_ZERO)
  		lflags |= __GFP_ZERO;
8758280fc   Nathan Scott   [XFS] Cleanup the...
58
  	return lflags;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
59
  }
77ba78776   Al Viro   xfs: switch to pr...
60
  extern void *kmem_alloc(size_t, xfs_km_flags_t);
fdd3cceef   Dave Chinner   xfs: factor all t...
61
  extern void *kmem_zalloc_large(size_t size, xfs_km_flags_t);
664b60f6b   Christoph Hellwig   xfs: improve kmem...
62
  extern void *kmem_realloc(const void *, size_t, xfs_km_flags_t);
f3d215526   Wang, Yalin   xfs: change kmem_...
63
64
65
66
  static inline void  kmem_free(const void *ptr)
  {
  	kvfree(ptr);
  }
8758280fc   Nathan Scott   [XFS] Cleanup the...
67

bdfb04301   Christoph Hellwig   xfs: replace KM_L...
68
69
  
  extern void *kmem_zalloc_greedy(size_t *, size_t, size_t);
359d992bc   Gu Zheng   xfs: simplify kme...
70
71
72
73
74
  static inline void *
  kmem_zalloc(size_t size, xfs_km_flags_t flags)
  {
  	return kmem_alloc(size, flags | KM_ZERO);
  }
8758280fc   Nathan Scott   [XFS] Cleanup the...
75
76
77
78
79
80
  /*
   * Zone interfaces
   */
  
  #define KM_ZONE_HWALIGN	SLAB_HWCACHE_ALIGN
  #define KM_ZONE_RECLAIM	SLAB_RECLAIM_ACCOUNT
b0196009d   Paul Jackson   [PATCH] cpuset me...
81
  #define KM_ZONE_SPREAD	SLAB_MEM_SPREAD
5d097056c   Vladimir Davydov   kmemcg: account c...
82
  #define KM_ZONE_ACCOUNT	SLAB_ACCOUNT
8758280fc   Nathan Scott   [XFS] Cleanup the...
83
84
85
86
87
  
  #define kmem_zone	kmem_cache
  #define kmem_zone_t	struct kmem_cache
  
  static inline kmem_zone_t *
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
88
89
  kmem_zone_init(int size, char *zone_name)
  {
20c2df83d   Paul Mundt   mm: Remove slab d...
90
  	return kmem_cache_create(zone_name, size, 0, 0, NULL);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
91
  }
8758280fc   Nathan Scott   [XFS] Cleanup the...
92
93
  static inline kmem_zone_t *
  kmem_zone_init_flags(int size, char *zone_name, unsigned long flags,
51cc50685   Alexey Dobriyan   SL*B: drop kmem c...
94
  		     void (*construct)(void *))
8758280fc   Nathan Scott   [XFS] Cleanup the...
95
  {
20c2df83d   Paul Mundt   mm: Remove slab d...
96
  	return kmem_cache_create(zone_name, size, 0, flags, construct);
8758280fc   Nathan Scott   [XFS] Cleanup the...
97
98
99
  }
  
  static inline void
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
100
101
102
103
  kmem_zone_free(kmem_zone_t *zone, void *ptr)
  {
  	kmem_cache_free(zone, ptr);
  }
8758280fc   Nathan Scott   [XFS] Cleanup the...
104
  static inline void
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
105
106
  kmem_zone_destroy(kmem_zone_t *zone)
  {
1a1d92c10   Alexey Dobriyan   [PATCH] Really ig...
107
108
  	if (zone)
  		kmem_cache_destroy(zone);
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
109
  }
77ba78776   Al Viro   xfs: switch to pr...
110
  extern void *kmem_zone_alloc(kmem_zone_t *, xfs_km_flags_t);
359d992bc   Gu Zheng   xfs: simplify kme...
111
112
113
114
115
116
  
  static inline void *
  kmem_zone_zalloc(kmem_zone_t *zone, xfs_km_flags_t flags)
  {
  	return kmem_zone_alloc(zone, flags | KM_ZERO);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
117

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
118
  #endif /* __XFS_SUPPORT_KMEM_H__ */