Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp654617pxv; Thu, 15 Jul 2021 12:35:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwg3YQ0YYH4xZ02rDVvJCze22570GCr+kx7peBzfpwrPZA8OVgNjFs/O4JKd6jNIauskRVE X-Received: by 2002:aa7:c9d8:: with SMTP id i24mr9341087edt.79.1626377726996; Thu, 15 Jul 2021 12:35:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626377726; cv=none; d=google.com; s=arc-20160816; b=yZQCLdC8K5jOg3uCbQEwtieGMLwDmZwSS/g3DtG/5UpQrHLMfafAt2k1ft2WGj1wmc ZWZtNFfewrZEMXc8ney+sXq01oLKZXcIaLTlAmmzihnShKjkR49SHj1JH3lKBcti7GHS 26jOp90zNwOR7lBrGutwmGPgsyUBkB545bFVT0GyGXvrU83565ZtKlVQKm/wMJdR0Gt+ LgZAUmVezIvkkL4K+dRVYgODJAcyosHplRj/PA5yd8W/kBP7cAvt7wQNYovXTiMVnroy wjF9Ax5jLA9KfCwkhk/KiKxly1G8YfxmJALjm7tuwpwqsFE/ko2ghljn+QJnnYCfYMeg /cig== 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=UWXUjMPlM8iqPcAghQS0evmGkq4Jeq+mFw1QyVMP120=; b=o77AfT4xkpC+/SudToX0GAehLfQiukcrvM3QZ+rWycsS4Sjwa8pGn5Xy6tTwvPwAUI TfKhDzoJSl7IqFYAbCfZUzELegqgzjLHA280hduTMzXT4dQ9Vv5QUKIMc7NI7PvI5Bm0 /e2XLz2oRA5iX0jzCxY9g7zzuMy65mBCWn7hqBbnVT+kbj6iNKtvf3PD1wkuXlWr3iCC KPe95BDt3LCx3+U2TU+4YUyg0nxW+EI2kX8MsCDCN+bmLXPO2kkqsyzXvMWZOBgtrz9X YT6h/j45MCaopmt5xET/UwGmhYgPUnavVYchgmMH8cKh2Z5/AYUmlkJ9HO3mrPA5BvZV wRKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="wqa/o49L"; 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 m9si8167378edc.148.2021.07.15.12.35.04; Thu, 15 Jul 2021 12:35:26 -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="wqa/o49L"; 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 S1343653AbhGOTdZ (ORCPT + 99 others); Thu, 15 Jul 2021 15:33:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:50684 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238211AbhGOTLD (ORCPT ); Thu, 15 Jul 2021 15:11:03 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 1879D613C0; Thu, 15 Jul 2021 19:08:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626376089; bh=fyCRoHsW4S5bpVs833INRq2BI0dlCcVLFy820FCeVBU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wqa/o49LFpcGTfX0WMQ/FYMnValLHlFoKusGVabvZMXuT+Rzy5PHR3Zz9WYesoXwp 7/ctmUhBvjqLyUgapif7kAYYTGo/zU+oHQWWTwiDSYSTluGmE0PiLPZfBaWmmuynWG IgeJ277ywSOh7LSOAbEuCtLrQg5dNLvybOAyx4NM= 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.13 069/266] dm writecache: dont split bios when overwriting contiguous cache content Date: Thu, 15 Jul 2021 20:37:04 +0200 Message-Id: <20210715182626.388119579@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182613.933608881@linuxfoundation.org> References: <20210715182613.933608881@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 aecc246ade26..a44007297e63 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