Results 1 to 9 of 9

Thread: Trimming and scrubbing btrfs volumes

  1. #1

    Question Trimming and scrubbing btrfs volumes

    Once a month I have script that scrubs and trims the SSDs with btrfs.

    In LEAP 42.3 this was not a problem.
    In LEAP 15.0 the OS keeps changing the /dev/sd* assignments at each boot. It makes the pre-recorded /dev/ values incorrect resulting in errors like below.

    Code:
    ERROR: cannot check /dev/sdb2: No such file or directory
    ERROR: '/dev/sdb2' is not a mounted btrfs device
    I can see no other option for specifying a volume besides "/dev/sdXN".

    Is there another way to perform these functions?

    The script:
    Code:
    LOGDIR="/home/xxx/logs"
    LOG="${LOGDIR}/disk-scrub.log"
    SCRUB="/usr/sbin/btrfs scrub";
    DATE="date +%Y%m%dT%H:%M:%S"
    
    DISKLIST="sdb2 sdb3 sdb4 sdc1 sdd1"
    
    echo Volume scrub began `$DATE` >> ${LOG}
    for dsk in $DISKLIST
    do
        echo Scrubbing ${dsk} >>  ${LOG}
        txt="${SCRUB} start -Bd /dev/${dsk}"
        echo $txt >> ${LOG}
        $txt >> ${LOG}
    done
    #
    echo Volume SSD TRIM began `$DATE` >> ${LOG}
    txt="/sbin/fstrim -v -a"
    echo $txt >>  ${LOG}
    $txt >>  ${LOG}

  2. #2
    Join Date
    Jun 2008
    Location
    Groningen, Netherlands
    Posts
    20,187
    Blog Entries
    14

    Default Re: Trimming and scrubbing btrfs volumes

    Why would you do this manually, the system by default takes care of trimming etc.
    ° Appreciate my reply? Click the star and let me know why.

    ° Perfection is not gonna happen. No way.

    https://en.opensuse.org/openSUSE:Board#Members
    http://en.opensuse.org/User:Knurpht
    http://nl.opensuse.org/Gebruiker:Knurpht

  3. #3

    Default Re: Trimming and scrubbing btrfs volumes

    Quote Originally Posted by Knurpht View Post
    Why would you do this manually, the system by default takes care of trimming etc.
    Originally it did not. Which is why the script was created.

    How do I determine if the system is indeed performing these functions?

  4. #4
    Join Date
    Jun 2008
    Location
    Groningen, Netherlands
    Posts
    20,187
    Blog Entries
    14

    Default Re: Trimming and scrubbing btrfs volumes

    Quote Originally Posted by jimoe666 View Post
    Originally it did not. Which is why the script was created.

    How do I determine if the system is indeed performing these functions?
    Have a look at the sysemd services re. btrfs.

    But, where did you get the system wouldn't ? Asking since we see quite a lot of people using things from a "computertips" site by someone that ( I know ) doesn't even run openSUSE and lets people do things manually that the system by default already does. Playing with trim, swappiness, that kind of stuff. With no support at all, so we get people here for support, with systems that are by no means default installs.
    ° Appreciate my reply? Click the star and let me know why.

    ° Perfection is not gonna happen. No way.

    https://en.opensuse.org/openSUSE:Board#Members
    http://en.opensuse.org/User:Knurpht
    http://nl.opensuse.org/Gebruiker:Knurpht

  5. #5

    Default Re: Trimming and scrubbing btrfs volumes

    Quote Originally Posted by Knurpht View Post
    Have a look at the sysemd services re. btrfs.
    Hmm. btrfs-(balance, defrag, trim, scrub). They are both disabled and inactive. And cannot be enabled or made active.
    Code:
    This service cannot be enabled/disabled because it has no "install" section in the description file.
    Possibly this is why I created a manual method; I do not recall how it came about as it was 2 - 3 years ago when btrfs was just going public and SSDs were no longer expensive toys.

    I do recall being deeply annoyed by having snapper on by default, and it creating dozens of Time Machine style backups that consumed the system disk's free space; that feature is next to useless for anyone besides kernel devs. And the trim and scrub features were not enabled, far more useful features.

    Note: the system journal has been rendered largely useless because Gnome is spewing stack traces every few minutes, and systemd is spewing useless symlink notices. These now represent nearly 95% of the log.

  6. #6
    Join Date
    Jan 2014
    Location
    Erlangen
    Posts
    1,151

    Default Re: Trimming and scrubbing btrfs volumes

    Quote Originally Posted by jimoe666 View Post
    Hmm. btrfs-(balance, defrag, trim, scrub). They are both disabled and inactive. And cannot be enabled or made active.
    Code:
    This service cannot be enabled/disabled because it has no "install" section in the description file.
    Possibly this is why I created a manual method; I do not recall how it came about as it was 2 - 3 years ago when btrfs was just going public and SSDs were no longer expensive toys.

    I do recall being deeply annoyed by having snapper on by default, and it creating dozens of Time Machine style backups that consumed the system disk's free space; that feature is next to useless for anyone besides kernel devs. And the trim and scrub features were not enabled, far more useful features.

    Note: the system journal has been rendered largely useless because Gnome is spewing stack traces every few minutes, and systemd is spewing useless symlink notices. These now represent nearly 95% of the log.
    You can't enable the service, but you can enable the timer.

    Code:
    erlangen:~ # systemctl enable btrfs-balance.service 
    The unit files have no installation config (WantedBy, RequiredBy, Also, Alias
    settings in the [Install] section, and DefaultInstance for template units).
    This means they are not meant to be enabled using systemctl.
    Possible reasons for having this kind of units are:
    1) A unit may be statically enabled by being symlinked from another unit's
       .wants/ or .requires/ directory.
    2) A unit's purpose may be to act as a helper for some other unit which has
       a requirement dependency on it.
    3) A unit may be started when needed via activation (socket, path, timer,
       D-Bus, udev, scripted systemctl call, ...).
    4) In case of template units, the unit is meant to be enabled with some
       instance name specified.
    erlangen:~ # systemctl enable btrfs-balance.timer
    Created symlink /etc/systemd/system/timers.target.wants/btrfs-balance.timer → /usr/lib/systemd/system/btrfs-balance.timer.
    erlangen:~ # 
    
    AMD Athlon 4850e (2009), openSUSE 13.1, KDE 4, Intel i3-4130 (2014), i7-6700K (2016), i5-8250U (2018), openSUSE Tumbleweed, KDE Plasma 5

  7. #7

    Default Re: Trimming and scrubbing btrfs volumes

    You can't enable the service, but you can enable the timer.
    Huh! That's cool.
    Thanks!

    Of the four, btrfs-(balance, defrag, trim, scrub).timer, only defrag failed to start. Not really a problem.
    Code:
     systemctl status btrfs-defrag.timer 
    ● btrfs-defrag.timer - Defragment file data and/or directory metadata
       Loaded: loaded (/usr/lib/systemd/system/btrfs-defrag.timer; enabled; vendor preset: enabled)
       Active: inactive (dead)
      Trigger: n/a
         Docs: man:btrfs-filesystem

  8. #8
    Join Date
    Jan 2014
    Location
    Erlangen
    Posts
    1,151

    Default Re: Trimming and scrubbing btrfs volumes

    Quote Originally Posted by jimoe666 View Post
    Huh! That's cool.
    Thanks!

    Of the four, btrfs-(balance, defrag, trim, scrub).timer, only defrag failed to start. Not really a problem.
    Code:
     systemctl status btrfs-defrag.timer 
    ● btrfs-defrag.timer - Defragment file data and/or directory metadata
       Loaded: loaded (/usr/lib/systemd/system/btrfs-defrag.timer; enabled; vendor preset: enabled)
       Active: inactive (dead)
      Trigger: n/a
         Docs: man:btrfs-filesystem
    Are you sure?

    Code:
    erlangen:~ # systemctl enable btrfs-defrag.timer 
    Created symlink /etc/systemd/system/timers.target.wants/btrfs-defrag.timer → /usr/lib/systemd/system/btrfs-defrag.timer.
    erlangen:~ # systemctl start btrfs-defrag.timer 
    erlangen:~ # systemctl status btrfs-defrag.timer 
    ● btrfs-defrag.timer - Defragment file data and/or directory metadata
       Loaded: loaded (/usr/lib/systemd/system/btrfs-defrag.timer; enabled; vendor preset: enabled)
       Active: active (waiting) since Tue 2018-09-11 06:20:37 CEST; 2min 6s ago
      Trigger: Mon 2018-10-01 00:00:00 CEST; 2 weeks 5 days left
         Docs: man:btrfs-filesystem
    
    Sep 11 06:20:37 erlangen systemd[1]: Started Defragment file data and/or directory metadata.
    erlangen:~ #
    AMD Athlon 4850e (2009), openSUSE 13.1, KDE 4, Intel i3-4130 (2014), i7-6700K (2016), i5-8250U (2018), openSUSE Tumbleweed, KDE Plasma 5

  9. #9

    Default Re: Trimming and scrubbing btrfs volumes

    Quote Originally Posted by karlmistelberger View Post
    Are you sure?
    Those results are straight from the kernel's mouth.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •