Received: by 10.223.176.5 with SMTP id f5csp703026wra; Tue, 30 Jan 2018 18:08:20 -0800 (PST) X-Google-Smtp-Source: AH8x2254gKQrW/RPmq1zcdVvod32vEmwZ9Of+Rn3f6LyFcodFuWGPTQClYM+mVvzDc/VgiBHvZzi X-Received: by 2002:a17:902:9343:: with SMTP id g3-v6mr27575920plp.319.1517364499995; Tue, 30 Jan 2018 18:08:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1517364499; cv=none; d=google.com; s=arc-20160816; b=YSgM70r6y09z3uSANKrWGYCzUNEYpRxLkjUCY4+nW/4vvnbMrVTnONWScIcThHFC+C cnmVRQV+rjyJpyp2GAbxDwRER8o/0ozTD9xvUUTrzfLotg2TGJRKfcEBLaxdBApfwaiL KNDh/WNVqDoV+m6CJ537rhCAgCq19FW+aByNw05oeOZMzU2laPoyke0YKHyTI9qSeOWp ya6pjWrdmAexCKg4TG5GrfxfbLByYc17ze0s6piUUT6LwLuYzTeMP7sCebMzd3FNjFuE TT3IoWgtrU8Ekgkq5bl5nmSxgXLlVWH6hql5hSYQIsH6eXXSX7uXocdO/HZN1ggpxS2l hObw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature:arc-authentication-results; bh=vWQN79z3OI8a8+iXtmHBrpBs8j8x2LyQOtBTtp33P74=; b=M+U5fkc8Cm1vvo0P9+N2JUoMl37B/empPdnkr+j8dgWh8JD+0zJ/eJBaSpJohIjERe CGkN6MSV/H+kfYYablywH/8gg6e7EZqBuJcpw41HVa2XoYqU1GjMZUfhuqZuxdcm/Cnn 4wxT1REczRZZDQZfcffLCQ0cthsBMSp+QsmRY0k/6TYCnUoH9SO+gOCXBQ+xi8CQHsp3 IoeBEIzJRzD74pqIzqg5eGcYzZIjUrKbCXqcouPdTQDoZCTMqxM1pdNv8nDk+cYJvZKt EsmXW6ZEn94EdQk4WescFaNuKrOnOfZcpVf8jwC1yo/qldsjaLKa6eW4i7nMKG03A31L Q8OA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lightnvm-io.20150623.gappssmtp.com header.s=20150623 header.b=dvS1ghij; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h1si15442988pfg.412.2018.01.30.18.08.05; Tue, 30 Jan 2018 18:08:19 -0800 (PST) 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=@lightnvm-io.20150623.gappssmtp.com header.s=20150623 header.b=dvS1ghij; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752649AbeAaCHK (ORCPT + 99 others); Tue, 30 Jan 2018 21:07:10 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:40380 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752382AbeAaCHF (ORCPT ); Tue, 30 Jan 2018 21:07:05 -0500 Received: by mail-wm0-f67.google.com with SMTP id v123so4861696wmd.5 for ; Tue, 30 Jan 2018 18:07:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=lightnvm-io.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=vWQN79z3OI8a8+iXtmHBrpBs8j8x2LyQOtBTtp33P74=; b=dvS1ghiju5K4BZJJ3hSNT/RvAGCYhUrHEwoOiTFDHW8Ij3HwaFn1OqgxeTLBGWqQGp hMf/PvVL25M3VVHcpNgIpT+ynA7rA3LoYNQN6FjZAOgab7XKSk8gR5ubpbmFGMiPjdgm unEOuUFa7NYfvBgwfNo2jPzMTdwneXFgi34k2ErtQxOzf+MNVKtcEVSLspdIS5zMunfD XQE7KP9I6+0Y/YGOlyhylAkDCkxSNbq+D+j5velQdxW0mIG+P5UeGeemDahdVutVzJS5 PFkCpe+/V9bn1DBZCK5V1a/jN7cJQuCVMHmz0CPWqV2soEmPxQzqTZhKpbPE2b4xQCFx cS5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=vWQN79z3OI8a8+iXtmHBrpBs8j8x2LyQOtBTtp33P74=; b=EAnlg1+7Us5P2z4lTpGldK4/QIP2B5cwbwRRKrwyD/G70uekh/BdyqFhTsC55XWTAj MzXftcGoEilhsNeH1PYb80HjhDcCCT3w23ODs2AOq7RHK8gveb3ns5YhsH167OF73HD8 qrhpyPo+QLV96V5ACflHKTl0oqdjlsTLfnFJl2yyvW0dNh8yRhdKM25lbf3GxFtwW+iV 0D26gwXzYAjdjFxOtu3dvVBPJoCsFXNB4vGvsgu9GLh7rUT5nnoDJD3q/H9z5u6BNlhE 6hEyY+k7oG89fpE1jYbDmlC5I2OwRuWGIDYbf/nh9Y7eAiZkd/xGBqXjLgan6vR76nFs bOjg== X-Gm-Message-State: AKwxyte6Qtf2c2kIi/cfY/kObhbt767doSMsWHN/9O/+B2YxPgDR+THl 0JBIYU0Y/61mKwPh0Jx4VJ94KQ== X-Received: by 10.80.215.146 with SMTP id w18mr54762452edi.208.1517364423841; Tue, 30 Jan 2018 18:07:03 -0800 (PST) Received: from uHalley.cnexlabs.com (6164211-cl69.boa.fiberby.dk. [193.106.164.211]) by smtp.gmail.com with ESMTPSA id m17sm8249001edc.31.2018.01.30.18.07.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 30 Jan 2018 18:07:03 -0800 (PST) From: "=?UTF-8?q?Javier=20Gonz=C3=A1lez?=" X-Google-Original-From: =?UTF-8?q?Javier=20Gonz=C3=A1lez?= To: mb@lightnvm.io Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org, Hans Holmberg , =?UTF-8?q?Javier=20Gonz=C3=A1lez?= Subject: [PATCH 4/5] lightnvm: pblk: add padding distribution sysfs attribute Date: Wed, 31 Jan 2018 03:06:50 +0100 Message-Id: <1517364411-22386-4-git-send-email-javier@cnexlabs.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1517364411-22386-1-git-send-email-javier@cnexlabs.com> References: <1517364411-22386-1-git-send-email-javier@cnexlabs.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Hans Holmberg When pblk receives a sync, all data up to that point in the write buffer must be comitted to persistent storage, and as flash memory comes with a minimal write size there is a significant cost involved both in terms of time for completing the sync and in terms of write amplification padded sectors for filling up to the minimal write size. In order to get a better understanding of the costs involved for syncs, Add a sysfs attribute to pblk: padded_dist, showing a normalized distribution of sectors padded. In order to facilitate measurements of specific workloads during the lifetime of the pblk instance, the distribution can be reset by writing 0 to the attribute. Do this by introducing counters for each possible padding: {0..(minimal write size - 1)} and calculate the normalized distribution when showing the attribute. Signed-off-by: Hans Holmberg Signed-off-by: Javier González --- drivers/lightnvm/pblk-init.c | 16 ++++++++-- drivers/lightnvm/pblk-rb.c | 15 +++++----- drivers/lightnvm/pblk-sysfs.c | 68 +++++++++++++++++++++++++++++++++++++++++++ drivers/lightnvm/pblk.h | 6 +++- 4 files changed, 95 insertions(+), 10 deletions(-) diff --git a/drivers/lightnvm/pblk-init.c b/drivers/lightnvm/pblk-init.c index 7eedc5daebc8..a5e3510c0f38 100644 --- a/drivers/lightnvm/pblk-init.c +++ b/drivers/lightnvm/pblk-init.c @@ -921,6 +921,7 @@ static void pblk_free(struct pblk *pblk) { pblk_luns_free(pblk); pblk_lines_free(pblk); + kfree(pblk->pad_dist); pblk_line_meta_free(pblk); pblk_core_free(pblk); pblk_l2p_free(pblk); @@ -998,11 +999,13 @@ static void *pblk_init(struct nvm_tgt_dev *dev, struct gendisk *tdisk, pblk->pad_rst_wa = 0; pblk->gc_rst_wa = 0; + atomic_long_set(&pblk->nr_flush, 0); + pblk->nr_flush_rst = 0; + #ifdef CONFIG_NVM_DEBUG atomic_long_set(&pblk->inflight_writes, 0); atomic_long_set(&pblk->padded_writes, 0); atomic_long_set(&pblk->padded_wb, 0); - atomic_long_set(&pblk->nr_flush, 0); atomic_long_set(&pblk->req_writes, 0); atomic_long_set(&pblk->sub_writes, 0); atomic_long_set(&pblk->sync_writes, 0); @@ -1034,10 +1037,17 @@ static void *pblk_init(struct nvm_tgt_dev *dev, struct gendisk *tdisk, goto fail_free_luns; } + pblk->pad_dist = kzalloc((pblk->min_write_pgs - 1) * sizeof(atomic64_t), + GFP_KERNEL); + if (!pblk->pad_dist) { + ret = -ENOMEM; + goto fail_free_line_meta; + } + ret = pblk_core_init(pblk); if (ret) { pr_err("pblk: could not initialize core\n"); - goto fail_free_line_meta; + goto fail_free_pad_dist; } ret = pblk_l2p_init(pblk); @@ -1097,6 +1107,8 @@ static void *pblk_init(struct nvm_tgt_dev *dev, struct gendisk *tdisk, pblk_l2p_free(pblk); fail_free_core: pblk_core_free(pblk); +fail_free_pad_dist: + kfree(pblk->pad_dist); fail_free_line_meta: pblk_line_meta_free(pblk); fail_free_luns: diff --git a/drivers/lightnvm/pblk-rb.c b/drivers/lightnvm/pblk-rb.c index 7044b5599cc4..264372d7b537 100644 --- a/drivers/lightnvm/pblk-rb.c +++ b/drivers/lightnvm/pblk-rb.c @@ -437,9 +437,7 @@ static int pblk_rb_may_write_flush(struct pblk_rb *rb, unsigned int nr_entries, if (bio->bi_opf & REQ_PREFLUSH) { struct pblk *pblk = container_of(rb, struct pblk, rwb); -#ifdef CONFIG_NVM_DEBUG atomic_long_inc(&pblk->nr_flush); -#endif if (pblk_rb_flush_point_set(&pblk->rwb, bio, mem)) *io_ret = NVM_IO_OK; } @@ -620,14 +618,17 @@ unsigned int pblk_rb_read_to_bio(struct pblk_rb *rb, struct nvm_rq *rqd, pr_err("pblk: could not pad page in write bio\n"); return NVM_IO_ERR; } + + if (pad < pblk->min_write_pgs) + atomic64_inc(&pblk->pad_dist[pad - 1]); + else + pr_warn("pblk: padding more than min. sectors\n"); + + atomic64_add(pad, &pblk->pad_wa); } - atomic64_add(pad, &((struct pblk *) - (container_of(rb, struct pblk, rwb)))->pad_wa); - #ifdef CONFIG_NVM_DEBUG - atomic_long_add(pad, &((struct pblk *) - (container_of(rb, struct pblk, rwb)))->padded_writes); + atomic_long_add(pad, &pblk->padded_writes); #endif return NVM_IO_OK; diff --git a/drivers/lightnvm/pblk-sysfs.c b/drivers/lightnvm/pblk-sysfs.c index 4804bbd32d5f..f902ac00d071 100644 --- a/drivers/lightnvm/pblk-sysfs.c +++ b/drivers/lightnvm/pblk-sysfs.c @@ -341,6 +341,38 @@ static ssize_t pblk_sysfs_get_write_amp_trip(struct pblk *pblk, char *page) atomic64_read(&pblk->pad_wa) - pblk->pad_rst_wa, page); } +static ssize_t pblk_sysfs_get_padding_dist(struct pblk *pblk, char *page) +{ + int sz = 0; + unsigned long long total; + unsigned long long total_buckets = 0; + int buckets = pblk->min_write_pgs - 1; + int i; + + total = atomic64_read(&pblk->nr_flush) - pblk->nr_flush_rst; + + for (i = 0; i < buckets; i++) + total_buckets += atomic64_read(&pblk->pad_dist[i]); + + if (!total) { + for (i = 0; i < (buckets + 1); i++) + sz += snprintf(page + sz, PAGE_SIZE - sz, + "%d:0 ", i); + sz += snprintf(page + sz, PAGE_SIZE - sz, "\n"); + + return sz; + } + + sz += snprintf(page + sz, PAGE_SIZE - sz, "0:%lld%% ", + ((total - total_buckets) * 100) / total); + for (i = 0; i < buckets; i++) + sz += snprintf(page + sz, PAGE_SIZE - sz, "%d:%lld%% ", i + 1, + (atomic64_read(&pblk->pad_dist[i]) * 100) / total); + sz += snprintf(page + sz, PAGE_SIZE - sz, "\n"); + + return sz; +} + #ifdef CONFIG_NVM_DEBUG static ssize_t pblk_sysfs_stats_debug(struct pblk *pblk, char *page) { @@ -427,6 +459,32 @@ static ssize_t pblk_sysfs_set_write_amp_trip(struct pblk *pblk, } +static ssize_t pblk_sysfs_set_padding_dist(struct pblk *pblk, + const char *page, size_t len) +{ + size_t c_len; + int reset_value; + int buckets = pblk->min_write_pgs - 1; + int i; + + c_len = strcspn(page, "\n"); + if (c_len >= len) + return -EINVAL; + + if (kstrtouint(page, 0, &reset_value)) + return -EINVAL; + + if (reset_value != 0) + return -EINVAL; + + for (i = 0; i < buckets; i++) + atomic64_set(&pblk->pad_dist[i], 0); + + pblk->nr_flush_rst = atomic64_read(&pblk->nr_flush); + + return len; +} + static struct attribute sys_write_luns = { .name = "write_luns", .mode = 0444, @@ -487,6 +545,11 @@ static struct attribute sys_write_amp_trip = { .mode = 0644, }; +static struct attribute sys_padding_dist = { + .name = "padding_dist", + .mode = 0644, +}; + #ifdef CONFIG_NVM_DEBUG static struct attribute sys_stats_debug_attr = { .name = "stats", @@ -507,6 +570,7 @@ static struct attribute *pblk_attrs[] = { &sys_lines_info_attr, &sys_write_amp_mileage, &sys_write_amp_trip, + &sys_padding_dist, #ifdef CONFIG_NVM_DEBUG &sys_stats_debug_attr, #endif @@ -540,6 +604,8 @@ static ssize_t pblk_sysfs_show(struct kobject *kobj, struct attribute *attr, return pblk_sysfs_get_write_amp_mileage(pblk, buf); else if (strcmp(attr->name, "write_amp_trip") == 0) return pblk_sysfs_get_write_amp_trip(pblk, buf); + else if (strcmp(attr->name, "padding_dist") == 0) + return pblk_sysfs_get_padding_dist(pblk, buf); #ifdef CONFIG_NVM_DEBUG else if (strcmp(attr->name, "stats") == 0) return pblk_sysfs_stats_debug(pblk, buf); @@ -558,6 +624,8 @@ static ssize_t pblk_sysfs_store(struct kobject *kobj, struct attribute *attr, return pblk_sysfs_set_sec_per_write(pblk, buf, len); else if (strcmp(attr->name, "write_amp_trip") == 0) return pblk_sysfs_set_write_amp_trip(pblk, buf, len); + else if (strcmp(attr->name, "padding_dist") == 0) + return pblk_sysfs_set_padding_dist(pblk, buf, len); return 0; } diff --git a/drivers/lightnvm/pblk.h b/drivers/lightnvm/pblk.h index 4b7d8618631f..88720e2441c0 100644 --- a/drivers/lightnvm/pblk.h +++ b/drivers/lightnvm/pblk.h @@ -626,12 +626,16 @@ struct pblk { u64 gc_rst_wa; u64 pad_rst_wa; + /* Counters used for calculating padding distribution */ + atomic64_t *pad_dist; /* Padding distribution buckets */ + u64 nr_flush_rst; /* Flushes reset value for pad dist.*/ + atomic_long_t nr_flush; /* Number of flush/fua I/O */ + #ifdef CONFIG_NVM_DEBUG /* Non-persistent debug counters, 4kb sector I/Os */ atomic_long_t inflight_writes; /* Inflight writes (user and gc) */ atomic_long_t padded_writes; /* Sectors padded due to flush/fua */ atomic_long_t padded_wb; /* Sectors padded in write buffer */ - atomic_long_t nr_flush; /* Number of flush/fua I/O */ atomic_long_t req_writes; /* Sectors stored on write buffer */ atomic_long_t sub_writes; /* Sectors submitted from buffer */ atomic_long_t sync_writes; /* Sectors synced to media */ -- 2.7.4