Received: by 2002:a05:6a10:1287:0:0:0:0 with SMTP id d7csp639322pxv; Thu, 15 Jul 2021 12:11:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUJUh1FnD0NOHxERjipRuvdAqkGJTLu/aHZsJBcQQi82/+Vy2Sj6/M53PQGuktHQLuYklh X-Received: by 2002:a6b:7905:: with SMTP id i5mr4357611iop.175.1626376263773; Thu, 15 Jul 2021 12:11:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1626376263; cv=none; d=google.com; s=arc-20160816; b=bg5sgiL8i0KxTO4mZhx5XW3G6dv9wFqUcDxrrdSn1WURhFJiiAeeStnEfNFpSggyev 0b//skZCIc9HyYDdHPHgSZTnaXF2rNUrpB6vwLYcWgcYAGTRxzFoAxGqcYpbzP2Gu1Vy ADD+j058+Be4fqssKJxBEC1HIHs4kSU4CQRBypcZZbw44lwhofb8j1Cy8bQ4DbpFk0OP YhaV8QcqgWGi023Fq0c3ebYQJGMeAe5mtJ8Amc9vcGQenUazTzExuxayFYLKVIS1C763 eJlrNP8CSrdQH/vPrsCjWHUykinu2gbEudMifmpiW3PAU36gzK/bYMYJo+afUfWckEaO 61tA== 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=ic6N18nV1WOBZqn2yyjLSnMQPHnORjrtm/Kx1bwuNiE=; b=WPqZEkthM3LfmhsqWWsRps0TLbO8YngybmTfnM6jw+J8xW/Zp+OP9lqEbwWW89rxit uvG6NQ1cfFDi2nR5aLGa8+N+tT8N2rp2JuN5KB434qIVaFvTpHQLgf1t6q6kfMNZ+Xi/ vRztPK/qFTttIwIFEJHVbpCdvNLIaYQqWLOnsW2Qb88jFApVODw70ZUbQBMGVlkgAjYF Mn0PAz0zeCFmr8hRTGIy9qK7jrTzGqiw9NfHO/kq5z5MzYJpTyJ45upAT0FR1CU48Yv9 Tvvo/zq40BFUU+Gl6ZztjbFKgIp4UmJId1rZ0avqTReCI/QM+R3Gt4GPN5ywlgk3dc3T FSqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="g4/RZBsp"; 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 x29si7656294jap.52.2021.07.15.12.10.51; Thu, 15 Jul 2021 12:11:03 -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="g4/RZBsp"; 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 S234100AbhGOTK4 (ORCPT + 99 others); Thu, 15 Jul 2021 15:10:56 -0400 Received: from mail.kernel.org ([198.145.29.99]:35730 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242168AbhGOS7a (ORCPT ); Thu, 15 Jul 2021 14:59:30 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 5C739613E0; Thu, 15 Jul 2021 18:56:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1626375370; bh=Ha6iwkdER5TDXSFcRtZXKp/qqNsAzSDivxMn88c7pf4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g4/RZBspk6aN1wH3pqCxg4A0NocBfwiWosAJB995R4Zju2aOhw50EyiMijWNI3d7G CT1pYk0bfxdlW5beHPfOb24DMAZR4/uFKbj3sLT3XIZ3ZJzQ7O3L/eA578I2voaV3S GrSfF3G1VvCLTGI39ehrS/Q3G7OWmv1RiWsc2y14= 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.12 057/242] dm writecache: dont split bios when overwriting contiguous cache content Date: Thu, 15 Jul 2021 20:36:59 +0200 Message-Id: <20210715182602.431384098@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210715182551.731989182@linuxfoundation.org> References: <20210715182551.731989182@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 4f72b6f66c3a..7bb4d83e90cc 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