Usar o dd para escrever zeros no cartão CF no leitor de cartão USB causa muita leitura

2

Estou zerando um cartão CF usando dd

dd if=/dev/zero of=/dev/sdg

Observando o sistema usando gkrellm ou iostat, vejo muitas leituras do dispositivo de cartão CF, seguidas por rajadas de gravações.

Com este exemplo:

# dd if=/dev/zero of=/dev/sdg count=200000
200000+0 records in
200000+0 records out
102400000 bytes (102 MB) copied, 46.1357 s, 2.2 MB/s

Iostat com um intervalo de 1 segundo produz isso:

Linux 2.6.32-573.3.1.el6.x86_64
Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
sdg               0.00         0.00         0.00          0          0
sdg               0.00         0.00         0.00          0          0
sdg               0.00         0.00         0.00          0          0
sdg             406.00      3248.00         0.00       3248          0
sdg             719.00      5752.00         0.00       5752          0
sdg             738.00      5904.00         0.00       5904          0
sdg             721.00      5768.00         0.00       5768          0
sdg             735.00      5880.00         0.00       5880          0
sdg             715.00      5720.00         0.00       5720          0
sdg             732.00      5856.00         0.00       5856          0
sdg             717.00      5736.00         0.00       5736          0
sdg             732.00      5856.00         0.00       5856          0
sdg             717.00      5736.00         0.00       5736          0
sdg             732.00      5856.00         0.00       5856          0
sdg             715.00      5720.00         0.00       5720          0
sdg             732.00      5856.00         0.00       5856          0
sdg             714.00      5712.00         0.00       5712          0
sdg             733.00      5864.00         0.00       5864          0
sdg             716.00      5728.00         0.00       5728          0
sdg             732.00      5856.00         0.00       5856          0
sdg             715.00      5720.00         0.00       5720          0
sdg             732.00      5856.00         0.00       5856          0
sdg             712.00      5696.00         0.00       5696          0
sdg             732.00      5856.00         0.00       5856          0
sdg             715.00      5720.00         0.00       5720          0
sdg             734.00      5872.00         0.00       5872          0
sdg             715.00      5720.00         0.00       5720          0
sdg             734.00      5872.00         0.00       5872          0
sdg             715.00      5720.00         0.00       5720          0
sdg             732.00      5856.00         0.00       5856          0
sdg             715.00      5720.00         0.00       5720          0
sdg             732.00      5856.00         0.00       5856          0
sdg             715.00      5720.00         0.00       5720          0
sdg             733.00      5864.00         0.00       5864          0
sdg             716.00      5728.00         0.00       5728          0
sdg             733.00      5864.00         0.00       5864          0
sdg             444.00      3320.00      6960.00       3320       6960
sdg              71.00        56.00     15360.00         56      15360
sdg              81.00        72.00     17280.00         72      17280
sdg              83.00        80.00     17520.00         80      17520
sdg              81.00        80.00     17040.00         80      17040
sdg              82.00        72.00     17520.00         72      17520
sdg              81.00        72.00     17280.00         72      17280
sdg              83.00        80.00     17520.00         80      17520
sdg              81.00        80.00     17040.00         80      17040
sdg              82.00        72.00     17520.00         72      17520
sdg              82.00        80.00     17280.00         80      17280
sdg             204.00      1152.00     14352.00       1152      14352
sdg             718.00      5744.00         0.00       5744          0
sdg             160.00      1024.00      7328.00       1024       7328
sdg               0.00         0.00         0.00          0          0
sdg               0.00         0.00         0.00          0          0
sdg               0.00         0.00         0.00          0          0
sdg               0.00         0.00         0.00          0          0

Correndo strace no dd não revela nada estranho:

open("/dev/zero", O_RDONLY)             = 3
dup2(3, 0)                              = 0
close(3)                                = 0
lseek(0, 0, SEEK_CUR)                   = 0
open("/dev/sdg", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
dup2(3, 1)                              = 1
close(3)                                = 0
read(0, "
cat /dev/zero >/dev/sdg
Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
sdg               0.00         0.00         0.00          0          0
sdg               0.00         0.00         0.00          0          0
sdg               0.00         0.00         0.00          0          0
sdg              37.00         0.00      8880.00          0       8880
sdg              73.00         0.00     17520.00          0      17520
sdg              74.00         0.00     17528.00          0      17528
sdg              75.00         0.00     17304.00          0      17304
sdg              50.00         0.00     11768.00          0      11768
sdg              56.00         0.00     12976.00          0      12976
sdg              44.00         0.00     10328.00          0      10328
sdg              76.00         0.00     17544.00          0      17544
sdg              75.00         0.00     17536.00          0      17536
sdg              75.00         0.00     17536.00          0      17536
dd if=/dev/zero of=/dev/sdg
# dd if=/dev/zero of=/dev/sdg count=200000
200000+0 records in
200000+0 records out
102400000 bytes (102 MB) copied, 46.1357 s, 2.2 MB/s
Linux 2.6.32-573.3.1.el6.x86_64
Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
sdg               0.00         0.00         0.00          0          0
sdg               0.00         0.00         0.00          0          0
sdg               0.00         0.00         0.00          0          0
sdg             406.00      3248.00         0.00       3248          0
sdg             719.00      5752.00         0.00       5752          0
sdg             738.00      5904.00         0.00       5904          0
sdg             721.00      5768.00         0.00       5768          0
sdg             735.00      5880.00         0.00       5880          0
sdg             715.00      5720.00         0.00       5720          0
sdg             732.00      5856.00         0.00       5856          0
sdg             717.00      5736.00         0.00       5736          0
sdg             732.00      5856.00         0.00       5856          0
sdg             717.00      5736.00         0.00       5736          0
sdg             732.00      5856.00         0.00       5856          0
sdg             715.00      5720.00         0.00       5720          0
sdg             732.00      5856.00         0.00       5856          0
sdg             714.00      5712.00         0.00       5712          0
sdg             733.00      5864.00         0.00       5864          0
sdg             716.00      5728.00         0.00       5728          0
sdg             732.00      5856.00         0.00       5856          0
sdg             715.00      5720.00         0.00       5720          0
sdg             732.00      5856.00         0.00       5856          0
sdg             712.00      5696.00         0.00       5696          0
sdg             732.00      5856.00         0.00       5856          0
sdg             715.00      5720.00         0.00       5720          0
sdg             734.00      5872.00         0.00       5872          0
sdg             715.00      5720.00         0.00       5720          0
sdg             734.00      5872.00         0.00       5872          0
sdg             715.00      5720.00         0.00       5720          0
sdg             732.00      5856.00         0.00       5856          0
sdg             715.00      5720.00         0.00       5720          0
sdg             732.00      5856.00         0.00       5856          0
sdg             715.00      5720.00         0.00       5720          0
sdg             733.00      5864.00         0.00       5864          0
sdg             716.00      5728.00         0.00       5728          0
sdg             733.00      5864.00         0.00       5864          0
sdg             444.00      3320.00      6960.00       3320       6960
sdg              71.00        56.00     15360.00         56      15360
sdg              81.00        72.00     17280.00         72      17280
sdg              83.00        80.00     17520.00         80      17520
sdg              81.00        80.00     17040.00         80      17040
sdg              82.00        72.00     17520.00         72      17520
sdg              81.00        72.00     17280.00         72      17280
sdg              83.00        80.00     17520.00         80      17520
sdg              81.00        80.00     17040.00         80      17040
sdg              82.00        72.00     17520.00         72      17520
sdg              82.00        80.00     17280.00         80      17280
sdg             204.00      1152.00     14352.00       1152      14352
sdg             718.00      5744.00         0.00       5744          0
sdg             160.00      1024.00      7328.00       1024       7328
sdg               0.00         0.00         0.00          0          0
sdg               0.00         0.00         0.00          0          0
sdg               0.00         0.00         0.00          0          0
sdg               0.00         0.00         0.00          0          0
open("/dev/zero", O_RDONLY)             = 3
dup2(3, 0)                              = 0
close(3)                                = 0
lseek(0, 0, SEEK_CUR)                   = 0
open("/dev/sdg", O_WRONLY|O_CREAT|O_TRUNC, 0666) = 3
dup2(3, 1)                              = 1
close(3)                                = 0
read(0, "
cat /dev/zero >/dev/sdg
Device:            tps   Blk_read/s   Blk_wrtn/s   Blk_read   Blk_wrtn
sdg               0.00         0.00         0.00          0          0
sdg               0.00         0.00         0.00          0          0
sdg               0.00         0.00         0.00          0          0
sdg              37.00         0.00      8880.00          0       8880
sdg              73.00         0.00     17520.00          0      17520
sdg              74.00         0.00     17528.00          0      17528
sdg              75.00         0.00     17304.00          0      17304
sdg              50.00         0.00     11768.00          0      11768
sdg              56.00         0.00     12976.00          0      12976
sdg              44.00         0.00     10328.00          0      10328
sdg              76.00         0.00     17544.00          0      17544
sdg              75.00         0.00     17536.00          0      17536
sdg              75.00         0.00     17536.00          0      17536
%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%"..., 512) = 512 write(1, "%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%"..., 512) = 512 read(0, "%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%"..., 512) = 512 write(1, "%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%"..., 512) = 512 read(0, "%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%"..., 512) = 512 write(1, "%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%"..., 512) = 512
%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%"..., 512) = 512 write(1, "%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%"..., 512) = 512 read(0, "%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%"..., 512) = 512 write(1, "%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%"..., 512) = 512 read(0, "%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%"..., 512) = 512 write(1, "%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%%pre%"..., 512) = 512

No entanto, o mesmo comportamento não é observado usando

%pre%

iostat:

%pre%

O que está acontecendo?

    
por Neik 18.08.2015 / 09:52

2 respostas

1

Embora o cartão CF seja reportado como tendo blocos de 512 bytes:

kernel: sd 11:0:0:0: [sdk] 15662304 512-byte logical blocks

Usar um tamanho de bloco de 4k no df remove a leitura e, portanto, aumenta o desempenho:

# dd if=/dev/zero of=/dev/sdk count=80000
80000+0 records in
80000+0 records out
40960000 bytes (41 MB) copied, 5.49363 s, 7.5 MB/s
# dd if=/dev/zero of=/dev/sdk count=10000 bs=4k
10000+0 records in
10000+0 records out
40960000 bytes (41 MB) copied, 2.82353 s, 14.5 MB/s

Eu acho que o kernel pode estar lendo a placa para montar um bloco inteiro para escrever de volta, mas isso não parece ser um comportamento correto.

    
por 19.08.2015 / 17:01
0

Seu dispositivo tem um pequeno buffer para ajudar a acelerar as coisas. Quando você redireciona usando cat, o buffer é feito pelo sistema operacional. Você pode dizer ao dd para escrever diretamente no dispositivo sem fazer cache. Por exemplo:

dd if=/dev/zero of=/dev/sdg oflag=direct

Veja man 5 open e leia sobre O_DIRECT . Claro que, isso será muito lento. Se você quiser acelerar, mas ainda aproveitar as capacidades de dd , você pode fazer algo assim:

dd if=/dev/zero | cat >/dev/sdg
    
por 18.08.2015 / 13:39

Tags