iostat.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. /*
  2. * linux/fs/nfs/iostat.h
  3. *
  4. * Declarations for NFS client per-mount statistics
  5. *
  6. * Copyright (C) 2005, 2006 Chuck Lever <cel@netapp.com>
  7. *
  8. * NFS client per-mount statistics provide information about the health of
  9. * the NFS client and the health of each NFS mount point. Generally these
  10. * are not for detailed problem diagnosis, but simply to indicate that there
  11. * is a problem.
  12. *
  13. * These counters are not meant to be human-readable, but are meant to be
  14. * integrated into system monitoring tools such as "sar" and "iostat". As
  15. * such, the counters are sampled by the tools over time, and are never
  16. * zeroed after a file system is mounted. Moving averages can be computed
  17. * by the tools by taking the difference between two instantaneous samples
  18. * and dividing that by the time between the samples.
  19. */
  20. #ifndef _NFS_IOSTAT
  21. #define _NFS_IOSTAT
  22. #define NFS_IOSTAT_VERS "1.0"
  23. /*
  24. * NFS byte counters
  25. *
  26. * 1. SERVER - the number of payload bytes read from or written to the
  27. * server by the NFS client via an NFS READ or WRITE request.
  28. *
  29. * 2. NORMAL - the number of bytes read or written by applications via
  30. * the read(2) and write(2) system call interfaces.
  31. *
  32. * 3. DIRECT - the number of bytes read or written from files opened
  33. * with the O_DIRECT flag.
  34. *
  35. * These counters give a view of the data throughput into and out of the NFS
  36. * client. Comparing the number of bytes requested by an application with the
  37. * number of bytes the client requests from the server can provide an
  38. * indication of client efficiency (per-op, cache hits, etc).
  39. *
  40. * These counters can also help characterize which access methods are in
  41. * use. DIRECT by itself shows whether there is any O_DIRECT traffic.
  42. * NORMAL + DIRECT shows how much data is going through the system call
  43. * interface. A large amount of SERVER traffic without much NORMAL or
  44. * DIRECT traffic shows that applications are using mapped files.
  45. *
  46. * NFS page counters
  47. *
  48. * These count the number of pages read or written via nfs_readpage(),
  49. * nfs_readpages(), or their write equivalents.
  50. */
  51. enum nfs_stat_bytecounters {
  52. NFSIOS_NORMALREADBYTES = 0,
  53. NFSIOS_NORMALWRITTENBYTES,
  54. NFSIOS_DIRECTREADBYTES,
  55. NFSIOS_DIRECTWRITTENBYTES,
  56. NFSIOS_SERVERREADBYTES,
  57. NFSIOS_SERVERWRITTENBYTES,
  58. NFSIOS_READPAGES,
  59. NFSIOS_WRITEPAGES,
  60. __NFSIOS_BYTESMAX,
  61. };
  62. /*
  63. * NFS event counters
  64. *
  65. * These counters provide a low-overhead way of monitoring client activity
  66. * without enabling NFS trace debugging. The counters show the rate at
  67. * which VFS requests are made, and how often the client invalidates its
  68. * data and attribute caches. This allows system administrators to monitor
  69. * such things as how close-to-open is working, and answer questions such
  70. * as "why are there so many GETATTR requests on the wire?"
  71. *
  72. * They also count anamolous events such as short reads and writes, silly
  73. * renames due to close-after-delete, and operations that change the size
  74. * of a file (such operations can often be the source of data corruption
  75. * if applications aren't using file locking properly).
  76. */
  77. enum nfs_stat_eventcounters {
  78. NFSIOS_INODEREVALIDATE = 0,
  79. NFSIOS_DENTRYREVALIDATE,
  80. NFSIOS_DATAINVALIDATE,
  81. NFSIOS_ATTRINVALIDATE,
  82. NFSIOS_VFSOPEN,
  83. NFSIOS_VFSLOOKUP,
  84. NFSIOS_VFSACCESS,
  85. NFSIOS_VFSUPDATEPAGE,
  86. NFSIOS_VFSREADPAGE,
  87. NFSIOS_VFSREADPAGES,
  88. NFSIOS_VFSWRITEPAGE,
  89. NFSIOS_VFSWRITEPAGES,
  90. NFSIOS_VFSGETDENTS,
  91. NFSIOS_VFSSETATTR,
  92. NFSIOS_VFSFLUSH,
  93. NFSIOS_VFSFSYNC,
  94. NFSIOS_VFSLOCK,
  95. NFSIOS_VFSRELEASE,
  96. NFSIOS_CONGESTIONWAIT,
  97. NFSIOS_SETATTRTRUNC,
  98. NFSIOS_EXTENDWRITE,
  99. NFSIOS_SILLYRENAME,
  100. NFSIOS_SHORTREAD,
  101. NFSIOS_SHORTWRITE,
  102. NFSIOS_DELAY,
  103. __NFSIOS_COUNTSMAX,
  104. };
  105. #ifdef __KERNEL__
  106. #include <linux/percpu.h>
  107. #include <linux/cache.h>
  108. struct nfs_iostats {
  109. unsigned long long bytes[__NFSIOS_BYTESMAX];
  110. unsigned long events[__NFSIOS_COUNTSMAX];
  111. } ____cacheline_aligned;
  112. static inline void nfs_inc_server_stats(struct nfs_server *server, enum nfs_stat_eventcounters stat)
  113. {
  114. struct nfs_iostats *iostats;
  115. int cpu;
  116. cpu = get_cpu();
  117. iostats = per_cpu_ptr(server->io_stats, cpu);
  118. iostats->events[stat] ++;
  119. put_cpu_no_resched();
  120. }
  121. static inline void nfs_inc_stats(struct inode *inode, enum nfs_stat_eventcounters stat)
  122. {
  123. nfs_inc_server_stats(NFS_SERVER(inode), stat);
  124. }
  125. static inline void nfs_add_server_stats(struct nfs_server *server, enum nfs_stat_bytecounters stat, unsigned long addend)
  126. {
  127. struct nfs_iostats *iostats;
  128. int cpu;
  129. cpu = get_cpu();
  130. iostats = per_cpu_ptr(server->io_stats, cpu);
  131. iostats->bytes[stat] += addend;
  132. put_cpu_no_resched();
  133. }
  134. static inline void nfs_add_stats(struct inode *inode, enum nfs_stat_bytecounters stat, unsigned long addend)
  135. {
  136. nfs_add_server_stats(NFS_SERVER(inode), stat, addend);
  137. }
  138. static inline struct nfs_iostats *nfs_alloc_iostats(void)
  139. {
  140. return alloc_percpu(struct nfs_iostats);
  141. }
  142. static inline void nfs_free_iostats(struct nfs_iostats *stats)
  143. {
  144. if (stats != NULL)
  145. free_percpu(stats);
  146. }
  147. #endif
  148. #endif