리눅스 디스크 I/O 최적화 방법

(1). I/O 상태 확인 도구

  1. 파일 시스템 블록 크기 확인

ext4 파일 시스템의 블록 크기를 확인하는 방법:

[root@Linux ~]# tune2fs -l /dev/sdb1 | grep Block
Block count:              2097152
Block size:               4096
Blocks per group:         32768

xfs 파일 시스템의 블록 크기를 확인하는 방법:

[root@Linux ~]# xfs_info /dev/sdb1 | grep bsize
meta-data=/dev/sdb1           isize=512    agcount=4, agsize=262144 blks
         =                       sectsz=512   attr=2, projid32bit=1
data     =                       bsize=4096   blocks=1048576, imaxpct=25
  1. iostat 사용

iostat는 yum을 통해 설치할 수 있습니다.

[root@Linux ~]# yum install sysstat
[root@Linux ~]# iostat -d -k /dev/sdb
Linux 4.18.0-193.el8.x86_64 (Linux)  08/01/21  _x86_64_ (4 CPU)

Device:            tps    kB_read/s    kB_wrtn/s    kB_read    kB_wrtn
sdb               2.05        25.60        10.24     524288     209715

다음은 각 항목에 대한 설명입니다:

kB_read/s 초당 읽은 데이터량(KB)
kB_wrtn/s 초당 쓴 데이터량(KB)
kB_read 전체 읽은 데이터량(KB)
kB_wrtn 전체 쓴 데이터량(KB)

테스트 예시:

[root@Linux ~]# dd if=/dev/zero of=testfile bs=1M count=1000; sync
[root@Linux ~]# iostat -d /dev/sdb -k
  1. iotop 사용

iotop도 yum을 통해 설치할 수 있습니다.

[root@Linux ~]# yum install iotop

두 개의 터미널 창을 열고, 한 창에서는 "iotop -o -d 1" 명령어를 실행하고 다른 창에서는 "dd if=/dev/zero of=testfile bs=1M count=1000; sync" 명령어를 실행합니다.

iotop의 주요 옵션:

  • -o, --only: 디스크 I/O 중인 프로세스만 표시
  • -d SEC, --delay=SEC: 새로 고침 간격 설정

iotop의 주요 상호 작용 명령:

  • 방향키: 정렬 순서 변경
  • r: 정렬 순서 전환
  • o: I/O 출력이 있는 프로세스만 표시
  • p: 프로세스/스레드 표시 모드 전환
  • a: 누적 사용량 표시
  • q: 종료
  1. 하드 드라이브 속도 테스트: hdparm과 dd

hdparm으로 순차 읽기 속도를, dd로 순차 쓰기 속도를 테스트합니다.

hdparm 설치 및 테스트:

[root@Linux ~]# yum install hdparm
[root@Linux ~]# hdparm -t --direct /dev/sdb
/dev/sdb:
 Timing O_DIRECT disk reads: 1234 MB in  3.00 seconds = 411.33 MB/sec

dd는 기본적으로 제공되는 명령어입니다.

[root@Linux ~]# dd if=/dev/zero of=test.dbf bs=1M count=2000 oflag=direct
2000+0 records in
2000+0 records out
2097152000 bytes (2.1 GB) copied, 14.62 s, 143 MB/s

위 예시에서 14.62초 동안 2GB 파일을 생성하며, I/O 쓰기 속도는 약 143MB/초입니다.

(2). 디스크 I/O 간단한 최적화

  1. ulimit 리소스 제한

모든 리소스 제한 정보를 확인:

[root@Linux ~]# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (kbytes, -f) unlimited
pending signals                 (-i) 15640
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1024
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 15640
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

임시로 리소스 제한을 수정하는 방법:

[root@Linux ~]# ulimit -n 2048

영구적으로 리소스 제한을 수정하려면 /etc/security/limits.conf 파일을 편집하고 시스템을 재부팅해야 합니다.

[root@Linux ~]# vim /etc/security/limits.conf
*       soft    nofile  4096
*       hard    nofile  4096
[root@Linux ~]# init 6

태그: linux tune2fs xfs_info iostat iotop

7월 2일 06:12에 게시됨