Commit af4ca457 authored by Al Viro's avatar Al Viro Committed by Linus Torvalds

[PATCH] gfp_t: infrastructure

Beginning of gfp_t annotations:

 - -Wbitwise added to CHECKFLAGS
 - old __bitwise renamed to __bitwise__
 - __bitwise defined to either __bitwise__ or nothing, depending on
   __CHECK_ENDIAN__ being defined
 - gfp_t switched from __nocast to __bitwise__
 - force cast to gfp_t added to __GFP_... constants
 - new helper - gfp_zone(); extracts zone bits out of gfp_t value and casts
   the result to int
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarLinus Torvalds <torvalds@osdl.org>
parent 434f1d10
...@@ -334,7 +334,7 @@ KALLSYMS = scripts/kallsyms ...@@ -334,7 +334,7 @@ KALLSYMS = scripts/kallsyms
PERL = perl PERL = perl
CHECK = sparse CHECK = sparse
CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ $(CF) CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ -Wbitwise $(CF)
MODFLAGS = -DMODULE MODFLAGS = -DMODULE
CFLAGS_MODULE = $(MODFLAGS) CFLAGS_MODULE = $(MODFLAGS)
AFLAGS_MODULE = $(MODFLAGS) AFLAGS_MODULE = $(MODFLAGS)
......
...@@ -502,7 +502,7 @@ static void free_more_memory(void) ...@@ -502,7 +502,7 @@ static void free_more_memory(void)
yield(); yield();
for_each_pgdat(pgdat) { for_each_pgdat(pgdat) {
zones = pgdat->node_zonelists[GFP_NOFS&GFP_ZONEMASK].zones; zones = pgdat->node_zonelists[gfp_zone(GFP_NOFS)].zones;
if (*zones) if (*zones)
try_to_free_pages(zones, GFP_NOFS); try_to_free_pages(zones, GFP_NOFS);
} }
......
...@@ -12,8 +12,8 @@ struct vm_area_struct; ...@@ -12,8 +12,8 @@ struct vm_area_struct;
* GFP bitmasks.. * GFP bitmasks..
*/ */
/* Zone modifiers in GFP_ZONEMASK (see linux/mmzone.h - low two bits) */ /* Zone modifiers in GFP_ZONEMASK (see linux/mmzone.h - low two bits) */
#define __GFP_DMA 0x01u #define __GFP_DMA ((__force gfp_t)0x01u)
#define __GFP_HIGHMEM 0x02u #define __GFP_HIGHMEM ((__force gfp_t)0x02u)
/* /*
* Action modifiers - doesn't change the zoning * Action modifiers - doesn't change the zoning
...@@ -26,24 +26,24 @@ struct vm_area_struct; ...@@ -26,24 +26,24 @@ struct vm_area_struct;
* *
* __GFP_NORETRY: The VM implementation must not retry indefinitely. * __GFP_NORETRY: The VM implementation must not retry indefinitely.
*/ */
#define __GFP_WAIT 0x10u /* Can wait and reschedule? */ #define __GFP_WAIT ((__force gfp_t)0x10u) /* Can wait and reschedule? */
#define __GFP_HIGH 0x20u /* Should access emergency pools? */ #define __GFP_HIGH ((__force gfp_t)0x20u) /* Should access emergency pools? */
#define __GFP_IO 0x40u /* Can start physical IO? */ #define __GFP_IO ((__force gfp_t)0x40u) /* Can start physical IO? */
#define __GFP_FS 0x80u /* Can call down to low-level FS? */ #define __GFP_FS ((__force gfp_t)0x80u) /* Can call down to low-level FS? */
#define __GFP_COLD 0x100u /* Cache-cold page required */ #define __GFP_COLD ((__force gfp_t)0x100u) /* Cache-cold page required */
#define __GFP_NOWARN 0x200u /* Suppress page allocation failure warning */ #define __GFP_NOWARN ((__force gfp_t)0x200u) /* Suppress page allocation failure warning */
#define __GFP_REPEAT 0x400u /* Retry the allocation. Might fail */ #define __GFP_REPEAT ((__force gfp_t)0x400u) /* Retry the allocation. Might fail */
#define __GFP_NOFAIL 0x800u /* Retry for ever. Cannot fail */ #define __GFP_NOFAIL ((__force gfp_t)0x800u) /* Retry for ever. Cannot fail */
#define __GFP_NORETRY 0x1000u /* Do not retry. Might fail */ #define __GFP_NORETRY ((__force gfp_t)0x1000u)/* Do not retry. Might fail */
#define __GFP_NO_GROW 0x2000u /* Slab internal usage */ #define __GFP_NO_GROW ((__force gfp_t)0x2000u)/* Slab internal usage */
#define __GFP_COMP 0x4000u /* Add compound page metadata */ #define __GFP_COMP ((__force gfp_t)0x4000u)/* Add compound page metadata */
#define __GFP_ZERO 0x8000u /* Return zeroed page on success */ #define __GFP_ZERO ((__force gfp_t)0x8000u)/* Return zeroed page on success */
#define __GFP_NOMEMALLOC 0x10000u /* Don't use emergency reserves */ #define __GFP_NOMEMALLOC ((__force gfp_t)0x10000u) /* Don't use emergency reserves */
#define __GFP_NORECLAIM 0x20000u /* No realy zone reclaim during allocation */ #define __GFP_NORECLAIM ((__force gfp_t)0x20000u) /* No realy zone reclaim during allocation */
#define __GFP_HARDWALL 0x40000u /* Enforce hardwall cpuset memory allocs */ #define __GFP_HARDWALL ((__force gfp_t)0x40000u) /* Enforce hardwall cpuset memory allocs */
#define __GFP_BITS_SHIFT 20 /* Room for 20 __GFP_FOO bits */ #define __GFP_BITS_SHIFT 20 /* Room for 20 __GFP_FOO bits */
#define __GFP_BITS_MASK ((1 << __GFP_BITS_SHIFT) - 1) #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
/* if you forget to add the bitmask here kernel will crash, period */ /* if you forget to add the bitmask here kernel will crash, period */
#define GFP_LEVEL_MASK (__GFP_WAIT|__GFP_HIGH|__GFP_IO|__GFP_FS| \ #define GFP_LEVEL_MASK (__GFP_WAIT|__GFP_HIGH|__GFP_IO|__GFP_FS| \
...@@ -64,6 +64,7 @@ struct vm_area_struct; ...@@ -64,6 +64,7 @@ struct vm_area_struct;
#define GFP_DMA __GFP_DMA #define GFP_DMA __GFP_DMA
#define gfp_zone(mask) ((__force int)((mask) & (__force gfp_t)GFP_ZONEMASK))
/* /*
* There is only one page-allocator function, and two main namespaces to * There is only one page-allocator function, and two main namespaces to
...@@ -94,7 +95,7 @@ static inline struct page *alloc_pages_node(int nid, gfp_t gfp_mask, ...@@ -94,7 +95,7 @@ static inline struct page *alloc_pages_node(int nid, gfp_t gfp_mask,
return NULL; return NULL;
return __alloc_pages(gfp_mask, order, return __alloc_pages(gfp_mask, order,
NODE_DATA(nid)->node_zonelists + (gfp_mask & GFP_ZONEMASK)); NODE_DATA(nid)->node_zonelists + gfp_zone(gfp_mask));
} }
#ifdef CONFIG_NUMA #ifdef CONFIG_NUMA
......
...@@ -151,7 +151,12 @@ typedef unsigned long sector_t; ...@@ -151,7 +151,12 @@ typedef unsigned long sector_t;
*/ */
#ifdef __CHECKER__ #ifdef __CHECKER__
#define __bitwise __attribute__((bitwise)) #define __bitwise__ __attribute__((bitwise))
#else
#define __bitwise__
#endif
#ifdef __CHECK_ENDIAN__
#define __bitwise __bitwise__
#else #else
#define __bitwise #define __bitwise
#endif #endif
...@@ -166,7 +171,7 @@ typedef __u64 __bitwise __be64; ...@@ -166,7 +171,7 @@ typedef __u64 __bitwise __be64;
#endif #endif
#ifdef __KERNEL__ #ifdef __KERNEL__
typedef unsigned __nocast gfp_t; typedef unsigned __bitwise__ gfp_t;
#endif #endif
struct ustat { struct ustat {
......
...@@ -700,7 +700,7 @@ static struct zonelist *zonelist_policy(gfp_t gfp, struct mempolicy *policy) ...@@ -700,7 +700,7 @@ static struct zonelist *zonelist_policy(gfp_t gfp, struct mempolicy *policy)
case MPOL_BIND: case MPOL_BIND:
/* Lower zones don't get a policy applied */ /* Lower zones don't get a policy applied */
/* Careful: current->mems_allowed might have moved */ /* Careful: current->mems_allowed might have moved */
if ((gfp & GFP_ZONEMASK) >= policy_zone) if (gfp_zone(gfp) >= policy_zone)
if (cpuset_zonelist_valid_mems_allowed(policy->v.zonelist)) if (cpuset_zonelist_valid_mems_allowed(policy->v.zonelist))
return policy->v.zonelist; return policy->v.zonelist;
/*FALL THROUGH*/ /*FALL THROUGH*/
...@@ -712,7 +712,7 @@ static struct zonelist *zonelist_policy(gfp_t gfp, struct mempolicy *policy) ...@@ -712,7 +712,7 @@ static struct zonelist *zonelist_policy(gfp_t gfp, struct mempolicy *policy)
nd = 0; nd = 0;
BUG(); BUG();
} }
return NODE_DATA(nd)->node_zonelists + (gfp & GFP_ZONEMASK); return NODE_DATA(nd)->node_zonelists + gfp_zone(gfp);
} }
/* Do dynamic interleaving for a process */ /* Do dynamic interleaving for a process */
...@@ -757,7 +757,7 @@ static struct page *alloc_page_interleave(gfp_t gfp, unsigned order, unsigned ni ...@@ -757,7 +757,7 @@ static struct page *alloc_page_interleave(gfp_t gfp, unsigned order, unsigned ni
struct page *page; struct page *page;
BUG_ON(!node_online(nid)); BUG_ON(!node_online(nid));
zl = NODE_DATA(nid)->node_zonelists + (gfp & GFP_ZONEMASK); zl = NODE_DATA(nid)->node_zonelists + gfp_zone(gfp);
page = __alloc_pages(gfp, order, zl); page = __alloc_pages(gfp, order, zl);
if (page && page_zone(page) == zl->zones[0]) { if (page && page_zone(page) == zl->zones[0]) {
zone_pcp(zl->zones[0],get_cpu())->interleave_hit++; zone_pcp(zl->zones[0],get_cpu())->interleave_hit++;
......
...@@ -1089,7 +1089,7 @@ static unsigned int nr_free_zone_pages(int offset) ...@@ -1089,7 +1089,7 @@ static unsigned int nr_free_zone_pages(int offset)
*/ */
unsigned int nr_free_buffer_pages(void) unsigned int nr_free_buffer_pages(void)
{ {
return nr_free_zone_pages(GFP_USER & GFP_ZONEMASK); return nr_free_zone_pages(gfp_zone(GFP_USER));
} }
/* /*
...@@ -1097,7 +1097,7 @@ unsigned int nr_free_buffer_pages(void) ...@@ -1097,7 +1097,7 @@ unsigned int nr_free_buffer_pages(void)
*/ */
unsigned int nr_free_pagecache_pages(void) unsigned int nr_free_pagecache_pages(void)
{ {
return nr_free_zone_pages(GFP_HIGHUSER & GFP_ZONEMASK); return nr_free_zone_pages(gfp_zone(GFP_HIGHUSER));
} }
#ifdef CONFIG_HIGHMEM #ifdef CONFIG_HIGHMEM
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment