This source file includes following definitions.
- appldata_get_mem_data
- appldata_mem_init
- appldata_mem_exit
1
2
3
4
5
6
7
8
9
10
11 #include <linux/module.h>
12 #include <linux/init.h>
13 #include <linux/errno.h>
14 #include <linux/kernel_stat.h>
15 #include <linux/pagemap.h>
16 #include <linux/swap.h>
17 #include <linux/slab.h>
18 #include <asm/io.h>
19
20 #include "appldata.h"
21
22
23 #define P2K(x) ((x) << (PAGE_SHIFT - 10))
24
25
26
27
28
29
30
31
32
33
34
35
36
37 struct appldata_mem_data {
38 u64 timestamp;
39 u32 sync_count_1;
40 u32 sync_count_2;
41
42
43
44
45 u64 pgpgin;
46 u64 pgpgout;
47 u64 pswpin;
48 u64 pswpout;
49
50 u64 sharedram;
51
52 u64 totalram;
53 u64 freeram;
54 u64 totalhigh;
55 u64 freehigh;
56
57 u64 bufferram;
58 u64 cached;
59 u64 totalswap;
60 u64 freeswap;
61
62
63 u64 pgalloc;
64 u64 pgfault;
65 u64 pgmajfault;
66
67
68 } __packed;
69
70
71
72
73
74
75
76 static void appldata_get_mem_data(void *data)
77 {
78
79
80
81
82 static struct sysinfo val;
83 unsigned long ev[NR_VM_EVENT_ITEMS];
84 struct appldata_mem_data *mem_data;
85
86 mem_data = data;
87 mem_data->sync_count_1++;
88
89 all_vm_events(ev);
90 mem_data->pgpgin = ev[PGPGIN] >> 1;
91 mem_data->pgpgout = ev[PGPGOUT] >> 1;
92 mem_data->pswpin = ev[PSWPIN];
93 mem_data->pswpout = ev[PSWPOUT];
94 mem_data->pgalloc = ev[PGALLOC_NORMAL];
95 mem_data->pgalloc += ev[PGALLOC_DMA];
96 mem_data->pgfault = ev[PGFAULT];
97 mem_data->pgmajfault = ev[PGMAJFAULT];
98
99 si_meminfo(&val);
100 mem_data->sharedram = val.sharedram;
101 mem_data->totalram = P2K(val.totalram);
102 mem_data->freeram = P2K(val.freeram);
103 mem_data->totalhigh = P2K(val.totalhigh);
104 mem_data->freehigh = P2K(val.freehigh);
105 mem_data->bufferram = P2K(val.bufferram);
106 mem_data->cached = P2K(global_node_page_state(NR_FILE_PAGES)
107 - val.bufferram);
108
109 si_swapinfo(&val);
110 mem_data->totalswap = P2K(val.totalswap);
111 mem_data->freeswap = P2K(val.freeswap);
112
113 mem_data->timestamp = get_tod_clock();
114 mem_data->sync_count_2++;
115 }
116
117
118 static struct appldata_ops ops = {
119 .name = "mem",
120 .record_nr = APPLDATA_RECORD_MEM_ID,
121 .size = sizeof(struct appldata_mem_data),
122 .callback = &appldata_get_mem_data,
123 .owner = THIS_MODULE,
124 .mod_lvl = {0xF0, 0xF0},
125 };
126
127
128
129
130
131
132
133 static int __init appldata_mem_init(void)
134 {
135 int ret;
136
137 ops.data = kzalloc(sizeof(struct appldata_mem_data), GFP_KERNEL);
138 if (!ops.data)
139 return -ENOMEM;
140
141 ret = appldata_register_ops(&ops);
142 if (ret)
143 kfree(ops.data);
144
145 return ret;
146 }
147
148
149
150
151
152
153 static void __exit appldata_mem_exit(void)
154 {
155 appldata_unregister_ops(&ops);
156 kfree(ops.data);
157 }
158
159
160 module_init(appldata_mem_init);
161 module_exit(appldata_mem_exit);
162
163 MODULE_LICENSE("GPL");
164 MODULE_AUTHOR("Gerald Schaefer");
165 MODULE_DESCRIPTION("Linux-VM Monitor Stream, MEMORY statistics");