From patchwork Wed Nov 30 07:36:39 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9453873 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 480A06071C for ; Wed, 30 Nov 2016 07:37:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3930C28119 for ; Wed, 30 Nov 2016 07:37:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2E1F628394; Wed, 30 Nov 2016 07:37:45 +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 8050C28365 for ; Wed, 30 Nov 2016 07:37:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752594AbcK3Hhm (ORCPT ); Wed, 30 Nov 2016 02:37:42 -0500 Received: from cn.fujitsu.com ([222.73.24.84]:11532 "EHLO song.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1751671AbcK3Hhj (ORCPT ); Wed, 30 Nov 2016 02:37:39 -0500 X-IronPort-AV: E=Sophos;i="5.20,367,1444665600"; d="scan'208";a="992790" Received: from unknown (HELO cn.fujitsu.com) ([10.167.250.3]) by song.cn.fujitsu.com with ESMTP; 30 Nov 2016 15:36:52 +0800 Received: from localhost.localdomain (unknown [10.167.226.34]) by cn.fujitsu.com (Postfix) with ESMTP id 24D0E4010D0D; Wed, 30 Nov 2016 15:36:52 +0800 (CST) From: Qu Wenruo To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz Subject: [PATCH v5 2/3] btrfs: Add trace point for qgroup reserved space Date: Wed, 30 Nov 2016 15:36:39 +0800 Message-Id: <20161130073640.20364-2-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161130073640.20364-1-quwenruo@cn.fujitsu.com> References: <20161130073640.20364-1-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-yoursite-MailScanner-ID: 24D0E4010D0D.AA21F X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com 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 Introduce the following trace points: qgroup_update_reserve qgroup_meta_reserve These trace points are handy to trace qgroup reserve space related problems. Signed-off-by: Qu Wenruo --- v2: None v3: Separate from trace point timing modification patch. v4: Change type casting from "(s64)-num_bytes" to "-(s64)num_bytes". Reported by Sanidhya Solanki and David Sterba. Change the trace point internal structure from (u64) to (s64). Reported by David Sterba. v5: None --- fs/btrfs/qgroup.c | 15 +++++++++++++++ include/trace/events/btrfs.h | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+) diff --git a/fs/btrfs/qgroup.c b/fs/btrfs/qgroup.c index 368cdaf..4fc4165 100644 --- a/fs/btrfs/qgroup.c +++ b/fs/btrfs/qgroup.c @@ -1068,6 +1068,8 @@ static int __qgroup_excl_accounting(struct btrfs_fs_info *fs_info, qgroup->excl += sign * num_bytes; qgroup->excl_cmpr += sign * num_bytes; if (sign > 0) { + trace_qgroup_update_reserve(fs_info, qgroup->qgroupid, + qgroup->reserved, -(s64)num_bytes); if (WARN_ON(qgroup->reserved < num_bytes)) report_reserved_underflow(fs_info, qgroup, num_bytes); @@ -1094,6 +1096,9 @@ static int __qgroup_excl_accounting(struct btrfs_fs_info *fs_info, WARN_ON(sign < 0 && qgroup->excl < num_bytes); qgroup->excl += sign * num_bytes; if (sign > 0) { + trace_qgroup_update_reserve(fs_info, qgroup->qgroupid, + qgroup->reserved, + -(s64)num_bytes); if (WARN_ON(qgroup->reserved < num_bytes)) report_reserved_underflow(fs_info, qgroup, num_bytes); @@ -2178,6 +2183,8 @@ static int qgroup_reserve(struct btrfs_root *root, u64 num_bytes) qg = u64_to_ptr(unode->aux); + trace_qgroup_update_reserve(fs_info, qg->qgroupid, + qg->reserved, num_bytes); qg->reserved += num_bytes; } @@ -2223,6 +2230,8 @@ void btrfs_qgroup_free_refroot(struct btrfs_fs_info *fs_info, qg = u64_to_ptr(unode->aux); + trace_qgroup_update_reserve(fs_info, qg->qgroupid, + qg->reserved, -(s64)num_bytes); if (WARN_ON(qg->reserved < num_bytes)) report_reserved_underflow(fs_info, qg, num_bytes); else @@ -2706,6 +2715,8 @@ int btrfs_qgroup_reserve_meta(struct btrfs_root *root, int num_bytes) return 0; BUG_ON(num_bytes != round_down(num_bytes, root->nodesize)); + trace_qgroup_meta_reserve(root->fs_info, root->objectid, + (s64)num_bytes); ret = qgroup_reserve(root, num_bytes); if (ret < 0) return ret; @@ -2724,6 +2735,8 @@ void btrfs_qgroup_free_meta_all(struct btrfs_root *root) reserved = atomic_xchg(&root->qgroup_meta_rsv, 0); if (reserved == 0) return; + trace_qgroup_meta_reserve(root->fs_info, root->objectid, + -(s64)reserved); qgroup_free(root, reserved); } @@ -2736,6 +2749,8 @@ void btrfs_qgroup_free_meta(struct btrfs_root *root, int num_bytes) BUG_ON(num_bytes != round_down(num_bytes, root->nodesize)); WARN_ON(atomic_read(&root->qgroup_meta_rsv) < num_bytes); atomic_sub(num_bytes, &root->qgroup_meta_rsv); + trace_qgroup_meta_reserve(root->fs_info, root->objectid, + -(s64)num_bytes); qgroup_free(root, num_bytes); } diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h index e030d6f..03f3194 100644 --- a/include/trace/events/btrfs.h +++ b/include/trace/events/btrfs.h @@ -1468,6 +1468,49 @@ TRACE_EVENT(qgroup_update_counters, __entry->cur_new_count) ); +TRACE_EVENT(qgroup_update_reserve, + + TP_PROTO(struct btrfs_fs_info *fs_info, u64 qgid, u64 cur_reserved, + s64 diff), + + TP_ARGS(fs_info, qgid, cur_reserved, diff), + + TP_STRUCT__entry_btrfs( + __field( u64, qgid ) + __field( u64, cur_reserved ) + __field( s64, diff ) + ), + + TP_fast_assign_btrfs(fs_info, + __entry->qgid = qgid; + __entry->cur_reserved = cur_reserved; + __entry->diff = diff; + ), + + TP_printk_btrfs("qgid = %llu, cur_reserved = %llu, diff = %lld", + __entry->qgid, __entry->cur_reserved, __entry->diff) +); + +TRACE_EVENT(qgroup_meta_reserve, + + TP_PROTO(struct btrfs_fs_info *fs_info, u64 refroot, s64 diff), + + TP_ARGS(fs_info, refroot, diff), + + TP_STRUCT__entry_btrfs( + __field( u64, refroot ) + __field( s64, diff ) + ), + + TP_fast_assign_btrfs(fs_info, + __entry->refroot = refroot; + __entry->diff = diff; + ), + + TP_printk_btrfs("refroot = %llu, diff = %lld", + __entry->refroot, __entry->diff) +); + #endif /* _TRACE_BTRFS_H */ /* This part must be outside protection */