Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | * Data gathering module for Linux-VM Monitor Stream, Stage 1. |
| 3 | * Collects data related to memory management. |
| 4 | * |
Heiko Carstens | a53c8fa | 2012-07-20 11:15:04 +0200 | [diff] [blame] | 5 | * Copyright IBM Corp. 2003, 2006 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | * |
Gerald Schaefer | 5b5dd21 | 2006-06-29 15:08:35 +0200 | [diff] [blame] | 7 | * Author: Gerald Schaefer <gerald.schaefer@de.ibm.com> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | */ |
| 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/module.h> |
| 11 | #include <linux/init.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/errno.h> |
| 13 | #include <linux/kernel_stat.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/pagemap.h> |
| 15 | #include <linux/swap.h> |
Jeff Mahoney | f1a8582 | 2014-04-27 17:35:43 -0400 | [diff] [blame] | 16 | #include <linux/slab.h> |
Gerald Schaefer | d3ae942 | 2008-07-14 09:59:34 +0200 | [diff] [blame] | 17 | #include <asm/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 19 | #include "appldata.h" |
| 20 | |
| 21 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | #define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* Converts #Pages to KB */ |
| 23 | |
| 24 | /* |
| 25 | * Memory data |
| 26 | * |
| 27 | * This is accessed as binary data by z/VM. If changes to it can't be avoided, |
| 28 | * the structure version (product ID, see appldata_base.c) needs to be changed |
| 29 | * as well and all documentation and z/VM applications using it must be |
| 30 | * updated. |
| 31 | * |
| 32 | * The record layout is documented in the Linux for zSeries Device Drivers |
| 33 | * book: |
| 34 | * http://oss.software.ibm.com/developerworks/opensource/linux390/index.shtml |
| 35 | */ |
Sebastian Ott | a94f0fb | 2013-06-25 15:36:12 +0200 | [diff] [blame] | 36 | struct appldata_mem_data { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | u64 timestamp; |
| 38 | u32 sync_count_1; /* after VM collected the record data, */ |
| 39 | u32 sync_count_2; /* sync_count_1 and sync_count_2 should be the |
| 40 | same. If not, the record has been updated on |
| 41 | the Linux side while VM was collecting the |
| 42 | (possibly corrupt) data */ |
| 43 | |
| 44 | u64 pgpgin; /* data read from disk */ |
| 45 | u64 pgpgout; /* data written to disk */ |
| 46 | u64 pswpin; /* pages swapped in */ |
| 47 | u64 pswpout; /* pages swapped out */ |
| 48 | |
| 49 | u64 sharedram; /* sharedram is currently set to 0 */ |
| 50 | |
| 51 | u64 totalram; /* total main memory size */ |
| 52 | u64 freeram; /* free main memory size */ |
| 53 | u64 totalhigh; /* total high memory size */ |
| 54 | u64 freehigh; /* free high memory size */ |
| 55 | |
| 56 | u64 bufferram; /* memory reserved for buffers, free cache */ |
| 57 | u64 cached; /* size of (used) cache, w/o buffers */ |
| 58 | u64 totalswap; /* total swap space size */ |
| 59 | u64 freeswap; /* free swap space */ |
| 60 | |
| 61 | // New in 2.6 --> |
| 62 | u64 pgalloc; /* page allocations */ |
| 63 | u64 pgfault; /* page faults (major+minor) */ |
| 64 | u64 pgmajfault; /* page faults (major only) */ |
| 65 | // <-- New in 2.6 |
| 66 | |
Sebastian Ott | a94f0fb | 2013-06-25 15:36:12 +0200 | [diff] [blame] | 67 | } __packed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | /* |
| 71 | * appldata_get_mem_data() |
| 72 | * |
| 73 | * gather memory data |
| 74 | */ |
| 75 | static void appldata_get_mem_data(void *data) |
| 76 | { |
| 77 | /* |
| 78 | * don't put large structures on the stack, we are |
Gerald Schaefer | b1ad171 | 2009-04-23 13:58:07 +0200 | [diff] [blame] | 79 | * serialized through the appldata_ops_mutex and can use static |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | */ |
| 81 | static struct sysinfo val; |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 82 | unsigned long ev[NR_VM_EVENT_ITEMS]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | struct appldata_mem_data *mem_data; |
| 84 | |
| 85 | mem_data = data; |
| 86 | mem_data->sync_count_1++; |
| 87 | |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 88 | all_vm_events(ev); |
| 89 | mem_data->pgpgin = ev[PGPGIN] >> 1; |
| 90 | mem_data->pgpgout = ev[PGPGOUT] >> 1; |
| 91 | mem_data->pswpin = ev[PSWPIN]; |
| 92 | mem_data->pswpout = ev[PSWPOUT]; |
Al Viro | bb81e60 | 2007-03-14 09:04:41 +0000 | [diff] [blame] | 93 | mem_data->pgalloc = ev[PGALLOC_NORMAL]; |
Al Viro | bb81e60 | 2007-03-14 09:04:41 +0000 | [diff] [blame] | 94 | mem_data->pgalloc += ev[PGALLOC_DMA]; |
Christoph Lameter | f8891e5 | 2006-06-30 01:55:45 -0700 | [diff] [blame] | 95 | mem_data->pgfault = ev[PGFAULT]; |
| 96 | mem_data->pgmajfault = ev[PGMAJFAULT]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | |
| 98 | si_meminfo(&val); |
| 99 | mem_data->sharedram = val.sharedram; |
| 100 | mem_data->totalram = P2K(val.totalram); |
| 101 | mem_data->freeram = P2K(val.freeram); |
| 102 | mem_data->totalhigh = P2K(val.totalhigh); |
| 103 | mem_data->freehigh = P2K(val.freehigh); |
| 104 | mem_data->bufferram = P2K(val.bufferram); |
Christoph Lameter | 347ce43 | 2006-06-30 01:55:35 -0700 | [diff] [blame] | 105 | mem_data->cached = P2K(global_page_state(NR_FILE_PAGES) |
| 106 | - val.bufferram); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | |
| 108 | si_swapinfo(&val); |
| 109 | mem_data->totalswap = P2K(val.totalswap); |
| 110 | mem_data->freeswap = P2K(val.freeswap); |
| 111 | |
Heiko Carstens | 1aae056 | 2013-01-30 09:49:40 +0100 | [diff] [blame] | 112 | mem_data->timestamp = get_tod_clock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | mem_data->sync_count_2++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | |
| 117 | static struct appldata_ops ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | .name = "mem", |
| 119 | .record_nr = APPLDATA_RECORD_MEM_ID, |
| 120 | .size = sizeof(struct appldata_mem_data), |
| 121 | .callback = &appldata_get_mem_data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | .owner = THIS_MODULE, |
Gerald Schaefer | 5b5dd21 | 2006-06-29 15:08:35 +0200 | [diff] [blame] | 123 | .mod_lvl = {0xF0, 0xF0}, /* EBCDIC "00" */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | }; |
| 125 | |
| 126 | |
| 127 | /* |
| 128 | * appldata_mem_init() |
| 129 | * |
| 130 | * init_data, register ops |
| 131 | */ |
| 132 | static int __init appldata_mem_init(void) |
| 133 | { |
Sebastian Ott | a94f0fb | 2013-06-25 15:36:12 +0200 | [diff] [blame] | 134 | int ret; |
| 135 | |
| 136 | ops.data = kzalloc(sizeof(struct appldata_mem_data), GFP_KERNEL); |
| 137 | if (!ops.data) |
| 138 | return -ENOMEM; |
| 139 | |
| 140 | ret = appldata_register_ops(&ops); |
| 141 | if (ret) |
| 142 | kfree(ops.data); |
| 143 | |
| 144 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /* |
| 148 | * appldata_mem_exit() |
| 149 | * |
| 150 | * unregister ops |
| 151 | */ |
| 152 | static void __exit appldata_mem_exit(void) |
| 153 | { |
| 154 | appldata_unregister_ops(&ops); |
Sebastian Ott | a94f0fb | 2013-06-25 15:36:12 +0200 | [diff] [blame] | 155 | kfree(ops.data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | |
| 159 | module_init(appldata_mem_init); |
| 160 | module_exit(appldata_mem_exit); |
| 161 | |
| 162 | MODULE_LICENSE("GPL"); |
| 163 | MODULE_AUTHOR("Gerald Schaefer"); |
| 164 | MODULE_DESCRIPTION("Linux-VM Monitor Stream, MEMORY statistics"); |