---
# System prepended metadata

title: Assignment 1 Report

---

# Assignment 1 Report
By. 311551169 劉宇承

[original spec](https://hackmd.io/@a3020008/rJSJXaYyn#1-Introduction-to-fio)

## Q0

**Question** : Please run q0.fio on your own HDD and write down your output q0 in report.

```
job1: (g=0): rw=read, bs=(R) 4096B-4096B, (W) 4096B-4096B, (T) 4096B-4096B, ioengine=psync, iodepth=1
fio-3.28
Starting 1 process

job1: (groupid=0, jobs=1): err= 0: pid=2918570: Sat Apr 15 20:56:31 2023
  read: IOPS=44.1k, BW=172MiB/s (180MB/s)(1024MiB/5951msec)
    clat (usec): min=20, max=18868, avg=22.54, stdev=40.86
     lat (usec): min=20, max=18868, avg=22.55, stdev=40.87
    clat percentiles (usec):
     |  1.00th=[   22],  5.00th=[   22], 10.00th=[   22], 20.00th=[   22],
     | 30.00th=[   22], 40.00th=[   22], 50.00th=[   22], 60.00th=[   22],
     | 70.00th=[   23], 80.00th=[   23], 90.00th=[   24], 95.00th=[   24],
     | 99.00th=[   30], 99.50th=[   48], 99.90th=[  133], 99.95th=[  137],
     | 99.99th=[  149]
   bw (  KiB/s): min=167680, max=180208, per=100.00%, avg=176250.18, stdev=4212.71, samples=11
   iops        : min=41920, max=45052, avg=44062.55, stdev=1053.18, samples=11
  lat (usec)   : 50=99.68%, 100=0.13%, 250=0.19%, 500=0.01%
  lat (msec)   : 2=0.01%, 4=0.01%, 10=0.01%, 20=0.01%
  cpu          : usr=1.21%, sys=9.55%, ctx=262150, majf=0, minf=16
  IO depths    : 1=100.0%, 2=0.0%, 4=0.0%, 8=0.0%, 16=0.0%, 32=0.0%, >=64=0.0%
     submit    : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     complete  : 0=0.0%, 4=100.0%, 8=0.0%, 16=0.0%, 32=0.0%, 64=0.0%, >=64=0.0%
     issued rwts: total=262144,0,0,0 short=0,0,0,0 dropped=0,0,0,0
     latency   : target=0, window=0, percentile=100.00%, depth=1

Run status group 0 (all jobs):
   READ: bw=172MiB/s (180MB/s), 172MiB/s-172MiB/s (180MB/s-180MB/s), io=1024MiB (1074MB), run=5951-5951msec

Disk stats (read/write):
  sdb: ios=259922/0, merge=0/0, ticks=5473/0, in_queue=5473, util=98.43%
```

## Q1

**Question** : Is there any significant difference between read/randread on HDD? Why or why not? Please justify your answer in brief.

sequencial read的結果
```
Run status group 0 (all jobs):
   READ: bw=80.3MiB/s (84.2MB/s), 80.3MiB/s-80.3MiB/s (84.2MB/s-84.2MB/s), io=64.0MiB (67.1MB), run=797-797msec
```

random read的結果則是
```
Run status group 1 (all jobs):
   READ: bw=37.3MiB/s (39.1MB/s), 37.3MiB/s-37.3MiB/s (39.1MB/s-39.1MB/s), io=64.0MiB (67.1MB), run=1716-1716msec
```

明顯sequencial read的結果較好，我認為的原因是因為HDD在處理random access時的效能較差，比如比較明顯的seek time，如果每次read的位置track都剛好距離很遠，挪動讀寫頭就會浪費大量時間


## Q2
**Question** :

(1) Is there any significant difference between write/randwrite on HDD? Why or why not? Please justify your answer in brief.
(2) Is there any significant difference between write/randwrite on SSD? Why or why not? Please justify your answer in brief.


(1)
HDD的結果
```
//sequencial write
Run status group 0 (all jobs):
  WRITE: bw=71.9MiB/s (75.4MB/s), 71.9MiB/s-71.9MiB/s (75.4MB/s-75.4MB/s), io=64.0MiB (67.1MB), run=890-890msec
```
```
//random write
Run status group 1 (all jobs):
  WRITE: bw=7676KiB/s (7860kB/s), 7676KiB/s-7676KiB/s (7860kB/s-7860kB/s), io=64.0MiB (67.1MB), run=8538-8538msec

```

(2)
SDD的結果
```
//sequencial write
Run status group 2 (all jobs):
  WRITE: bw=66.4MiB/s (69.6MB/s), 66.4MiB/s-66.4MiB/s (69.6MB/s-69.6MB/s), io=64.0MiB (67.1MB), run=964-964msec
```
```
//random write
Run status group 3 (all jobs):
  WRITE: bw=67.2MiB/s (70.5MB/s), 67.2MiB/s-67.2MiB/s (70.5MB/s-70.5MB/s), io=64.0MiB (67.1MB), run=952-952msec
```

可以發現HDD的write/randwrite會導致**效能有所差異**，而SSD的write/randwrite則**差異不明顯**
我認為的原因是因為，HDD的讀或寫都依賴讀寫頭的挪動或是硬碟本身的轉動，如果不符合locality的話會導致挪動讀寫頭浪費很多時間(原因同Q1)；SDD則因為寫入跟讀取是依靠電流寫入，較沒有random access overhead

## Q3
**Question** : Is there any significant difference between forward/backward write on HDD? Why or why not? Please justify your answer in brief.

```
//Forward write
Run status group 0 (all jobs):
  WRITE: bw=73.8MiB/s (77.4MB/s), 73.8MiB/s-73.8MiB/s (77.4MB/s-77.4MB/s), io=128MiB (134MB), run=1735-1735msec

//Backward write
Run status group 1 (all jobs):
  WRITE: bw=12.9MiB/s (13.5MB/s), 12.9MiB/s-12.9MiB/s (13.5MB/s-13.5MB/s), io=128MiB (134MB), run=9934-9934msec
```
兩者之間**有明顯差異**，我認為是因為backward讀取會導致HDD讀取完一個block的資料以後，需要等磁碟再轉一圈才能「往後讀」他需要的資料，所以導致效能緩慢


## Q4
**Question** :

(1) Is there any significant difference between buffered/nonbuffered sequential read on SSD? Why or why not? Please justify your answer in brief.
(2) Replace sequential read with random read. Is there any significant difference between buffered/nonbuffered random read on SSD? Why or why not? Please justify your answer in brief.

```
//buffered sequential
Run status group 0 (all jobs):
   READ: bw=384MiB/s (403MB/s), 384MiB/s-384MiB/s (403MB/s-403MB/s), io=256MiB (268MB), run=666-666msec

//nonbuffered sequential
Run status group 1 (all jobs):
   READ: bw=71.2MiB/s (74.7MB/s), 71.2MiB/s-71.2MiB/s (74.7MB/s-74.7MB/s), io=256MiB (268MB), run=3594-3594msec

//buffered random
Run status group 2 (all jobs):
   READ: bw=19.7MiB/s (20.7MB/s), 19.7MiB/s-19.7MiB/s (20.7MB/s-20.7MB/s), io=256MiB (268MB), run=12967-12967msec

//nonbuffered random
Run status group 3 (all jobs):
   READ: bw=19.7MiB/s (20.7MB/s), 19.7MiB/s-19.7MiB/s (20.7MB/s-20.7MB/s), io=256MiB (268MB), run=12983-12983msec
```
(1) 有明顯差異，我認為原因是因為SSD可以透過readahead機制先將後續的資料讀取完放在DRAM buffer中，加速整體讀取的throughput
(2) 無明顯差異，我認為是因為random access會破壞memory spatial locality，使得快取效益減低甚至無效





## Q5

**Question** : Is there any bandwidth trend between these jobs? Why or why not? Please justify your answer in brief.

```
Run status group 0 (all jobs):
  WRITE: bw=157MiB/s (165MB/s), 157MiB/s-157MiB/s (165MB/s-165MB/s), io=1024MiB (1074MB), run=6524-6524msec

Run status group 1 (all jobs):
  WRITE: bw=195MiB/s (204MB/s), 195MiB/s-195MiB/s (204MB/s-204MB/s), io=1024MiB (1074MB), run=5252-5252msec

Run status group 2 (all jobs):
  WRITE: bw=216MiB/s (227MB/s), 216MiB/s-216MiB/s (227MB/s-227MB/s), io=1024MiB (1074MB), run=4733-4733msec

Run status group 3 (all jobs):
  WRITE: bw=244MiB/s (255MB/s), 244MiB/s-244MiB/s (255MB/s-255MB/s), io=1024MiB (1074MB), run=4203-4203msec

Run status group 4 (all jobs):
  WRITE: bw=248MiB/s (260MB/s), 248MiB/s-248MiB/s (260MB/s-260MB/s), io=1024MiB (1074MB), run=4124-4124msec
```
觀察了一下io_log，我認為是因為當記憶體位置太大的時候，LBA的轉換時間會比較久

另外，位置低的時候，會從HDD的外圈開始寫入，因為disc外圈比較長，物理上的原因外圈的寫入速度(offset = 0)會比在內圈寫入(offset 0.8)還快




## Q6
**Question**
(1) Is there any significant difference between 4k/1k write on HDD? Why or why not? Please justify your answer in brief.
(2) If you want to achieve the best performance in the condition above, how would you modify blocksize? Explain it briefly.

```
//4K bs
Run status group 0 (all jobs):
  WRITE: bw=77.5MiB/s (81.2MB/s), 77.5MiB/s-77.5MiB/s (81.2MB/s-81.2MB/s), io=1024MiB (1074MB), run=13219-13219msec

//1k bs
Run status group 1 (all jobs):
  WRITE: bw=34.6MiB/s (36.2MB/s), 34.6MiB/s-34.6MiB/s (36.2MB/s-36.2MB/s), io=1024MiB (1074MB), run=29634-29634msec
```
(1) 有明顯差異，我認為原因是因為1k block size相比於4k block size，需要呼叫IO的次數會多很多，這導致了明顯的performance overhead
(2) 在記憶體空間沒有限制的前提下，我會把blocksize調成1g(檔案大小)

## Q7
**Question :** Please explain how you achieve the fastest 1G nonbuffered write on HDD in brief.

我將bs調成了1g，成績如下
```
Run status group 0 (all jobs):
  WRITE: bw=251MiB/s (263MB/s), 251MiB/s-251MiB/s (263MB/s-263MB/s), io=1024MiB (1074MB), run=4077-4077msec
```

# Bonus

## Q1
(5%) Replace HDD with SSD in Q1.
Is there any significant difference between read/randread on SSD? Why or why not? Please justify your answer in brief.

輸出如下
```
Run status group 0 (all jobs):
   READ: bw=74.0MiB/s (77.6MB/s), 74.0MiB/s-74.0MiB/s (77.6MB/s-77.6MB/s), io=64.0MiB (67.1MB), run=865-865msec

Run status group 1 (all jobs):
   READ: bw=31.1MiB/s (32.6MB/s), 31.1MiB/s-31.1MiB/s (32.6MB/s-32.6MB/s), io=64.0MiB (67.1MB), run=2058-2058msec
```
read跟randread仍有明顯差距，我認為主要效能差在sequencial read會有buffer輔助


## Q3
(5%) Replace HDD with SSD in Q3.
Is there any significant difference between forward/backward write on SSD? Why or why not? Please justify your answer in brief.

輸出如下
```
Run status group 0 (all jobs):
  WRITE: bw=67.1MiB/s (70.4MB/s), 67.1MiB/s-67.1MiB/s (70.4MB/s-70.4MB/s), io=128MiB (134MB), run=1907-1907msec

Run status group 1 (all jobs):
  WRITE: bw=67.0MiB/s (70.3MB/s), 67.0MiB/s-67.0MiB/s (70.3MB/s-70.3MB/s), io=128MiB (134MB), run=1910-1910msec
```
兩者沒有明顯差距，我認為是因為SSD不需要像HDD等待磁碟轉動來讀取上一個block的資料導致，由於要讀取的block都在相鄰位置，同時也不會像bonus Q1一樣有buffer上的問題

