0001
0002
0003
0004
0005
0006 #ifndef __XFS_SUPPORT_KMEM_H__
0007 #define __XFS_SUPPORT_KMEM_H__
0008
0009 #include <linux/slab.h>
0010 #include <linux/sched.h>
0011 #include <linux/mm.h>
0012 #include <linux/vmalloc.h>
0013
0014
0015
0016
0017
0018 typedef unsigned __bitwise xfs_km_flags_t;
0019 #define KM_NOFS ((__force xfs_km_flags_t)0x0004u)
0020 #define KM_MAYFAIL ((__force xfs_km_flags_t)0x0008u)
0021 #define KM_ZERO ((__force xfs_km_flags_t)0x0010u)
0022 #define KM_NOLOCKDEP ((__force xfs_km_flags_t)0x0020u)
0023
0024
0025
0026
0027
0028
0029 static inline gfp_t
0030 kmem_flags_convert(xfs_km_flags_t flags)
0031 {
0032 gfp_t lflags;
0033
0034 BUG_ON(flags & ~(KM_NOFS | KM_MAYFAIL | KM_ZERO | KM_NOLOCKDEP));
0035
0036 lflags = GFP_KERNEL | __GFP_NOWARN;
0037 if (flags & KM_NOFS)
0038 lflags &= ~__GFP_FS;
0039
0040
0041
0042
0043
0044
0045
0046
0047 if (flags & KM_MAYFAIL)
0048 lflags |= __GFP_RETRY_MAYFAIL;
0049
0050 if (flags & KM_ZERO)
0051 lflags |= __GFP_ZERO;
0052
0053 if (flags & KM_NOLOCKDEP)
0054 lflags |= __GFP_NOLOCKDEP;
0055
0056 return lflags;
0057 }
0058
0059 extern void *kmem_alloc(size_t, xfs_km_flags_t);
0060 static inline void kmem_free(const void *ptr)
0061 {
0062 kvfree(ptr);
0063 }
0064
0065
0066 static inline void *
0067 kmem_zalloc(size_t size, xfs_km_flags_t flags)
0068 {
0069 return kmem_alloc(size, flags | KM_ZERO);
0070 }
0071
0072
0073
0074
0075 static inline struct page *
0076 kmem_to_page(void *addr)
0077 {
0078 if (is_vmalloc_addr(addr))
0079 return vmalloc_to_page(addr);
0080 return virt_to_page(addr);
0081 }
0082
0083 #endif