Improving kernel scheduler with SSD in Ubuntu 10.10

Discussion in 'Linux' started by ags, Nov 2, 2010.

  1. ags

    ags

    Joined:
    Jul 22, 2008
    Messages:
    34
    Likes Received:
    0
    For SSD devices the kernel scheduler has never been totally optimal. For my Acer Aspire One ZG5 (A110) with an aftermarket SSD upgrade, I have played with adding elevator=noop and elevator=deadline to GRUB, but it's still a bit of a kludge.

    The newer kernels are meant to detect the SSD and adjust the scheduler automatically. However for many cheaper SSD, like mine, the kernel can't seem to autodetect the SSD. For a a drive /dev/sda/ the autodetect is shown by:
    Code:
    $ cat /sys/block/sda/queue/rotational
    
    An SSD device should '0' for non-rotational.

    To change the kernel parameter we could do 'echo 0 > /sys/block/sda/queue/rotational', but that would have to occur after the boot process. A better approach is to use udev.

    First of all we need to get some unique drive attributes so that udev can identify the drive on initialisation. This command will show all the attributes for my SSD on /dev/sda1:
    Code:
    $ udevadm info -a -p $(udevadm info -q path /dev/sda1)
    
    Looking at device  '/devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0/block/sda/sda1':
    
      SUBSYSTEM=="block"
      ...
    
    Looking at parent device '/devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0/block/sda':
    ...
    
    Looking at parent device '/devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0/block':
    ...
    
    Looking at parent device '/devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0':
    
      ATTRS{vendor}=="ATA     "
      ATTRS{model}=="Flash Module     "
      ...
    
    Looking at parent device '/devices/pci0000:00/0000:00:1f.2/host1/target1:0:0':
    ...
    
    (Entries are snipped for brevity)

    Apparently my SSD vendor is called 'ATA', and the model is 'Flash Module'. I guess it really was a cheap SSD, but it's not very imaginative naming!

    Now choosing some unique identifying attributes - SUBSYSTEM and ATTRS{vendor} (from a parent) - we can write a udev rule that changes the kernel flag:
    Code:
    SUBSYSTEM=="block", ATTRS{vendor}=="ATA", ATTR{queue/rotational}="0"
    
    You don't have to allow for the whitespace after 'ATA' in the earlier listing above.

    I saved this file as 'lib/udev/rules.d/70-SSD.rules' along with the other udev rules.

    Now to test it all works. No need to reboot, inotify will 'see' the new udev rule immediately...:
    Code:
    $ sudo udevadm test /sys/block/sda
    ...
    parse_file: reading 'lib/udev/rules.d/70-SSD.rules as rules file
    ...
    udev_rules_apply_to_event: ATTR '/sys/devices/.../block/sda/queue/rotational' writing '0' /lib/.../70-SSD.rules:1
    
    (Entries are snipped for brevity)

    Yep, it works.

    So, how does it feel? Boot up seems about the same, but the system /feels/ more responsive and snappy. I notice that disk intensive operations such as apt-get will now often return the command prompt, but the HDD light will keep flashing for a while. I guess the kernel is caching writes more often.
     
    ags, Nov 2, 2010
    #1
  2. ags

    lordofthemoon

    Joined:
    Dec 14, 2008
    Messages:
    10
    Likes Received:
    0
    Location:
    Glasgow, Scotland
    There appears to be a bug in your udevadm line below. The following worked for me:

    Code:
    $ udevadm info -a -p $(udevadm info -q path -n /dev/sda1)
     
    lordofthemoon, Nov 4, 2010
    #2
  3. ags

    rockfrog

    Joined:
    Mar 4, 2009
    Messages:
    18
    Likes Received:
    0
    I couldn't get the udev rules to work under 10.04. So I added the following to /etc/rc.local:

    Code:
    echo 0 > /sys/block/sda/queue/rotational
    Didn't hurt :)
     
    rockfrog, Nov 18, 2010
    #3
  4. ags

    ags

    Joined:
    Jul 22, 2008
    Messages:
    34
    Likes Received:
    0
    That will work, but you won't get any benefit during system boot up because /etc/rc.local is the last file to be processed after boot. By comparison the udev rules are processed as the drive is actually mounted.
     
    ags, Nov 25, 2010
    #4
  5. ags

    jango

    Joined:
    Aug 2, 2008
    Messages:
    307
    Likes Received:
    0
    What are the beneficts to do this???
     
    jango, Nov 25, 2010
    #5
  6. ags

    rockfrog

    Joined:
    Mar 4, 2009
    Messages:
    18
    Likes Received:
    0
    Of course, but I just couldn't get the udev rules to work...
     
    rockfrog, Nov 30, 2010
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.