Skip to content

PerformanceTuning:DiskIO

디스크 입출력에 대한 성능튜닝 이슈를 정리한다.

Optimal buffer size

As discussed in comments, I believe the exact size don't matter that much, assuming it is :

  1. a small multiple of the file system size (see comment by Joachim Pileborg suggesting stat(".") etc.)
  2. a power of two (because computers and kernels like them)
  3. not too big (e.g. fitting in some cache inside your processor, e.g. L2 cache)
  4. aligned in memory (e.g. to a page size using posix_memalign).

So a power of two between 16kbytes and a few megabytes should probably fit. Most of the time is spent on reading the disk. Filesystem and disk benchmarks are quite flat in that range.

4Kbytes seems to often be the page size and the disk chunk size.

Of course, you can tune things, even tune, when making the file system with mke2fs, the file system block size.

And I'll bet that the optimal is really dependent upon your hardware (SSD, hard disks?) and your system (and its load).

Server Operations Guide: I/O Request Size

The size of requests and the rate at which they are sent are important for evaluating the way applications work with the disk. If you are an application developer, you can use the counters, such as Avg. Disk Bytes/Read, that reveal these types of information about I/O requests.

It is typically faster and more efficient to read a few large records than many small ones. However, transfer rates eventually peak due to the fact that the disk is moving blocks of data so large that each transfer occurs more slowly—although its total throughput is quite high. Unfortunately, it is not always easy to control this factor. However, if your system is used to transfer many small units of data, this inefficiency might help to explain, though not resolve, high disk use.

Requests should be at least 8 KB, and, if possible, 64 KB. Sequential I/O requests of 2 KB consume a substantial amount of processor time, which affects overall system performance. However, if you can be sure that only 2 KB of data is necessary, doing a 2 KB I/O is the most efficient, because a larger I/O wastes direct memory access (DMA) controller bandwidth. As the record size increases, the throughput increases and the transfer rate falls because it takes fewer reads to move the same amount data.

Using 64 KB requests results in faster throughput with very little processor time. Maximum throughput typically occurs at 64 KB, although some devices might have a higher maximum throughput size. When transferring data blocks greater than 64 KB, the I/O subsystem breaks the transfers into 64-KB blocks. Above 64 KB, the transfer rate drops sharply, and throughput levels off. Processor use and interrupts also appear to level off at 64 KB.

SSD에서 HDD로 데이터 복사 방법 및 최적화 (Ubuntu)

Ubuntu 시스템에서 SSD에서 HDD로 데이터를 옮길 때 CPU를 거치지 않고 복사하거나, 가장 빠르게 데이터를 전송하는 방법에 대해 설명합니다.

dd 명령어를 사용한 복사 (저수준 복사)

dd 명령어는 데이터를 블록 단위로 복사하며 CPU를 최소한으로 사용하면서 빠른 복사가 가능합니다.

실행 명령:

sudo dd if=/dev/sdX of=/dev/sdY bs=64M status=progress

설명:

  • if=/dev/sdX: 원본 디스크(SSD) 장치 파일
  • of=/dev/sdY: 대상 디스크(HDD) 장치 파일
  • bs=64M: 블록 크기를 설정 (큰 블록 크기 설정 시 속도 향상)
  • status=progress: 진행 상황 표시

주의사항:

  • 복사하려는 대상(HDD)에 중요한 데이터가 있다면 사전에 백업이 필요합니다.
  • 전체 디스크를 복사하므로 파티션 정보도 그대로 복제됩니다.

rsync로 파일 복사

rsync는 파일 단위 복사 시 효율적이고 빠른 방법입니다.

실행 명령:

sudo rsync -avh --progress /mnt/ssd/ /mnt/hdd/

설명:

  • -a: 아카이브 모드 (파일 권한, 타임스탬프 유지)
  • -v: 상세한 출력
  • -h: 사람 읽기 쉬운 출력
  • --progress: 복사 진행 상황 표시

cp 명령어

간단한 복사가 필요할 경우, cp 명령어를 사용할 수 있습니다.

실행 명령:

sudo cp -a /mnt/ssd/. /mnt/hdd/

설명:

  • -a: 파일 권한과 속성을 유지하며 복사
  • .: 모든 내용을 복사

고성능 파일 시스템 복사 (tar 사용)

압축 없이 데이터를 빠르게 이동하려면 tar 명령어를 활용할 수 있습니다.

실행 명령:

tar cf - -C /mnt/ssd . | tar xf - -C /mnt/hdd

파일 시스템 스냅샷 복사

LVM이나 ZFS와 같은 스냅샷 지원 파일 시스템을 사용하면 복사 속도를 높일 수 있습니다.

LVM 스냅샷 생성 및 복사

스냅샷 생성:

lvcreate --size 10G --snapshot --name snap_name /dev/volume_group/logical_volume

스냅샷을 HDD로 복사:

dd if=/dev/volume_group/snap_name of=/dev/sdY bs=64M status=progress

NVMe-to-NVMe Direct Storage Copy

NVMe SSD라면 nvme-cli를 사용하여 디스크 간 직접 복사를 수행할 수 있습니다. 단, 일반 HDD에는 이 방법이 적합하지 않습니다.

최적화 팁

  • 파일 시스템 마운트 옵션: I/O 오버헤드를 줄이기 위해 noatime 옵션으로 마운트합니다.
sudo mount -o noatime /dev/sdX /mnt/ssd
sudo mount -o noatime /dev/sdY /mnt/hdd
  • 읽기/쓰기 캐싱: hdparm으로 디스크 읽기/쓰기 캐시를 활성화합니다.
sudo hdparm -W1 /dev/sdY
  • I/O 스케줄러 조정: HDD 디스크는 deadline 스케줄러를 설정하면 적합합니다.
echo deadline | sudo tee /sys/block/sdY/queue/scheduler
  • 네트워크 전송: SSD와 HDD가 서로 다른 시스템에 있다면 rsync를 SSH와 결합하여 속도를 높일 수 있습니다.

결론

위 방법 중 dd와 rsync가 Ubuntu 환경에서 가장 널리 사용되며 효율적인 데이터 복사 방식입니다. 사용 목적과 데이터 크기에 따라 적합한 방법을 선택하세요.

See also

Favorite site

References


  1. File_Buffering_(Windows).pdf 

  2. Presentation_-Kyungroh_Kim-_Embedded_System_Random_Performance_Issue.pdf