NOTE

Disk Tuning

1. Disk Performance Metrics 1.1. Filesystem I/O Performance Metrics 1.1.1. Storage Space Usage Capacity, used amount, remaining space, etc. 1.1.2. Cache Usage Page cache, directory entry cache, inode cache, and caches for specific filesystems (such a

Operating Systems / LinuxCreated Updated 2 min readhistorical

This is a historical learning note and may contain outdated or incomplete understanding.

1. Disk Performance Metrics

1.1. Filesystem I/O Performance Metrics

1.1.1. Storage-Space Usage

Capacity, used amount, remaining space, etc.

1.1.2. Cache Usage

Page cache, directory-entry cache, inode cache, and caches for specific filesystems (such as ext4, XFS, etc.).

1.2. Disk I/O Performance Metrics

1.2.1. Utilization

Percentage of time the disk is busy processing I/O requests.

1.2.2. IOPS

Number of I/O requests per second.

1.2.3. Throughput

Size of I/O requests per second.

1.2.4. Response Time

Time interval from issuing an I/O request to receiving a response.

2. Disk Performance Tools

2.1. df

df

2.2. iostat

iostat

2.3. pidstat

pidstat

2.4. strace

strace

2.5. lsof

lsof

3. How to Analyze a Disk Performance Bottleneck

3.1. Check Whether I/O Is the Bottleneck

  • Use top to view CPU load (load average) and CPU utilization (%Cpu). If the former is high and the latter is low, the bottleneck is network I/O or disk I/O.
  • Data from disk to the kernel uses DMA copy and does not consume CPU. The CPU state is iowait (iowait is a type of idle state), while the program state depends on the I/O Model.
    • Synchronous blocking: normally the CPU is idle, but in server programming it is generally used with multiple threads, so the CPU becomes busy switching threads.
    • Synchronous nonblocking: the CPU is busy with context switching.
    • I/O multiplexing: the CPU is not busy; one CPU is sufficient.
  • Data from the kernel to the application uses CPU copy and consumes CPU + the program state is blocking = the CPU state is sys (kernel mode).

3.2. Check Whether Disk I/O Is the Bottleneck

  • Use top to see whether iowait is relatively high; if so, it may be a disk I/O bottleneck. Use iostat -xdk 1 10 to see whether %util is relatively high; if so, it is indeed a disk I/O bottleneck.

3.3. Find the Process with High I/O Usage

  • Use pidstat -d 1 10 to locate processes with relatively heavy read/write operations.
  • ps -e -L h o state,cmd | awk '{if($1=="R"||$1=="D"){print $0}}' | sort | uniq -c | sort -k 1nr

3.4. Analyze the Process

  • Use strace -f -T -tt -p PID to see what the process is doing.
  • Use lsof -p PID to see which files the process is operating on.

4. References

Discussion

Sign in with GitHub to comment. Discussions are stored as GitHub Issues.View on GitHub