From patchwork Wed Jun 19 08:03:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 11006027 X-Patchwork-Delegate: snitzer@redhat.com Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C1B2729B1 for ; Thu, 20 Jun 2019 07:21:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9D4F2851A for ; Thu, 20 Jun 2019 07:21:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9E7FF28538; Thu, 20 Jun 2019 07:21:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E31632851A for ; Thu, 20 Jun 2019 07:21:48 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D40BC307D91E; Thu, 20 Jun 2019 07:21:47 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id B201E608A7; Thu, 20 Jun 2019 07:21:47 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 3307C206D1; Thu, 20 Jun 2019 07:21:45 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id x5J83nc1006760 for ; Wed, 19 Jun 2019 04:03:49 -0400 Received: by smtp.corp.redhat.com (Postfix) id 70A9C601A5; Wed, 19 Jun 2019 08:03:49 +0000 (UTC) Delivered-To: dm-devel@redhat.com Received: from mx1.redhat.com (ext-mx19.extmail.prod.ext.phx2.redhat.com [10.5.110.48]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6B070600C7 for ; Wed, 19 Jun 2019 08:03:47 +0000 (UTC) Received: from mx1.suse.de (mx2.suse.de [195.135.220.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 735B1307D851 for ; Wed, 19 Jun 2019 08:03:22 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 1A296AF61; Wed, 19 Jun 2019 08:03:21 +0000 (UTC) From: Qu Wenruo To: dm-devel@redhat.com Date: Wed, 19 Jun 2019 16:03:11 +0800 Message-Id: <20190619080312.11549-2-wqu@suse.com> In-Reply-To: <20190619080312.11549-1-wqu@suse.com> References: <20190619080312.11549-1-wqu@suse.com> MIME-Version: 1.0 X-Greylist: Sender passed SPF test, Sender IP whitelisted by DNSRBL, ACL 216 matched, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 19 Jun 2019 08:03:37 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Wed, 19 Jun 2019 08:03:37 +0000 (UTC) for IP:'195.135.220.15' DOMAIN:'mx2.suse.de' HELO:'mx1.suse.de' FROM:'wqu@suse.com' RCPT:'' X-RedHat-Spam-Score: -2.298 (RCVD_IN_DNSWL_MED, SPF_HELO_NONE, SPF_NONE) 195.135.220.15 mx2.suse.de 195.135.220.15 mx2.suse.de X-Scanned-By: MIMEDefang 2.84 on 10.5.110.48 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-loop: dm-devel@redhat.com X-Mailman-Approved-At: Thu, 20 Jun 2019 03:21:43 -0400 Cc: linux-btrfs@vger.kernel.org Subject: [dm-devel] [PATCH 1/2] dm log writes: Allow dm-log-writes to filter bios based on types to reduce log device space usage X-BeenThere: dm-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: device-mapper development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: dm-devel-bounces@redhat.com Errors-To: dm-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.48]); Thu, 20 Jun 2019 07:21:48 +0000 (UTC) X-Virus-Scanned: ClamAV using ClamSMTP Since dm-log-writes will record all writes, include data and metadata writes, it can consume a lot of space. However for a lot of filesystems, the data bio (without METADATA flag) can be skipped for certain use case, thus we can skip them in dm-log-writes to hugely reduce space usage. This patch will introduce a new optional constructor parameter, "dump_type=%s", for dm-log-writes. The '%s' can be ALL, METADATA, FUA, FLUSH, DISCARD, MARK or the ORed result of them. The default dump_type will be 'ALL', so the behavior is not changed at all. But user can specify dump_type=METADATA|FUA|FLUSH|DISCARD|MARK to skip data writes to save space on log device. Currently the dump_type can only be speicified at contruction time. Signed-off-by: Qu Wenruo --- drivers/md/dm-log-writes.c | 146 +++++++++++++++++++++++++++++++++++-- 1 file changed, 141 insertions(+), 5 deletions(-) diff --git a/drivers/md/dm-log-writes.c b/drivers/md/dm-log-writes.c index af94bbe77ce2..9edf0bdcae39 100644 --- a/drivers/md/dm-log-writes.c +++ b/drivers/md/dm-log-writes.c @@ -115,6 +115,7 @@ struct log_writes_c { struct list_head logging_blocks; wait_queue_head_t wait; struct task_struct *log_kthread; + u32 dump_type; }; struct pending_block { @@ -503,15 +504,99 @@ static int log_writes_kthread(void *arg) return 0; } +#define string_type_to_bit(string) \ +({ \ + if (!strcasecmp(p, #string)) { \ + dump_type |= LOG_##string##_FLAG; \ + continue; \ + } \ +}) +static int parse_dump_types(struct log_writes_c *lc, const char *string) +{ + char *orig; + char *opts; + char *p; + u32 dump_type = LOG_MARK_FLAG; + int ret = 0; + + opts = kstrdup(string, GFP_KERNEL); + if (!opts) + return -ENOMEM; + orig = opts; + + while ((p = strsep(&opts, "|")) != NULL) { + if (!*p) + continue; + if (!strcasecmp(p, "ALL")) { + dump_type = (u32)-1; + /* No need to check other flags */ + break; + } + string_type_to_bit(METADATA); + string_type_to_bit(FUA); + string_type_to_bit(FLUSH); + string_type_to_bit(DISCARD); + string_type_to_bit(MARK); + ret = -EINVAL; + goto out; + } +out: + kfree(orig); + if (!ret) + lc->dump_type = dump_type; + return ret; +} +#undef string_type_to_bit + +/* Must be large enough to contain "METADATA|FUA|FLUSH|DISCARD|MARK" */ +#define DUMP_TYPES_BUF_SIZE 256 +#define dump_type_to_string(name) \ +({ \ + if (lc->dump_type & LOG_##name##_FLAG) { \ + if (!first_word) \ + strcat(buf, "|"); \ + strcat(buf, #name); \ + first_word = false; \ + } \ + }) +static void status_dump_types(struct log_writes_c *lc, char *buf) +{ + bool first_word = true; + + buf[0] = '\0'; + + if (lc->dump_type == (u32)-1) { + strcat(buf, "ALL"); + return; + } + dump_type_to_string(METADATA); + dump_type_to_string(FUA); + dump_type_to_string(FLUSH); + dump_type_to_string(DISCARD); + dump_type_to_string(MARK); + return; +} +#undef dump_type_to_string + /* * Construct a log-writes mapping: - * log-writes + * log-writes [