2017-11-24 14:00:35 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2010-05-26 21:27:10 +00:00
|
|
|
* Collaborative memory management interface.
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
2012-07-20 09:15:04 +00:00
|
|
|
* Copyright IBM Corp 2003, 2010
|
2010-05-26 21:27:10 +00:00
|
|
|
* Author(s): Martin Schwidefsky <schwidefsky@de.ibm.com>,
|
2005-04-16 22:20:36 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/errno.h>
|
|
|
|
#include <linux/fs.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
#include <linux/module.h>
|
2017-02-09 20:20:24 +00:00
|
|
|
#include <linux/moduleparam.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 08:04:11 +00:00
|
|
|
#include <linux/gfp.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/sysctl.h>
|
|
|
|
#include <linux/ctype.h>
|
2006-09-26 06:31:20 +00:00
|
|
|
#include <linux/swap.h>
|
2006-09-26 06:33:11 +00:00
|
|
|
#include <linux/kthread.h>
|
2007-10-17 06:25:53 +00:00
|
|
|
#include <linux/oom.h>
|
2010-05-26 21:27:10 +00:00
|
|
|
#include <linux/uaccess.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2007-08-22 11:51:40 +00:00
|
|
|
#include <asm/diag.h>
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-10-25 14:10:21 +00:00
|
|
|
#ifdef CONFIG_CMM_IUCV
|
|
|
|
static char *cmm_default_sender = "VMRMSVM";
|
|
|
|
#endif
|
|
|
|
static char *sender;
|
2005-06-22 00:16:29 +00:00
|
|
|
module_param(sender, charp, 0400);
|
2005-05-01 15:58:58 +00:00
|
|
|
MODULE_PARM_DESC(sender,
|
|
|
|
"Guest name that may send SMSG messages (default VMRMSVM)");
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#include "../../../drivers/s390/net/smsgiucv.h"
|
|
|
|
|
|
|
|
#define CMM_NR_PAGES ((PAGE_SIZE / sizeof(unsigned long)) - 2)
|
|
|
|
|
|
|
|
struct cmm_page_array {
|
|
|
|
struct cmm_page_array *next;
|
|
|
|
unsigned long index;
|
|
|
|
unsigned long pages[CMM_NR_PAGES];
|
|
|
|
};
|
|
|
|
|
2006-09-26 06:31:20 +00:00
|
|
|
static long cmm_pages;
|
|
|
|
static long cmm_timed_pages;
|
|
|
|
static volatile long cmm_pages_target;
|
|
|
|
static volatile long cmm_timed_pages_target;
|
|
|
|
static long cmm_timeout_pages;
|
|
|
|
static long cmm_timeout_seconds;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-09-26 06:31:20 +00:00
|
|
|
static struct cmm_page_array *cmm_page_list;
|
|
|
|
static struct cmm_page_array *cmm_timed_page_list;
|
|
|
|
static DEFINE_SPINLOCK(cmm_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-09-26 06:33:11 +00:00
|
|
|
static struct task_struct *cmm_thread_ptr;
|
2010-05-26 21:26:17 +00:00
|
|
|
static DECLARE_WAIT_QUEUE_HEAD(cmm_thread_wait);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-10-24 05:41:17 +00:00
|
|
|
static void cmm_timer_fn(struct timer_list *);
|
2005-04-16 22:20:36 +00:00
|
|
|
static void cmm_set_timer(void);
|
2017-10-24 05:41:17 +00:00
|
|
|
static DEFINE_TIMER(cmm_timer, cmm_timer_fn);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-05-26 21:27:10 +00:00
|
|
|
static long cmm_alloc_pages(long nr, long *counter,
|
|
|
|
struct cmm_page_array **list)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-09-26 06:31:20 +00:00
|
|
|
struct cmm_page_array *pa, *npa;
|
|
|
|
unsigned long addr;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-09-26 06:31:20 +00:00
|
|
|
while (nr) {
|
|
|
|
addr = __get_free_page(GFP_NOIO);
|
|
|
|
if (!addr)
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
2006-09-26 06:31:20 +00:00
|
|
|
spin_lock(&cmm_lock);
|
|
|
|
pa = *list;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!pa || pa->index >= CMM_NR_PAGES) {
|
|
|
|
/* Need a new page for the page list. */
|
2006-09-26 06:31:20 +00:00
|
|
|
spin_unlock(&cmm_lock);
|
|
|
|
npa = (struct cmm_page_array *)
|
2005-04-16 22:20:36 +00:00
|
|
|
__get_free_page(GFP_NOIO);
|
2006-09-26 06:31:20 +00:00
|
|
|
if (!npa) {
|
|
|
|
free_page(addr);
|
2005-04-16 22:20:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2006-09-26 06:31:20 +00:00
|
|
|
spin_lock(&cmm_lock);
|
|
|
|
pa = *list;
|
|
|
|
if (!pa || pa->index >= CMM_NR_PAGES) {
|
|
|
|
npa->next = pa;
|
|
|
|
npa->index = 0;
|
|
|
|
pa = npa;
|
|
|
|
*list = pa;
|
|
|
|
} else
|
|
|
|
free_page((unsigned long) npa);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2011-05-10 15:13:41 +00:00
|
|
|
diag10_range(addr >> PAGE_SHIFT, 1);
|
2006-09-26 06:31:20 +00:00
|
|
|
pa->pages[pa->index++] = addr;
|
2005-04-16 22:20:36 +00:00
|
|
|
(*counter)++;
|
2006-09-26 06:31:20 +00:00
|
|
|
spin_unlock(&cmm_lock);
|
|
|
|
nr--;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2006-09-26 06:31:20 +00:00
|
|
|
return nr;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2010-05-26 21:27:10 +00:00
|
|
|
static long cmm_free_pages(long nr, long *counter, struct cmm_page_array **list)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
struct cmm_page_array *pa;
|
2006-09-26 06:31:20 +00:00
|
|
|
unsigned long addr;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-09-26 06:31:20 +00:00
|
|
|
spin_lock(&cmm_lock);
|
2005-04-16 22:20:36 +00:00
|
|
|
pa = *list;
|
2006-09-26 06:31:20 +00:00
|
|
|
while (nr) {
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!pa || pa->index <= 0)
|
|
|
|
break;
|
2006-09-26 06:31:20 +00:00
|
|
|
addr = pa->pages[--pa->index];
|
2005-04-16 22:20:36 +00:00
|
|
|
if (pa->index == 0) {
|
|
|
|
pa = pa->next;
|
|
|
|
free_page((unsigned long) *list);
|
|
|
|
*list = pa;
|
|
|
|
}
|
2006-09-26 06:31:20 +00:00
|
|
|
free_page(addr);
|
2005-04-16 22:20:36 +00:00
|
|
|
(*counter)--;
|
2006-09-26 06:31:20 +00:00
|
|
|
nr--;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2006-09-26 06:31:20 +00:00
|
|
|
spin_unlock(&cmm_lock);
|
|
|
|
return nr;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2006-09-26 06:31:20 +00:00
|
|
|
static int cmm_oom_notify(struct notifier_block *self,
|
|
|
|
unsigned long dummy, void *parm)
|
|
|
|
{
|
|
|
|
unsigned long *freed = parm;
|
|
|
|
long nr = 256;
|
|
|
|
|
|
|
|
nr = cmm_free_pages(nr, &cmm_timed_pages, &cmm_timed_page_list);
|
|
|
|
if (nr > 0)
|
|
|
|
nr = cmm_free_pages(nr, &cmm_pages, &cmm_page_list);
|
|
|
|
cmm_pages_target = cmm_pages;
|
|
|
|
cmm_timed_pages_target = cmm_timed_pages;
|
|
|
|
*freed += 256 - nr;
|
|
|
|
return NOTIFY_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct notifier_block cmm_oom_nb = {
|
2010-05-26 21:27:10 +00:00
|
|
|
.notifier_call = cmm_oom_notify,
|
2006-09-26 06:31:20 +00:00
|
|
|
};
|
|
|
|
|
2010-05-26 21:27:10 +00:00
|
|
|
static int cmm_thread(void *dummy)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
rc = wait_event_interruptible(cmm_thread_wait,
|
2020-03-18 19:55:24 +00:00
|
|
|
cmm_pages != cmm_pages_target ||
|
|
|
|
cmm_timed_pages != cmm_timed_pages_target ||
|
|
|
|
kthread_should_stop());
|
2006-09-26 06:33:11 +00:00
|
|
|
if (kthread_should_stop() || rc == -ERESTARTSYS) {
|
2005-04-16 22:20:36 +00:00
|
|
|
cmm_pages_target = cmm_pages;
|
|
|
|
cmm_timed_pages_target = cmm_timed_pages;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (cmm_pages_target > cmm_pages) {
|
|
|
|
if (cmm_alloc_pages(1, &cmm_pages, &cmm_page_list))
|
|
|
|
cmm_pages_target = cmm_pages;
|
|
|
|
} else if (cmm_pages_target < cmm_pages) {
|
|
|
|
cmm_free_pages(1, &cmm_pages, &cmm_page_list);
|
|
|
|
}
|
|
|
|
if (cmm_timed_pages_target > cmm_timed_pages) {
|
|
|
|
if (cmm_alloc_pages(1, &cmm_timed_pages,
|
|
|
|
&cmm_timed_page_list))
|
|
|
|
cmm_timed_pages_target = cmm_timed_pages;
|
|
|
|
} else if (cmm_timed_pages_target < cmm_timed_pages) {
|
|
|
|
cmm_free_pages(1, &cmm_timed_pages,
|
2010-05-26 21:27:10 +00:00
|
|
|
&cmm_timed_page_list);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
if (cmm_timed_pages > 0 && !timer_pending(&cmm_timer))
|
|
|
|
cmm_set_timer();
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2010-05-26 21:27:10 +00:00
|
|
|
static void cmm_kick_thread(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
wake_up(&cmm_thread_wait);
|
|
|
|
}
|
|
|
|
|
2010-05-26 21:27:10 +00:00
|
|
|
static void cmm_set_timer(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
if (cmm_timed_pages_target <= 0 || cmm_timeout_seconds <= 0) {
|
|
|
|
if (timer_pending(&cmm_timer))
|
|
|
|
del_timer(&cmm_timer);
|
|
|
|
return;
|
|
|
|
}
|
2020-06-12 11:06:07 +00:00
|
|
|
mod_timer(&cmm_timer, jiffies + msecs_to_jiffies(cmm_timeout_seconds * MSEC_PER_SEC));
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
|
2017-10-24 05:41:17 +00:00
|
|
|
static void cmm_timer_fn(struct timer_list *unused)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-09-26 06:31:20 +00:00
|
|
|
long nr;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2006-09-26 06:31:20 +00:00
|
|
|
nr = cmm_timed_pages_target - cmm_timeout_pages;
|
|
|
|
if (nr < 0)
|
2005-04-16 22:20:36 +00:00
|
|
|
cmm_timed_pages_target = 0;
|
|
|
|
else
|
2006-09-26 06:31:20 +00:00
|
|
|
cmm_timed_pages_target = nr;
|
2005-04-16 22:20:36 +00:00
|
|
|
cmm_kick_thread();
|
|
|
|
cmm_set_timer();
|
|
|
|
}
|
|
|
|
|
2010-05-26 21:27:10 +00:00
|
|
|
static void cmm_set_pages(long nr)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-09-26 06:31:20 +00:00
|
|
|
cmm_pages_target = nr;
|
2005-04-16 22:20:36 +00:00
|
|
|
cmm_kick_thread();
|
|
|
|
}
|
|
|
|
|
2010-05-26 21:27:10 +00:00
|
|
|
static long cmm_get_pages(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
return cmm_pages;
|
|
|
|
}
|
|
|
|
|
2010-05-26 21:27:10 +00:00
|
|
|
static void cmm_add_timed_pages(long nr)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-09-26 06:31:20 +00:00
|
|
|
cmm_timed_pages_target += nr;
|
2005-04-16 22:20:36 +00:00
|
|
|
cmm_kick_thread();
|
|
|
|
}
|
|
|
|
|
2010-05-26 21:27:10 +00:00
|
|
|
static long cmm_get_timed_pages(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
return cmm_timed_pages;
|
|
|
|
}
|
|
|
|
|
2010-05-26 21:27:10 +00:00
|
|
|
static void cmm_set_timeout(long nr, long seconds)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-09-26 06:31:20 +00:00
|
|
|
cmm_timeout_pages = nr;
|
2005-04-16 22:20:36 +00:00
|
|
|
cmm_timeout_seconds = seconds;
|
|
|
|
cmm_set_timer();
|
|
|
|
}
|
|
|
|
|
2010-05-26 21:27:10 +00:00
|
|
|
static int cmm_skip_blanks(char *cp, char **endp)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
char *str;
|
|
|
|
|
2010-05-26 21:27:10 +00:00
|
|
|
for (str = cp; *str == ' ' || *str == '\t'; str++)
|
|
|
|
;
|
2005-04-16 22:20:36 +00:00
|
|
|
*endp = str;
|
|
|
|
return str != cp;
|
|
|
|
}
|
|
|
|
|
2013-10-22 22:29:46 +00:00
|
|
|
static int cmm_pages_handler(struct ctl_table *ctl, int write,
|
2020-04-24 06:43:38 +00:00
|
|
|
void *buffer, size_t *lenp, loff_t *ppos)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2018-07-01 13:56:28 +00:00
|
|
|
long nr = cmm_get_pages();
|
|
|
|
struct ctl_table ctl_entry = {
|
|
|
|
.procname = ctl->procname,
|
|
|
|
.data = &nr,
|
|
|
|
.maxlen = sizeof(long),
|
|
|
|
};
|
|
|
|
int rc;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2018-07-01 13:56:28 +00:00
|
|
|
rc = proc_doulongvec_minmax(&ctl_entry, write, buffer, lenp, ppos);
|
|
|
|
if (rc < 0 || !write)
|
|
|
|
return rc;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2018-07-01 13:56:28 +00:00
|
|
|
cmm_set_pages(nr);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cmm_timed_pages_handler(struct ctl_table *ctl, int write,
|
2020-04-24 06:43:38 +00:00
|
|
|
void *buffer, size_t *lenp,
|
2018-07-01 13:56:28 +00:00
|
|
|
loff_t *ppos)
|
|
|
|
{
|
|
|
|
long nr = cmm_get_timed_pages();
|
|
|
|
struct ctl_table ctl_entry = {
|
|
|
|
.procname = ctl->procname,
|
|
|
|
.data = &nr,
|
|
|
|
.maxlen = sizeof(long),
|
|
|
|
};
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = proc_doulongvec_minmax(&ctl_entry, write, buffer, lenp, ppos);
|
|
|
|
if (rc < 0 || !write)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
cmm_add_timed_pages(nr);
|
2005-04-16 22:20:36 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-10-22 22:29:46 +00:00
|
|
|
static int cmm_timeout_handler(struct ctl_table *ctl, int write,
|
2020-04-24 06:43:38 +00:00
|
|
|
void *buffer, size_t *lenp, loff_t *ppos)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
char buf[64], *p;
|
2006-09-26 06:31:20 +00:00
|
|
|
long nr, seconds;
|
2013-10-14 11:58:10 +00:00
|
|
|
unsigned int len;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
|
|
|
if (!*lenp || (*ppos && !write)) {
|
|
|
|
*lenp = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (write) {
|
2019-10-25 09:31:48 +00:00
|
|
|
len = min(*lenp, sizeof(buf));
|
2020-04-24 06:43:38 +00:00
|
|
|
memcpy(buf, buffer, len);
|
2019-10-25 09:31:48 +00:00
|
|
|
buf[len - 1] = '\0';
|
2005-04-16 22:20:36 +00:00
|
|
|
cmm_skip_blanks(buf, &p);
|
2006-09-26 06:31:20 +00:00
|
|
|
nr = simple_strtoul(p, &p, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
cmm_skip_blanks(p, &p);
|
2006-09-20 13:59:00 +00:00
|
|
|
seconds = simple_strtoul(p, &p, 0);
|
2006-09-26 06:31:20 +00:00
|
|
|
cmm_set_timeout(nr, seconds);
|
2019-10-25 09:31:48 +00:00
|
|
|
*ppos += *lenp;
|
2005-04-16 22:20:36 +00:00
|
|
|
} else {
|
|
|
|
len = sprintf(buf, "%ld %ld\n",
|
|
|
|
cmm_timeout_pages, cmm_timeout_seconds);
|
|
|
|
if (len > *lenp)
|
|
|
|
len = *lenp;
|
2020-04-24 06:43:38 +00:00
|
|
|
memcpy(buffer, buf, len);
|
2019-10-25 09:31:48 +00:00
|
|
|
*lenp = len;
|
|
|
|
*ppos += len;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct ctl_table cmm_table[] = {
|
|
|
|
{
|
|
|
|
.procname = "cmm_pages",
|
2006-03-24 11:15:16 +00:00
|
|
|
.mode = 0644,
|
2009-11-16 11:11:48 +00:00
|
|
|
.proc_handler = cmm_pages_handler,
|
2005-04-16 22:20:36 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "cmm_timed_pages",
|
2006-03-24 11:15:16 +00:00
|
|
|
.mode = 0644,
|
2018-07-01 13:56:28 +00:00
|
|
|
.proc_handler = cmm_timed_pages_handler,
|
2005-04-16 22:20:36 +00:00
|
|
|
},
|
|
|
|
{
|
|
|
|
.procname = "cmm_timeout",
|
2006-03-24 11:15:16 +00:00
|
|
|
.mode = 0644,
|
2009-11-16 11:11:48 +00:00
|
|
|
.proc_handler = cmm_timeout_handler,
|
2005-04-16 22:20:36 +00:00
|
|
|
},
|
2009-04-03 11:36:34 +00:00
|
|
|
{ }
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct ctl_table cmm_dir_table[] = {
|
|
|
|
{
|
|
|
|
.procname = "vm",
|
|
|
|
.maxlen = 0,
|
|
|
|
.mode = 0555,
|
|
|
|
.child = cmm_table,
|
|
|
|
},
|
2009-04-03 11:36:34 +00:00
|
|
|
{ }
|
2005-04-16 22:20:36 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef CONFIG_CMM_IUCV
|
|
|
|
#define SMSG_PREFIX "CMM"
|
2010-05-26 21:27:10 +00:00
|
|
|
static void cmm_smsg_target(const char *from, char *msg)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-09-26 06:31:20 +00:00
|
|
|
long nr, seconds;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2005-05-01 15:58:58 +00:00
|
|
|
if (strlen(sender) > 0 && strcmp(from, sender) != 0)
|
|
|
|
return;
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!cmm_skip_blanks(msg + strlen(SMSG_PREFIX), &msg))
|
|
|
|
return;
|
|
|
|
if (strncmp(msg, "SHRINK", 6) == 0) {
|
|
|
|
if (!cmm_skip_blanks(msg + 6, &msg))
|
|
|
|
return;
|
2006-09-26 06:31:20 +00:00
|
|
|
nr = simple_strtoul(msg, &msg, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
cmm_skip_blanks(msg, &msg);
|
|
|
|
if (*msg == '\0')
|
2006-09-26 06:31:20 +00:00
|
|
|
cmm_set_pages(nr);
|
2005-04-16 22:20:36 +00:00
|
|
|
} else if (strncmp(msg, "RELEASE", 7) == 0) {
|
|
|
|
if (!cmm_skip_blanks(msg + 7, &msg))
|
|
|
|
return;
|
2006-09-26 06:31:20 +00:00
|
|
|
nr = simple_strtoul(msg, &msg, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
cmm_skip_blanks(msg, &msg);
|
|
|
|
if (*msg == '\0')
|
2006-09-26 06:31:20 +00:00
|
|
|
cmm_add_timed_pages(nr);
|
2005-04-16 22:20:36 +00:00
|
|
|
} else if (strncmp(msg, "REUSE", 5) == 0) {
|
|
|
|
if (!cmm_skip_blanks(msg + 5, &msg))
|
|
|
|
return;
|
2006-09-26 06:31:20 +00:00
|
|
|
nr = simple_strtoul(msg, &msg, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
if (!cmm_skip_blanks(msg, &msg))
|
|
|
|
return;
|
2006-09-20 13:59:00 +00:00
|
|
|
seconds = simple_strtoul(msg, &msg, 0);
|
2005-04-16 22:20:36 +00:00
|
|
|
cmm_skip_blanks(msg, &msg);
|
|
|
|
if (*msg == '\0')
|
2006-09-26 06:31:20 +00:00
|
|
|
cmm_set_timeout(nr, seconds);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2007-02-05 20:16:47 +00:00
|
|
|
static struct ctl_table_header *cmm_sysctl_header;
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-08-09 16:12:55 +00:00
|
|
|
static int __init cmm_init(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
2006-09-26 06:33:11 +00:00
|
|
|
int rc = -ENOMEM;
|
|
|
|
|
2007-02-14 08:34:09 +00:00
|
|
|
cmm_sysctl_header = register_sysctl_table(cmm_dir_table);
|
2006-09-26 06:33:11 +00:00
|
|
|
if (!cmm_sysctl_header)
|
2009-12-07 11:52:06 +00:00
|
|
|
goto out_sysctl;
|
2005-04-16 22:20:36 +00:00
|
|
|
#ifdef CONFIG_CMM_IUCV
|
2010-08-09 16:12:56 +00:00
|
|
|
/* convert sender to uppercase characters */
|
|
|
|
if (sender) {
|
|
|
|
int len = strlen(sender);
|
|
|
|
while (len--)
|
|
|
|
sender[len] = toupper(sender[len]);
|
2010-10-25 14:10:21 +00:00
|
|
|
} else {
|
|
|
|
sender = cmm_default_sender;
|
2010-08-09 16:12:56 +00:00
|
|
|
}
|
|
|
|
|
2006-09-26 06:33:11 +00:00
|
|
|
rc = smsg_register_callback(SMSG_PREFIX, cmm_smsg_target);
|
|
|
|
if (rc < 0)
|
|
|
|
goto out_smsg;
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif
|
2006-09-26 06:33:11 +00:00
|
|
|
rc = register_oom_notifier(&cmm_oom_nb);
|
|
|
|
if (rc < 0)
|
|
|
|
goto out_oom_notify;
|
|
|
|
cmm_thread_ptr = kthread_run(cmm_thread, NULL, "cmmthread");
|
2013-03-13 19:46:08 +00:00
|
|
|
if (!IS_ERR(cmm_thread_ptr))
|
|
|
|
return 0;
|
2006-09-26 06:33:11 +00:00
|
|
|
|
2013-03-13 19:46:08 +00:00
|
|
|
rc = PTR_ERR(cmm_thread_ptr);
|
2009-12-07 11:52:06 +00:00
|
|
|
unregister_oom_notifier(&cmm_oom_nb);
|
2006-09-26 06:33:11 +00:00
|
|
|
out_oom_notify:
|
|
|
|
#ifdef CONFIG_CMM_IUCV
|
|
|
|
smsg_unregister_callback(SMSG_PREFIX, cmm_smsg_target);
|
|
|
|
out_smsg:
|
|
|
|
#endif
|
|
|
|
unregister_sysctl_table(cmm_sysctl_header);
|
2009-12-07 11:52:06 +00:00
|
|
|
out_sysctl:
|
2010-05-26 21:26:17 +00:00
|
|
|
del_timer_sync(&cmm_timer);
|
2006-09-26 06:33:11 +00:00
|
|
|
return rc;
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
2010-05-26 21:27:10 +00:00
|
|
|
module_init(cmm_init);
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2010-08-09 16:12:55 +00:00
|
|
|
static void __exit cmm_exit(void)
|
2005-04-16 22:20:36 +00:00
|
|
|
{
|
|
|
|
unregister_sysctl_table(cmm_sysctl_header);
|
|
|
|
#ifdef CONFIG_CMM_IUCV
|
|
|
|
smsg_unregister_callback(SMSG_PREFIX, cmm_smsg_target);
|
|
|
|
#endif
|
2010-05-26 21:26:17 +00:00
|
|
|
unregister_oom_notifier(&cmm_oom_nb);
|
|
|
|
kthread_stop(cmm_thread_ptr);
|
|
|
|
del_timer_sync(&cmm_timer);
|
|
|
|
cmm_free_pages(cmm_pages, &cmm_pages, &cmm_page_list);
|
|
|
|
cmm_free_pages(cmm_timed_pages, &cmm_timed_pages, &cmm_timed_page_list);
|
2005-04-16 22:20:36 +00:00
|
|
|
}
|
|
|
|
module_exit(cmm_exit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|