blob: ff58779bf7e95662363d6b42f9cba05d0b61b942 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/s390/mm/cmm.c
3 *
4 * S390 version
5 * Copyright (C) 2003 IBM Deutschland Entwicklung GmbH, IBM Corporation
6 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com)
7 *
8 * Collaborative memory management interface.
9 */
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/errno.h>
12#include <linux/fs.h>
13#include <linux/init.h>
14#include <linux/module.h>
15#include <linux/sched.h>
16#include <linux/sysctl.h>
17#include <linux/ctype.h>
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -070018#include <linux/swap.h>
Heiko Carstense8216de2006-09-25 23:33:11 -070019#include <linux/kthread.h>
David Rientjes5a3135c2007-10-16 23:25:53 -070020#include <linux/oom.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021
22#include <asm/pgalloc.h>
23#include <asm/uaccess.h>
Michael Holzheu0a87c5c2007-08-22 13:51:40 +020024#include <asm/diag.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
Martin Schwidefsky15439d72005-05-01 08:58:58 -070026static char *sender = "VMRMSVM";
Heiko Carstens447570c2005-06-21 17:16:29 -070027module_param(sender, charp, 0400);
Martin Schwidefsky15439d72005-05-01 08:58:58 -070028MODULE_PARM_DESC(sender,
29 "Guest name that may send SMSG messages (default VMRMSVM)");
30
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include "../../../drivers/s390/net/smsgiucv.h"
32
33#define CMM_NR_PAGES ((PAGE_SIZE / sizeof(unsigned long)) - 2)
34
35struct cmm_page_array {
36 struct cmm_page_array *next;
37 unsigned long index;
38 unsigned long pages[CMM_NR_PAGES];
39};
40
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -070041static long cmm_pages;
42static long cmm_timed_pages;
43static volatile long cmm_pages_target;
44static volatile long cmm_timed_pages_target;
45static long cmm_timeout_pages;
46static long cmm_timeout_seconds;
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -070048static struct cmm_page_array *cmm_page_list;
49static struct cmm_page_array *cmm_timed_page_list;
50static DEFINE_SPINLOCK(cmm_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Heiko Carstense8216de2006-09-25 23:33:11 -070052static struct task_struct *cmm_thread_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053static wait_queue_head_t cmm_thread_wait;
54static struct timer_list cmm_timer;
55
56static void cmm_timer_fn(unsigned long);
57static void cmm_set_timer(void);
58
59static long
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -070060cmm_alloc_pages(long nr, long *counter, struct cmm_page_array **list)
Linus Torvalds1da177e2005-04-16 15:20:36 -070061{
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -070062 struct cmm_page_array *pa, *npa;
63 unsigned long addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -070065 while (nr) {
66 addr = __get_free_page(GFP_NOIO);
67 if (!addr)
Linus Torvalds1da177e2005-04-16 15:20:36 -070068 break;
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -070069 spin_lock(&cmm_lock);
70 pa = *list;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 if (!pa || pa->index >= CMM_NR_PAGES) {
72 /* Need a new page for the page list. */
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -070073 spin_unlock(&cmm_lock);
74 npa = (struct cmm_page_array *)
Linus Torvalds1da177e2005-04-16 15:20:36 -070075 __get_free_page(GFP_NOIO);
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -070076 if (!npa) {
77 free_page(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 break;
79 }
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -070080 spin_lock(&cmm_lock);
81 pa = *list;
82 if (!pa || pa->index >= CMM_NR_PAGES) {
83 npa->next = pa;
84 npa->index = 0;
85 pa = npa;
86 *list = pa;
87 } else
88 free_page((unsigned long) npa);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 }
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -070090 diag10(addr);
91 pa->pages[pa->index++] = addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 (*counter)++;
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -070093 spin_unlock(&cmm_lock);
94 nr--;
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 }
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -070096 return nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097}
98
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -070099static long
100cmm_free_pages(long nr, long *counter, struct cmm_page_array **list)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101{
102 struct cmm_page_array *pa;
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700103 unsigned long addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700105 spin_lock(&cmm_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 pa = *list;
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700107 while (nr) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 if (!pa || pa->index <= 0)
109 break;
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700110 addr = pa->pages[--pa->index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 if (pa->index == 0) {
112 pa = pa->next;
113 free_page((unsigned long) *list);
114 *list = pa;
115 }
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700116 free_page(addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 (*counter)--;
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700118 nr--;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 }
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700120 spin_unlock(&cmm_lock);
121 return nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122}
123
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700124static int cmm_oom_notify(struct notifier_block *self,
125 unsigned long dummy, void *parm)
126{
127 unsigned long *freed = parm;
128 long nr = 256;
129
130 nr = cmm_free_pages(nr, &cmm_timed_pages, &cmm_timed_page_list);
131 if (nr > 0)
132 nr = cmm_free_pages(nr, &cmm_pages, &cmm_page_list);
133 cmm_pages_target = cmm_pages;
134 cmm_timed_pages_target = cmm_timed_pages;
135 *freed += 256 - nr;
136 return NOTIFY_OK;
137}
138
139static struct notifier_block cmm_oom_nb = {
140 .notifier_call = cmm_oom_notify
141};
142
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143static int
144cmm_thread(void *dummy)
145{
146 int rc;
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 while (1) {
149 rc = wait_event_interruptible(cmm_thread_wait,
150 (cmm_pages != cmm_pages_target ||
Heiko Carstense8216de2006-09-25 23:33:11 -0700151 cmm_timed_pages != cmm_timed_pages_target ||
152 kthread_should_stop()));
153 if (kthread_should_stop() || rc == -ERESTARTSYS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 cmm_pages_target = cmm_pages;
155 cmm_timed_pages_target = cmm_timed_pages;
156 break;
157 }
158 if (cmm_pages_target > cmm_pages) {
159 if (cmm_alloc_pages(1, &cmm_pages, &cmm_page_list))
160 cmm_pages_target = cmm_pages;
161 } else if (cmm_pages_target < cmm_pages) {
162 cmm_free_pages(1, &cmm_pages, &cmm_page_list);
163 }
164 if (cmm_timed_pages_target > cmm_timed_pages) {
165 if (cmm_alloc_pages(1, &cmm_timed_pages,
166 &cmm_timed_page_list))
167 cmm_timed_pages_target = cmm_timed_pages;
168 } else if (cmm_timed_pages_target < cmm_timed_pages) {
169 cmm_free_pages(1, &cmm_timed_pages,
170 &cmm_timed_page_list);
171 }
172 if (cmm_timed_pages > 0 && !timer_pending(&cmm_timer))
173 cmm_set_timer();
174 }
175 return 0;
176}
177
178static void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179cmm_kick_thread(void)
180{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 wake_up(&cmm_thread_wait);
182}
183
184static void
185cmm_set_timer(void)
186{
187 if (cmm_timed_pages_target <= 0 || cmm_timeout_seconds <= 0) {
188 if (timer_pending(&cmm_timer))
189 del_timer(&cmm_timer);
190 return;
191 }
192 if (timer_pending(&cmm_timer)) {
193 if (mod_timer(&cmm_timer, jiffies + cmm_timeout_seconds*HZ))
194 return;
195 }
196 cmm_timer.function = cmm_timer_fn;
197 cmm_timer.data = 0;
198 cmm_timer.expires = jiffies + cmm_timeout_seconds*HZ;
199 add_timer(&cmm_timer);
200}
201
202static void
203cmm_timer_fn(unsigned long ignored)
204{
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700205 long nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700207 nr = cmm_timed_pages_target - cmm_timeout_pages;
208 if (nr < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 cmm_timed_pages_target = 0;
210 else
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700211 cmm_timed_pages_target = nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 cmm_kick_thread();
213 cmm_set_timer();
214}
215
216void
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700217cmm_set_pages(long nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218{
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700219 cmm_pages_target = nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 cmm_kick_thread();
221}
222
223long
224cmm_get_pages(void)
225{
226 return cmm_pages;
227}
228
229void
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700230cmm_add_timed_pages(long nr)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231{
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700232 cmm_timed_pages_target += nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 cmm_kick_thread();
234}
235
236long
237cmm_get_timed_pages(void)
238{
239 return cmm_timed_pages;
240}
241
242void
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700243cmm_set_timeout(long nr, long seconds)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244{
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700245 cmm_timeout_pages = nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 cmm_timeout_seconds = seconds;
247 cmm_set_timer();
248}
249
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100250static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251cmm_skip_blanks(char *cp, char **endp)
252{
253 char *str;
254
255 for (str = cp; *str == ' ' || *str == '\t'; str++);
256 *endp = str;
257 return str != cp;
258}
259
260#ifdef CONFIG_CMM_PROC
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
262static struct ctl_table cmm_table[];
263
264static int
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700265cmm_pages_handler(ctl_table *ctl, int write,
Al Viroaaedd942006-02-01 06:29:14 -0500266 void __user *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267{
268 char buf[16], *p;
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700269 long nr;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 int len;
271
272 if (!*lenp || (*ppos && !write)) {
273 *lenp = 0;
274 return 0;
275 }
276
277 if (write) {
278 len = *lenp;
279 if (copy_from_user(buf, buffer,
280 len > sizeof(buf) ? sizeof(buf) : len))
281 return -EFAULT;
282 buf[sizeof(buf) - 1] = '\0';
283 cmm_skip_blanks(buf, &p);
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700284 nr = simple_strtoul(p, &p, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 if (ctl == &cmm_table[0])
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700286 cmm_set_pages(nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 else
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700288 cmm_add_timed_pages(nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 } else {
290 if (ctl == &cmm_table[0])
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700291 nr = cmm_get_pages();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 else
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700293 nr = cmm_get_timed_pages();
294 len = sprintf(buf, "%ld\n", nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295 if (len > *lenp)
296 len = *lenp;
297 if (copy_to_user(buffer, buf, len))
298 return -EFAULT;
299 }
300 *lenp = len;
301 *ppos += len;
302 return 0;
303}
304
305static int
Alexey Dobriyan8d65af72009-09-23 15:57:19 -0700306cmm_timeout_handler(ctl_table *ctl, int write,
Al Viroaaedd942006-02-01 06:29:14 -0500307 void __user *buffer, size_t *lenp, loff_t *ppos)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308{
309 char buf[64], *p;
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700310 long nr, seconds;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 int len;
312
313 if (!*lenp || (*ppos && !write)) {
314 *lenp = 0;
315 return 0;
316 }
317
318 if (write) {
319 len = *lenp;
320 if (copy_from_user(buf, buffer,
321 len > sizeof(buf) ? sizeof(buf) : len))
322 return -EFAULT;
323 buf[sizeof(buf) - 1] = '\0';
324 cmm_skip_blanks(buf, &p);
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700325 nr = simple_strtoul(p, &p, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 cmm_skip_blanks(p, &p);
Heiko Carstens7d5d6882006-09-20 15:59:00 +0200327 seconds = simple_strtoul(p, &p, 0);
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700328 cmm_set_timeout(nr, seconds);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 } else {
330 len = sprintf(buf, "%ld %ld\n",
331 cmm_timeout_pages, cmm_timeout_seconds);
332 if (len > *lenp)
333 len = *lenp;
334 if (copy_to_user(buffer, buf, len))
335 return -EFAULT;
336 }
337 *lenp = len;
338 *ppos += len;
339 return 0;
340}
341
342static struct ctl_table cmm_table[] = {
343 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 .procname = "cmm_pages",
Martin Schwidefsky5e8b1c42006-03-24 03:15:16 -0800345 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800346 .proc_handler = cmm_pages_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 },
348 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 .procname = "cmm_timed_pages",
Martin Schwidefsky5e8b1c42006-03-24 03:15:16 -0800350 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800351 .proc_handler = cmm_pages_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700352 },
353 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 .procname = "cmm_timeout",
Martin Schwidefsky5e8b1c42006-03-24 03:15:16 -0800355 .mode = 0644,
Eric W. Biederman6d456112009-11-16 03:11:48 -0800356 .proc_handler = cmm_timeout_handler,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 },
Eric W. Biedermanb05fd352009-04-03 04:36:34 -0700358 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359};
360
361static struct ctl_table cmm_dir_table[] = {
362 {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 .procname = "vm",
364 .maxlen = 0,
365 .mode = 0555,
366 .child = cmm_table,
367 },
Eric W. Biedermanb05fd352009-04-03 04:36:34 -0700368 { }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369};
370#endif
371
372#ifdef CONFIG_CMM_IUCV
373#define SMSG_PREFIX "CMM"
374static void
Martin Schwidefsky15439d72005-05-01 08:58:58 -0700375cmm_smsg_target(char *from, char *msg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376{
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700377 long nr, seconds;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
Martin Schwidefsky15439d72005-05-01 08:58:58 -0700379 if (strlen(sender) > 0 && strcmp(from, sender) != 0)
380 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 if (!cmm_skip_blanks(msg + strlen(SMSG_PREFIX), &msg))
382 return;
383 if (strncmp(msg, "SHRINK", 6) == 0) {
384 if (!cmm_skip_blanks(msg + 6, &msg))
385 return;
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700386 nr = simple_strtoul(msg, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 cmm_skip_blanks(msg, &msg);
388 if (*msg == '\0')
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700389 cmm_set_pages(nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 } else if (strncmp(msg, "RELEASE", 7) == 0) {
391 if (!cmm_skip_blanks(msg + 7, &msg))
392 return;
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700393 nr = simple_strtoul(msg, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394 cmm_skip_blanks(msg, &msg);
395 if (*msg == '\0')
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700396 cmm_add_timed_pages(nr);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 } else if (strncmp(msg, "REUSE", 5) == 0) {
398 if (!cmm_skip_blanks(msg + 5, &msg))
399 return;
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700400 nr = simple_strtoul(msg, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 if (!cmm_skip_blanks(msg, &msg))
402 return;
Heiko Carstens7d5d6882006-09-20 15:59:00 +0200403 seconds = simple_strtoul(msg, &msg, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 cmm_skip_blanks(msg, &msg);
405 if (*msg == '\0')
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700406 cmm_set_timeout(nr, seconds);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 }
408}
409#endif
410
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100411static struct ctl_table_header *cmm_sysctl_header;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412
413static int
414cmm_init (void)
415{
Heiko Carstense8216de2006-09-25 23:33:11 -0700416 int rc = -ENOMEM;
417
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418#ifdef CONFIG_CMM_PROC
Eric W. Biederman0b4d4142007-02-14 00:34:09 -0800419 cmm_sysctl_header = register_sysctl_table(cmm_dir_table);
Heiko Carstense8216de2006-09-25 23:33:11 -0700420 if (!cmm_sysctl_header)
421 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422#endif
423#ifdef CONFIG_CMM_IUCV
Heiko Carstense8216de2006-09-25 23:33:11 -0700424 rc = smsg_register_callback(SMSG_PREFIX, cmm_smsg_target);
425 if (rc < 0)
426 goto out_smsg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427#endif
Heiko Carstense8216de2006-09-25 23:33:11 -0700428 rc = register_oom_notifier(&cmm_oom_nb);
429 if (rc < 0)
430 goto out_oom_notify;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 init_waitqueue_head(&cmm_thread_wait);
432 init_timer(&cmm_timer);
Heiko Carstense8216de2006-09-25 23:33:11 -0700433 cmm_thread_ptr = kthread_run(cmm_thread, NULL, "cmmthread");
434 rc = IS_ERR(cmm_thread_ptr) ? PTR_ERR(cmm_thread_ptr) : 0;
435 if (!rc)
436 goto out;
437 /*
438 * kthread_create failed. undo all the stuff from above again.
439 */
440 unregister_oom_notifier(&cmm_oom_nb);
441
442out_oom_notify:
443#ifdef CONFIG_CMM_IUCV
444 smsg_unregister_callback(SMSG_PREFIX, cmm_smsg_target);
445out_smsg:
446#endif
447#ifdef CONFIG_CMM_PROC
448 unregister_sysctl_table(cmm_sysctl_header);
449#endif
450out:
451 return rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452}
453
454static void
455cmm_exit(void)
456{
Heiko Carstense8216de2006-09-25 23:33:11 -0700457 kthread_stop(cmm_thread_ptr);
Martin Schwidefsky8bc719d2006-09-25 23:31:20 -0700458 unregister_oom_notifier(&cmm_oom_nb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 cmm_free_pages(cmm_pages, &cmm_pages, &cmm_page_list);
460 cmm_free_pages(cmm_timed_pages, &cmm_timed_pages, &cmm_timed_page_list);
461#ifdef CONFIG_CMM_PROC
462 unregister_sysctl_table(cmm_sysctl_header);
463#endif
464#ifdef CONFIG_CMM_IUCV
465 smsg_unregister_callback(SMSG_PREFIX, cmm_smsg_target);
466#endif
467}
468
469module_init(cmm_init);
470module_exit(cmm_exit);
471
472EXPORT_SYMBOL(cmm_set_pages);
473EXPORT_SYMBOL(cmm_get_pages);
474EXPORT_SYMBOL(cmm_add_timed_pages);
475EXPORT_SYMBOL(cmm_get_timed_pages);
476EXPORT_SYMBOL(cmm_set_timeout);
477
478MODULE_LICENSE("GPL");