From patchwork Wed Jul 13 07:05:36 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: kernel@kyup.com X-Patchwork-Id: 9226905 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 5CA966088F for ; Wed, 13 Jul 2016 07:06:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 47E20277D9 for ; Wed, 13 Jul 2016 07:06:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3AE4027BF9; Wed, 13 Jul 2016 07:06:16 +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,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 A591C27DCD for ; Wed, 13 Jul 2016 07:06:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751523AbcGMHGM (ORCPT ); Wed, 13 Jul 2016 03:06:12 -0400 Received: from mail-wm0-f51.google.com ([74.125.82.51]:36180 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751363AbcGMHGG (ORCPT ); Wed, 13 Jul 2016 03:06:06 -0400 Received: by mail-wm0-f51.google.com with SMTP id f126so15970328wma.1 for ; Wed, 13 Jul 2016 00:05:45 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=bsTGrdgW9Q5wvUyZfMmAmAErzSS0rSDOub+RRFUruH0=; b=O7CzhSXkXJ4HFE7H5dQXQZk5380H+FN+/NTGsL5yOsmawvgY22sA4xSbBF555CpcDh xt642M00IbT0/ygFtqoq3Xb5EsQ64GU+WLcsfEiV6PWvNwE8Pjetzz+wwYWc0JJpdcct m0lCm9+8MJUOX9NQTRu/vOfLzfhlhF+xT45pu+phRlv9bT00yISatDqmroTBVn3SEmz3 9zc6oEn4Ap32Cduke5m9iPmkYvDQ/KF+Ske98t2i9xIA9lulPGhXq/rCkRCHFBBgq06V gbyrBv8rAIItbWOsKFpzVQJgyEU2e59Jh5jodt00FTNRrlk4OCyDULupX8xNoOZctGi8 SYgA== X-Gm-Message-State: ALyK8tKTACtn0nFx+6Cwdwm1DGnwIcicweAhJA0FrcVY3MUkvlyijsFJNc6j5Ayv50d1kG8J X-Received: by 10.28.126.195 with SMTP id z186mr26120898wmc.95.1468393542801; Wed, 13 Jul 2016 00:05:42 -0700 (PDT) Received: from localhost.localdomain (admins.1h.com. [82.118.240.130]) by smtp.gmail.com with ESMTPSA id z5sm26033424wme.5.2016.07.13.00.05.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 13 Jul 2016 00:05:41 -0700 (PDT) From: Nikolay Borisov To: dsterba@suse.cz Cc: linux-btrfs@vger.kernel.org, Nikolay Borisov Subject: [PATCH] btrfs: Ratelimit message printing Date: Wed, 13 Jul 2016 10:05:36 +0300 Message-Id: <1468393536-25798-1-git-send-email-kernel@kyup.com> X-Mailer: git-send-email 1.7.1 In-Reply-To: <20160712160126.GD10595@suse.cz> References: <20160712160126.GD10595@suse.cz> Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently most of the messages btrfs produce are not rate limited. Recently I came accross a case where due to FS corruption an excessive amount of printk caused the softlockup detector to trigger and reset the server. This patch does the following changes: * The message which was printed is converted to use the ratelimited version of btrfs_info function. This will prevent it from exploding in the future. * In addition to the above change, also add a sort of a "safet net" to all non-ratelimited prints by introducing separate ratelimiting for every message class when the "naked" btrfs_info is called. Signed-off-by: Nikolay Borisov --- Hello David, How about something like that? fs/btrfs/file-item.c | 2 +- fs/btrfs/super.c | 21 +++++++++++++++++++-- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/file-item.c b/fs/btrfs/file-item.c index 62a81ee13a5f..6b58d0620e2f 100644 --- a/fs/btrfs/file-item.c +++ b/fs/btrfs/file-item.c @@ -250,7 +250,7 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root, offset + root->sectorsize - 1, EXTENT_NODATASUM); } else { - btrfs_info(BTRFS_I(inode)->root->fs_info, + btrfs_info_rl(BTRFS_I(inode)->root->fs_info, "no csum found for inode %llu start %llu", btrfs_ino(inode), offset); } diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index 60e7179ed4b7..01a87dd89732 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -184,6 +184,17 @@ static const char * const logtypes[] = { "debug", }; +static struct ratelimit_state printk_limits[] = { + RATELIMIT_STATE_INIT(printk_limits[0], DEFAULT_RATELIMIT_INTERVAL, 100), + RATELIMIT_STATE_INIT(printk_limits[1], DEFAULT_RATELIMIT_INTERVAL, 100), + RATELIMIT_STATE_INIT(printk_limits[2], DEFAULT_RATELIMIT_INTERVAL, 100), + RATELIMIT_STATE_INIT(printk_limits[3], DEFAULT_RATELIMIT_INTERVAL, 100), + RATELIMIT_STATE_INIT(printk_limits[4], DEFAULT_RATELIMIT_INTERVAL, 100), + RATELIMIT_STATE_INIT(printk_limits[5], DEFAULT_RATELIMIT_INTERVAL, 100), + RATELIMIT_STATE_INIT(printk_limits[6], DEFAULT_RATELIMIT_INTERVAL, 100), + RATELIMIT_STATE_INIT(printk_limits[7], DEFAULT_RATELIMIT_INTERVAL, 100), +}; + void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) { struct super_block *sb = fs_info->sb; @@ -192,6 +203,7 @@ void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) va_list args; const char *type = logtypes[4]; int kern_level; + struct ratelimit_state *ratelimit; va_start(args, fmt); @@ -202,13 +214,18 @@ void btrfs_printk(const struct btrfs_fs_info *fs_info, const char *fmt, ...) lvl[size] = '\0'; fmt += size; type = logtypes[kern_level - '0']; - } else + ratelimit = &printk_limits[kern_level - '0']; + } else { *lvl = '\0'; + /* Default to debug output */ + ratelimit = &printk_limits[7]; + } vaf.fmt = fmt; vaf.va = &args; - printk("%sBTRFS %s (device %s): %pV\n", lvl, type, sb->s_id, &vaf); + if (__ratelimit(ratelimit)) + printk("%sBTRFS %s (device %s): %pV\n", lvl, type, sb->s_id, &vaf); va_end(args); }