Received: by 10.213.65.68 with SMTP id h4csp3157014imn; Mon, 2 Apr 2018 23:08:52 -0700 (PDT) X-Google-Smtp-Source: AIpwx48HQWshmyKuuXV6ochM68lcZ0wLjlVDrh0lX2gr08nwmt8+nKRYC4ECFRQCjsEogoCnnL98 X-Received: by 10.101.70.8 with SMTP id v8mr8136193pgq.336.1522735732868; Mon, 02 Apr 2018 23:08:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1522735732; cv=none; d=google.com; s=arc-20160816; b=VaL1CAfhwaewKRQcpa3Ilpj9kcaq4aHCjV/jW9dN4ePSq+2VvwVk0E5eHjLFcs9EOw aTZGxqOTTAgFTnDGsINUi6a1DzpcgVLeAx7NSsKJbCoZJPS/UT2M1fNytTvR0eHzh9R2 qYXY1UWfi3JalSGqxcZendbFy7Od6GNAKN8uMhAM1fwtw+XcZ1JM9RR6WirYPYNOK26r leWJK2PnrQpUP+qoFN0Koc6MH6+NZNiXVHSlWJALxt8PHkdIahwTinG/daYsUyzt2QA4 RmtzmjQxiHrw0Cs2VKdXhtgwB5CkPVYkQ0EweJDTat37YVdlVdWq/gqS8u13OPIEsJv6 2NSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from :arc-authentication-results; bh=MTVns+ajkvLztpil4MXKAzbdodEnTVuXvCEK3G7yGLI=; b=PfAwX7hEw4fsQpnstRA5NfEJmPrbTpiUXPu5hO5lelPoULqSypzo07QOWYJ08j0FmV EADhbC6/G54COeQvq9fs0BIGiBag5Xj9vCdGEfuerD6jyAjg0pEePGv1gdvQ6x545AIp ZgN1usknH6hFHlBaXZ0+zagr8HN472+FgwTvSJCy3ULBVpEWr7kssYfoVwfPiuzaE3i4 vocjwuVu8ESpNqEntGTHkYemb32A3JPV+V+x+1Ho6vVbdPvb7sYZAABNxYZbwcYGsp+3 TYZDBIwf3qA7eZdv3ikbq0WZEu09xWQk0H7k4ijFv/LBac3/UiI3aougnEL5CKH0uUZ3 LENw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v24si1551599pff.274.2018.04.02.23.08.38; Mon, 02 Apr 2018 23:08:52 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752788AbeDCGHd (ORCPT + 99 others); Tue, 3 Apr 2018 02:07:33 -0400 Received: from mxhk.zte.com.cn ([63.217.80.70]:16978 "EHLO mxhk.zte.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750736AbeDCGHb (ORCPT ); Tue, 3 Apr 2018 02:07:31 -0400 Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id 8305AA5A7354FE320009; Tue, 3 Apr 2018 14:07:29 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id w3367Ktn058615; Tue, 3 Apr 2018 14:07:20 +0800 (GMT-8) (envelope-from wen.yang99@zte.com.cn) Received: from localhost.localdomain ([10.75.10.200]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2018040314072382-4189560 ; Tue, 3 Apr 2018 14:07:23 +0800 From: Wen Yang To: jejb@linux.vnet.ibm.com, martin.petersen@oracle.com Cc: linux-scsi@vger.kernel.org, linux-kernel@vger.kernel.org, Bart.VanAssche@wdc.com, pmladek@suse.com, sergey.senozhatsky.work@gmail.com, tj@kernel.org, jiang.biao2@zte.com.cn, zhong.weidong@zte.com.cn, wen.yang99@zte.com.cn, Tan Hu , JasonYan Subject: [PATCH v3] scsi: Introduce sdev_printk_ratelimited to throttle frequent printk Date: Tue, 3 Apr 2018 14:04:40 +0800 Message-Id: <1522735480-159023-1-git-send-email-wen.yang99@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2018-04-03 14:07:23, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2018-04-03 14:07:16, Serialize complete at 2018-04-03 14:07:16 X-MAIL: mse01.zte.com.cn w3367Ktn058615 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There would be so many same lines printed by frequent printk if one disk went wrong, like, [ 546.185242] sd 0:1:0:0: rejecting I/O to offline device [ 546.185258] sd 0:1:0:0: rejecting I/O to offline device [ 546.185280] sd 0:1:0:0: rejecting I/O to offline device [ 546.185307] sd 0:1:0:0: rejecting I/O to offline device [ 546.185334] sd 0:1:0:0: rejecting I/O to offline device [ 546.185364] sd 0:1:0:0: rejecting I/O to offline device [ 546.185390] sd 0:1:0:0: rejecting I/O to offline device [ 546.185410] sd 0:1:0:0: rejecting I/O to offline device For slow serial console, the frequent printk may be blocked for a long time, and if any spin_lock has been acquired before the printk like in scsi_request_fn, watchdog could be triggered. Related disscussion can be found here, https://bugzilla.kernel.org/show_bug.cgi?id=199003 And Petr brought the idea to throttle the frequent printk, it's useless to print the same lines frequently after all. v2: fix some typos v3: limit the print only for the same device Suggested-by: Petr Mladek Suggested-by: Sergey Senozhatsky Signed-off-by: Wen Yang Signed-off-by: Jiang Biao Signed-off-by: Tan Hu Reviewed-by: Bart Van Assche CC: BartVanAssche CC: Petr Mladek CC: Sergey Senozhatsky CC: Martin K. Petersen CC: "James E.J. Bottomley" CC: Tejun Heo CC: JasonYan --- drivers/scsi/scsi_lib.c | 6 +++--- drivers/scsi/scsi_scan.c | 3 +++ include/scsi/scsi_device.h | 8 ++++++++ 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c index c84f931..f77e801 100644 --- a/drivers/scsi/scsi_lib.c +++ b/drivers/scsi/scsi_lib.c @@ -1301,7 +1301,7 @@ static int scsi_setup_cmnd(struct scsi_device *sdev, struct request *req) * commands. The device must be brought online * before trying any recovery commands. */ - sdev_printk(KERN_ERR, sdev, + sdev_printk_ratelimited(KERN_ERR, sdev, "rejecting I/O to offline device\n"); ret = BLKPREP_KILL; break; @@ -1310,7 +1310,7 @@ static int scsi_setup_cmnd(struct scsi_device *sdev, struct request *req) * If the device is fully deleted, we refuse to * process any commands as well. */ - sdev_printk(KERN_ERR, sdev, + sdev_printk_ratelimited(KERN_ERR, sdev, "rejecting I/O to dead device\n"); ret = BLKPREP_KILL; break; @@ -1802,7 +1802,7 @@ static void scsi_request_fn(struct request_queue *q) break; if (unlikely(!scsi_device_online(sdev))) { - sdev_printk(KERN_ERR, sdev, + sdev_printk_ratelimited(KERN_ERR, sdev, "rejecting I/O to offline device\n"); scsi_kill_request(req, q); continue; diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c index 0880d97..a6da935 100644 --- a/drivers/scsi/scsi_scan.c +++ b/drivers/scsi/scsi_scan.c @@ -288,6 +288,9 @@ static struct scsi_device *scsi_alloc_sdev(struct scsi_target *starget, scsi_change_queue_depth(sdev, sdev->host->cmd_per_lun ? sdev->host->cmd_per_lun : 1); + /* Enable message ratelimiting. Default is 10 messages per 5 secs. */ + ratelimit_state_init(&sdev->sdev_ratelimit_state, + DEFAULT_RATELIMIT_INTERVAL, DEFAULT_RATELIMIT_BURST); scsi_sysfs_device_initialize(sdev); if (shost->hostt->slave_alloc) { diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h index 7ae177c..f1db7f3 100644 --- a/include/scsi/scsi_device.h +++ b/include/scsi/scsi_device.h @@ -215,6 +215,8 @@ struct scsi_device { struct device sdev_gendev, sdev_dev; + struct ratelimit_state sdev_ratelimit_state; /* Ratelimit sdev messages. */ + struct execute_work ew; /* used to get process context on put */ struct work_struct requeue_work; @@ -249,6 +251,12 @@ struct scsi_device { #define sdev_printk(l, sdev, fmt, a...) \ sdev_prefix_printk(l, sdev, NULL, fmt, ##a) +#define sdev_printk_ratelimited(l, sdev, fmt, a...) \ +({ \ + if (sdev && __ratelimit(&sdev->sdev_ratelimit_state)) \ + sdev_prefix_printk(l, sdev, NULL, fmt, ##a); \ +}) + __printf(3, 4) void scmd_printk(const char *, const struct scsi_cmnd *, const char *, ...); -- 1.8.3.1