appldata_mem.c 4.0 KB

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