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