From patchwork Mon Jun 13 22:37:09 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tahsin Erdogan X-Patchwork-Id: 9174611 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 15BAB6075D for ; Mon, 13 Jun 2016 22:38:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 07FFB26861 for ; Mon, 13 Jun 2016 22:38:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F0DE627C0C; Mon, 13 Jun 2016 22:38:08 +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.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=unavailable 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 A46C726861 for ; Mon, 13 Jun 2016 22:38:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1423547AbcFMWhw (ORCPT ); Mon, 13 Jun 2016 18:37:52 -0400 Received: from mail-pa0-f51.google.com ([209.85.220.51]:33123 "EHLO mail-pa0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1423291AbcFMWhv (ORCPT ); Mon, 13 Jun 2016 18:37:51 -0400 Received: by mail-pa0-f51.google.com with SMTP id b13so27341349pat.0 for ; Mon, 13 Jun 2016 15:37:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=3Ytl8hoOeJ0qQf77SSEURGXWOviW3bFh5d9Lm6HtmTU=; b=eoO0ATD7EjwKrof3bT98+jZcjGuRAD8JX5rVOEO75ciZ15kZ9FjBV+sH7LpVKjylJY IQFegVpVrPxraGG8u024/lgQslP4sIKOu0+pCn1QRLbqCd7qeN4u/H+ERf35HZb2+ZJa dfDHFI/5jOFrvYfI6inuerFRe9iAPeL5XFQBPiRQsgaLt5wUsgaGUwkj7TBomoGw2On9 j7MrbBYqvkpGeaVLsdcSE3oyOtGw9OtAidB/H2iFNFGIXxisL9TjB6MFjTkLpKlM60Sx OsOMwPP/aNwO/qwlxjml4xvPN2v/DhJd3BYH18/35qIkCiWylaW3EyuZXhlxPYC1lgTu zPLg== 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; bh=3Ytl8hoOeJ0qQf77SSEURGXWOviW3bFh5d9Lm6HtmTU=; b=N/pdtg0jinfTfpn8osSDh2LzBBHGwP0MS8FFJGaW2OtBEAxhv9DTO/ZjjG/jOSJgau 7Xouiv2sYUAHsZMIyjyBcfSQ+ODhdVJ7Ug+BKx7o17GSE9JK1XsNNDJBSGnDxJqbko7i h2iBeZEr+jG0edyYt3Db3C2/30w+VH3cKG2KES/+V1si5mspRqqbksM8fFbhnI0L0hPF NQgC3XiZIhhNAyyjD7WnBQmGBSaFacHewDXSS1c6Xa21f3R7SvzKadfz1gHgmDj0nb/j q9NmpdByEYoPWR3OCI4pO/bwGSXy5VG1Lw5KxqnI4SPjUm3xnGsjFb6q+GvDd0+upPth Dd9w== X-Gm-Message-State: ALyK8tLGlvWS6zGwHS+AhmcznL0dPPCIpFNnHtKAU8tk+qtMIZWqx8rGQ5wht+lOs1IoN4va X-Received: by 10.67.16.108 with SMTP id fv12mr24458649pad.8.1465857470194; Mon, 13 Jun 2016 15:37:50 -0700 (PDT) Received: from tahsin1.mtv.corp.google.com ([172.17.128.201]) by smtp.gmail.com with ESMTPSA id i17sm39979245pfj.77.2016.06.13.15.37.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 13 Jun 2016 15:37:45 -0700 (PDT) From: Tahsin Erdogan To: Jens Axboe , Tejun Heo , Alexander Viro Cc: Jan Kara , linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Tahsin Erdogan Subject: [PATCH] writeback: inode cgroup wb switch should skip inode with zero i_count Date: Mon, 13 Jun 2016 15:37:09 -0700 Message-Id: <1465857429-8405-1-git-send-email-tahsin@google.com> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Asynchronous wb switching of inodes takes an additional ref count on an inode to make sure inode remains valid until switchover is completed. However, it is possible that inode->i_count has already reached zero while inode is in writeback queue: ------------[ cut here ]------------ WARNING: CPU: 1 PID: 917 at fs/inode.c:397 ihold+0x2b/0x30 CPU: 1 PID: 917 Comm: kworker/u4:5 Not tainted 4.7.0-rc2+ #49 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS Bochs 01/01/2011 Workqueue: writeback wb_workfn (flush-8:16) 0000000000000000 ffff88007ca0fb58 ffffffff805990af 0000000000000000 0000000000000000 ffff88007ca0fb98 ffffffff80268702 0000018d000004e2 ffff88007cef40e8 ffff88007c9b89a8 ffff880079e3a740 0000000000000003 Call Trace: [] dump_stack+0x4d/0x6e [] __warn+0xc2/0xe0 [] warn_slowpath_null+0x18/0x20 [] ihold+0x2b/0x30 [] inode_switch_wbs+0x11c/0x180 [] wbc_detach_inode+0x170/0x1a0 [] writeback_sb_inodes+0x21c/0x530 [] wb_writeback+0xee/0x1e0 [] wb_workfn+0xd7/0x280 [] ? try_to_wake_up+0x1b1/0x2b0 [] process_one_work+0x129/0x300 [] worker_thread+0x126/0x480 [] ? __schedule+0x1c7/0x561 [] ? process_one_work+0x300/0x300 [] kthread+0xc4/0xe0 [] ? kfree+0xc8/0x100 [] ret_from_fork+0x1f/0x40 [] ? __kthread_parkme+0x70/0x70 ---[ end trace aaefd2fd9f306bc4 ]--- Acked-by: Tejun Heo Signed-off-by: Tahsin Erdogan --- fs/fs-writeback.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/fs-writeback.c b/fs/fs-writeback.c index 989a2ce..b44ede0 100644 --- a/fs/fs-writeback.c +++ b/fs/fs-writeback.c @@ -478,14 +478,15 @@ static void inode_switch_wbs(struct inode *inode, int new_wb_id) spin_lock(&inode->i_lock); if (!(inode->i_sb->s_flags & MS_ACTIVE) || inode->i_state & (I_WB_SWITCH | I_FREEING) || + atomic_read(&inode->i_count) == 0 || inode_to_wb(inode) == isw->new_wb) { spin_unlock(&inode->i_lock); goto out_free; } inode->i_state |= I_WB_SWITCH; + ihold(inode); spin_unlock(&inode->i_lock); - ihold(inode); isw->inode = inode; atomic_inc(&isw_nr_in_flight);