Blame view

fs/xfs/kmem.h 2.09 KB
508578f2f   Nishad Kamdar   xfs: Use the corr...
1
  /* SPDX-License-Identifier: GPL-2.0 */
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
2
  /*
7b7187698   Nathan Scott   [XFS] Update lice...
3
4
   * Copyright (c) 2000-2005 Silicon Graphics, Inc.
   * All Rights Reserved.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
5
6
7
8
9
10
11
   */
  #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...
12
  #include <linux/vmalloc.h>
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
13
14
  
  /*
8758280fc   Nathan Scott   [XFS] Cleanup the...
15
16
   * General memory allocation interfaces
   */
77ba78776   Al Viro   xfs: switch to pr...
17
  typedef unsigned __bitwise xfs_km_flags_t;
77ba78776   Al Viro   xfs: switch to pr...
18
19
  #define KM_NOFS		((__force xfs_km_flags_t)0x0004u)
  #define KM_MAYFAIL	((__force xfs_km_flags_t)0x0008u)
359d992bc   Gu Zheng   xfs: simplify kme...
20
  #define KM_ZERO		((__force xfs_km_flags_t)0x0010u)
6dcde60ef   Darrick J. Wong   xfs: more lockdep...
21
  #define KM_NOLOCKDEP	((__force xfs_km_flags_t)0x0020u)
8758280fc   Nathan Scott   [XFS] Cleanup the...
22
23
24
25
26
27
28
  
  /*
   * 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...
29
  kmem_flags_convert(xfs_km_flags_t flags)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
30
  {
8758280fc   Nathan Scott   [XFS] Cleanup the...
31
  	gfp_t	lflags;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
32

6dcde60ef   Darrick J. Wong   xfs: more lockdep...
33
  	BUG_ON(flags & ~(KM_NOFS | KM_MAYFAIL | KM_ZERO | KM_NOLOCKDEP));
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
34

707e0ddaf   Tetsuo Handa   fs: xfs: Remove K...
35
36
37
  	lflags = GFP_KERNEL | __GFP_NOWARN;
  	if (flags & KM_NOFS)
  		lflags &= ~__GFP_FS;
359d992bc   Gu Zheng   xfs: simplify kme...
38

91c63ecda   Michal Hocko   xfs: map KM_MAYFA...
39
40
41
42
43
44
45
46
47
  	/*
  	 * 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;
359d992bc   Gu Zheng   xfs: simplify kme...
48
49
  	if (flags & KM_ZERO)
  		lflags |= __GFP_ZERO;
6dcde60ef   Darrick J. Wong   xfs: more lockdep...
50
51
  	if (flags & KM_NOLOCKDEP)
  		lflags |= __GFP_NOLOCKDEP;
8758280fc   Nathan Scott   [XFS] Cleanup the...
52
  	return lflags;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
53
  }
77ba78776   Al Viro   xfs: switch to pr...
54
  extern void *kmem_alloc(size_t, xfs_km_flags_t);
f8f9ee479   Dave Chinner   xfs: add kmem_all...
55
  extern void *kmem_alloc_io(size_t size, int align_mask, xfs_km_flags_t flags);
cb0a8d230   Dave Chinner   xfs: fall back to...
56
  extern void *kmem_alloc_large(size_t size, xfs_km_flags_t);
f3d215526   Wang, Yalin   xfs: change kmem_...
57
58
59
60
  static inline void  kmem_free(const void *ptr)
  {
  	kvfree(ptr);
  }
8758280fc   Nathan Scott   [XFS] Cleanup the...
61

bdfb04301   Christoph Hellwig   xfs: replace KM_L...
62

359d992bc   Gu Zheng   xfs: simplify kme...
63
64
65
66
  static inline void *
  kmem_zalloc(size_t size, xfs_km_flags_t flags)
  {
  	return kmem_alloc(size, flags | KM_ZERO);
cb0a8d230   Dave Chinner   xfs: fall back to...
67
  }
8758280fc   Nathan Scott   [XFS] Cleanup the...
68
69
70
  /*
   * Zone interfaces
   */
8758280fc   Nathan Scott   [XFS] Cleanup the...
71
72
  #define kmem_zone	kmem_cache
  #define kmem_zone_t	struct kmem_cache
72945d86d   Christoph Hellwig   xfs: make mem_to_...
73
74
75
76
77
78
79
  static inline struct page *
  kmem_to_page(void *addr)
  {
  	if (is_vmalloc_addr(addr))
  		return vmalloc_to_page(addr);
  	return virt_to_page(addr);
  }
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
80
  #endif /* __XFS_SUPPORT_KMEM_H__ */