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