From patchwork Tue Mar 28 06:28:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Omar Sandoval X-Patchwork-Id: 9648187 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 1F685601D7 for ; Tue, 28 Mar 2017 06:29:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 10D3520008 for ; Tue, 28 Mar 2017 06:29:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 05B9A2839B; Tue, 28 Mar 2017 06:29:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCBC6283FF for ; Tue, 28 Mar 2017 06:29:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754092AbdC1G3u (ORCPT ); Tue, 28 Mar 2017 02:29:50 -0400 Received: from mail-pg0-f54.google.com ([74.125.83.54]:34903 "EHLO mail-pg0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753925AbdC1G3t (ORCPT ); Tue, 28 Mar 2017 02:29:49 -0400 Received: by mail-pg0-f54.google.com with SMTP id 81so48592565pgh.2 for ; Mon, 27 Mar 2017 23:29:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=osandov-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=X5ZyjOU602dQYfMmtftwySb1RK6c4rk0NZknqdTMNGw=; b=j4U03D4O1nL5/Q/7iwffGtyc7DVxfzLi1KGye0YcwTW3FgVB5BjUA1rB5AIGnNT6YA aqtLx5lCgggz9c/+mB3HogjoMmY+t3f7+PesGPOhrjF3YZ4AzRRYkknJ9vKc4AonLMC4 9g3K6lE7gRzZVjCRA8JAy4z/lbmsWM/7yl4h/aHjUdHzVUQdOu6k8zlSZCaozyBiunmJ nWfjmvVwJGyx1Yy59lwTmKBcYpYbnI+NyE5EI5LS+9YNh6CqK/FwmK7kD8hKBy4T0UC6 Q7v2qyvhEUARW3mYVz4HcrOAVX2WCLQwg3PBRtkeBEuHhFrIS+rGT9rTHInQ3+ALRKuR f4Qg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=X5ZyjOU602dQYfMmtftwySb1RK6c4rk0NZknqdTMNGw=; b=oAisIq5nL21Y4eYEypwqTL08Q4qGHUtJlTihWEpM7H2GM7hm52mB89bUtIQbjsGWnZ a68sjItlvgrnloaYIlrue9B/+4AqlfcoxLxZLtvjj+zqD5U74vGMy/sFFXHn8irEEjFd FnNziaGN+vRiR0AX84HGeR0D7t+5AOHOVouk+gFJqTk/bkNPpHudIflRSCMKMW9rPQHg YjCxpl3YSlut/0HZsIz+riYcy4HhzUG5GPvY2Tr6m9biFanVmizC/B1YAwkSk7Q85f0z a8QzEZqz5PoSjfDHSVYYsQ9Vr9HlocpGfxS3Esml2XJ01vWr/2ZM6bSFqI01pmTfgWSC /llQ== X-Gm-Message-State: AFeK/H2hpHTg/depfGzyw7vTFM0+EPj1rXKUuQrn9aTqtw7sUORUv7M8le5TIyzyhqodpFcb X-Received: by 10.99.178.81 with SMTP id t17mr28276031pgo.136.1490682587943; Mon, 27 Mar 2017 23:29:47 -0700 (PDT) Received: from localhost.localdomain ([2601:602:8801:8110:e6a7:a0ff:fe0b:c9a8]) by smtp.gmail.com with ESMTPSA id n85sm4774809pfi.101.2017.03.27.23.29.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 27 Mar 2017 23:29:47 -0700 (PDT) From: Omar Sandoval To: Jens Axboe , Vivek Goyal , linux-block@vger.kernel.org Cc: kernel-team@fb.com Subject: [PATCH 1/6] hd: stop sharing request queue across multiple gendisks Date: Mon, 27 Mar 2017 23:28:42 -0700 Message-Id: X-Mailer: git-send-email 2.12.1 In-Reply-To: References: In-Reply-To: References: Sender: linux-block-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Omar Sandoval Compile-tested only. Signed-off-by: Omar Sandoval --- drivers/block/hd.c | 62 ++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/drivers/block/hd.c b/drivers/block/hd.c index 6043648da1e8..79d63b20a297 100644 --- a/drivers/block/hd.c +++ b/drivers/block/hd.c @@ -95,7 +95,7 @@ #define ICRC_ERR 0x80 /* new meaning: CRC error during transfer */ static DEFINE_SPINLOCK(hd_lock); -static struct request_queue *hd_queue; +static unsigned int hd_queue; static struct request *hd_req; #define TIMEOUT_VALUE (6*HZ) @@ -537,7 +537,7 @@ static void hd_times_out(unsigned long dummy) if (!hd_req) return; - spin_lock_irq(hd_queue->queue_lock); + spin_lock_irq(&hd_lock); reset = 1; name = hd_req->rq_disk->disk_name; printk("%s: timeout\n", name); @@ -548,7 +548,7 @@ static void hd_times_out(unsigned long dummy) hd_end_request_cur(-EIO); } hd_request(); - spin_unlock_irq(hd_queue->queue_lock); + spin_unlock_irq(&hd_lock); } static int do_special_op(struct hd_i_struct *disk, struct request *req) @@ -566,6 +566,25 @@ static int do_special_op(struct hd_i_struct *disk, struct request *req) return 1; } +static int set_next_request(void) +{ + struct request_queue *q; + int old_pos = hd_queue; + + do { + q = hd_gendisk[hd_queue]->queue; + if (++hd_queue == NR_HD) + hd_queue = 0; + if (q) { + hd_req = blk_fetch_request(q); + if (hd_req) + break; + } + } while (hd_queue != old_pos); + + return hd_req != NULL; +} + /* * The driver enables interrupts as much as possible. In order to do this, * (a) the device-interrupt is disabled before entering hd_request(), @@ -587,12 +606,9 @@ static void hd_request(void) repeat: del_timer(&device_timer); - if (!hd_req) { - hd_req = blk_fetch_request(hd_queue); - if (!hd_req) { - do_hd = NULL; - return; - } + if (!hd_req && !set_next_request()) { + do_hd = NULL; + return; } req = hd_req; @@ -676,7 +692,7 @@ static irqreturn_t hd_interrupt(int irq, void *dev_id) { void (*handler)(void) = do_hd; - spin_lock(hd_queue->queue_lock); + spin_lock(&hd_lock); do_hd = NULL; del_timer(&device_timer); @@ -684,7 +700,7 @@ static irqreturn_t hd_interrupt(int irq, void *dev_id) handler = unexpected_hd_interrupt; handler(); - spin_unlock(hd_queue->queue_lock); + spin_unlock(&hd_lock); return IRQ_HANDLED; } @@ -700,16 +716,8 @@ static int __init hd_init(void) if (register_blkdev(HD_MAJOR, "hd")) return -1; - hd_queue = blk_init_queue(do_hd_request, &hd_lock); - if (!hd_queue) { - unregister_blkdev(HD_MAJOR, "hd"); - return -ENOMEM; - } - - blk_queue_max_hw_sectors(hd_queue, 255); init_timer(&device_timer); device_timer.function = hd_times_out; - blk_queue_logical_block_size(hd_queue, 512); if (!NR_HD) { /* @@ -742,7 +750,11 @@ static int __init hd_init(void) sprintf(disk->disk_name, "hd%c", 'a'+drive); disk->private_data = p; set_capacity(disk, p->head * p->sect * p->cyl); - disk->queue = hd_queue; + disk->queue = blk_init_queue(do_hd_request, &hd_lock); + if (!disk->queue) + goto Enomem; + blk_queue_max_hw_sectors(disk->queue, 255); + blk_queue_logical_block_size(disk->queue, 512); p->unit = drive; hd_gendisk[drive] = disk; printk("%s: %luMB, CHS=%d/%d/%d\n", @@ -781,11 +793,15 @@ static int __init hd_init(void) out: del_timer(&device_timer); unregister_blkdev(HD_MAJOR, "hd"); - blk_cleanup_queue(hd_queue); return -1; Enomem: - while (drive--) - put_disk(hd_gendisk[drive]); + for (drive = 0; drive < NR_HD; drive++) { + if (hd_gendisk[drive]) { + if (hd_gendisk[drive]->queue) + blk_cleanup_queue(hd_gendisk[drive]->queue); + put_disk(hd_gendisk[drive]); + } + } goto out; }