From patchwork Tue Jan 26 11:04:07 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhaolei X-Patchwork-Id: 8120391 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id D75189F8AA for ; Tue, 26 Jan 2016 11:06:22 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id E9EC320266 for ; Tue, 26 Jan 2016 11:06:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 1969720270 for ; Tue, 26 Jan 2016 11:06:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965043AbcAZLGQ (ORCPT ); Tue, 26 Jan 2016 06:06:16 -0500 Received: from cn.fujitsu.com ([59.151.112.132]:54594 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S934219AbcAZLGO (ORCPT ); Tue, 26 Jan 2016 06:06:14 -0500 X-IronPort-AV: E=Sophos;i="5.20,346,1444665600"; d="scan'208";a="2985099" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 26 Jan 2016 19:06:07 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (unknown [10.167.33.80]) by cn.fujitsu.com (Postfix) with ESMTP id A8DDF41824FD for ; Tue, 26 Jan 2016 19:05:33 +0800 (CST) Received: from localhost.localdomain (10.167.226.114) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server id 14.3.181.6; Tue, 26 Jan 2016 19:05:33 +0800 From: Zhao Lei To: CC: Zhao Lei Subject: [PATCH v2 2/2] btrfs: reada: avoid undone reada extents in btrfs_reada_wait Date: Tue, 26 Jan 2016 19:04:07 +0800 Message-ID: X-Mailer: git-send-email 1.8.5.1 In-Reply-To: <84455a12ceda75ad15a97cdbf01f99787eda0b89.1453806157.git.zhaolei@cn.fujitsu.com> References: <84455a12ceda75ad15a97cdbf01f99787eda0b89.1453806157.git.zhaolei@cn.fujitsu.com> MIME-Version: 1.0 X-yoursite-MailScanner-ID: A8DDF41824FD.A636C X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: zhaolei@cn.fujitsu.com X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP reada background works is not designed to finish all jobs completely, it will break in following case: 1: When a device reachs workload limit(MAX_IN_FLIGHT) 2: Total reads reachs max limit(10000) 3: All devices haven't queue more jobs, often happened in DUP case And if all background works exit with remain jobs, btrfs_reada_wait() will enter into infinite wait. Above problem is rarely happened in old code, because: 1: Every works queues 2x new works So many works reduced odds of undone jobs. 2: One work will continue 10000 times loop in case of no-jobs It reduced no-thread window time. But after we fixed above case, the "undone reada extents" frequently happened. Fix: Check to ensure we have at least one thread if there are undone jobs in btrfs_reada_wait(). Changelog v1->v2: 1: RFC->PATCH 2: Some cleanup and wait_time adjust. Signed-off-by: Zhao Lei --- fs/btrfs/reada.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/reada.c b/fs/btrfs/reada.c index 245a961..12a9c9c 100644 --- a/fs/btrfs/reada.c +++ b/fs/btrfs/reada.c @@ -953,8 +953,11 @@ struct reada_control *btrfs_reada_add(struct btrfs_root *root, int btrfs_reada_wait(void *handle) { struct reada_control *rc = handle; + struct btrfs_fs_info *fs_info = rc->root->fs_info; while (atomic_read(&rc->elems)) { + if (!atomic_read(&fs_info->reada_works_cnt)) + reada_start_machine(fs_info); wait_event_timeout(rc->wait, atomic_read(&rc->elems) == 0, 5 * HZ); dump_devs(rc->root->fs_info, @@ -971,9 +974,13 @@ int btrfs_reada_wait(void *handle) int btrfs_reada_wait(void *handle) { struct reada_control *rc = handle; + struct btrfs_fs_info *fs_info = rc->root->fs_info; while (atomic_read(&rc->elems)) { - wait_event(rc->wait, atomic_read(&rc->elems) == 0); + if (!atomic_read(&fs_info->reada_works_cnt)) + reada_start_machine(fs_info); + wait_event_timeout(rc->wait, atomic_read(&rc->elems) == 0, + (HZ + 9) / 10); } kref_put(&rc->refcnt, reada_control_release);