1 #ifndef __ASM_GENERIC_GETORDER_H
2 #define __ASM_GENERIC_GETORDER_H
6 #include <linux/compiler.h>
7 #include <linux/log2.h>
10 * get_order - Determine the allocation order of a memory size
11 * @size: The size for which to get the order
13 * Determine the allocation order of a particular sized block of memory. This
14 * is on a logarithmic scale, where:
16 * 0 -> 2^0 * PAGE_SIZE and below
17 * 1 -> 2^1 * PAGE_SIZE to 2^0 * PAGE_SIZE + 1
18 * 2 -> 2^2 * PAGE_SIZE to 2^1 * PAGE_SIZE + 1
19 * 3 -> 2^3 * PAGE_SIZE to 2^2 * PAGE_SIZE + 1
20 * 4 -> 2^4 * PAGE_SIZE to 2^3 * PAGE_SIZE + 1
23 * The order returned is used to find the smallest allocation granule required
24 * to hold an object of the specified size.
26 * The result is undefined if the size is 0.
28 static inline __attribute_const__
int get_order(unsigned long size
)
30 if (__builtin_constant_p(size
)) {
32 return BITS_PER_LONG
- PAGE_SHIFT
;
34 if (size
< (1UL << PAGE_SHIFT
))
37 return ilog2((size
) - 1) - PAGE_SHIFT
+ 1;
42 #if BITS_PER_LONG == 32
49 #endif /* __ASSEMBLY__ */
51 #endif /* __ASM_GENERIC_GETORDER_H */