From: Coly Li <colyli@suse.de>
To: linux-bcache@vger.kernel.org
Cc: Coly Li <colyli@suse.de>, Mingzhe Zou <mingzhe.zou@easystack.cn>
Subject: [PATCH] bcache: don't allocate full_dirty_stripes and stripe_sectors_dirty for flash device
Date: Tue, 6 Jun 2023 18:52:05 +0800 [thread overview]
Message-ID: <20230606105205.9161-1-colyli@suse.de> (raw)
The flash device is a special bcache device which doesn't have backing
device and stores all data on cache set. Although its data is treated
as dirty data but the writeback to backing device never happens.
Therefore it is unncessary to always allocate memory for counters
full_dirty_stripes and stripe_sectors_dirty when the bcache device is
on flash only.
This patch avoids to allocate/free memory for full_dirty_stripes and
stripe_sectors_dirty in bcache_device_init() and bcache_device_free().
Also in bcache_dev_sectors_dirty_add(), if the data is written onto
flash device, avoid to update the counters in full_dirty_stripes and
stripe_sectors_dirty because they are not used at all.
Signed-off-by: Coly Li <colyli@suse.de>
Cc: Mingzhe Zou <mingzhe.zou@easystack.cn>
---
drivers/md/bcache/super.c | 18 ++++++++++++++----
drivers/md/bcache/writeback.c | 8 +++++++-
2 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
index 077149c4050b..00edc093e544 100644
--- a/drivers/md/bcache/super.c
+++ b/drivers/md/bcache/super.c
@@ -887,12 +887,15 @@ static void bcache_device_free(struct bcache_device *d)
}
bioset_exit(&d->bio_split);
- kvfree(d->full_dirty_stripes);
- kvfree(d->stripe_sectors_dirty);
+ if (d->full_dirty_stripes)
+ kvfree(d->full_dirty_stripes);
+ if (d->stripe_sectors_dirty)
+ kvfree(d->stripe_sectors_dirty);
closure_debug_destroy(&d->cl);
}
+
static int bcache_device_init(struct bcache_device *d, unsigned int block_size,
sector_t sectors, struct block_device *cached_bdev,
const struct block_device_operations *ops)
@@ -914,6 +917,10 @@ static int bcache_device_init(struct bcache_device *d, unsigned int block_size,
}
d->nr_stripes = n;
+ /* Skip allocating stripes counters for flash device */
+ if (d->c && UUID_FLASH_ONLY(&d->c->uuids[d->id]))
+ goto get_idx;
+
n = d->nr_stripes * sizeof(atomic_t);
d->stripe_sectors_dirty = kvzalloc(n, GFP_KERNEL);
if (!d->stripe_sectors_dirty)
@@ -924,6 +931,7 @@ static int bcache_device_init(struct bcache_device *d, unsigned int block_size,
if (!d->full_dirty_stripes)
goto out_free_stripe_sectors_dirty;
+get_idx:
idx = ida_simple_get(&bcache_device_idx, 0,
BCACHE_DEVICE_IDX_MAX, GFP_KERNEL);
if (idx < 0)
@@ -981,9 +989,11 @@ static int bcache_device_init(struct bcache_device *d, unsigned int block_size,
out_ida_remove:
ida_simple_remove(&bcache_device_idx, idx);
out_free_full_dirty_stripes:
- kvfree(d->full_dirty_stripes);
+ if (d->full_dirty_stripes)
+ kvfree(d->full_dirty_stripes);
out_free_stripe_sectors_dirty:
- kvfree(d->stripe_sectors_dirty);
+ if (d->stripe_sectors_dirty)
+ kvfree(d->stripe_sectors_dirty);
return -ENOMEM;
}
diff --git a/drivers/md/bcache/writeback.c b/drivers/md/bcache/writeback.c
index 24c049067f61..32a034e74622 100644
--- a/drivers/md/bcache/writeback.c
+++ b/drivers/md/bcache/writeback.c
@@ -607,8 +607,14 @@ void bcache_dev_sectors_dirty_add(struct cache_set *c, unsigned int inode,
if (stripe < 0)
return;
- if (UUID_FLASH_ONLY(&c->uuids[inode]))
+ /*
+ * The flash device doesn't have backing device to writeback,
+ * it is unncessary to calculate stripes related stuffs.
+ */
+ if (UUID_FLASH_ONLY(&c->uuids[inode])) {
atomic_long_add(nr_sectors, &c->flash_dev_dirty_sectors);
+ return;
+ }
stripe_offset = offset & (d->stripe_size - 1);
--
2.35.3
next reply other threads:[~2023-06-06 10:57 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-06 10:52 Coly Li [this message]
2023-06-06 12:50 ` Re:[PATCH] bcache: don't allocate full_dirty_stripes and stripe_sectors_dirty for flash device 邹明哲
2023-06-06 13:15 ` [PATCH] " Coly Li
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230606105205.9161-1-colyli@suse.de \
--to=colyli@suse.de \
--cc=linux-bcache@vger.kernel.org \
--cc=mingzhe.zou@easystack.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).