Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp2705601ybl; Sun, 25 Aug 2019 00:28:41 -0700 (PDT) X-Google-Smtp-Source: APXvYqyX0/JR5RL5ndkV3KXzOaV2M61Jzmm8vibhpKVMCLz62evrv/QGI3Gc4EHmjYVr4Hjh0Lxa X-Received: by 2002:a17:902:b605:: with SMTP id b5mr13313395pls.103.1566718121591; Sun, 25 Aug 2019 00:28:41 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1566718121; cv=pass; d=google.com; s=arc-20160816; b=eRdGACmadibIrSnhSOmXBD94zFK/vjwoHTCM6aLZI1+sEDZ9i1u1oVPIBDHtg5oA9M WSIBuE5Gk38+/ozfSKe2iqKPs0Im7B8u5bJ2+60pEXXmCHU51uliSOyheBHEgANcFlgX IigayROZMhKIC5RmZHFOqUBe47kJt43oPNqEWqZ+zN10Wg/tqUJYgZRwqtOm70CG3qAG JXMVeDkja3iWtXmegpAtO75V4b71Y9m4CsgTCFjA7TLEVT5G0E/wwiQDkR6pCreYVsSg lGXmZPvutSZdcJ0fOfY+CPQfAtlW1HKlZSC6LRGXbF/EJkmPHHvu9yCvLw9VbxQYSEJA 9Qxg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:domainkey-signature; bh=JbPeKwL0y9K5o8QvWTYI+guOBqyfTVLeLMRqF8VDqWc=; b=b5/dFq7GyYAJLtuL2SKOAkxiFGoULokkKkKnk3SBCi0AsDGuIPPq7ViBd/n2/Ro/D4 TAgVnqu40YbR1CwhJetf7kByZIb1G9YO1D9M86uIA1270NWBRMZI3bc7f4G6sBLB3pgW ZsKXgirjrJd6ESBLLH+jgZTDb16HlrTz+6skAyTZqM7qgSOx9GQZ/RJ36A+b2A/S8ePt VdaVc4ipgRRAppJdclhgSBxZdnSBSuOqMxMbrJAA4JPTmtJYvjcw5mmlQW9hhEq86EsG tFT+X3/khwvok/rbcQJo61/cJwDPIr+w5Kb7ALwL28gQubb+62wTjLQHqlPxHsPYrZje HNjg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@zoho.com header.s=zm2019 header.b="pu/b7LyN"; arc=pass (i=1 spf=pass spfdomain=zoho.com dkim=pass dkdomain=zoho.com dmarc=pass fromdomain=zoho.com>); spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=zoho.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n6si6302149pgs.333.2019.08.25.00.28.26; Sun, 25 Aug 2019 00:28:41 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@zoho.com header.s=zm2019 header.b="pu/b7LyN"; arc=pass (i=1 spf=pass spfdomain=zoho.com dkim=pass dkdomain=zoho.com dmarc=pass fromdomain=zoho.com>); spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=zoho.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727056AbfHYHZT (ORCPT + 99 others); Sun, 25 Aug 2019 03:25:19 -0400 Received: from sender4-pp-o95.zoho.com ([136.143.188.95]:25502 "EHLO sender4-pp-o95.zoho.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725809AbfHYHZT (ORCPT ); Sun, 25 Aug 2019 03:25:19 -0400 ARC-Seal: i=1; a=rsa-sha256; t=1566717910; cv=none; d=zoho.com; s=zohoarc; b=SJpPVL1y/fFECRiorlnRKTcsvUGgqfPM0WCrlkRXq8+ksnLCjUjhcIUt5HbILFyAwN83keYNb1iiCZPha5JSnCw777qcvl0QGgkKThpwDmVYpZhQvTljG69SAy5OVPLKDPN8eO9KTK7SrPtB4VBKdknWrMNvTuMlxav37Bb1KgA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1566717910; h=Cc:Date:From:In-Reply-To:Message-ID:References:Subject:To:ARC-Authentication-Results; bh=JbPeKwL0y9K5o8QvWTYI+guOBqyfTVLeLMRqF8VDqWc=; b=bEMCgOUh1pBeKMb/u7u3grM3ujaZVzGTOPRRROtLXOs3C3/3x7mZdsFrbsIq2pGe74AtMToDOtvkZuomTBAhmPmKfyWGqBWVcWtiwcn2hXIRFUzPEa2aJA681FW6sXyAzmOXXM6jmWXvqeHo7Z3cGHAzMDlRGQEqXVYPn84DaNI= ARC-Authentication-Results: i=1; mx.zoho.com; dkim=pass header.i=zoho.com; spf=pass smtp.mailfrom=yehs2007@zoho.com; dmarc=pass header.from= header.from= DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=zapps768; d=zoho.com; h=from:to:cc:subject:date:message-id:in-reply-to:references; b=i7y2aEyOHh/la9dU3CPx42PbzlTdsTP9AIatWSaev26MhvxazXL9kgiLtuYSGKE0vaAVtr7CacPu UxeGSKrTnyEcL66hHrbYbIu4R8iV5qlMuOhCWOOUWmaib0WCiuuq DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1566717910; s=zm2019; d=zoho.com; i=yehs2007@zoho.com; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; l=3969; bh=JbPeKwL0y9K5o8QvWTYI+guOBqyfTVLeLMRqF8VDqWc=; b=pu/b7LyNmYvufL43cLjOm9uc6q7eI2PfNoaarhXUjd/qlCh2Hi2xduAPONT5OyO7 rofiHB/FJvRmrIOJRH42WcnkP/TxtGQNeZNa4V/HbXxJi0nrMlKVBvj+1YqyZRu/bej 1qq2aaLi8arB2HnAeusARLo0U0rhRbhoqewsZhnU= Received: from YEHS1XR3054QMS.lenovo.com (123.120.58.107 [123.120.58.107]) by mx.zohomail.com with SMTPS id 15667179088951020.9475134769934; Sun, 25 Aug 2019 00:25:08 -0700 (PDT) From: Huaisheng Ye To: mpatocka@redhat.com, snitzer@redhat.com, agk@redhat.com Cc: prarit@redhat.com, tyu1@lenovo.com, dm-devel@redhat.com, linux-kernel@vger.kernel.org, Huaisheng Ye Subject: [PATCH 3/3] dm writecache: optimize performance by sorting the blocks for writeback_all Date: Sun, 25 Aug 2019 15:24:33 +0800 Message-Id: <20190825072433.2628-4-yehs2007@zoho.com> X-Mailer: git-send-email 2.17.0.windows.1 In-Reply-To: <20190825072433.2628-1-yehs2007@zoho.com> References: <20190825072433.2628-1-yehs2007@zoho.com> X-ZohoMailClient: External Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Huaisheng Ye During the process of writeback, the blocks, which have been placed in wbl.list for writeback soon, are partially ordered for the contiguous ones. When writeback_all has been set, for most cases, also by default, there will be a lot of blocks in pmem need to writeback at the same time. For this case, we could optimize the performance by sorting all blocks in wbl.list. writecache_writeback doesn't need to get blocks from the tail of wc->lru, whereas from the first rb_node from the rb_tree. The benefit is that, writecache_writeback doesn't need to have any cost to sort the blocks, because of all blocks are incremental originally in rb_tree. There will be a writecache_flush when writeback_all begins to work, that will eliminate duplicate blocks in cache by committed/uncommitted. Testing platform: Thinksystem SR630 with persistent memory. The cache comes from pmem, which has 1006MB size. The origin device is HDD, 2GB of which for using. Testing steps: 1) dmsetup create mycache --table '0 4194304 writecache p /dev/sdb1 /dev/pmem4 4096 0' 2) fio -filename=/dev/mapper/mycache -direct=1 -iodepth=20 -rw=randwrite -ioengine=libaio -bs=4k -loops=1 -size=2g -group_reporting -name=mytest1 3) time dmsetup message /dev/mapper/mycache 0 flush Here is the results below, With the patch: # fio -filename=/dev/mapper/mycache -direct=1 -iodepth=20 -rw=randwrite -ioengine=libaio -bs=4k -loops=1 -size=2g -group_reporting -name=mytest1 iops : min= 1582, max=199470, avg=5305.94, stdev=21273.44, samples=197 # time dmsetup message /dev/mapper/mycache 0 flush real 0m44.020s user 0m0.002s sys 0m0.003s Without the patch: # fio -filename=/dev/mapper/mycache -direct=1 -iodepth=20 -rw=randwrite -ioengine=libaio -bs=4k -loops=1 -size=2g -group_reporting -name=mytest1 iops : min= 1202, max=197650, avg=4968.67, stdev=20480.17, samples=211 # time dmsetup message /dev/mapper/mycache 0 flush real 1m39.221s user 0m0.001s sys 0m0.003s I also have checked the data accuracy with this patch by making EXT4 filesystem on mycache, then mount it for checking md5 of files on that. The test result is positive, with this patch it could save more than half of time when writeback_all. Signed-off-by: Huaisheng Ye --- drivers/md/dm-writecache.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/drivers/md/dm-writecache.c b/drivers/md/dm-writecache.c index 3643084..c481947 100644 --- a/drivers/md/dm-writecache.c +++ b/drivers/md/dm-writecache.c @@ -1560,7 +1560,7 @@ static void writecache_writeback(struct work_struct *work) { struct dm_writecache *wc = container_of(work, struct dm_writecache, writeback_work); struct blk_plug plug; - struct wc_entry *e, *f, *g; + struct wc_entry *f, *g, *e = NULL; struct rb_node *node, *next_node; struct list_head skipped; struct writeback_list wbl; @@ -1597,7 +1597,14 @@ static void writecache_writeback(struct work_struct *work) break; } - e = container_of(wc->lru.prev, struct wc_entry, lru); + if (unlikely(wc->writeback_all)) { + if (unlikely(!e)) { + writecache_flush(wc); + e = container_of(rb_first(&wc->tree), struct wc_entry, rb_node); + } else + e = g; + } else + e = container_of(wc->lru.prev, struct wc_entry, lru); BUG_ON(e->write_in_progress); if (unlikely(!writecache_entry_is_committed(wc, e))) { writecache_flush(wc); @@ -1658,8 +1665,14 @@ static void writecache_writeback(struct work_struct *work) g->wc_list_contiguous = BIO_MAX_PAGES; f = g; e->wc_list_contiguous++; - if (unlikely(e->wc_list_contiguous == BIO_MAX_PAGES)) + if (unlikely(e->wc_list_contiguous == BIO_MAX_PAGES)) { + if (unlikely(wc->writeback_all)) { + next_node = rb_next(&f->rb_node); + if (likely(next_node)) + g = container_of(next_node, struct wc_entry, rb_node); + } break; + } } cond_resched(); } -- 1.8.3.1