zramctl fails if called within a certain interval after modprobe zram.

Bug #1645846 reported by hackerb9
22
This bug affects 4 people
Affects Status Importance Assigned to Milestone
util-linux (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

On my machine, I can trigger the bug 100% of the time if I do this:
  modprobe zram; d=$(zramctl --find) && zramctl --size 256M $d

Here is the error message zramctl emits:
  zramctl: /dev/zram0: failed to reset: Device or resource busy

However, the following always work (0% failure)!
  modprobe zram; sleep 0.1; d=$(zramctl --find) && zramctl --size 256M $d
  modprobe zram; d=$(zramctl --find) && sleep 0.1 && zramctl --size 256M $d

And the following sometimes works and sometimes doesn't:
  modprobe zram; d=$(zramctl --find --size 256M)
Chances are about 25% of failure according to this:
    for i in {0..99};
    do
      echo $i;
      modprobe -r zram;
      modprobe zram;
      d=$(zramctl --find --size 256M);
      sleep 0.05;
    done 2>&1 | grep -c failed

Bizarrely, while putting a long sleep (0.1s) after the modprobe fixes
the problem, putting a short sleep in (0.01s) increases the failure
rate to 95%!

----------------------------------------------------------------------
    for i in {0..99};
    do
      echo $i;
      modprobe -r zram;
      modprobe zram;
      sleep 0.01 # <-- this makes things worse!
      d=$(zramctl --find --size 256M);
      sleep 0.05;
    done 2>&1 | grep -c failed
----------------------------------------------------------------------
    for i in {0..99};
    do
      echo $i;
      modprobe -r zram;
      modprobe zram;
      sleep 0.10 # <-- this completely fixes the problem
      d=$(zramctl --find --size 256M);
      sleep 0.05;
    done 2>&1 | grep -c failed
----------------------------------------------------------------------

Because of the weird window of time in which this bug occurs, I assume it is caused by some asynchronous process briefly locking the device shortly after 'modprobe zram'. I'm guessing zramctl's --find part is running before the lock but the --size part happens while the device is in use.

Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in util-linux (Ubuntu):
status: New → Confirmed
Revision history for this message
Björn (bjmi) wrote (last edit ):

Thank you very much for sharing your findings, now I can stop troubleshooting my script.
Your proposed workaround with sleep 0.1 works.
I'm affected by this bug in UnraidOS that is based on Slackware Linux.
I got "zramctl: /dev/zram0: failed to reset: Device or resource busy" when
    modprobe zram
    zramctl -f -s 8G -a zstd
was used.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.