Path: blob/master/arch/s390/appldata/appldata_mem.c
10817 views
/*1* arch/s390/appldata/appldata_mem.c2*3* Data gathering module for Linux-VM Monitor Stream, Stage 1.4* Collects data related to memory management.5*6* Copyright (C) 2003,2006 IBM Corporation, IBM Deutschland Entwicklung GmbH.7*8* Author: Gerald Schaefer <[email protected]>9*/1011#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 <asm/io.h>1819#include "appldata.h"202122#define P2K(x) ((x) << (PAGE_SHIFT - 10)) /* Converts #Pages to KB */2324/*25* Memory data26*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 changed29* as well and all documentation and z/VM applications using it must be30* updated.31*32* The record layout is documented in the Linux for zSeries Device Drivers33* book:34* http://oss.software.ibm.com/developerworks/opensource/linux390/index.shtml35*/36static struct appldata_mem_data {37u64 timestamp;38u32 sync_count_1; /* after VM collected the record data, */39u32 sync_count_2; /* sync_count_1 and sync_count_2 should be the40same. If not, the record has been updated on41the Linux side while VM was collecting the42(possibly corrupt) data */4344u64 pgpgin; /* data read from disk */45u64 pgpgout; /* data written to disk */46u64 pswpin; /* pages swapped in */47u64 pswpout; /* pages swapped out */4849u64 sharedram; /* sharedram is currently set to 0 */5051u64 totalram; /* total main memory size */52u64 freeram; /* free main memory size */53u64 totalhigh; /* total high memory size */54u64 freehigh; /* free high memory size */5556u64 bufferram; /* memory reserved for buffers, free cache */57u64 cached; /* size of (used) cache, w/o buffers */58u64 totalswap; /* total swap space size */59u64 freeswap; /* free swap space */6061// New in 2.6 -->62u64 pgalloc; /* page allocations */63u64 pgfault; /* page faults (major+minor) */64u64 pgmajfault; /* page faults (major only) */65// <-- New in 2.66667} __attribute__((packed)) appldata_mem_data;686970/*71* appldata_get_mem_data()72*73* gather memory data74*/75static void appldata_get_mem_data(void *data)76{77/*78* don't put large structures on the stack, we are79* serialized through the appldata_ops_mutex and can use static80*/81static struct sysinfo val;82unsigned long ev[NR_VM_EVENT_ITEMS];83struct appldata_mem_data *mem_data;8485mem_data = data;86mem_data->sync_count_1++;8788all_vm_events(ev);89mem_data->pgpgin = ev[PGPGIN] >> 1;90mem_data->pgpgout = ev[PGPGOUT] >> 1;91mem_data->pswpin = ev[PSWPIN];92mem_data->pswpout = ev[PSWPOUT];93mem_data->pgalloc = ev[PGALLOC_NORMAL];94mem_data->pgalloc += ev[PGALLOC_DMA];95mem_data->pgfault = ev[PGFAULT];96mem_data->pgmajfault = ev[PGMAJFAULT];9798si_meminfo(&val);99mem_data->sharedram = val.sharedram;100mem_data->totalram = P2K(val.totalram);101mem_data->freeram = P2K(val.freeram);102mem_data->totalhigh = P2K(val.totalhigh);103mem_data->freehigh = P2K(val.freehigh);104mem_data->bufferram = P2K(val.bufferram);105mem_data->cached = P2K(global_page_state(NR_FILE_PAGES)106- val.bufferram);107108si_swapinfo(&val);109mem_data->totalswap = P2K(val.totalswap);110mem_data->freeswap = P2K(val.freeswap);111112mem_data->timestamp = get_clock();113mem_data->sync_count_2++;114}115116117static struct appldata_ops ops = {118.name = "mem",119.record_nr = APPLDATA_RECORD_MEM_ID,120.size = sizeof(struct appldata_mem_data),121.callback = &appldata_get_mem_data,122.data = &appldata_mem_data,123.owner = THIS_MODULE,124.mod_lvl = {0xF0, 0xF0}, /* EBCDIC "00" */125};126127128/*129* appldata_mem_init()130*131* init_data, register ops132*/133static int __init appldata_mem_init(void)134{135return appldata_register_ops(&ops);136}137138/*139* appldata_mem_exit()140*141* unregister ops142*/143static void __exit appldata_mem_exit(void)144{145appldata_unregister_ops(&ops);146}147148149module_init(appldata_mem_init);150module_exit(appldata_mem_exit);151152MODULE_LICENSE("GPL");153MODULE_AUTHOR("Gerald Schaefer");154MODULE_DESCRIPTION("Linux-VM Monitor Stream, MEMORY statistics");155156157