2 * linux/fs/nfs/iostat.h
4 * Declarations for NFS client per-mount statistics
6 * Copyright (C) 2005, 2006 Chuck Lever <cel@netapp.com>
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
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.
24 #define NFS_IOSTAT_VERS "1.0"
29 * 1. SERVER - the number of payload bytes read from or written to the
30 * server by the NFS client via an NFS READ or WRITE request.
32 * 2. NORMAL - the number of bytes read or written by applications via
33 * the read(2) and write(2) system call interfaces.
35 * 3. DIRECT - the number of bytes read or written from files opened
36 * with the O_DIRECT flag.
38 * These counters give a view of the data throughput into and out of the NFS
39 * client. Comparing the number of bytes requested by an application with the
40 * number of bytes the client requests from the server can provide an
41 * indication of client efficiency (per-op, cache hits, etc).
43 * These counters can also help characterize which access methods are in
44 * use. DIRECT by itself shows whether there is any O_DIRECT traffic.
45 * NORMAL + DIRECT shows how much data is going through the system call
46 * interface. A large amount of SERVER traffic without much NORMAL or
47 * DIRECT traffic shows that applications are using mapped files.
51 * These count the number of pages read or written via nfs_readpage(),
52 * nfs_readpages(), or their write equivalents.
54 enum nfs_stat_bytecounters
{
55 NFSIOS_NORMALREADBYTES
= 0,
56 NFSIOS_NORMALWRITTENBYTES
,
57 NFSIOS_DIRECTREADBYTES
,
58 NFSIOS_DIRECTWRITTENBYTES
,
59 NFSIOS_SERVERREADBYTES
,
60 NFSIOS_SERVERWRITTENBYTES
,
69 * These counters provide a low-overhead way of monitoring client activity
70 * without enabling NFS trace debugging. The counters show the rate at
71 * which VFS requests are made, and how often the client invalidates its
72 * data and attribute caches. This allows system administrators to monitor
73 * such things as how close-to-open is working, and answer questions such
74 * as "why are there so many GETATTR requests on the wire?"
76 * They also count anamolous events such as short reads and writes, silly
77 * renames due to close-after-delete, and operations that change the size
78 * of a file (such operations can often be the source of data corruption
79 * if applications aren't using file locking properly).
81 enum nfs_stat_eventcounters
{
82 NFSIOS_INODEREVALIDATE
= 0,
83 NFSIOS_DENTRYREVALIDATE
,
84 NFSIOS_DATAINVALIDATE
,
85 NFSIOS_ATTRINVALIDATE
,
100 NFSIOS_CONGESTIONWAIT
,
112 #include <linux/percpu.h>
113 #include <linux/cache.h>
116 unsigned long long bytes
[__NFSIOS_BYTESMAX
];
117 unsigned long events
[__NFSIOS_COUNTSMAX
];
118 } ____cacheline_aligned
;
120 static inline void nfs_inc_server_stats(struct nfs_server
*server
, enum nfs_stat_eventcounters stat
)
122 struct nfs_iostats
*iostats
;
126 iostats
= per_cpu_ptr(server
->io_stats
, cpu
);
127 iostats
->events
[stat
] ++;
128 put_cpu_no_resched();
131 static inline void nfs_inc_stats(struct inode
*inode
, enum nfs_stat_eventcounters stat
)
133 nfs_inc_server_stats(NFS_SERVER(inode
), stat
);
136 static inline void nfs_add_server_stats(struct nfs_server
*server
, enum nfs_stat_bytecounters stat
, unsigned long addend
)
138 struct nfs_iostats
*iostats
;
142 iostats
= per_cpu_ptr(server
->io_stats
, cpu
);
143 iostats
->bytes
[stat
] += addend
;
144 put_cpu_no_resched();
147 static inline void nfs_add_stats(struct inode
*inode
, enum nfs_stat_bytecounters stat
, unsigned long addend
)
149 nfs_add_server_stats(NFS_SERVER(inode
), stat
, addend
);
152 static inline struct nfs_iostats
*nfs_alloc_iostats(void)
154 return alloc_percpu(struct nfs_iostats
);
157 static inline void nfs_free_iostats(struct nfs_iostats
*stats
)