From patchwork Thu Oct 8 12:24:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 11822819 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ECD4B13B2 for ; Thu, 8 Oct 2020 12:24:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C463820659 for ; Thu, 8 Oct 2020 12:24:35 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="nfQipQ7b" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729830AbgJHMYe (ORCPT ); Thu, 8 Oct 2020 08:24:34 -0400 Received: from mx2.suse.de ([195.135.220.15]:59484 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729674AbgJHMYd (ORCPT ); Thu, 8 Oct 2020 08:24:33 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1602159872; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=q/XxDsYAK0whX3TXMX+rzVeOIsPDL9xUGfNx4EeShKY=; b=nfQipQ7bCVxHdXuWvaQl/9eVpD3UwyU6sijXIz/cPZlOjiyoOwdTCd4R2zGnsHGMkEdEqj AwDpmRufdSuc+7TWzE23hqRRfUNuz10pWNSZhmnq/WhXI461ZvkUQMLY29ymVnUYPa70q6 AG5oevBe1qhUPjRg9jtJ1ymcLw1hRGI= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B55F2AF2A; Thu, 8 Oct 2020 12:24:32 +0000 (UTC) From: Nikolay Borisov To: linux-btrfs@vger.kernel.org Cc: Nikolay Borisov Subject: [PATCH 1/4] btrfs: Use helpers to convert from seconds to jiffies in transaction_kthread Date: Thu, 8 Oct 2020 15:24:27 +0300 Message-Id: <20201008122430.93433-2-nborisov@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201008122430.93433-1-nborisov@suse.com> References: <20201008122430.93433-1-nborisov@suse.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The kernel provides easy to understand helpers to convert from human understandable units to the kernel-friendly 'jiffies'. So let's use those to make the code easier to understand. No functional changes. Signed-off-by: Nikolay Borisov --- fs/btrfs/disk-io.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 764001609a15..77b52b724733 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1721,7 +1721,7 @@ static int transaction_kthread(void *arg) do { cannot_commit = false; - delay = HZ * fs_info->commit_interval; + delay = msecs_to_jiffies(fs_info->commit_interval * 1000); mutex_lock(&fs_info->transaction_kthread_mutex); spin_lock(&fs_info->trans_lock); @@ -1736,7 +1736,7 @@ static int transaction_kthread(void *arg) (now < cur->start_time || now - cur->start_time < fs_info->commit_interval)) { spin_unlock(&fs_info->trans_lock); - delay = HZ * 5; + delay = msecs_to_jiffies(5000); goto sleep; } transid = cur->transid; From patchwork Thu Oct 8 12:24:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 11822825 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C149313B2 for ; Thu, 8 Oct 2020 12:24:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9489D20659 for ; Thu, 8 Oct 2020 12:24:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="LNOniD3n" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729828AbgJHMYe (ORCPT ); Thu, 8 Oct 2020 08:24:34 -0400 Received: from mx2.suse.de ([195.135.220.15]:59496 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729745AbgJHMYe (ORCPT ); Thu, 8 Oct 2020 08:24:34 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1602159873; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sV1sF8ixVQfzmAV78oZC+azm3lFs5wHCEAt3QP6A3N0=; b=LNOniD3nfEG/xRj394GkkrMNNzgsexFG34CLxr5wU6lO7ow+aMRcPQeeMI+jU57MvJwIUM IquTtK4Q6ix8pxTLNA5OO/zFQxbmSYDZpOZ6psHUvMfB7FfmMpmXuvyqKacb0pwAJxyAMs DPqph5IrygGLPGOg3rgRoCU76meNLcQ= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id EE321AFBF; Thu, 8 Oct 2020 12:24:32 +0000 (UTC) From: Nikolay Borisov To: linux-btrfs@vger.kernel.org Cc: Nikolay Borisov Subject: [PATCH 2/4] btrfs: Remove redundant check Date: Thu, 8 Oct 2020 15:24:28 +0300 Message-Id: <20201008122430.93433-3-nborisov@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201008122430.93433-1-nborisov@suse.com> References: <20201008122430.93433-1-nborisov@suse.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org The value obtained from ktime_get_seconds() is guaranteed to be monotonically increasing since it's taken from CLOCK_MONOTONIC. As transaction_kthread obtains a reference to the currently running transaction under holding btrfs_fs_info::trans_lock it's guaranteed to: a) See an initialized 'cur', whose start_tim is guaranteed to be smaller than 'now' or b) Not obtain a 'cur' and simply go to sleep. Given this remove the unnecessary check, if it sees now < cur->start_time this would imply there are far greated problems on the machine. Signed-off-by: Nikolay Borisov --- fs/btrfs/disk-io.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 77b52b724733..b9fbbf66ccee 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1733,8 +1733,7 @@ static int transaction_kthread(void *arg) now = ktime_get_seconds(); if (cur->state < TRANS_STATE_COMMIT_START && - (now < cur->start_time || - now - cur->start_time < fs_info->commit_interval)) { + (now - cur->start_time < fs_info->commit_interval)) { spin_unlock(&fs_info->trans_lock); delay = msecs_to_jiffies(5000); goto sleep; From patchwork Thu Oct 8 12:24:29 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 11822823 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 47B9013B2 for ; Thu, 8 Oct 2020 12:24:37 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 207A02184D for ; Thu, 8 Oct 2020 12:24:37 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="oipXAsc1" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729833AbgJHMYf (ORCPT ); Thu, 8 Oct 2020 08:24:35 -0400 Received: from mx2.suse.de ([195.135.220.15]:59508 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729635AbgJHMYe (ORCPT ); Thu, 8 Oct 2020 08:24:34 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1602159873; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=cJ4Qa7nORCLQdmS1s8yYxpavd4g/7zE6ogFfHLiX/0A=; b=oipXAsc1bY1ZtDQOOQ53yhr/+fX0zpMpvbl2NN6oK4zorAPWp8hTiBK5+pDwh5cvRUWtA+ anRgqAkOP7goW8E6V/FGkIAthvkspABg/1J6CwJMjaqClVqFgns4y2mee9qf3lEGYX99Kf rjZwsuMlaNk68LTgQ0eQmHqM9LAcLoU= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 368EFAFDB; Thu, 8 Oct 2020 12:24:33 +0000 (UTC) From: Nikolay Borisov To: linux-btrfs@vger.kernel.org Cc: Nikolay Borisov Subject: [PATCH 3/4] btrfs: Record delta directly in transaction_kthread Date: Thu, 8 Oct 2020 15:24:29 +0300 Message-Id: <20201008122430.93433-4-nborisov@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201008122430.93433-1-nborisov@suse.com> References: <20201008122430.93433-1-nborisov@suse.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org Rename 'now' to 'delta' and store there the delta between transaction start time and current time. This is in preparation for optimising the sleep logic in the next patch. No functional changes. Signed-off-by: Nikolay Borisov --- fs/btrfs/disk-io.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index b9fbbf66ccee..c5d3e7f75066 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1715,7 +1715,7 @@ static int transaction_kthread(void *arg) struct btrfs_trans_handle *trans; struct btrfs_transaction *cur; u64 transid; - time64_t now; + time64_t delta; unsigned long delay; bool cannot_commit; @@ -1731,9 +1731,9 @@ static int transaction_kthread(void *arg) goto sleep; } - now = ktime_get_seconds(); + delta = ktime_get_seconds() - cur->start_time; if (cur->state < TRANS_STATE_COMMIT_START && - (now - cur->start_time < fs_info->commit_interval)) { + delta < fs_info->commit_interval) { spin_unlock(&fs_info->trans_lock); delay = msecs_to_jiffies(5000); goto sleep; From patchwork Thu Oct 8 12:24:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nikolay Borisov X-Patchwork-Id: 11822821 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 84F6814D5 for ; Thu, 8 Oct 2020 12:24:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 53D142184D for ; Thu, 8 Oct 2020 12:24:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="TjnRFR6r" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729835AbgJHMYf (ORCPT ); Thu, 8 Oct 2020 08:24:35 -0400 Received: from mx2.suse.de ([195.135.220.15]:59524 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729822AbgJHMYe (ORCPT ); Thu, 8 Oct 2020 08:24:34 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1602159873; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7sZzHF12dVjWQvyAo2v4Tr9ckMm/xZXm5B0nhIiKano=; b=TjnRFR6rTHH70BtN84Gfs2glhYr5+Q7zBPCh9BOzoD5Xy4DynBvffiZ/s5NPT2wPuyZBsq R0NjWdOZUbHgyH/4RfrlbLd2MwUE+e6BQ4zApRwokyDwMbnXal7odV6SsMhfxH+gAF2iIY sLelvSb9L49mdGpbYIyImVk+WeO72Cg= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 73A31AFDF; Thu, 8 Oct 2020 12:24:33 +0000 (UTC) From: Nikolay Borisov To: linux-btrfs@vger.kernel.org Cc: Nikolay Borisov Subject: [PATCH 4/4] btrfs: Be smarter when sleeping in transaction_kthread Date: Thu, 8 Oct 2020 15:24:30 +0300 Message-Id: <20201008122430.93433-5-nborisov@suse.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201008122430.93433-1-nborisov@suse.com> References: <20201008122430.93433-1-nborisov@suse.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org If transaction_kthread is woken up before btrfs_fs_info::commit_interval seconds have elapsed it will sleep for a fixed period of 5 seconds. This is not a problem per-se but is not accuaret, instead the code should sleep for an interval which guarantees on next wakeup commit_interval would have passed. Since time tracking is not accurate add 1 second to ensure next wake up would be after commit_interval. Signed-off-by: Nikolay Borisov --- fs/btrfs/disk-io.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index c5d3e7f75066..a1fe99cf0831 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1735,7 +1735,7 @@ static int transaction_kthread(void *arg) if (cur->state < TRANS_STATE_COMMIT_START && delta < fs_info->commit_interval) { spin_unlock(&fs_info->trans_lock); - delay = msecs_to_jiffies(5000); + delay = msecs_to_jiffies((1+delta) * 1000); goto sleep; } transid = cur->transid;