10 Dec, 2014

1 commit

  • When a CPU is hotplugged, the current blk-mq spews a warning like:

    kobject '(null)' (ffffe8ffffc8b5d8): tried to add an uninitialized object, something is seriously wrong.
    CPU: 1 PID: 1386 Comm: systemd-udevd Not tainted 3.18.0-rc7-2.g088d59b-default #1
    Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.7.5-20140531_171129-lamiak 04/01/2014
    0000000000000000 0000000000000002 ffffffff81605f07 ffffe8ffffc8b5d8
    ffffffff8132c7a0 ffff88023341d370 0000000000000020 ffff8800bb05bd58
    ffff8800bb05bd08 000000000000a0a0 000000003f441940 0000000000000007
    Call Trace:
    [] dump_trace+0x86/0x330
    [] show_stack_log_lvl+0x94/0x170
    [] show_stack+0x21/0x50
    [] dump_stack+0x41/0x51
    [] kobject_add+0xa0/0xb0
    [] blk_mq_register_hctx+0x91/0xb0
    [] blk_mq_sysfs_register+0x3e/0x60
    [] blk_mq_queue_reinit_notify+0xf8/0x190
    [] notifier_call_chain+0x4c/0x70
    [] cpu_notify+0x23/0x50
    [] _cpu_up+0x157/0x170
    [] cpu_up+0x89/0xb0
    [] cpu_subsys_online+0x35/0x80
    [] device_online+0x5d/0xa0
    [] online_store+0x75/0x80
    [] kernfs_fop_write+0xda/0x150
    [] vfs_write+0xb2/0x1f0
    [] SyS_write+0x42/0xb0
    [] system_call_fastpath+0x16/0x1b
    [] 0x7f0132fb24e0

    This is indeed because of an uninitialized kobject for blk_mq_ctx.
    The blk_mq_ctx kobjects are initialized in blk_mq_sysfs_init(), but it
    goes loop over hctx_for_each_ctx(), i.e. it initializes only for
    online CPUs. Thus, when a CPU is hotplugged, the ctx for the newly
    onlined CPU is registered without initialization.

    This patch fixes the issue by initializing the all ctx kobjects
    belonging to each queue.

    Bugzilla: https://bugzilla.novell.com/show_bug.cgi?id=908794
    Cc:
    Signed-off-by: Takashi Iwai
    Signed-off-by: Jens Axboe

    Takashi Iwai
     

25 Sep, 2014

1 commit

  • blk-mq uses percpu_ref for its usage counter which tracks the number
    of in-flight commands and used to synchronously drain the queue on
    freeze. percpu_ref shutdown takes measureable wallclock time as it
    involves a sched RCU grace period. This means that draining a blk-mq
    takes measureable wallclock time. One would think that this shouldn't
    matter as queue shutdown should be a rare event which takes place
    asynchronously w.r.t. userland.

    Unfortunately, SCSI probing involves synchronously setting up and then
    tearing down a lot of request_queues back-to-back for non-existent
    LUNs. This means that SCSI probing may take above ten seconds when
    scsi-mq is used.

    [ 0.949892] scsi host0: Virtio SCSI HBA
    [ 1.007864] scsi 0:0:0:0: Direct-Access QEMU QEMU HARDDISK 1.1. PQ: 0 ANSI: 5
    [ 1.021299] scsi 0:0:1:0: Direct-Access QEMU QEMU HARDDISK 1.1. PQ: 0 ANSI: 5
    [ 1.520356] tsc: Refined TSC clocksource calibration: 2491.910 MHz

    [ 16.186549] sd 0:0:0:0: Attached scsi generic sg0 type 0
    [ 16.190478] sd 0:0:1:0: Attached scsi generic sg1 type 0
    [ 16.194099] osd: LOADED open-osd 0.2.1
    [ 16.203202] sd 0:0:0:0: [sda] 31457280 512-byte logical blocks: (16.1 GB/15.0 GiB)
    [ 16.208478] sd 0:0:0:0: [sda] Write Protect is off
    [ 16.211439] sd 0:0:0:0: [sda] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA
    [ 16.218771] sd 0:0:1:0: [sdb] 31457280 512-byte logical blocks: (16.1 GB/15.0 GiB)
    [ 16.223264] sd 0:0:1:0: [sdb] Write Protect is off
    [ 16.225682] sd 0:0:1:0: [sdb] Write cache: enabled, read cache: enabled, doesn't support DPO or FUA

    This is also the reason why request_queues start in bypass mode which
    is ended on blk_register_queue() as shutting down a fully functional
    queue also involves a RCU grace period and the queues for non-existent
    SCSI devices never reach registration.

    blk-mq basically needs to do the same thing - start the mq in a
    degraded mode which is faster to shut down and then make it fully
    functional only after the queue reaches registration. percpu_ref
    recently grew facilities to force atomic operation until explicitly
    switched to percpu mode, which can be used for this purpose. This
    patch makes blk-mq initialize q->mq_usage_counter in atomic mode and
    switch it to percpu mode only once blk_register_queue() is reached.

    Note that this issue was previously worked around by 0a30288da1ae
    ("blk-mq, percpu_ref: implement a kludge for SCSI blk-mq stall during
    probe") for v3.17. The temp fix was reverted in preparation of adding
    persistent atomic mode to percpu_ref by 9eca80461a45 ("Revert "blk-mq,
    percpu_ref: implement a kludge for SCSI blk-mq stall during probe"").
    This patch and the prerequisite percpu_ref changes will be merged
    during v3.18 devel cycle.

    Signed-off-by: Tejun Heo
    Reported-by: Christoph Hellwig
    Link: http://lkml.kernel.org/g/20140919113815.GA10791@lst.de
    Fixes: add703fda981 ("blk-mq: use percpu_ref for mq usage count")
    Reviewed-by: Kent Overstreet
    Cc: Jens Axboe
    Cc: Johannes Weiner

    Tejun Heo
     

31 May, 2014

1 commit


30 May, 2014

1 commit

  • Currently blk-mq registers all the hardware queues in sysfs,
    regardless of whether it uses them (e.g. they have CPU mappings)
    or not. The unused hardware queues lack the cpux/ directories,
    and the other sysfs entries (like active, pending, etc) are all
    zeroes.

    Change this so that sysfs correctly reflects the current mappings
    of the hardware queues.

    Signed-off-by: Jens Axboe

    Jens Axboe
     

14 May, 2014

1 commit

  • This adds support for active queue tracking, meaning that the
    blk-mq tagging maintains a count of active users of a tag set.
    This allows us to maintain a notion of fairness between users,
    so that we can distribute the tag depth evenly without starving
    some users while allowing others to try unfair deep queues.

    If sharing of a tag set is detected, each hardware queue will
    track the depth of its own queue. And if this exceeds the total
    depth divided by the number of active queues, the user is actively
    throttled down.

    The active queue count is done lazily to avoid bouncing that data
    between submitter and completer. Each hardware queue gets marked
    active when it allocates its first tag, and gets marked inactive
    when 1) the last tag is cleared, and 2) the queue timeout grace
    period has passed.

    Signed-off-by: Jens Axboe

    Jens Axboe
     

25 Apr, 2014

1 commit

  • The blk-mq code is using it's own version of the I/O completion affinity
    tunables, which causes a few issues:

    - the rq_affinity sysfs file doesn't work for blk-mq devices, even if it
    still is present, thus breaking existing tuning setups.
    - the rq_affinity = 1 mode, which is the defauly for legacy request based
    drivers isn't implemented at all.
    - blk-mq drivers don't implement any completion affinity with the default
    flag settings.

    This patches removes the blk-mq ipi_redirect flag and sysfs file, as well
    as the internal BLK_MQ_F_SHOULD_IPI flag and replaces it with code that
    respects the queue-wide rq_affinity flags and also implements the
    rq_affinity = 1 mode.

    This means I/O completion affinity can now only be tuned block-queue wide
    instead of per context, which seems more sensible to me anyway.

    Signed-off-by: Christoph Hellwig
    Signed-off-by: Jens Axboe

    Christoph Hellwig
     

10 Apr, 2014

1 commit


21 Mar, 2014

1 commit


07 Dec, 2013

1 commit

  • All objects, which are allocated in blk_mq_register_disk, must be
    released in blk_mq_unregister_disk.

    I use a KVM virtual machine and virtio disk to reproduce this issue.

    kmemleak: 18 new suspected memory leaks (see /sys/kernel/debug/kmemleak)
    $ cat /sys/kernel/debug/kmemleak | head -n 30
    unreferenced object 0xffff8800b6636150 (size 8):
    comm "kworker/0:2", pid 65, jiffies 4294809903 (age 86.358s)
    hex dump (first 8 bytes):
    76 69 72 74 69 6f 34 00 virtio4.
    backtrace:
    [] kmemleak_alloc+0x4e/0xb0
    [] __kmalloc_track_caller+0xf5/0x260
    [] kstrdup+0x31/0x60
    [] sysfs_new_dirent+0x2e/0x140
    [] create_dir+0x38/0xe0
    [] sysfs_create_dir_ns+0x73/0xc0
    [] kobject_add_internal+0xc9/0x340
    [] kobject_add+0x65/0xb0
    [] device_add+0x128/0x660
    [] device_register+0x1a/0x20
    [] register_virtio_device+0x98/0xe0
    [] virtio_pci_probe+0x12e/0x1c0
    [] local_pci_probe+0x45/0xa0
    [] pci_device_probe+0x121/0x130
    [] driver_probe_device+0x87/0x390
    [] __device_attach+0x3b/0x40
    unreferenced object 0xffff8800b65aa1d8 (size 144):

    Fixes: 320ae51feed5 (blk-mq: new multi-queue block IO queueing mechanism)
    Cc: Jens Axboe
    Signed-off-by: Andrey Vagin
    Signed-off-by: Jens Axboe

    Andrey Vagin
     

25 Oct, 2013

1 commit

  • Linux currently has two models for block devices:

    - The classic request_fn based approach, where drivers use struct
    request units for IO. The block layer provides various helper
    functionalities to let drivers share code, things like tag
    management, timeout handling, queueing, etc.

    - The "stacked" approach, where a driver squeezes in between the
    block layer and IO submitter. Since this bypasses the IO stack,
    driver generally have to manage everything themselves.

    With drivers being written for new high IOPS devices, the classic
    request_fn based driver doesn't work well enough. The design dates
    back to when both SMP and high IOPS was rare. It has problems with
    scaling to bigger machines, and runs into scaling issues even on
    smaller machines when you have IOPS in the hundreds of thousands
    per device.

    The stacked approach is then most often selected as the model
    for the driver. But this means that everybody has to re-invent
    everything, and along with that we get all the problems again
    that the shared approach solved.

    This commit introduces blk-mq, block multi queue support. The
    design is centered around per-cpu queues for queueing IO, which
    then funnel down into x number of hardware submission queues.
    We might have a 1:1 mapping between the two, or it might be
    an N:M mapping. That all depends on what the hardware supports.

    blk-mq provides various helper functions, which include:

    - Scalable support for request tagging. Most devices need to
    be able to uniquely identify a request both in the driver and
    to the hardware. The tagging uses per-cpu caches for freed
    tags, to enable cache hot reuse.

    - Timeout handling without tracking request on a per-device
    basis. Basically the driver should be able to get a notification,
    if a request happens to fail.

    - Optional support for non 1:1 mappings between issue and
    submission queues. blk-mq can redirect IO completions to the
    desired location.

    - Support for per-request payloads. Drivers almost always need
    to associate a request structure with some driver private
    command structure. Drivers can tell blk-mq this at init time,
    and then any request handed to the driver will have the
    required size of memory associated with it.

    - Support for merging of IO, and plugging. The stacked model
    gets neither of these. Even for high IOPS devices, merging
    sequential IO reduces per-command overhead and thus
    increases bandwidth.

    For now, this is provided as a potential 3rd queueing model, with
    the hope being that, as it matures, it can replace both the classic
    and stacked model. That would get us back to having just 1 real
    model for block devices, leaving the stacked approach to dm/md
    devices (as it was originally intended).

    Contributions in this patch from the following people:

    Shaohua Li
    Alexander Gordeev
    Christoph Hellwig
    Mike Christie
    Matias Bjorling
    Jeff Moyer

    Acked-by: Christoph Hellwig
    Signed-off-by: Jens Axboe

    Jens Axboe