Skip to content

Commit 54a6eb5

Browse files
gormanmtorvalds
authored andcommitted
mm: use two zonelist that are filtered by GFP mask
Currently a node has two sets of zonelists, one for each zone type in the system and a second set for GFP_THISNODE allocations. Based on the zones allowed by a gfp mask, one of these zonelists is selected. All of these zonelists consume memory and occupy cache lines. This patch replaces the multiple zonelists per-node with two zonelists. The first contains all populated zones in the system, ordered by distance, for fallback allocations when the target/preferred node has no free pages. The second contains all populated zones in the node suitable for GFP_THISNODE allocations. An iterator macro is introduced called for_each_zone_zonelist() that interates through each zone allowed by the GFP flags in the selected zonelist. Signed-off-by: Mel Gorman <mel@csn.ul.ie> Acked-by: Christoph Lameter <clameter@sgi.com> Signed-off-by: Lee Schermerhorn <lee.schermerhorn@hp.com> Cc: KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com> Cc: Mel Gorman <mel@csn.ul.ie> Cc: Christoph Lameter <clameter@sgi.com> Cc: Hugh Dickins <hugh@veritas.com> Cc: Nick Piggin <nickpiggin@yahoo.com.au> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 18ea7e7 commit 54a6eb5

10 files changed

Lines changed: 168 additions & 154 deletions

File tree

‎arch/parisc/mm/init.c‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -603,15 +603,18 @@ void show_mem(void)
603603
#ifdef CONFIG_DISCONTIGMEM
604604
{
605605
struct zonelist *zl;
606-
int i, j, k;
606+
int i, j;
607607

608608
for (i = 0; i < npmem_ranges; i++) {
609+
zl = node_zonelist(i);
609610
for (j = 0; j < MAX_NR_ZONES; j++) {
610-
zl = NODE_DATA(i)->node_zonelists + j;
611+
struct zone **z;
612+
struct zone *zone;
611613

612614
printk("Zone list for zone %d on node %d: ", j, i);
613-
for (k = 0; zl->zones[k] != NULL; k++)
614-
printk("[%d/%s] ", zone_to_nid(zl->zones[k]), zl->zones[k]->name);
615+
for_each_zone_zonelist(zone, z, zl, j)
616+
printk("[%d/%s] ", zone_to_nid(zone),
617+
zone->name);
615618
printk("\n");
616619
}
617620
}

‎fs/buffer.c‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -360,16 +360,18 @@ void invalidate_bdev(struct block_device *bdev)
360360
*/
361361
static void free_more_memory(void)
362362
{
363-
struct zonelist *zonelist;
363+
struct zone **zones;
364364
int nid;
365365

366366
wakeup_pdflush(1024);
367367
yield();
368368

369369
for_each_online_node(nid) {
370-
zonelist = node_zonelist(nid, GFP_NOFS);
371-
if (zonelist->zones[0])
372-
try_to_free_pages(zonelist, 0, GFP_NOFS);
370+
zones = first_zones_zonelist(node_zonelist(nid, GFP_NOFS),
371+
gfp_zone(GFP_NOFS));
372+
if (*zones)
373+
try_to_free_pages(node_zonelist(nid, GFP_NOFS), 0,
374+
GFP_NOFS);
373375
}
374376
}
375377

‎include/linux/gfp.h‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,17 +151,26 @@ static inline enum zone_type gfp_zone(gfp_t flags)
151151
* virtual kernel addresses to the allocated page(s).
152152
*/
153153

154+
static inline int gfp_zonelist(gfp_t flags)
155+
{
156+
if (NUMA_BUILD && unlikely(flags & __GFP_THISNODE))
157+
return 1;
158+
159+
return 0;
160+
}
161+
154162
/*
155163
* We get the zone list from the current node and the gfp_mask.
156164
* This zone list contains a maximum of MAXNODES*MAX_NR_ZONES zones.
157-
* There are many zonelists per node, two for each active zone.
165+
* There are two zonelists per node, one for all zones with memory and
166+
* one containing just zones from the node the zonelist belongs to.
158167
*
159168
* For the normal case of non-DISCONTIGMEM systems the NODE_DATA() gets
160169
* optimized to &contig_page_data at compile-time.
161170
*/
162171
static inline struct zonelist *node_zonelist(int nid, gfp_t flags)
163172
{
164-
return NODE_DATA(nid)->node_zonelists + gfp_zone(flags);
173+
return NODE_DATA(nid)->node_zonelists + gfp_zonelist(flags);
165174
}
166175

167176
#ifndef HAVE_ARCH_FREE_PAGE

‎include/linux/mmzone.h‎

Lines changed: 43 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -393,10 +393,10 @@ static inline int zone_is_oom_locked(const struct zone *zone)
393393
* The NUMA zonelists are doubled becausse we need zonelists that restrict the
394394
* allocations to a single node for GFP_THISNODE.
395395
*
396-
* [0 .. MAX_NR_ZONES -1] : Zonelists with fallback
397-
* [MAZ_NR_ZONES ... MAZ_ZONELISTS -1] : No fallback (GFP_THISNODE)
396+
* [0] : Zonelist with fallback
397+
* [1] : No fallback (GFP_THISNODE)
398398
*/
399-
#define MAX_ZONELISTS (2 * MAX_NR_ZONES)
399+
#define MAX_ZONELISTS 2
400400

401401

402402
/*
@@ -464,7 +464,7 @@ struct zonelist_cache {
464464
unsigned long last_full_zap; /* when last zap'd (jiffies) */
465465
};
466466
#else
467-
#define MAX_ZONELISTS MAX_NR_ZONES
467+
#define MAX_ZONELISTS 1
468468
struct zonelist_cache;
469469
#endif
470470

@@ -486,24 +486,6 @@ struct zonelist {
486486
#endif
487487
};
488488

489-
#ifdef CONFIG_NUMA
490-
/*
491-
* Only custom zonelists like MPOL_BIND need to be filtered as part of
492-
* policies. As described in the comment for struct zonelist_cache, these
493-
* zonelists will not have a zlcache so zlcache_ptr will not be set. Use
494-
* that to determine if the zonelists needs to be filtered or not.
495-
*/
496-
static inline int alloc_should_filter_zonelist(struct zonelist *zonelist)
497-
{
498-
return !zonelist->zlcache_ptr;
499-
}
500-
#else
501-
static inline int alloc_should_filter_zonelist(struct zonelist *zonelist)
502-
{
503-
return 0;
504-
}
505-
#endif /* CONFIG_NUMA */
506-
507489
#ifdef CONFIG_ARCH_POPULATES_NODE_MAP
508490
struct node_active_region {
509491
unsigned long start_pfn;
@@ -731,6 +713,45 @@ extern struct zone *next_zone(struct zone *zone);
731713
zone; \
732714
zone = next_zone(zone))
733715

716+
/* Returns the first zone at or below highest_zoneidx in a zonelist */
717+
static inline struct zone **first_zones_zonelist(struct zonelist *zonelist,
718+
enum zone_type highest_zoneidx)
719+
{
720+
struct zone **z;
721+
722+
/* Find the first suitable zone to use for the allocation */
723+
z = zonelist->zones;
724+
while (*z && zone_idx(*z) > highest_zoneidx)
725+
z++;
726+
727+
return z;
728+
}
729+
730+
/* Returns the next zone at or below highest_zoneidx in a zonelist */
731+
static inline struct zone **next_zones_zonelist(struct zone **z,
732+
enum zone_type highest_zoneidx)
733+
{
734+
/* Find the next suitable zone to use for the allocation */
735+
while (*z && zone_idx(*z) > highest_zoneidx)
736+
z++;
737+
738+
return z;
739+
}
740+
741+
/**
742+
* for_each_zone_zonelist - helper macro to iterate over valid zones in a zonelist at or below a given zone index
743+
* @zone - The current zone in the iterator
744+
* @z - The current pointer within zonelist->zones being iterated
745+
* @zlist - The zonelist being iterated
746+
* @highidx - The zone index of the highest zone to return
747+
*
748+
* This iterator iterates though all zones at or below a given zone index.
749+
*/
750+
#define for_each_zone_zonelist(zone, z, zlist, highidx) \
751+
for (z = first_zones_zonelist(zlist, highidx), zone = *z++; \
752+
zone; \
753+
z = next_zones_zonelist(z, highidx), zone = *z++)
754+
734755
#ifdef CONFIG_SPARSEMEM
735756
#include <asm/sparsemem.h>
736757
#endif

‎mm/hugetlb.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,11 @@ static struct page *dequeue_huge_page_vma(struct vm_area_struct *vma,
9797
struct mempolicy *mpol;
9898
struct zonelist *zonelist = huge_zonelist(vma, address,
9999
htlb_alloc_mask, &mpol);
100-
struct zone **z;
100+
struct zone *zone, **z;
101101

102-
for (z = zonelist->zones; *z; z++) {
103-
nid = zone_to_nid(*z);
104-
if (cpuset_zone_allowed_softwall(*z, htlb_alloc_mask) &&
102+
for_each_zone_zonelist(zone, z, zonelist, MAX_NR_ZONES - 1) {
103+
nid = zone_to_nid(zone);
104+
if (cpuset_zone_allowed_softwall(zone, htlb_alloc_mask) &&
105105
!list_empty(&hugepage_freelists[nid])) {
106106
page = list_entry(hugepage_freelists[nid].next,
107107
struct page, lru);

‎mm/oom_kill.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,14 @@ static inline enum oom_constraint constrained_alloc(struct zonelist *zonelist,
175175
gfp_t gfp_mask)
176176
{
177177
#ifdef CONFIG_NUMA
178+
struct zone *zone;
178179
struct zone **z;
180+
enum zone_type high_zoneidx = gfp_zone(gfp_mask);
179181
nodemask_t nodes = node_states[N_HIGH_MEMORY];
180182

181-
for (z = zonelist->zones; *z; z++)
182-
if (cpuset_zone_allowed_softwall(*z, gfp_mask))
183-
node_clear(zone_to_nid(*z), nodes);
183+
for_each_zone_zonelist(zone, z, zonelist, high_zoneidx)
184+
if (cpuset_zone_allowed_softwall(zone, gfp_mask))
185+
node_clear(zone_to_nid(zone), nodes);
184186
else
185187
return CONSTRAINT_CPUSET;
186188

0 commit comments

Comments
 (0)