Blame view

drivers/xen/xen-selfballoon.c 17 KB
a50777c79   Dan Magenheimer   xen: tmem: self-b...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  /******************************************************************************
   * Xen selfballoon driver (and optional frontswap self-shrinking driver)
   *
   * Copyright (c) 2009-2011, Dan Magenheimer, Oracle Corp.
   *
   * This code complements the cleancache and frontswap patchsets to optimize
   * support for Xen Transcendent Memory ("tmem").  The policy it implements
   * is rudimentary and will likely improve over time, but it does work well
   * enough today.
   *
   * Two functionalities are implemented here which both use "control theory"
   * (feedback) to optimize memory utilization. In a virtualized environment
   * such as Xen, RAM is often a scarce resource and we would like to ensure
   * that each of a possibly large number of virtual machines is using RAM
   * efficiently, i.e. using as little as possible when under light load
   * and obtaining as much as possible when memory demands are high.
   * Since RAM needs vary highly dynamically and sometimes dramatically,
   * "hysteresis" is used, that is, memory target is determined not just
   * on current data but also on past data stored in the system.
   *
   * "Selfballooning" creates memory pressure by managing the Xen balloon
   * driver to decrease and increase available kernel memory, driven
   * largely by the target value of "Committed_AS" (see /proc/meminfo).
   * Since Committed_AS does not account for clean mapped pages (i.e. pages
   * in RAM that are identical to pages on disk), selfballooning has the
   * affect of pushing less frequently used clean pagecache pages out of
   * kernel RAM and, presumably using cleancache, into Xen tmem where
   * Xen can more efficiently optimize RAM utilization for such pages.
   *
   * When kernel memory demand unexpectedly increases faster than Xen, via
   * the selfballoon driver, is able to (or chooses to) provide usable RAM,
   * the kernel may invoke swapping.  In most cases, frontswap is able
   * to absorb this swapping into Xen tmem.  However, due to the fact
   * that the kernel swap subsystem assumes swapping occurs to a disk,
   * swapped pages may sit on the disk for a very long time; even if
   * the kernel knows the page will never be used again.  This is because
   * the disk space costs very little and can be overwritten when
   * necessary.  When such stale pages are in frontswap, however, they
   * are taking up valuable real estate.  "Frontswap selfshrinking" works
   * to resolve this:  When frontswap activity is otherwise stable
   * and the guest kernel is not under memory pressure, the "frontswap
   * selfshrinking" accounts for this by providing pressure to remove some
   * pages from frontswap and return them to kernel memory.
   *
   * For both "selfballooning" and "frontswap-selfshrinking", a worker
   * thread is used and sysfs tunables are provided to adjust the frequency
   * and rate of adjustments to achieve the goal, as well as to disable one
   * or both functions independently.
   *
   * While some argue that this functionality can and should be implemented
   * in userspace, it has been observed that bad things happen (e.g. OOMs).
   *
   * System configuration note: Selfballooning should not be enabled on
   * systems without a sufficiently large swap device configured; for best
   * results, it is recommended that total swap be increased by the size
   * of the guest memory.  Also, while technically not required to be
   * configured, it is highly recommended that frontswap also be configured
   * and enabled when selfballooning is running.  So, selfballooning
   * is disabled by default if frontswap is not configured and can only
   * be enabled with the "selfballooning" kernel boot option; similarly
   * selfballooning is enabled by default if frontswap is configured and
   * can be disabled with the "noselfballooning" kernel boot option.  Finally,
   * when frontswap is configured, frontswap-selfshrinking can be disabled
   * with the "noselfshrink" kernel boot option.
   *
   * Selfballooning is disallowed in domain0 and force-disabled.
   *
   */
  
  #include <linux/kernel.h>
38a1ed4f0   Dan Magenheimer   xen: Fix selfball...
71
72
  #include <linux/bootmem.h>
  #include <linux/swap.h>
a50777c79   Dan Magenheimer   xen: tmem: self-b...
73
74
  #include <linux/mm.h>
  #include <linux/mman.h>
4fec0e0bd   Randy Dunlap   xen: self-balloon...
75
  #include <linux/module.h>
0642d2edc   Konrad Rzeszutek Wilk   xen/balloon: Fix ...
76
  #include <linux/workqueue.h>
cb0c05c5f   Greg Kroah-Hartman   xen: fix build br...
77
  #include <linux/device.h>
a50777c79   Dan Magenheimer   xen: tmem: self-b...
78
  #include <xen/balloon.h>
a50777c79   Dan Magenheimer   xen: tmem: self-b...
79
  #include <xen/tmem.h>
0642d2edc   Konrad Rzeszutek Wilk   xen/balloon: Fix ...
80
  #include <xen/xen.h>
a50777c79   Dan Magenheimer   xen: tmem: self-b...
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
  
  /* Enable/disable with sysfs. */
  static int xen_selfballooning_enabled __read_mostly;
  
  /*
   * Controls rate at which memory target (this iteration) approaches
   * ultimate goal when memory need is increasing (up-hysteresis) or
   * decreasing (down-hysteresis). Higher values of hysteresis cause
   * slower increases/decreases. The default values for the various
   * parameters were deemed reasonable by experimentation, may be
   * workload-dependent, and can all be adjusted via sysfs.
   */
  static unsigned int selfballoon_downhysteresis __read_mostly = 8;
  static unsigned int selfballoon_uphysteresis __read_mostly = 1;
  
  /* In HZ, controls frequency of worker invocation. */
  static unsigned int selfballoon_interval __read_mostly = 5;
38a1ed4f0   Dan Magenheimer   xen: Fix selfball...
98
99
100
101
102
103
104
105
  /*
   * Minimum usable RAM in MB for selfballooning target for balloon.
   * If non-zero, it is added to totalreserve_pages and self-ballooning
   * will not balloon below the sum.  If zero, a piecewise linear function
   * is calculated as a minimum and added to totalreserve_pages.  Note that
   * setting this value indiscriminately may cause OOMs and crashes.
   */
  static unsigned int selfballoon_min_usable_mb;
a50777c79   Dan Magenheimer   xen: tmem: self-b...
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
  static void selfballoon_process(struct work_struct *work);
  static DECLARE_DELAYED_WORK(selfballoon_worker, selfballoon_process);
  
  #ifdef CONFIG_FRONTSWAP
  #include <linux/frontswap.h>
  
  /* Enable/disable with sysfs. */
  static bool frontswap_selfshrinking __read_mostly;
  
  /* Enable/disable with kernel boot option. */
  static bool use_frontswap_selfshrink __initdata = true;
  
  /*
   * The default values for the following parameters were deemed reasonable
   * by experimentation, may be workload-dependent, and can all be
   * adjusted via sysfs.
   */
  
  /* Control rate for frontswap shrinking. Higher hysteresis is slower. */
  static unsigned int frontswap_hysteresis __read_mostly = 20;
  
  /*
   * Number of selfballoon worker invocations to wait before observing that
   * frontswap selfshrinking should commence. Note that selfshrinking does
   * not use a separate worker thread.
   */
  static unsigned int frontswap_inertia __read_mostly = 3;
  
  /* Countdown to next invocation of frontswap_shrink() */
  static unsigned long frontswap_inertia_counter;
  
  /*
   * Invoked by the selfballoon worker thread, uses current number of pages
   * in frontswap (frontswap_curr_pages()), previous status, and control
   * values (hysteresis and inertia) to determine if frontswap should be
   * shrunk and what the new frontswap size should be.  Note that
   * frontswap_shrink is essentially a partial swapoff that immediately
   * transfers pages from the "swap device" (frontswap) back into kernel
   * RAM; despite the name, frontswap "shrinking" is very different from
   * the "shrinker" interface used by the kernel MM subsystem to reclaim
   * memory.
   */
  static void frontswap_selfshrink(void)
  {
  	static unsigned long cur_frontswap_pages;
  	static unsigned long last_frontswap_pages;
  	static unsigned long tgt_frontswap_pages;
  
  	last_frontswap_pages = cur_frontswap_pages;
  	cur_frontswap_pages = frontswap_curr_pages();
  	if (!cur_frontswap_pages ||
  			(cur_frontswap_pages > last_frontswap_pages)) {
  		frontswap_inertia_counter = frontswap_inertia;
  		return;
  	}
  	if (frontswap_inertia_counter && --frontswap_inertia_counter)
  		return;
  	if (cur_frontswap_pages <= frontswap_hysteresis)
  		tgt_frontswap_pages = 0;
  	else
  		tgt_frontswap_pages = cur_frontswap_pages -
  			(cur_frontswap_pages / frontswap_hysteresis);
  	frontswap_shrink(tgt_frontswap_pages);
  }
  
  static int __init xen_nofrontswap_selfshrink_setup(char *s)
  {
  	use_frontswap_selfshrink = false;
  	return 1;
  }
  
  __setup("noselfshrink", xen_nofrontswap_selfshrink_setup);
  
  /* Disable with kernel boot option. */
  static bool use_selfballooning __initdata = true;
  
  static int __init xen_noselfballooning_setup(char *s)
  {
  	use_selfballooning = false;
  	return 1;
  }
  
  __setup("noselfballooning", xen_noselfballooning_setup);
  #else /* !CONFIG_FRONTSWAP */
  /* Enable with kernel boot option. */
  static bool use_selfballooning __initdata = false;
  
  static int __init xen_selfballooning_setup(char *s)
  {
  	use_selfballooning = true;
  	return 1;
  }
  
  __setup("selfballooning", xen_selfballooning_setup);
  #endif /* CONFIG_FRONTSWAP */
38a1ed4f0   Dan Magenheimer   xen: Fix selfball...
201
  #define MB2PAGES(mb)	((mb) << (20 - PAGE_SHIFT))
a50777c79   Dan Magenheimer   xen: tmem: self-b...
202
203
204
205
206
207
  /*
   * Use current balloon size, the goal (vm_committed_as), and hysteresis
   * parameters to set a new target balloon size
   */
  static void selfballoon_process(struct work_struct *work)
  {
38a1ed4f0   Dan Magenheimer   xen: Fix selfball...
208
209
  	unsigned long cur_pages, goal_pages, tgt_pages, floor_pages;
  	unsigned long useful_pages;
a50777c79   Dan Magenheimer   xen: tmem: self-b...
210
211
212
  	bool reset_timer = false;
  
  	if (xen_selfballooning_enabled) {
38a1ed4f0   Dan Magenheimer   xen: Fix selfball...
213
  		cur_pages = totalram_pages;
a50777c79   Dan Magenheimer   xen: tmem: self-b...
214
215
  		tgt_pages = cur_pages; /* default is no change */
  		goal_pages = percpu_counter_read_positive(&vm_committed_as) +
38a1ed4f0   Dan Magenheimer   xen: Fix selfball...
216
  				totalreserve_pages;
a50777c79   Dan Magenheimer   xen: tmem: self-b...
217
218
219
220
221
222
223
224
225
226
227
228
229
230
  #ifdef CONFIG_FRONTSWAP
  		/* allow space for frontswap pages to be repatriated */
  		if (frontswap_selfshrinking && frontswap_enabled)
  			goal_pages += frontswap_curr_pages();
  #endif
  		if (cur_pages > goal_pages)
  			tgt_pages = cur_pages -
  				((cur_pages - goal_pages) /
  				  selfballoon_downhysteresis);
  		else if (cur_pages < goal_pages)
  			tgt_pages = cur_pages +
  				((goal_pages - cur_pages) /
  				  selfballoon_uphysteresis);
  		/* else if cur_pages == goal_pages, no change */
38a1ed4f0   Dan Magenheimer   xen: Fix selfball...
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
  		useful_pages = max_pfn - totalreserve_pages;
  		if (selfballoon_min_usable_mb != 0)
  			floor_pages = totalreserve_pages +
  					MB2PAGES(selfballoon_min_usable_mb);
  		/* piecewise linear function ending in ~3% slope */
  		else if (useful_pages < MB2PAGES(16))
  			floor_pages = max_pfn; /* not worth ballooning */
  		else if (useful_pages < MB2PAGES(64))
  			floor_pages = totalreserve_pages + MB2PAGES(16) +
  					((useful_pages - MB2PAGES(16)) >> 1);
  		else if (useful_pages < MB2PAGES(512))
  			floor_pages = totalreserve_pages + MB2PAGES(40) +
  					((useful_pages - MB2PAGES(40)) >> 3);
  		else /* useful_pages >= MB2PAGES(512) */
  			floor_pages = totalreserve_pages + MB2PAGES(99) +
  					((useful_pages - MB2PAGES(99)) >> 5);
  		if (tgt_pages < floor_pages)
  			tgt_pages = floor_pages;
  		balloon_set_new_target(tgt_pages +
  			balloon_stats.current_pages - totalram_pages);
a50777c79   Dan Magenheimer   xen: tmem: self-b...
251
252
253
254
255
256
257
258
259
260
261
262
263
264
  		reset_timer = true;
  	}
  #ifdef CONFIG_FRONTSWAP
  	if (frontswap_selfshrinking && frontswap_enabled) {
  		frontswap_selfshrink();
  		reset_timer = true;
  	}
  #endif
  	if (reset_timer)
  		schedule_delayed_work(&selfballoon_worker,
  			selfballoon_interval * HZ);
  }
  
  #ifdef CONFIG_SYSFS
a50777c79   Dan Magenheimer   xen: tmem: self-b...
265
266
267
  #include <linux/capability.h>
  
  #define SELFBALLOON_SHOW(name, format, args...)				\
070680218   Kay Sievers   xen-balloon: conv...
268
269
270
  	static ssize_t show_##name(struct device *dev,	\
  					  struct device_attribute *attr, \
  					  char *buf) \
a50777c79   Dan Magenheimer   xen: tmem: self-b...
271
272
273
274
275
276
  	{ \
  		return sprintf(buf, format, ##args); \
  	}
  
  SELFBALLOON_SHOW(selfballooning, "%d
  ", xen_selfballooning_enabled);
070680218   Kay Sievers   xen-balloon: conv...
277
278
  static ssize_t store_selfballooning(struct device *dev,
  			    struct device_attribute *attr,
a50777c79   Dan Magenheimer   xen: tmem: self-b...
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
  			    const char *buf,
  			    size_t count)
  {
  	bool was_enabled = xen_selfballooning_enabled;
  	unsigned long tmp;
  	int err;
  
  	if (!capable(CAP_SYS_ADMIN))
  		return -EPERM;
  
  	err = strict_strtoul(buf, 10, &tmp);
  	if (err || ((tmp != 0) && (tmp != 1)))
  		return -EINVAL;
  
  	xen_selfballooning_enabled = !!tmp;
  	if (!was_enabled && xen_selfballooning_enabled)
  		schedule_delayed_work(&selfballoon_worker,
  			selfballoon_interval * HZ);
  
  	return count;
  }
070680218   Kay Sievers   xen-balloon: conv...
300
  static DEVICE_ATTR(selfballooning, S_IRUGO | S_IWUSR,
a50777c79   Dan Magenheimer   xen: tmem: self-b...
301
302
303
304
  		   show_selfballooning, store_selfballooning);
  
  SELFBALLOON_SHOW(selfballoon_interval, "%d
  ", selfballoon_interval);
070680218   Kay Sievers   xen-balloon: conv...
305
306
  static ssize_t store_selfballoon_interval(struct device *dev,
  					  struct device_attribute *attr,
a50777c79   Dan Magenheimer   xen: tmem: self-b...
307
308
309
310
311
312
313
314
315
316
317
318
319
320
  					  const char *buf,
  					  size_t count)
  {
  	unsigned long val;
  	int err;
  
  	if (!capable(CAP_SYS_ADMIN))
  		return -EPERM;
  	err = strict_strtoul(buf, 10, &val);
  	if (err || val == 0)
  		return -EINVAL;
  	selfballoon_interval = val;
  	return count;
  }
070680218   Kay Sievers   xen-balloon: conv...
321
  static DEVICE_ATTR(selfballoon_interval, S_IRUGO | S_IWUSR,
a50777c79   Dan Magenheimer   xen: tmem: self-b...
322
323
324
325
  		   show_selfballoon_interval, store_selfballoon_interval);
  
  SELFBALLOON_SHOW(selfballoon_downhys, "%d
  ", selfballoon_downhysteresis);
070680218   Kay Sievers   xen-balloon: conv...
326
327
  static ssize_t store_selfballoon_downhys(struct device *dev,
  					 struct device_attribute *attr,
a50777c79   Dan Magenheimer   xen: tmem: self-b...
328
329
330
331
332
333
334
335
336
337
338
339
340
341
  					 const char *buf,
  					 size_t count)
  {
  	unsigned long val;
  	int err;
  
  	if (!capable(CAP_SYS_ADMIN))
  		return -EPERM;
  	err = strict_strtoul(buf, 10, &val);
  	if (err || val == 0)
  		return -EINVAL;
  	selfballoon_downhysteresis = val;
  	return count;
  }
070680218   Kay Sievers   xen-balloon: conv...
342
  static DEVICE_ATTR(selfballoon_downhysteresis, S_IRUGO | S_IWUSR,
a50777c79   Dan Magenheimer   xen: tmem: self-b...
343
344
345
346
347
  		   show_selfballoon_downhys, store_selfballoon_downhys);
  
  
  SELFBALLOON_SHOW(selfballoon_uphys, "%d
  ", selfballoon_uphysteresis);
070680218   Kay Sievers   xen-balloon: conv...
348
349
  static ssize_t store_selfballoon_uphys(struct device *dev,
  				       struct device_attribute *attr,
a50777c79   Dan Magenheimer   xen: tmem: self-b...
350
351
352
353
354
355
356
357
358
359
360
361
362
363
  				       const char *buf,
  				       size_t count)
  {
  	unsigned long val;
  	int err;
  
  	if (!capable(CAP_SYS_ADMIN))
  		return -EPERM;
  	err = strict_strtoul(buf, 10, &val);
  	if (err || val == 0)
  		return -EINVAL;
  	selfballoon_uphysteresis = val;
  	return count;
  }
070680218   Kay Sievers   xen-balloon: conv...
364
  static DEVICE_ATTR(selfballoon_uphysteresis, S_IRUGO | S_IWUSR,
a50777c79   Dan Magenheimer   xen: tmem: self-b...
365
  		   show_selfballoon_uphys, store_selfballoon_uphys);
38a1ed4f0   Dan Magenheimer   xen: Fix selfball...
366
367
368
  SELFBALLOON_SHOW(selfballoon_min_usable_mb, "%d
  ",
  				selfballoon_min_usable_mb);
070680218   Kay Sievers   xen-balloon: conv...
369
370
  static ssize_t store_selfballoon_min_usable_mb(struct device *dev,
  					       struct device_attribute *attr,
38a1ed4f0   Dan Magenheimer   xen: Fix selfball...
371
372
373
374
375
376
377
378
379
380
381
382
383
384
  					       const char *buf,
  					       size_t count)
  {
  	unsigned long val;
  	int err;
  
  	if (!capable(CAP_SYS_ADMIN))
  		return -EPERM;
  	err = strict_strtoul(buf, 10, &val);
  	if (err || val == 0)
  		return -EINVAL;
  	selfballoon_min_usable_mb = val;
  	return count;
  }
070680218   Kay Sievers   xen-balloon: conv...
385
  static DEVICE_ATTR(selfballoon_min_usable_mb, S_IRUGO | S_IWUSR,
38a1ed4f0   Dan Magenheimer   xen: Fix selfball...
386
387
  		   show_selfballoon_min_usable_mb,
  		   store_selfballoon_min_usable_mb);
a50777c79   Dan Magenheimer   xen: tmem: self-b...
388
389
390
  #ifdef CONFIG_FRONTSWAP
  SELFBALLOON_SHOW(frontswap_selfshrinking, "%d
  ", frontswap_selfshrinking);
070680218   Kay Sievers   xen-balloon: conv...
391
392
  static ssize_t store_frontswap_selfshrinking(struct device *dev,
  					     struct device_attribute *attr,
a50777c79   Dan Magenheimer   xen: tmem: self-b...
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
  					     const char *buf,
  					     size_t count)
  {
  	bool was_enabled = frontswap_selfshrinking;
  	unsigned long tmp;
  	int err;
  
  	if (!capable(CAP_SYS_ADMIN))
  		return -EPERM;
  	err = strict_strtoul(buf, 10, &tmp);
  	if (err || ((tmp != 0) && (tmp != 1)))
  		return -EINVAL;
  	frontswap_selfshrinking = !!tmp;
  	if (!was_enabled && !xen_selfballooning_enabled &&
  	     frontswap_selfshrinking)
  		schedule_delayed_work(&selfballoon_worker,
  			selfballoon_interval * HZ);
  
  	return count;
  }
070680218   Kay Sievers   xen-balloon: conv...
413
  static DEVICE_ATTR(frontswap_selfshrinking, S_IRUGO | S_IWUSR,
a50777c79   Dan Magenheimer   xen: tmem: self-b...
414
415
416
417
  		   show_frontswap_selfshrinking, store_frontswap_selfshrinking);
  
  SELFBALLOON_SHOW(frontswap_inertia, "%d
  ", frontswap_inertia);
070680218   Kay Sievers   xen-balloon: conv...
418
419
  static ssize_t store_frontswap_inertia(struct device *dev,
  				       struct device_attribute *attr,
a50777c79   Dan Magenheimer   xen: tmem: self-b...
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
  				       const char *buf,
  				       size_t count)
  {
  	unsigned long val;
  	int err;
  
  	if (!capable(CAP_SYS_ADMIN))
  		return -EPERM;
  	err = strict_strtoul(buf, 10, &val);
  	if (err || val == 0)
  		return -EINVAL;
  	frontswap_inertia = val;
  	frontswap_inertia_counter = val;
  	return count;
  }
070680218   Kay Sievers   xen-balloon: conv...
435
  static DEVICE_ATTR(frontswap_inertia, S_IRUGO | S_IWUSR,
a50777c79   Dan Magenheimer   xen: tmem: self-b...
436
437
438
439
  		   show_frontswap_inertia, store_frontswap_inertia);
  
  SELFBALLOON_SHOW(frontswap_hysteresis, "%d
  ", frontswap_hysteresis);
070680218   Kay Sievers   xen-balloon: conv...
440
441
  static ssize_t store_frontswap_hysteresis(struct device *dev,
  					  struct device_attribute *attr,
a50777c79   Dan Magenheimer   xen: tmem: self-b...
442
443
444
445
446
447
448
449
450
451
452
453
454
455
  					  const char *buf,
  					  size_t count)
  {
  	unsigned long val;
  	int err;
  
  	if (!capable(CAP_SYS_ADMIN))
  		return -EPERM;
  	err = strict_strtoul(buf, 10, &val);
  	if (err || val == 0)
  		return -EINVAL;
  	frontswap_hysteresis = val;
  	return count;
  }
070680218   Kay Sievers   xen-balloon: conv...
456
  static DEVICE_ATTR(frontswap_hysteresis, S_IRUGO | S_IWUSR,
a50777c79   Dan Magenheimer   xen: tmem: self-b...
457
458
459
460
461
  		   show_frontswap_hysteresis, store_frontswap_hysteresis);
  
  #endif /* CONFIG_FRONTSWAP */
  
  static struct attribute *selfballoon_attrs[] = {
070680218   Kay Sievers   xen-balloon: conv...
462
463
464
465
466
  	&dev_attr_selfballooning.attr,
  	&dev_attr_selfballoon_interval.attr,
  	&dev_attr_selfballoon_downhysteresis.attr,
  	&dev_attr_selfballoon_uphysteresis.attr,
  	&dev_attr_selfballoon_min_usable_mb.attr,
a50777c79   Dan Magenheimer   xen: tmem: self-b...
467
  #ifdef CONFIG_FRONTSWAP
070680218   Kay Sievers   xen-balloon: conv...
468
469
470
  	&dev_attr_frontswap_selfshrinking.attr,
  	&dev_attr_frontswap_hysteresis.attr,
  	&dev_attr_frontswap_inertia.attr,
a50777c79   Dan Magenheimer   xen: tmem: self-b...
471
472
473
474
475
476
477
478
479
  #endif
  	NULL
  };
  
  static struct attribute_group selfballoon_group = {
  	.name = "selfballoon",
  	.attrs = selfballoon_attrs
  };
  #endif
070680218   Kay Sievers   xen-balloon: conv...
480
  int register_xen_selfballooning(struct device *dev)
a50777c79   Dan Magenheimer   xen: tmem: self-b...
481
482
483
484
  {
  	int error = -1;
  
  #ifdef CONFIG_SYSFS
070680218   Kay Sievers   xen-balloon: conv...
485
  	error = sysfs_create_group(&dev->kobj, &selfballoon_group);
a50777c79   Dan Magenheimer   xen: tmem: self-b...
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
  #endif
  	return error;
  }
  EXPORT_SYMBOL(register_xen_selfballooning);
  
  static int __init xen_selfballoon_init(void)
  {
  	bool enable = false;
  
  	if (!xen_domain())
  		return -ENODEV;
  
  	if (xen_initial_domain()) {
  		pr_info("xen/balloon: Xen selfballooning driver "
  				"disabled for domain0.
  ");
  		return -ENODEV;
  	}
  
  	xen_selfballooning_enabled = tmem_enabled && use_selfballooning;
  	if (xen_selfballooning_enabled) {
  		pr_info("xen/balloon: Initializing Xen "
  					"selfballooning driver.
  ");
  		enable = true;
  	}
  #ifdef CONFIG_FRONTSWAP
  	frontswap_selfshrinking = tmem_enabled && use_frontswap_selfshrink;
  	if (frontswap_selfshrinking) {
  		pr_info("xen/balloon: Initializing frontswap "
  					"selfshrinking driver.
  ");
  		enable = true;
  	}
  #endif
  	if (!enable)
  		return -ENODEV;
  
  	schedule_delayed_work(&selfballoon_worker, selfballoon_interval * HZ);
  
  	return 0;
  }
  
  subsys_initcall(xen_selfballoon_init);
  
  MODULE_LICENSE("GPL");