Magellan Linux

Annotation of /trunk/kernel26-magellan/patches-2.6.17-r6/0019-2.6.17-mm-convert_swappiness_to_mapped.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 105 - (hide annotations) (download)
Sun Mar 11 16:17:56 2007 UTC (17 years, 2 months ago) by niro
File size: 7713 byte(s)
2.6.17-magellan-r6

1 niro 105 Turn the "swappiness" knob into one with well defined semantics. Rename it
2     "mapped" to correspond directly with the percentage of mapped ram or
3     "applications" as users think of it. Currently the swappiness algorithm can
4     easily lead to swapping situations on simple file copies due to the distress
5     algorithm which too easily overrides the swappiness value. Add a
6     "hardmaplimit" tunable, on by default, which only allows the vm to override
7     the "mapped" tunable when distress is at its greatest to prevent false
8     out-of-memory situations.
9    
10     Signed-off-by: Con Kolivas <kernel@kolivas.org>
11    
12     Documentation/sysctl/vm.txt | 23 +++++++++++++++++++++++
13     include/linux/swap.h | 3 ++-
14     include/linux/sysctl.h | 3 ++-
15     kernel/sysctl.c | 16 ++++++++++++----
16     mm/vmscan.c | 29 +++++++++++++++++------------
17     5 files changed, 56 insertions(+), 18 deletions(-)
18    
19     Index: linux-ck-dev/include/linux/swap.h
20     ===================================================================
21     --- linux-ck-dev.orig/include/linux/swap.h 2006-06-18 15:24:48.000000000 +1000
22     +++ linux-ck-dev/include/linux/swap.h 2006-06-18 15:24:58.000000000 +1000
23     @@ -176,7 +176,8 @@ extern void swap_setup(void);
24     /* linux/mm/vmscan.c */
25     extern unsigned long try_to_free_pages(struct zone **, gfp_t);
26     extern unsigned long shrink_all_memory(unsigned long nr_pages);
27     -extern int vm_swappiness;
28     +extern int vm_mapped;
29     +extern int vm_hardmaplimit;
30     extern int remove_mapping(struct address_space *mapping, struct page *page);
31    
32     /* possible outcome of pageout() */
33     Index: linux-ck-dev/include/linux/sysctl.h
34     ===================================================================
35     --- linux-ck-dev.orig/include/linux/sysctl.h 2006-06-18 15:24:48.000000000 +1000
36     +++ linux-ck-dev/include/linux/sysctl.h 2006-06-18 15:24:58.000000000 +1000
37     @@ -175,7 +175,7 @@ enum
38     VM_OVERCOMMIT_RATIO=16, /* percent of RAM to allow overcommit in */
39     VM_PAGEBUF=17, /* struct: Control pagebuf parameters */
40     VM_HUGETLB_PAGES=18, /* int: Number of available Huge Pages */
41     - VM_SWAPPINESS=19, /* Tendency to steal mapped memory */
42     + VM_MAPPED=19, /* percent mapped min while evicting cache */
43     VM_LOWMEM_RESERVE_RATIO=20,/* reservation ratio for lower memory zones */
44     VM_MIN_FREE_KBYTES=21, /* Minimum free kilobytes to maintain */
45     VM_MAX_MAP_COUNT=22, /* int: Maximum number of mmaps/address-space */
46     @@ -190,6 +190,7 @@ enum
47     VM_ZONE_RECLAIM_MODE=31, /* reclaim local zone memory before going off node */
48     VM_ZONE_RECLAIM_INTERVAL=32, /* time period to wait after reclaim failure */
49     VM_SWAP_PREFETCH=33, /* swap prefetch */
50     + VM_HARDMAPLIMIT=34, /* Make mapped a hard limit */
51     };
52    
53    
54     Index: linux-ck-dev/kernel/sysctl.c
55     ===================================================================
56     --- linux-ck-dev.orig/kernel/sysctl.c 2006-06-18 15:24:48.000000000 +1000
57     +++ linux-ck-dev/kernel/sysctl.c 2006-06-18 15:24:58.000000000 +1000
58     @@ -791,16 +791,24 @@ static ctl_table vm_table[] = {
59     .proc_handler = &proc_dointvec,
60     },
61     {
62     - .ctl_name = VM_SWAPPINESS,
63     - .procname = "swappiness",
64     - .data = &vm_swappiness,
65     - .maxlen = sizeof(vm_swappiness),
66     + .ctl_name = VM_MAPPED,
67     + .procname = "mapped",
68     + .data = &vm_mapped,
69     + .maxlen = sizeof(vm_mapped),
70     .mode = 0644,
71     .proc_handler = &proc_dointvec_minmax,
72     .strategy = &sysctl_intvec,
73     .extra1 = &zero,
74     .extra2 = &one_hundred,
75     },
76     + {
77     + .ctl_name = VM_HARDMAPLIMIT,
78     + .procname = "hardmaplimit",
79     + .data = &vm_hardmaplimit,
80     + .maxlen = sizeof(int),
81     + .mode = 0644,
82     + .proc_handler = &proc_dointvec,
83     + },
84     #ifdef CONFIG_HUGETLB_PAGE
85     {
86     .ctl_name = VM_HUGETLB_PAGES,
87     Index: linux-ck-dev/mm/vmscan.c
88     ===================================================================
89     --- linux-ck-dev.orig/mm/vmscan.c 2006-06-18 15:24:52.000000000 +1000
90     +++ linux-ck-dev/mm/vmscan.c 2006-06-18 15:24:58.000000000 +1000
91     @@ -63,7 +63,7 @@ struct scan_control {
92     * whole list at once. */
93     int swap_cluster_max;
94    
95     - int swappiness;
96     + int mapped;
97     };
98    
99     /*
100     @@ -108,10 +108,11 @@ struct shrinker {
101     #endif
102    
103     /*
104     - * From 0 .. 100. Higher means more swappy.
105     + * From 0 .. 100. Lower means more swappy.
106     */
107     -int vm_swappiness = 60;
108     -static long total_memory;
109     +int vm_mapped __read_mostly = 66;
110     +int vm_hardmaplimit __read_mostly = 1;
111     +static long total_memory __read_mostly;
112    
113     static LIST_HEAD(shrinker_list);
114     static DECLARE_RWSEM(shrinker_rwsem);
115     @@ -742,10 +743,14 @@ static void shrink_active_list(unsigned
116     * The distress ratio is important - we don't want to start
117     * going oom.
118     *
119     - * A 100% value of vm_swappiness overrides this algorithm
120     - * altogether.
121     + * This distress value is ignored if we apply a hardmaplimit except
122     + * in extreme distress.
123     + *
124     + * A 0% value of vm_mapped overrides this algorithm altogether.
125     */
126     - swap_tendency = mapped_ratio / 2 + distress + sc->swappiness;
127     + swap_tendency = mapped_ratio * 100 / (sc->mapped + 1);
128     + if (!vm_hardmaplimit || distress == 100)
129     + swap_tendency += distress;
130    
131     /*
132     * Now use this metric to decide whether to start moving mapped
133     @@ -961,7 +966,7 @@ unsigned long try_to_free_pages(struct z
134     .may_writepage = !laptop_mode,
135     .swap_cluster_max = SWAP_CLUSTER_MAX,
136     .may_swap = 1,
137     - .swappiness = vm_swappiness,
138     + .mapped = vm_mapped,
139     };
140    
141     delay_swap_prefetch();
142     @@ -1057,7 +1062,7 @@ static unsigned long balance_pgdat(pg_da
143     .gfp_mask = GFP_KERNEL,
144     .may_swap = 1,
145     .swap_cluster_max = SWAP_CLUSTER_MAX,
146     - .swappiness = vm_swappiness,
147     + .mapped = vm_mapped,
148     };
149    
150     loop_again:
151     @@ -1346,7 +1351,7 @@ unsigned long shrink_all_memory(unsigned
152     .may_swap = 0,
153     .swap_cluster_max = nr_pages,
154     .may_writepage = 1,
155     - .swappiness = vm_swappiness,
156     + .mapped = vm_mapped,
157     };
158    
159     current->reclaim_state = &reclaim_state;
160     @@ -1391,7 +1396,7 @@ unsigned long shrink_all_memory(unsigned
161     /* Force reclaiming mapped pages in the passes #3 and #4 */
162     if (pass > 2) {
163     sc.may_swap = 1;
164     - sc.swappiness = 100;
165     + sc.mapped = 0;
166     }
167    
168     for (prio = DEF_PRIORITY; prio >= 0; prio--) {
169     @@ -1528,7 +1533,7 @@ static int __zone_reclaim(struct zone *z
170     .swap_cluster_max = max_t(unsigned long, nr_pages,
171     SWAP_CLUSTER_MAX),
172     .gfp_mask = gfp_mask,
173     - .swappiness = vm_swappiness,
174     + .mapped = vm_mapped,
175     };
176    
177     disable_swap_token();
178     Index: linux-ck-dev/Documentation/sysctl/vm.txt
179     ===================================================================
180     --- linux-ck-dev.orig/Documentation/sysctl/vm.txt 2006-06-18 15:24:48.000000000 +1000
181     +++ linux-ck-dev/Documentation/sysctl/vm.txt 2006-06-18 15:24:58.000000000 +1000
182     @@ -22,6 +22,8 @@ Currently, these files are in /proc/sys/
183     - dirty_background_ratio
184     - dirty_expire_centisecs
185     - dirty_writeback_centisecs
186     +- hardmaplimit
187     +- mapped
188     - max_map_count
189     - min_free_kbytes
190     - laptop_mode
191     @@ -85,6 +87,27 @@ for swap because we only cluster swap da
192    
193     ==============================================================
194    
195     +hardmaplimit:
196     +
197     +This flag makes the vm adhere to the mapped value as closely as possible
198     +except in the most extreme vm stress where doing so would provoke an out
199     +of memory condition (see mapped below).
200     +
201     +Enabled by default.
202     +
203     +==============================================================
204     +
205     +mapped:
206     +
207     +This is the percentage ram that is filled with mapped pages (applications)
208     +before the vm will start reclaiming mapped pages by moving them to swap.
209     +It is altered by the relative stress of the vm at the time so is not
210     +strictly adhered to to prevent provoking out of memory kills.
211     +
212     +Set to 66 by default.
213     +
214     +==============================================================
215     +
216     max_map_count:
217    
218     This file contains the maximum number of memory map areas a process