Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2814099rwb; Mon, 15 Aug 2022 11:53:21 -0700 (PDT) X-Google-Smtp-Source: AA6agR6p+eq+ATEH/eeVrMdTmiefNKB0Jb9C49XyX5LHtcZXw4qTRU3GnXiJnMuFLv10c5W3DJtk X-Received: by 2002:a17:907:1623:b0:731:492f:da93 with SMTP id hb35-20020a170907162300b00731492fda93mr10756955ejc.687.1660589600865; Mon, 15 Aug 2022 11:53:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660589600; cv=none; d=google.com; s=arc-20160816; b=AZJcsACN7gLTlFGgE/sRNqm87DA/BbrvIdchGv90JZLnD7+iLDK2GQrgS8Mc0adn6y +lmUHjhX2JKxB5EDdsNHShM6Qek9PTtcQhsiWyxMu8kCNVXCNpPEV6qCJkKfd0guTJEE FV2DHxlEAu5YPgOIkIDZBAo9WMCJG8ESwYevdQkMwHchKzwuJyGTxATm0z7mXIesTOSO lnUy5LSylpKfbg3vGd/HUFWCO2jzo7LQoSXbg5DRXFCuWd1uaBv7H7x+KM5wyaDctF4D AFrIU+J8fnBoIc8ntkR62vecXLrr2zxAtjizTH8CblZDTtnTU1PX9MRL8NJhVKNhuheh 69ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cMdRdaCO/dOFHStnQOOMLDvPDFmRjnDvShI4eQSxC9I=; b=o6DzDyTAJCq7xqWu2Z0LC3bwRclm6QRhouGC6tWhph1fcuD+QkaCFQkmkN4qfK5hCn Wnry4OQpPhOrQbokOV2/HM1wl3JSTiwMtSXrzk+SNmd1L/66j25f92dM08qteVTy9/HJ mmfXRnam1edl8Ycxq1BBbipw/nYyjFVGzmPagHneV588XPoz3DEtl+Tqwv7zG3R1Eelr A9droQTOOj4yHxIBTSwQkD6VD0nNndQUbswuxX5jJA+g7F0CdCS3MUbPJhGJ7VpDFg+a 4WXd58uT5sMiEGAVyl5lGxtsMIy55a6yP9A5UyMQLgJlz4CYlG6v+VPag0gK6IfFiHfH 7SJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DLafvVNo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dp21-20020a170906c15500b0073860fab971si1933434ejc.215.2022.08.15.11.52.54; Mon, 15 Aug 2022 11:53:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DLafvVNo; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242683AbiHOSm5 (ORCPT + 99 others); Mon, 15 Aug 2022 14:42:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38108 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242581AbiHOSkj (ORCPT ); Mon, 15 Aug 2022 14:40:39 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D4EDC3DBF5; Mon, 15 Aug 2022 11:24:19 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 6BBF5B80F99; Mon, 15 Aug 2022 18:24:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B52A3C433C1; Mon, 15 Aug 2022 18:24:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1660587856; bh=puVQCDxV+dBSjrwYCK79NSsZDZj3njSZ6AHPcdAQAN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DLafvVNoDlYR1fWQxNjtkKqBS11EtuLGB3CsZV8od0yIqL5CeWAcHA+vwEpyTTOkl zWePwcU4mLI7zHCrm5YzfFKWiASCCvdmNKBXVYZgoJdxh0YEqH4q1l7JvfmWWl6jRc g9zlDgr2k8gZT9GaxecYYirJynNWyhsDjtBBhgLY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Yu Kuai , Mikulas Patocka , Mike Snitzer , Sasha Levin Subject: [PATCH 5.15 216/779] dm writecache: count number of blocks written, not number of write bios Date: Mon, 15 Aug 2022 19:57:40 +0200 Message-Id: <20220815180346.504719896@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220815180337.130757997@linuxfoundation.org> References: <20220815180337.130757997@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mikulas Patocka [ Upstream commit b2676e1482af89714af6988ce5d31a84692e2530 ] Change dm-writecache, so that it counts the number of blocks written instead of the number of write bios. Bios can be split and requeued using the dm_accept_partial_bio function, so counting bios caused inaccurate results. Fixes: e3a35d03407c ("dm writecache: add event counters") Reported-by: Yu Kuai Signed-off-by: Mikulas Patocka Signed-off-by: Mike Snitzer Signed-off-by: Sasha Levin --- .../admin-guide/device-mapper/writecache.rst | 10 +++++----- drivers/md/dm-writecache.c | 12 +++++++++--- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Documentation/admin-guide/device-mapper/writecache.rst b/Documentation/admin-guide/device-mapper/writecache.rst index 7bead3b52690..6c9a2c74df8a 100644 --- a/Documentation/admin-guide/device-mapper/writecache.rst +++ b/Documentation/admin-guide/device-mapper/writecache.rst @@ -80,11 +80,11 @@ Status: 4. the number of blocks under writeback 5. the number of read blocks 6. the number of read blocks that hit the cache -7. the number of write requests -8. the number of write requests that hit uncommitted block -9. the number of write requests that hit committed block -10. the number of write requests that bypass the cache -11. the number of write requests that are allocated in the cache +7. the number of write blocks +8. the number of write blocks that hit uncommitted block +9. the number of write blocks that hit committed block +10. the number of write blocks that bypass the cache +11. the number of write blocks that are allocated in the cache 12. the number of write requests that are blocked on the freelist 13. the number of flush requests 14. the number of discard requests diff --git a/drivers/md/dm-writecache.c b/drivers/md/dm-writecache.c index 9d6b7b706a65..c90408eb9c3a 100644 --- a/drivers/md/dm-writecache.c +++ b/drivers/md/dm-writecache.c @@ -1412,6 +1412,9 @@ static void writecache_bio_copy_ssd(struct dm_writecache *wc, struct bio *bio, bio->bi_iter.bi_sector = start_cache_sec; dm_accept_partial_bio(bio, bio_size >> SECTOR_SHIFT); + wc->stats.writes += bio->bi_iter.bi_size >> wc->block_size_bits; + wc->stats.writes_allocate += (bio->bi_iter.bi_size - wc->block_size) >> wc->block_size_bits; + if (unlikely(wc->uncommitted_blocks >= wc->autocommit_blocks)) { wc->uncommitted_blocks = 0; queue_work(wc->writeback_wq, &wc->flush_work); @@ -1427,9 +1430,10 @@ static enum wc_map_op writecache_map_write(struct dm_writecache *wc, struct bio do { bool found_entry = false; bool search_used = false; - wc->stats.writes++; - if (writecache_has_error(wc)) + if (writecache_has_error(wc)) { + wc->stats.writes += bio->bi_iter.bi_size >> wc->block_size_bits; return WC_MAP_ERROR; + } e = writecache_find_entry(wc, bio->bi_iter.bi_sector, 0); if (e) { if (!writecache_entry_is_committed(wc, e)) { @@ -1453,9 +1457,10 @@ static enum wc_map_op writecache_map_write(struct dm_writecache *wc, struct bio if (unlikely(!e)) { if (!WC_MODE_PMEM(wc) && !found_entry) { direct_write: - wc->stats.writes_around++; e = writecache_find_entry(wc, bio->bi_iter.bi_sector, WFE_RETURN_FOLLOWING); writecache_map_remap_origin(wc, bio, e); + wc->stats.writes_around += bio->bi_iter.bi_size >> wc->block_size_bits; + wc->stats.writes += bio->bi_iter.bi_size >> wc->block_size_bits; return WC_MAP_REMAP_ORIGIN; } wc->stats.writes_blocked_on_freelist++; @@ -1469,6 +1474,7 @@ static enum wc_map_op writecache_map_write(struct dm_writecache *wc, struct bio bio_copy: if (WC_MODE_PMEM(wc)) { bio_copy_block(wc, bio, memory_data(wc, e)); + wc->stats.writes++; } else { writecache_bio_copy_ssd(wc, bio, e, search_used); return WC_MAP_REMAP; -- 2.35.1