Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp626948pxv; Thu, 15 Jul 2021 11:54:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzrlw5wWPC1sJd19cS0NS4UGqGT1rcCmJmbzo5N38utGdkC73ebYUrXPJIMXWTyAHMwVdV6 X-Received: by 2002:a05:6e02:4d2:: with SMTP id f18mr3645679ils.21.1626375248497; Thu, 15 Jul 2021 11:54:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626375248; cv=none; d=google.com; s=arc-20160816; b=j4p7rx9+0dtmELSoLc/dQ5gZA5YXBZMNk5JpSEHDVTBsRz7Ex/MxJyJKfqzPOT+NFJ XHs2UQsi+TZNaF/RAxJVKuinbvbOd9U/3WtSYJI6qKEzfhirJud5UN62KIt3DhLFJr02 UwTboi9pxSjYItZaHgtiiYWOqp2eyFPJjqX0MSpcYCh4rbhHj00nWQHHHmu0cQHogp9X g5X5cyUMowutFLYvzbzNc3hRJlQamA8/0HvHVyEnerwushmLBdrsHjp3lNzfaj19QYmQ FQEL0pDySRN2TVfoee7Yq/5iP3eDvUKfLn/I3V8IsRcE5aKXgLLKdxSpqz5DUqrAzlFa wx1A== 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=XLj0sxgWtx7xWeIObBwCQ5sbmfS+QtJk8Fh/qeBw2+Y=; b=M2RJpvrr9oaCBThCzNf5evD7qe50+4qZcF7a39HCGAmVFoiUUBKvAKewTQNFFeUk9G AT4g7NVoDtRkTiEA2iuqMknGtgmBCDosjBlw1qk5BUsxhS0BctHQH0IGAAthUv6a/xSt qAsgbdevjGq0b2uqTodL1fHVPNNZY0CdrRNXc41hteOCO8n8utcizn4fEPUG4IiiFkpe n0yxl7EbwzVr1ERst19+JKH3PzARZRyd8kqUjFdk6E3RMSXI0AnbYc9dFX7JeZmRb8Oi fzvZvUkkZgHRkmX1jBLddcSuxZwVQ8F0ZgxJlwzB0rmd9Ldh8KKB0qwlobfZZMHQyvdZ vgBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hMhEINag; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e16si8565155iom.90.2021.07.15.11.53.55; Thu, 15 Jul 2021 11:54:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=hMhEINag; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S241331AbhGOSyR (ORCPT + 99 others); Thu, 15 Jul 2021 14:54:17 -0400 Received: from mail.kernel.org ([198.145.29.99]:52636 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239773AbhGOSuZ (ORCPT ); Thu, 15 Jul 2021 14:50:25 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 8F1F2613D0; Thu, 15 Jul 2021 18:47:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626374852; bh=zIOGho+xru4zoi4b+B/R8U5ZpRrPePcpzgoepV2FLus=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hMhEINag088GwdseXLKFW3wsWefAKEO7DnfzV5LK6AheI3yc2DwhTti3ZItRySIEU O+MCadchNe53oWdT5sAH+y+0oxan5STujXADPWeQxbKHQBKjYkTH0mkmekehzTYV4s NWCI9dZSPTvaoSnS/MTAUjf8Plh41K/VysIm+RuY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mikulas Patocka , Mike Snitzer , Sasha Levin Subject: [PATCH 5.10 052/215] dm writecache: dont split bios when overwriting contiguous cache content Date: Thu, 15 Jul 2021 20:37:04 +0200 Message-Id: <20210715182608.597407892@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182558.381078833@linuxfoundation.org> References: <20210715182558.381078833@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Mikulas Patocka [ Upstream commit ee50cc19d80e9b9a8283d1fb517a778faf2f6899 ] If dm-writecache overwrites existing cached data, it splits the incoming bio into many block-sized bios. The I/O scheduler does merge these bios into one large request but this needless splitting and merging causes performance degradation. Fix this by avoiding bio splitting if the cache target area that is being overwritten is contiguous. Signed-off-by: Mikulas Patocka Signed-off-by: Mike Snitzer Signed-off-by: Sasha Levin --- drivers/md/dm-writecache.c | 38 ++++++++++++++++++++++++++++++-------- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/drivers/md/dm-writecache.c b/drivers/md/dm-writecache.c index 8628c4aa2e85..64c2980aaa54 100644 --- a/drivers/md/dm-writecache.c +++ b/drivers/md/dm-writecache.c @@ -1360,14 +1360,18 @@ read_next_block: } else { do { bool found_entry = false; + bool search_used = false; if (writecache_has_error(wc)) goto unlock_error; e = writecache_find_entry(wc, bio->bi_iter.bi_sector, 0); if (e) { - if (!writecache_entry_is_committed(wc, e)) + if (!writecache_entry_is_committed(wc, e)) { + search_used = true; goto bio_copy; + } if (!WC_MODE_PMEM(wc) && !e->write_in_progress) { wc->overwrote_committed = true; + search_used = true; goto bio_copy; } found_entry = true; @@ -1404,13 +1408,31 @@ bio_copy: sector_t current_cache_sec = start_cache_sec + (bio_size >> SECTOR_SHIFT); while (bio_size < bio->bi_iter.bi_size) { - struct wc_entry *f = writecache_pop_from_freelist(wc, current_cache_sec); - if (!f) - break; - write_original_sector_seq_count(wc, f, bio->bi_iter.bi_sector + - (bio_size >> SECTOR_SHIFT), wc->seq_count); - writecache_insert_entry(wc, f); - wc->uncommitted_blocks++; + if (!search_used) { + struct wc_entry *f = writecache_pop_from_freelist(wc, current_cache_sec); + if (!f) + break; + write_original_sector_seq_count(wc, f, bio->bi_iter.bi_sector + + (bio_size >> SECTOR_SHIFT), wc->seq_count); + writecache_insert_entry(wc, f); + wc->uncommitted_blocks++; + } else { + struct wc_entry *f; + struct rb_node *next = rb_next(&e->rb_node); + if (!next) + break; + f = container_of(next, struct wc_entry, rb_node); + if (f != e + 1) + break; + if (read_original_sector(wc, f) != + read_original_sector(wc, e) + (wc->block_size >> SECTOR_SHIFT)) + break; + if (unlikely(f->write_in_progress)) + break; + if (writecache_entry_is_committed(wc, f)) + wc->overwrote_committed = true; + e = f; + } bio_size += wc->block_size; current_cache_sec += wc->block_size >> SECTOR_SHIFT; } -- 2.30.2