Skip to content

Commit

Permalink
[PATCH] mm: consolidate get_order
Browse files Browse the repository at this point in the history
Someone mentioned that almost all the architectures used basically the same
implementation of get_order.  This patch consolidates them into
asm-generic/page.h and includes that in the appropriate places.  The
exceptions are ia64 and ppc which have their own (presumably optimised)
versions.

Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
  • Loading branch information
Stephen Rothwell authored and Linus Torvalds committed Sep 5, 2005
1 parent 28ae55c commit fd4fd5a
Show file tree
Hide file tree
Showing 22 changed files with 69 additions and 312 deletions.
16 changes: 2 additions & 14 deletions include/asm-alpha/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,20 +63,6 @@ typedef unsigned long pgprot_t;

#endif /* STRICT_MM_TYPECHECKS */

/* Pure 2^n version of get_order */
extern __inline__ int get_order(unsigned long size)
{
int order;

size = (size-1) >> (PAGE_SHIFT-1);
order = -1;
do {
size >>= 1;
order++;
} while (size);
return order;
}

#ifdef USE_48_BIT_KSEG
#define PAGE_OFFSET 0xffff800000000000UL
#else
Expand Down Expand Up @@ -112,4 +98,6 @@ extern __inline__ int get_order(unsigned long size)

#endif /* __KERNEL__ */

#include <asm-generic/page.h>

#endif /* _ALPHA_PAGE_H */
16 changes: 2 additions & 14 deletions include/asm-arm/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,20 +163,6 @@ typedef unsigned long pgprot_t;
/* the upper-most page table pointer */
extern pmd_t *top_pmd;

/* Pure 2^n version of get_order */
static inline int get_order(unsigned long size)
{
int order;

size = (size-1) >> (PAGE_SHIFT-1);
order = -1;
do {
size >>= 1;
order++;
} while (size);
return order;
}

#include <asm/memory.h>

#endif /* !__ASSEMBLY__ */
Expand All @@ -186,4 +172,6 @@ static inline int get_order(unsigned long size)

#endif /* __KERNEL__ */

#include <asm-generic/page.h>

#endif
16 changes: 2 additions & 14 deletions include/asm-arm26/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,6 @@ typedef unsigned long pgprot_t;
#ifdef __KERNEL__
#ifndef __ASSEMBLY__

/* Pure 2^n version of get_order */
static inline int get_order(unsigned long size)
{
int order;

size = (size-1) >> (PAGE_SHIFT-1);
order = -1;
do {
size >>= 1;
order++;
} while (size);
return order;
}

#include <asm/memory.h>

#endif /* !__ASSEMBLY__ */
Expand All @@ -112,4 +98,6 @@ static inline int get_order(unsigned long size)

#endif /* __KERNEL__ */

#include <asm-generic/page.h>

#endif
15 changes: 2 additions & 13 deletions include/asm-cris/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,25 +70,14 @@ typedef struct { unsigned long pgprot; } pgprot_t;

#ifndef __ASSEMBLY__

/* Pure 2^n version of get_order */
static inline int get_order(unsigned long size)
{
int order;

size = (size-1) >> (PAGE_SHIFT-1);
order = -1;
do {
size >>= 1;
order++;
} while (size);
return order;
}
#endif /* __ASSEMBLY__ */

#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)

#endif /* __KERNEL__ */

#include <asm-generic/page.h>

#endif /* _CRIS_PAGE_H */

17 changes: 2 additions & 15 deletions include/asm-frv/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,21 +45,6 @@ typedef struct { unsigned long pgprot; } pgprot_t;
/* to align the pointer to the (next) page boundary */
#define PAGE_ALIGN(addr) (((addr) + PAGE_SIZE - 1) & PAGE_MASK)

/* Pure 2^n version of get_order */
static inline int get_order(unsigned long size) __attribute_const__;
static inline int get_order(unsigned long size)
{
int order;

size = (size - 1) >> (PAGE_SHIFT - 1);
order = -1;
do {
size >>= 1;
order++;
} while (size);
return order;
}

#define devmem_is_allowed(pfn) 1

#define __pa(vaddr) virt_to_phys((void *) vaddr)
Expand Down Expand Up @@ -102,4 +87,6 @@ extern unsigned long max_pfn;
#define WANT_PAGE_VIRTUAL 1
#endif

#include <asm-generic/page.h>

#endif /* _ASM_PAGE_H */
26 changes: 26 additions & 0 deletions include/asm-generic/page.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#ifndef _ASM_GENERIC_PAGE_H
#define _ASM_GENERIC_PAGE_H

#ifdef __KERNEL__
#ifndef __ASSEMBLY__

#include <linux/compiler.h>

/* Pure 2^n version of get_order */
static __inline__ __attribute_const__ int get_order(unsigned long size)
{
int order;

size = (size - 1) >> (PAGE_SHIFT - 1);
order = -1;
do {
size >>= 1;
order++;
} while (size);
return order;
}

#endif /* __ASSEMBLY__ */
#endif /* __KERNEL__ */

#endif /* _ASM_GENERIC_PAGE_H */
16 changes: 2 additions & 14 deletions include/asm-h8300/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,6 @@ typedef struct { unsigned long pgprot; } pgprot_t;
/* to align the pointer to the (next) page boundary */
#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)

/* Pure 2^n version of get_order */
extern __inline__ int get_order(unsigned long size)
{
int order;

size = (size-1) >> (PAGE_SHIFT-1);
order = -1;
do {
size >>= 1;
order++;
} while (size);
return order;
}

extern unsigned long memory_start;
extern unsigned long memory_end;

Expand Down Expand Up @@ -101,4 +87,6 @@ extern unsigned long memory_end;

#endif /* __KERNEL__ */

#include <asm-generic/page.h>

#endif /* _H8300_PAGE_H */
16 changes: 2 additions & 14 deletions include/asm-i386/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,6 @@ typedef struct { unsigned long pgprot; } pgprot_t;
*/
extern unsigned int __VMALLOC_RESERVE;

/* Pure 2^n version of get_order */
static __inline__ int get_order(unsigned long size)
{
int order;

size = (size-1) >> (PAGE_SHIFT-1);
order = -1;
do {
size >>= 1;
order++;
} while (size);
return order;
}

extern int sysctl_legacy_va_layout;

extern int page_is_ram(unsigned long pagenr);
Expand Down Expand Up @@ -156,4 +142,6 @@ extern int page_is_ram(unsigned long pagenr);

#endif /* __KERNEL__ */

#include <asm-generic/page.h>

#endif /* _I386_PAGE_H */
21 changes: 2 additions & 19 deletions include/asm-m32r/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,25 +61,6 @@ typedef struct { unsigned long pgprot; } pgprot_t;

/* This handles the memory map.. */

#ifndef __ASSEMBLY__

/* Pure 2^n version of get_order */
static __inline__ int get_order(unsigned long size)
{
int order;

size = (size - 1) >> (PAGE_SHIFT - 1);
order = -1;
do {
size >>= 1;
order++;
} while (size);

return order;
}

#endif /* __ASSEMBLY__ */

#define __MEMORY_START CONFIG_MEMORY_START
#define __MEMORY_SIZE CONFIG_MEMORY_SIZE

Expand Down Expand Up @@ -111,5 +92,7 @@ static __inline__ int get_order(unsigned long size)

#endif /* __KERNEL__ */

#include <asm-generic/page.h>

#endif /* _ASM_M32R_PAGE_H */

16 changes: 2 additions & 14 deletions include/asm-m68k/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,20 +107,6 @@ typedef struct { unsigned long pgprot; } pgprot_t;
/* to align the pointer to the (next) page boundary */
#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)

/* Pure 2^n version of get_order */
static inline int get_order(unsigned long size)
{
int order;

size = (size-1) >> (PAGE_SHIFT-1);
order = -1;
do {
size >>= 1;
order++;
} while (size);
return order;
}

#endif /* !__ASSEMBLY__ */

#include <asm/page_offset.h>
Expand Down Expand Up @@ -192,4 +178,6 @@ static inline void *__va(unsigned long x)

#endif /* __KERNEL__ */

#include <asm-generic/page.h>

#endif /* _M68K_PAGE_H */
16 changes: 2 additions & 14 deletions include/asm-m68knommu/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,20 +48,6 @@ typedef struct { unsigned long pgprot; } pgprot_t;
/* to align the pointer to the (next) page boundary */
#define PAGE_ALIGN(addr) (((addr)+PAGE_SIZE-1)&PAGE_MASK)

/* Pure 2^n version of get_order */
extern __inline__ int get_order(unsigned long size)
{
int order;

size = (size-1) >> (PAGE_SHIFT-1);
order = -1;
do {
size >>= 1;
order++;
} while (size);
return order;
}

extern unsigned long memory_start;
extern unsigned long memory_end;

Expand Down Expand Up @@ -93,4 +79,6 @@ extern unsigned long memory_end;

#endif /* __KERNEL__ */

#include <asm-generic/page.h>

#endif /* _M68KNOMMU_PAGE_H */
16 changes: 2 additions & 14 deletions include/asm-mips/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,20 +103,6 @@ typedef struct { unsigned long pgprot; } pgprot_t;
#define __pgd(x) ((pgd_t) { (x) } )
#define __pgprot(x) ((pgprot_t) { (x) } )

/* Pure 2^n version of get_order */
static __inline__ int get_order(unsigned long size)
{
int order;

size = (size-1) >> (PAGE_SHIFT-1);
order = -1;
do {
size >>= 1;
order++;
} while (size);
return order;
}

#endif /* !__ASSEMBLY__ */

/* to align the pointer to the (next) page boundary */
Expand Down Expand Up @@ -148,4 +134,6 @@ static __inline__ int get_order(unsigned long size)
#define WANT_PAGE_VIRTUAL
#endif

#include <asm-generic/page.h>

#endif /* _ASM_PAGE_H */
16 changes: 2 additions & 14 deletions include/asm-parisc/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,20 +74,6 @@ typedef struct { unsigned long pgprot; } pgprot_t;
#define __pgd(x) ((pgd_t) { (x) } )
#define __pgprot(x) ((pgprot_t) { (x) } )

/* Pure 2^n version of get_order */
extern __inline__ int get_order(unsigned long size)
{
int order;

size = (size-1) >> (PAGE_SHIFT-1);
order = -1;
do {
size >>= 1;
order++;
} while (size);
return order;
}

typedef struct __physmem_range {
unsigned long start_pfn;
unsigned long pages; /* PAGE_SIZE pages */
Expand Down Expand Up @@ -159,4 +145,6 @@ extern int npmem_ranges;

#endif /* __KERNEL__ */

#include <asm-generic/page.h>

#endif /* _PARISC_PAGE_H */
17 changes: 3 additions & 14 deletions include/asm-ppc64/page.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,6 @@ typedef unsigned long pgprot_t;

#endif

/* Pure 2^n version of get_order */
static inline int get_order(unsigned long size)
{
int order;

size = (size-1) >> (PAGE_SHIFT-1);
order = -1;
do {
size >>= 1;
order++;
} while (size);
return order;
}

#define __pa(x) ((unsigned long)(x)-PAGE_OFFSET)

extern int page_is_ram(unsigned long pfn);
Expand Down Expand Up @@ -270,4 +256,7 @@ extern u64 ppc64_pft_size; /* Log 2 of page table size */
VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)

#endif /* __KERNEL__ */

#include <asm-generic/page.h>

#endif /* _PPC64_PAGE_H */
Loading

0 comments on commit fd4fd5a

Please sign in to comment.