From patchwork Wed Feb 8 05:41:06 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Song Liu X-Patchwork-Id: 9561799 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 6AF2560434 for ; Wed, 8 Feb 2017 06:38:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5F28528490 for ; Wed, 8 Feb 2017 06:38:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 53BAF2849A; Wed, 8 Feb 2017 06:38:09 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, 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 DE90428490 for ; Wed, 8 Feb 2017 06:38:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932143AbdBHGiI (ORCPT ); Wed, 8 Feb 2017 01:38:08 -0500 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:37912 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932093AbdBHGiH (ORCPT ); Wed, 8 Feb 2017 01:38:07 -0500 Received: from pps.filterd (m0044008.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.20/8.16.0.20) with SMTP id v185cw0K017361 for ; Tue, 7 Feb 2017 21:41:16 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-type; s=facebook; bh=K2sHVOIZegE2ftUnaVJ0fUNdMnaohNG0BHxatvnsdiw=; b=Rk31C8Y9q27Q4HExFphjhuWz3bzKa2ZA/fRIMW72kB9pI3ZsgsQRQEFZV9TwEJpSVWN8 nDHxLlqEZ/hREi6wpOYzFzdI13FP28mK1VGhQu+0RMbcvO5AHf2PUyFkNjA6JTWrvgsM xdB5sASMhHlqfrynaqPLPfM3Np+HYS+w4Dw= Received: from mail.thefacebook.com ([199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 28fjcwj4te-1 (version=TLSv1 cipher=ECDHE-RSA-AES256-SHA bits=256 verify=NOT) for ; Tue, 07 Feb 2017 21:41:16 -0800 Received: from mx-out.facebook.com (192.168.52.123) by PRN-CHUB03.TheFacebook.com (192.168.16.13) with Microsoft SMTP Server (TLS) id 14.3.294.0; Tue, 7 Feb 2017 21:41:15 -0800 Received: from facebook.com (2401:db00:11:d0be:face:0:17:0) by mx-out.facebook.com (10.212.232.59) with ESMTP id 348f28aeedc111e6999f0002c991e86a-b81f5a50 for ; Tue, 07 Feb 2017 21:41:14 -0800 Received: by devbig334.prn1.facebook.com (Postfix, from userid 4523) id 4519542A2AEF; Tue, 7 Feb 2017 21:41:14 -0800 (PST) Smtp-Origin-Hostprefix: devbig From: Song Liu Smtp-Origin-Hostname: devbig334.prn1.facebook.com To: CC: Song Liu Smtp-Origin-Cluster: prn1c29 Subject: [PATCH] scsi/sd: release scan_mutex during sync_cache and start_stop Date: Tue, 7 Feb 2017 21:41:06 -0800 Message-ID: <20170208054106.2156053-1-songliubraving@fb.com> X-Mailer: git-send-email 2.9.3 X-FB-Internal: Safe MIME-Version: 1.0 X-Proofpoint-Spam-Reason: safe X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, , definitions=2017-02-08_03:, , signatures=0 Sender: linux-scsi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-scsi@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When a device is deleted through sysfs handle "delete", the code locks shost->scan_mutex. If multiple devices are deleted at the same time, these deletes will be handled in series. On the other hand, sd_shutdown() sometimes issues long latency commands: sync cache and start_stop. It is not necessary for these commands to run in series. To reduce latency of parallel "delete" requests, this patch unlock shost->scan_mutex before long latency commands and relock the mutex after the command. Signed-off-by: Song Liu --- drivers/scsi/sd.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 2ea3568..39aa209 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3241,6 +3241,8 @@ static int sd_start_stop_device(struct scsi_disk *sdkp, int start) static void sd_shutdown(struct device *dev) { struct scsi_disk *sdkp = dev_get_drvdata(dev); + struct scsi_device *sdev = sdkp->device; + struct Scsi_Host *shost = sdev->host; if (!sdkp) return; /* this can happen */ @@ -3249,13 +3251,17 @@ static void sd_shutdown(struct device *dev) return; if (sdkp->WCE && sdkp->media_present) { + mutex_unlock(&shost->scan_mutex); sd_printk(KERN_NOTICE, sdkp, "Synchronizing SCSI cache\n"); sd_sync_cache(sdkp); + mutex_lock(&shost->scan_mutex); } if (system_state != SYSTEM_RESTART && sdkp->device->manage_start_stop) { + mutex_unlock(&shost->scan_mutex); sd_printk(KERN_NOTICE, sdkp, "Stopping disk\n"); sd_start_stop_device(sdkp, 0); + mutex_lock(&shost->scan_mutex); } }