Commit bb451fdf authored by Greg Thelen's avatar Greg Thelen Committed by Linus Torvalds

mm/vmscan.c: condense scan_control

Use smaller scan_control fields for order, priority, and reclaim_idx.
Convert fields from int => s8.  All easily fit within a byte:

 - allocation order range: 0..MAX_ORDER(64?)
 - priority range:         0..12(DEF_PRIORITY)
 - reclaim_idx range:      0..6(__MAX_NR_ZONES)

Since 6538b8ea ("x86_64: expand kernel stack to 16K") x86_64 stack
overflows are not an issue.  But it's inefficient to use ints.

Use s8 (signed byte) rather than u8 to allow for loops like:
	do {
		...
	} while (--sc.priority >= 0);

Add BUILD_BUG_ON to verify that s8 is capable of storing max values.

This reduces sizeof(struct scan_control):
 - 96 => 80 bytes (x86_64)
 - 68 => 56 bytes (i386)

scan_control structure field order is changed to utilize padding.  After
this patch there is 1 bit of scan_control padding.

akpm: makes my vmscan.o's .text 572 bytes smaller as well.

Link: http://lkml.kernel.org/r/20180530061212.84915-1-gthelen@google.comSigned-off-by: default avatarGreg Thelen <gthelen@google.com>
Suggested-by: default avatarMatthew Wilcox <willy@infradead.org>
Reviewed-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 10ed6341
...@@ -65,12 +65,6 @@ struct scan_control { ...@@ -65,12 +65,6 @@ struct scan_control {
/* How many pages shrink_list() should reclaim */ /* How many pages shrink_list() should reclaim */
unsigned long nr_to_reclaim; unsigned long nr_to_reclaim;
/* This context's GFP mask */
gfp_t gfp_mask;
/* Allocation order */
int order;
/* /*
* Nodemask of nodes allowed by the caller. If NULL, all nodes * Nodemask of nodes allowed by the caller. If NULL, all nodes
* are scanned. * are scanned.
...@@ -83,12 +77,6 @@ struct scan_control { ...@@ -83,12 +77,6 @@ struct scan_control {
*/ */
struct mem_cgroup *target_mem_cgroup; struct mem_cgroup *target_mem_cgroup;
/* Scan (total_size >> priority) pages at once */
int priority;
/* The highest zone to isolate pages for reclaim from */
enum zone_type reclaim_idx;
/* Writepage batching in laptop mode; RECLAIM_WRITE */ /* Writepage batching in laptop mode; RECLAIM_WRITE */
unsigned int may_writepage:1; unsigned int may_writepage:1;
...@@ -111,6 +99,18 @@ struct scan_control { ...@@ -111,6 +99,18 @@ struct scan_control {
/* One of the zones is ready for compaction */ /* One of the zones is ready for compaction */
unsigned int compaction_ready:1; unsigned int compaction_ready:1;
/* Allocation order */
s8 order;
/* Scan (total_size >> priority) pages at once */
s8 priority;
/* The highest zone to isolate pages for reclaim from */
s8 reclaim_idx;
/* This context's GFP mask */
gfp_t gfp_mask;
/* Incremented by the number of inactive pages that were scanned */ /* Incremented by the number of inactive pages that were scanned */
unsigned long nr_scanned; unsigned long nr_scanned;
...@@ -3063,6 +3063,14 @@ unsigned long try_to_free_pages(struct zonelist *zonelist, int order, ...@@ -3063,6 +3063,14 @@ unsigned long try_to_free_pages(struct zonelist *zonelist, int order,
.may_swap = 1, .may_swap = 1,
}; };
/*
* scan_control uses s8 fields for order, priority, and reclaim_idx.
* Confirm they are large enough for max values.
*/
BUILD_BUG_ON(MAX_ORDER > S8_MAX);
BUILD_BUG_ON(DEF_PRIORITY > S8_MAX);
BUILD_BUG_ON(MAX_NR_ZONES > S8_MAX);
/* /*
* Do not enter reclaim if fatal signal was delivered while throttled. * Do not enter reclaim if fatal signal was delivered while throttled.
* 1 is returned so that the page allocator does not OOM kill at this * 1 is returned so that the page allocator does not OOM kill at this
......
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