2009-05-14 06:56:30 +08:00
|
|
|
#ifndef __ASM_GENERIC_GETORDER_H
|
|
|
|
#define __ASM_GENERIC_GETORDER_H
|
2005-09-04 06:54:30 +08:00
|
|
|
|
|
|
|
#ifndef __ASSEMBLY__
|
|
|
|
|
2007-03-07 11:38:01 +08:00
|
|
|
#include <linux/compiler.h>
|
2005-09-04 06:54:30 +08:00
|
|
|
|
2012-02-21 06:39:18 +08:00
|
|
|
/**
|
|
|
|
* get_order - Determine the allocation order of a memory size
|
|
|
|
* @size: The size for which to get the order
|
|
|
|
*
|
|
|
|
* Determine the allocation order of a particular sized block of memory. This
|
|
|
|
* is on a logarithmic scale, where:
|
|
|
|
*
|
|
|
|
* 0 -> 2^0 * PAGE_SIZE and below
|
|
|
|
* 1 -> 2^1 * PAGE_SIZE to 2^0 * PAGE_SIZE + 1
|
|
|
|
* 2 -> 2^2 * PAGE_SIZE to 2^1 * PAGE_SIZE + 1
|
|
|
|
* 3 -> 2^3 * PAGE_SIZE to 2^2 * PAGE_SIZE + 1
|
|
|
|
* 4 -> 2^4 * PAGE_SIZE to 2^3 * PAGE_SIZE + 1
|
|
|
|
* ...
|
|
|
|
*
|
|
|
|
* The order returned is used to find the smallest allocation granule required
|
|
|
|
* to hold an object of the specified size.
|
|
|
|
*
|
|
|
|
* The result is undefined if the size is 0.
|
|
|
|
*
|
|
|
|
* This function may be used to initialise variables with compile time
|
|
|
|
* evaluations of constants.
|
|
|
|
*/
|
2009-05-14 06:56:30 +08:00
|
|
|
static inline __attribute_const__ int get_order(unsigned long size)
|
2005-09-04 06:54:30 +08:00
|
|
|
{
|
|
|
|
int order;
|
|
|
|
|
2007-03-07 11:38:01 +08:00
|
|
|
size = (size - 1) >> (PAGE_SHIFT - 1);
|
2005-09-04 06:54:30 +08:00
|
|
|
order = -1;
|
|
|
|
do {
|
|
|
|
size >>= 1;
|
|
|
|
order++;
|
|
|
|
} while (size);
|
|
|
|
return order;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* __ASSEMBLY__ */
|
|
|
|
|
2009-05-14 06:56:30 +08:00
|
|
|
#endif /* __ASM_GENERIC_GETORDER_H */
|