File: mem.c

package info (click to toggle)
s390-tools 2.40.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 13,288 kB
  • sloc: ansic: 187,079; sh: 12,157; cpp: 5,049; makefile: 2,812; perl: 2,541; asm: 1,097; python: 697; xml: 29
file content (82 lines) | stat: -rw-r--r-- 1,702 bytes parent folder | download | duplicates (5)
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
71
72
73
74
75
76
77
78
79
80
81
82
/*
 * cpuplugd - Linux for System z Hotplug Daemon
 *
 * cmm functions
 *
 * Copyright IBM Corp. 2007, 2017
 *
 * s390-tools is free software; you can redistribute it and/or modify
 * it under the terms of the MIT license. See LICENSE for details.
 */

#include "cpuplugd.h"

/*
 * The cmm_pages value defines the size of the balloon of blocked memory.
 * Increasing the value is removing memory from Linux, which is an memunplug.
 * Decreasing the value is adding memory back to Linux, which is memplug.
 */

/*
 * Set the value of cmm_pages
 */
void set_cmm_pages(long pages)
{
	FILE *filp;

	filp = fopen("/proc/sys/vm/cmm_pages", "w");
	if (!filp)
		cpuplugd_exit("Cannot open /proc/sys/vm/cmmpages: %s\n",
			      strerror(errno));
	cpuplugd_debug("changing number of pages permanently reserved to %ld\n",
		       pages);
	fprintf(filp, "%ld\n", pages);
	fclose(filp);
	return;
}

/*
 * Read number of pages permanently reserved
 */
long get_cmmpages_size()
{
	FILE *filp;
	long size;
	int rc;

	filp = fopen("/proc/sys/vm/cmm_pages", "r");
	if (!filp)
		cpuplugd_exit("Cannot open /proc/sys/vm/cmm_pages: %s\n",
			      strerror(errno));
	rc = fscanf(filp, "%ld", &size);
	if (rc == 0)
		cpuplugd_exit("Can not read /proc/sys/vm/cmm_pages: %s\n",
			      strerror(errno));
	fclose(filp);
	return size;
}

/*
 * Reset cmm pagesize to value we found prior to daemon startup
 */
void cleanup_cmm()
{
	set_cmm_pages(cmm_pagesize_start);
	return;
}

/*
 * Function to check if the cmm kernel module is loaded and the required
 * files below /proc exit
 */
int check_cmmfiles(void)
{
	FILE *filp;

	filp = fopen("/proc/sys/vm/cmm_pages", "r");
	if (!filp)
		return -1;
	fclose(filp);
	return 0;
}