1 #ifndef __ASM_GENERIC_GETORDER_H 2 #define __ASM_GENERIC_GETORDER_H 3 4 #ifndef __ASSEMBLY__ 5 6 #include <linux/compiler.h> 7 8 /** 9 * get_order - Determine the allocation order of a memory size 10 * @size: The size for which to get the order 11 * 12 * Determine the allocation order of a particular sized block of memory. This 13 * is on a logarithmic scale, where: 14 * 15 * 0 -> 2^0 * PAGE_SIZE and below 16 * 1 -> 2^1 * PAGE_SIZE to 2^0 * PAGE_SIZE + 1 17 * 2 -> 2^2 * PAGE_SIZE to 2^1 * PAGE_SIZE + 1 18 * 3 -> 2^3 * PAGE_SIZE to 2^2 * PAGE_SIZE + 1 19 * 4 -> 2^4 * PAGE_SIZE to 2^3 * PAGE_SIZE + 1 20 * ... 21 * 22 * The order returned is used to find the smallest allocation granule required 23 * to hold an object of the specified size. 24 * 25 * The result is undefined if the size is 0. 26 * 27 * This function may be used to initialise variables with compile time 28 * evaluations of constants. 29 */ 30 static inline __attribute_const__ int get_order(unsigned long size) 31 { 32 int order; 33 34 size = (size - 1) >> (PAGE_SHIFT - 1); 35 order = -1; 36 do { 37 size >>= 1; 38 order++; 39 } while (size); 40 return order; 41 } 42 43 #endif /* __ASSEMBLY__ */ 44 45 #endif /* __ASM_GENERIC_GETORDER_H */ 46