linux/arch/s390/appldata/appldata_mem.c
<<
>>
Prefs
   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 *
   7 * Copyright (C) 2003,2006 IBM Corporation, IBM Deutschland Entwicklung GmbH.
   8 *
   9 * Author: Gerald Schaefer <gerald.schaefer@de.ibm.com>
  10 */
  11
  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>
  17#include <linux/pagemap.h>
  18#include <linux/swap.h>
  19#include <asm/io.h>
  20
  21#include "appldata.h"
  22
  23
  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 */
  38static struct appldata_mem_data {
  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
  69} __attribute__((packed)) appldata_mem_data;
  70
  71
  72/*
  73 * appldata_get_mem_data()
  74 *
  75 * gather memory data
  76 */
  77static void appldata_get_mem_data(void *data)
  78{
  79        /*
  80         * don't put large structures on the stack, we are
  81         * serialized through the appldata_ops_mutex and can use static
  82         */
  83        static struct sysinfo val;
  84        unsigned long ev[NR_VM_EVENT_ITEMS];
  85        struct appldata_mem_data *mem_data;
  86
  87        mem_data = data;
  88        mem_data->sync_count_1++;
  89
  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];
  95        mem_data->pgalloc    = ev[PGALLOC_NORMAL];
  96#ifdef CONFIG_ZONE_DMA
  97        mem_data->pgalloc    += ev[PGALLOC_DMA];
  98#endif
  99        mem_data->pgfault    = ev[PGFAULT];
 100        mem_data->pgmajfault = ev[PGMAJFAULT];
 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);
 109        mem_data->cached    = P2K(global_page_state(NR_FILE_PAGES)
 110                                - val.bufferram);
 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++;
 118}
 119
 120
 121static struct appldata_ops ops = {
 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,
 128        .mod_lvl   = {0xF0, 0xF0},              /* EBCDIC "00" */
 129};
 130
 131
 132/*
 133 * appldata_mem_init()
 134 *
 135 * init_data, register ops
 136 */
 137static int __init appldata_mem_init(void)
 138{
 139        return appldata_register_ops(&ops);
 140}
 141
 142/*
 143 * appldata_mem_exit()
 144 *
 145 * unregister ops
 146 */
 147static void __exit appldata_mem_exit(void)
 148{
 149        appldata_unregister_ops(&ops);
 150}
 151
 152
 153module_init(appldata_mem_init);
 154module_exit(appldata_mem_exit);
 155
 156MODULE_LICENSE("GPL");
 157MODULE_AUTHOR("Gerald Schaefer");
 158MODULE_DESCRIPTION("Linux-VM Monitor Stream, MEMORY statistics");
 159