/* SPDX-License-Identifier: GPL-2.0 */1#ifndef __ASM_GENERIC_GETORDER_H2#define __ASM_GENERIC_GETORDER_H34#ifndef __ASSEMBLY__56#include <linux/compiler.h>7#include <linux/log2.h>89/**10* get_order - Determine the allocation order of a memory size11* @size: The size for which to get the order12*13* Determine the allocation order of a particular sized block of memory. This14* is on a logarithmic scale, where:15*16* 0 -> 2^0 * PAGE_SIZE and below17* 1 -> 2^1 * PAGE_SIZE to 2^0 * PAGE_SIZE + 118* 2 -> 2^2 * PAGE_SIZE to 2^1 * PAGE_SIZE + 119* 3 -> 2^3 * PAGE_SIZE to 2^2 * PAGE_SIZE + 120* 4 -> 2^4 * PAGE_SIZE to 2^3 * PAGE_SIZE + 121* ...22*23* The order returned is used to find the smallest allocation granule required24* to hold an object of the specified size.25*26* The result is undefined if the size is 0.27*/28static __always_inline __attribute_const__ int get_order(unsigned long size)29{30if (__builtin_constant_p(size)) {31if (!size)32return BITS_PER_LONG - PAGE_SHIFT;3334if (size < (1UL << PAGE_SHIFT))35return 0;3637return ilog2((size) - 1) - PAGE_SHIFT + 1;38}3940size--;41size >>= PAGE_SHIFT;42#if BITS_PER_LONG == 3243return fls(size);44#else45return fls64(size);46#endif47}4849#endif /* __ASSEMBLY__ */5051#endif /* __ASM_GENERIC_GETORDER_H */525354