bcache does not allow a disk to enter standby

While writing an article about power saving in Linux I found that using bcache might stop your disks from entering standby/sleep. See yourself…

Here’s what I did / tried already (these are just settings to VERIFY what happens, I wouldn’t use them productive environments, so please don’t use them):

  • I’ve disabled all services/applications which are not required to run the machine (apart from systemd).
  • I’ve mounted everything which could cause writes on tmpfs (e.g. /var/log, /tmp)
  • I’ve installed inotifywait and checked inotifywait -m / as well as /home – Here I can see that something happens ~every minute
  • I’ve modified the vm.dirty* settings to 5 minutes, I’ve set commit= to 5 minutes and set max_batch_time to 0 for my ext4 filesystems. I’ve set swapiness to 0.
  • I’ve set writeback_delay of bcache to 5 minutes.

So, there really shouldn’t be any writes. Here’s an example (running X11 with all stuff disabled; I did the same tests without X11 – same result)

    Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util
    nvme0n1          1.00    1.00     32.00      0.50     0.00     0.00   0.00   0.00    4.00    4.00   0.00    32.00     0.50   0.00   0.00
    sda              0.00    1.00      0.00     32.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00    32.00   0.00   0.00
    bcache0          0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00
 
    Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util
    nvme0n1          0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00
    sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00
    bcache0          0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00
 
    Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util
    nvme0n1          0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00
    sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00
    bcache0          0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00
 
    Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util
    nvme0n1          1.00    0.00     32.00      0.00     0.00     0.00   0.00   0.00    4.00    0.00   0.00    32.00     0.00   0.00   0.00
    sda              0.00    1.00      0.00     32.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00    32.00   0.00   0.00
    bcache0          0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00
 
    Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util
    nvme0n1          0.00    1.00      0.00      1.00     0.00     0.00   0.00   0.00    0.00    4.00   0.00     0.00     1.00   0.00   0.00
    sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00
    bcache0          0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00
 
    Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util
    nvme0n1          0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00
    sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00
    bcache0          0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00
 
    Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util
    nvme0n1          1.00    0.00     32.00      0.00     0.00     0.00   0.00   0.00    4.00    0.00   0.00    32.00     0.00   0.00   0.00
    sda              0.00    1.00      0.00     32.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00    32.00   0.00   0.00
    bcache0          0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00
 
    Device            r/s     w/s     rkB/s     wkB/s   rrqm/s   wrqm/s  %rrqm  %wrqm r_await w_await aqu-sz rareq-sz wareq-sz  svctm  %util
    nvme0n1          0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00
    sda              0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00
    bcache0          0.00    0.00      0.00      0.00     0.00     0.00   0.00   0.00    0.00    0.00   0.00     0.00     0.00   0.00   0.00

Note the 32.00 entries at rkB/s and wkB/s.

    root@asuna:/home/jean# iotop -o -b -d 60
    Total DISK READ :       0.00 B/s | Total DISK WRITE :       0.00 B/s
    Actual DISK READ:       0.00 B/s | Actual DISK WRITE:       0.00 B/s
      TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN      IO    COMMAND
    Total DISK READ :       0.00 B/s | Total DISK WRITE :     408.86 B/s
    Actual DISK READ:      71.80 K/s | Actual DISK WRITE:     408.86 B/s
      TID  PRIO  USER     DISK READ  DISK WRITE  SWAPIN      IO    COMMAND
     5434 be/4 root        0.00 B/s    0.00 B/s  0.00 %  0.28 % Xorg :0 -seat seat0 -auth /var/run/lightdm/root/:0 -nolisten tcp vt7 -novtswitch
    17706 be/4 jean        0.00 B/s    0.00 B/s  0.00 %  0.00 % thunderbird [JS Helper]
     9502 be/4 jean        0.00 B/s  408.86 B/s  0.00 %  0.00 % enlightenment

This is for ~60 seconds while X11 is running (just to make sure: with X11 disabled (no lightdm, no enlightenment, no xorg) I can still see the small writes and reads in iostat -dx 1 and iotop shows nothing.

At this stage I’ve was still not sure if this is due to bcache or not; though since rkB/s and wkB/s looks equal – at the same second – both on nvme0n1 and sda (bcache uses the nvme as cache and sda as backing device).. I initially thought this might have to do with bcache (writing a cached entry (read) to the backing device (write) or something). On the other hand, shouldn’t I see something on bcache0 as well in iostat?

Trying to get the disk into standby:

    root@asuna:/home/jean# PROMPT_COMMAND="echo -n \[\$(date +%H:%M:%S)\]\ "
    [20:55:00] root@asuna:/home/jean#
    [20:55:05] root@asuna:/home/jean# hdparm -C /dev/sda
 
    /dev/sda:
     drive state is:  active/idle
    [20:55:15] root@asuna:/home/jean# hdparm -y /dev/sda
 
    /dev/sda:
     issuing standby command
    [20:55:19] root@asuna:/home/jean# hdparm -C /dev/sda
 
    /dev/sda:
     drive state is:  active/idle

Okay, so, this might mean the disk is not entering standby at all. Right? That’s why I added the time. Between -y and -C I do have ~4 seconds. Now check this one:

    [20:55:55] root@asuna:/home/jean# hdparm -C /dev/sda && hdparm -y /dev/sda && hdparm -C /dev/sda
 
    /dev/sda:
     drive state is:  active/idle
 
    /dev/sda:
     issuing standby command
 
    /dev/sda:
     drive state is:  standby
    [20:55:58] root@asuna:/home/jean#

This combo does not always work; sometimes it’s fast enough. So the disk enters standby, though it does not stay there.

A few hours later .. yes, it’s bcache. And I should have tried disabling bcache before-hand…

Test #1

  • umounting /home (I’ve got bcache only for /home)
  • periodic read/write persists.

Test #2

  • issuing echo 1 > /sys/block/bcache0/bcache/stop
  • periodic read/write is gone.

So, there is something in bcache which keeps the backing-device pretty much active all the time. Since the reason for bcache is performance and not power-saving this might be a non-issue.

No Comments

Post a Comment