* [PATCH 1/8] null_blk: add module parameter for REQ_OP_DISCARD
2019-07-11 17:53 [PATCH 0/8] null_blk: add missing write-zeroes and discard support Chaitanya Kulkarni
@ 2019-07-11 17:53 ` Chaitanya Kulkarni
2019-07-28 6:04 ` Minwoo Im
2019-07-11 17:53 ` [PATCH 2/8] null_blk: add REQ_OP_WRITE_ZEROES config property Chaitanya Kulkarni
` (6 subsequent siblings)
7 siblings, 1 reply; 16+ messages in thread
From: Chaitanya Kulkarni @ 2019-07-11 17:53 UTC (permalink / raw)
To: linux-block; +Cc: axboe, hch, Chaitanya Kulkarni
This patch adds a module parameter to configure the REQ_OP_DISCARD
handling support when null_blk module is not memory-backed. This support
is useful in the various scenarios such as examining REQ_OP_DISCARD path
tests, blktrace and discard with priorities.
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
drivers/block/null_blk_main.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
index 99328ded60d1..20d60b951622 100644
--- a/drivers/block/null_blk_main.c
+++ b/drivers/block/null_blk_main.c
@@ -3,6 +3,7 @@
* Add configfs and memory store: Kyungchan Koh <kkc6196@fb.com> and
* Shaohua Li <shli@fb.com>
*/
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/module.h>
#include <linux/moduleparam.h>
@@ -193,6 +194,10 @@ static unsigned int g_zone_nr_conv;
module_param_named(zone_nr_conv, g_zone_nr_conv, uint, 0444);
MODULE_PARM_DESC(zone_nr_conv, "Number of conventional zones when block device is zoned. Default: 0");
+static bool g_discard;
+module_param_named(discard, g_discard, bool, 0444);
+MODULE_PARM_DESC(discard, "Allow REQ_OP_DISCARD processing. Default: false");
+
static struct nullb_device *null_alloc_dev(void);
static void null_free_dev(struct nullb_device *dev);
static void null_del_dev(struct nullb *nullb);
@@ -529,6 +534,8 @@ static struct nullb_device *null_alloc_dev(void)
dev->zoned = g_zoned;
dev->zone_size = g_zone_size;
dev->zone_nr_conv = g_zone_nr_conv;
+ dev->discard = g_discard;
+ pr_info("discard : %s\n", dev->discard ? "TRUE" : "FALSE");
return dev;
}
--
2.17.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 1/8] null_blk: add module parameter for REQ_OP_DISCARD
2019-07-11 17:53 ` [PATCH 1/8] null_blk: add module parameter for REQ_OP_DISCARD Chaitanya Kulkarni
@ 2019-07-28 6:04 ` Minwoo Im
2019-07-30 4:48 ` Chaitanya Kulkarni
0 siblings, 1 reply; 16+ messages in thread
From: Minwoo Im @ 2019-07-28 6:04 UTC (permalink / raw)
To: Chaitanya Kulkarni; +Cc: linux-block, axboe, hch, Minwoo Im
Hi Chaitanya,
On 19-07-11 10:53:21, Chaitanya Kulkarni wrote:
> This patch adds a module parameter to configure the REQ_OP_DISCARD
> handling support when null_blk module is not memory-backed. This support
> is useful in the various scenarios such as examining REQ_OP_DISCARD path
> tests, blktrace and discard with priorities.
>
> Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
> ---
> drivers/block/null_blk_main.c | 7 +++++++
> 1 file changed, 7 insertions(+)
>
> diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
> index 99328ded60d1..20d60b951622 100644
> --- a/drivers/block/null_blk_main.c
> +++ b/drivers/block/null_blk_main.c
> @@ -3,6 +3,7 @@
> * Add configfs and memory store: Kyungchan Koh <kkc6196@fb.com> and
> * Shaohua Li <shli@fb.com>
> */
> +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
Maybe it casue other pr_ family prints "null_blk" twice, doesn't it? If
so, can we have this change with the other pr_ family updated?
Thanks!
^ permalink raw reply [flat|nested] 16+ messages in thread
* Re: [PATCH 1/8] null_blk: add module parameter for REQ_OP_DISCARD
2019-07-28 6:04 ` Minwoo Im
@ 2019-07-30 4:48 ` Chaitanya Kulkarni
0 siblings, 0 replies; 16+ messages in thread
From: Chaitanya Kulkarni @ 2019-07-30 4:48 UTC (permalink / raw)
To: Minwoo Im; +Cc: linux-block, axboe, hch
On 7/27/19 11:04 PM, Minwoo Im wrote:
> Hi Chaitanya,
>
> On 19-07-11 10:53:21, Chaitanya Kulkarni wrote:
>> This patch adds a module parameter to configure the REQ_OP_DISCARD
>> handling support when null_blk module is not memory-backed. This support
>> is useful in the various scenarios such as examining REQ_OP_DISCARD path
>> tests, blktrace and discard with priorities.
>>
>> Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
>> ---
>> drivers/block/null_blk_main.c | 7 +++++++
>> 1 file changed, 7 insertions(+)
>>
>> diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
>> index 99328ded60d1..20d60b951622 100644
>> --- a/drivers/block/null_blk_main.c
>> +++ b/drivers/block/null_blk_main.c
>> @@ -3,6 +3,7 @@
>> * Add configfs and memory store: Kyungchan Koh <kkc6196@fb.com> and
>> * Shaohua Li <shli@fb.com>
>> */
>> +#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> Maybe it casue other pr_ family prints "null_blk" twice, doesn't it? If
> so, can we have this change with the other pr_ family updated?
>
> Thanks!
>
Okay, I'll add this in next version.
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 2/8] null_blk: add REQ_OP_WRITE_ZEROES config property
2019-07-11 17:53 [PATCH 0/8] null_blk: add missing write-zeroes and discard support Chaitanya Kulkarni
2019-07-11 17:53 ` [PATCH 1/8] null_blk: add module parameter for REQ_OP_DISCARD Chaitanya Kulkarni
@ 2019-07-11 17:53 ` Chaitanya Kulkarni
2019-07-28 6:17 ` Minwoo Im
2019-07-11 17:53 ` [PATCH 3/8] null_blk: add support for write-zeroes Chaitanya Kulkarni
` (5 subsequent siblings)
7 siblings, 1 reply; 16+ messages in thread
From: Chaitanya Kulkarni @ 2019-07-11 17:53 UTC (permalink / raw)
To: linux-block; +Cc: axboe, hch, Chaitanya Kulkarni
This is a preparation patch for implementing the support for the
write-zeroes operations for null_blk. We introduce a new bool flag
write-zeroes for nullb_device structure so that user can either set
this value through configfs when null_blk is memory backed or use
module parameter. Following two patches are implementing respective
support for REQ_OP_WRITE_ZEROES.
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
drivers/block/null_blk.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/drivers/block/null_blk.h b/drivers/block/null_blk.h
index 34b22d6523ba..ecd1e45f6eb9 100644
--- a/drivers/block/null_blk.h
+++ b/drivers/block/null_blk.h
@@ -63,6 +63,7 @@ struct nullb_device {
bool power; /* power on/off the device */
bool memory_backed; /* if data is stored in memory */
bool discard; /* if support discard */
+ bool write_zeroes; /* if support write_zeroes */
bool zoned; /* if device is zoned */
};
--
2.17.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 2/8] null_blk: add REQ_OP_WRITE_ZEROES config property
2019-07-11 17:53 ` [PATCH 2/8] null_blk: add REQ_OP_WRITE_ZEROES config property Chaitanya Kulkarni
@ 2019-07-28 6:17 ` Minwoo Im
0 siblings, 0 replies; 16+ messages in thread
From: Minwoo Im @ 2019-07-28 6:17 UTC (permalink / raw)
To: Chaitanya Kulkarni; +Cc: linux-block, axboe, hch, Minwoo Im
On 19-07-11 10:53:22, Chaitanya Kulkarni wrote:
> This is a preparation patch for implementing the support for the
> write-zeroes operations for null_blk. We introduce a new bool flag
> write-zeroes for nullb_device structure so that user can either set
> this value through configfs when null_blk is memory backed or use
> module parameter. Following two patches are implementing respective
> support for REQ_OP_WRITE_ZEROES.
>
> Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Hi Chaitanya,
It looks good to be squashed with 3rd patch. Code looks good to me.
Thanks!
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 3/8] null_blk: add support for write-zeroes
2019-07-11 17:53 [PATCH 0/8] null_blk: add missing write-zeroes and discard support Chaitanya Kulkarni
2019-07-11 17:53 ` [PATCH 1/8] null_blk: add module parameter for REQ_OP_DISCARD Chaitanya Kulkarni
2019-07-11 17:53 ` [PATCH 2/8] null_blk: add REQ_OP_WRITE_ZEROES config property Chaitanya Kulkarni
@ 2019-07-11 17:53 ` Chaitanya Kulkarni
2019-07-28 6:08 ` Minwoo Im
2019-07-11 17:53 ` [PATCH 4/8] null_blk: allow memory-backed write-zeroes-req Chaitanya Kulkarni
` (4 subsequent siblings)
7 siblings, 1 reply; 16+ messages in thread
From: Chaitanya Kulkarni @ 2019-07-11 17:53 UTC (permalink / raw)
To: linux-block; +Cc: axboe, hch, Chaitanya Kulkarni
This patch adds support to execute REQ_OP_WRITE_ZEROES operations on
the null_blk device when device is not memory-backed. Just like
REQ_OP_DISCARD we add a new module parameter to enable this support.
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
drivers/block/null_blk_main.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
index 20d60b951622..65da7c2d93b9 100644
--- a/drivers/block/null_blk_main.c
+++ b/drivers/block/null_blk_main.c
@@ -198,6 +198,10 @@ static bool g_discard;
module_param_named(discard, g_discard, bool, 0444);
MODULE_PARM_DESC(discard, "Allow REQ_OP_DISCARD processing. Default: false");
+static bool g_write_zeroes;
+module_param_named(write_zeroes, g_write_zeroes, bool, 0444);
+MODULE_PARM_DESC(write_zeroes, "Allow REQ_OP_WRITE_ZEROES processing. Default: false");
+
static struct nullb_device *null_alloc_dev(void);
static void null_free_dev(struct nullb_device *dev);
static void null_del_dev(struct nullb *nullb);
@@ -535,7 +539,10 @@ static struct nullb_device *null_alloc_dev(void)
dev->zone_size = g_zone_size;
dev->zone_nr_conv = g_zone_nr_conv;
dev->discard = g_discard;
+ dev->write_zeroes = g_write_zeroes;
pr_info("discard : %s\n", dev->discard ? "TRUE" : "FALSE");
+ pr_info("write-zeroes : %s\n", dev->write_zeroes ? "TRUE" : "FALSE");
+
return dev;
}
@@ -1419,6 +1426,13 @@ static void null_config_discard(struct nullb *nullb)
blk_queue_flag_set(QUEUE_FLAG_DISCARD, nullb->q);
}
+static void null_config_write_zeroes(struct nullb *nullb)
+{
+ if (nullb->dev->write_zeroes == false)
+ return;
+ blk_queue_max_write_zeroes_sectors(nullb->q, UINT_MAX >> SECTOR_SHIFT);
+}
+
static int null_open(struct block_device *bdev, fmode_t mode)
{
return 0;
@@ -1710,6 +1724,7 @@ static int null_add_dev(struct nullb_device *dev)
blk_queue_physical_block_size(nullb->q, dev->blocksize);
null_config_discard(nullb);
+ null_config_write_zeroes(nullb);
sprintf(nullb->disk_name, "nullb%d", nullb->index);
--
2.17.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 3/8] null_blk: add support for write-zeroes
2019-07-11 17:53 ` [PATCH 3/8] null_blk: add support for write-zeroes Chaitanya Kulkarni
@ 2019-07-28 6:08 ` Minwoo Im
0 siblings, 0 replies; 16+ messages in thread
From: Minwoo Im @ 2019-07-28 6:08 UTC (permalink / raw)
To: Chaitanya Kulkarni; +Cc: linux-block, axboe, hch, Minwoo Im
On 19-07-11 10:53:23, Chaitanya Kulkarni wrote:
> This patch adds support to execute REQ_OP_WRITE_ZEROES operations on
> the null_blk device when device is not memory-backed. Just like
> REQ_OP_DISCARD we add a new module parameter to enable this support.
>
> Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
> ---
> drivers/block/null_blk_main.c | 15 +++++++++++++++
> 1 file changed, 15 insertions(+)
>
> diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
> index 20d60b951622..65da7c2d93b9 100644
> --- a/drivers/block/null_blk_main.c
> +++ b/drivers/block/null_blk_main.c
> @@ -198,6 +198,10 @@ static bool g_discard;
> module_param_named(discard, g_discard, bool, 0444);
> MODULE_PARM_DESC(discard, "Allow REQ_OP_DISCARD processing. Default: false");
>
> +static bool g_write_zeroes;
> +module_param_named(write_zeroes, g_write_zeroes, bool, 0444);
> +MODULE_PARM_DESC(write_zeroes, "Allow REQ_OP_WRITE_ZEROES processing. Default: false");
> +
> static struct nullb_device *null_alloc_dev(void);
> static void null_free_dev(struct nullb_device *dev);
> static void null_del_dev(struct nullb *nullb);
> @@ -535,7 +539,10 @@ static struct nullb_device *null_alloc_dev(void)
> dev->zone_size = g_zone_size;
> dev->zone_nr_conv = g_zone_nr_conv;
> dev->discard = g_discard;
> + dev->write_zeroes = g_write_zeroes;
> pr_info("discard : %s\n", dev->discard ? "TRUE" : "FALSE");
> + pr_info("write-zeroes : %s\n", dev->write_zeroes ? "TRUE" : "FALSE");
> +
> return dev;
> }
>
> @@ -1419,6 +1426,13 @@ static void null_config_discard(struct nullb *nullb)
> blk_queue_flag_set(QUEUE_FLAG_DISCARD, nullb->q);
> }
>
> +static void null_config_write_zeroes(struct nullb *nullb)
> +{
> + if (nullb->dev->write_zeroes == false)
Can this trivial one for the style like the others in this module ?
if (!nullb->dev->write_zeroes)
Besides that it looks good to me :)
Thanks!
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 4/8] null_blk: allow memory-backed write-zeroes-req
2019-07-11 17:53 [PATCH 0/8] null_blk: add missing write-zeroes and discard support Chaitanya Kulkarni
` (2 preceding siblings ...)
2019-07-11 17:53 ` [PATCH 3/8] null_blk: add support for write-zeroes Chaitanya Kulkarni
@ 2019-07-11 17:53 ` Chaitanya Kulkarni
2019-07-28 6:11 ` Minwoo Im
2019-07-11 17:53 ` [PATCH 5/8] null_blk: code cleaup Chaitanya Kulkarni
` (3 subsequent siblings)
7 siblings, 1 reply; 16+ messages in thread
From: Chaitanya Kulkarni @ 2019-07-11 17:53 UTC (permalink / raw)
To: linux-block; +Cc: axboe, hch, Chaitanya Kulkarni
This patch adds support for memory backed REQ_OP_WRITE_ZEROES
operations for the null_blk request mode. We introduce two new
functions where we zeroout the sector(s) using memset which are part
of the payloadless write-zeroes request.
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
drivers/block/null_blk_main.c | 45 ++++++++++++++++++++++++++++++++++-
1 file changed, 44 insertions(+), 1 deletion(-)
diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
index 65da7c2d93b9..fca011a05277 100644
--- a/drivers/block/null_blk_main.c
+++ b/drivers/block/null_blk_main.c
@@ -725,6 +725,24 @@ static void null_free_sector(struct nullb *nullb, sector_t sector,
}
}
+static void null_zero_sector(struct nullb_device *d, sector_t sect,
+ sector_t nr_sects, bool cache)
+{
+ struct radix_tree_root *root = cache ? &d->cache : &d->data;
+ struct nullb_page *t_page;
+ unsigned int offset;
+ void *dest;
+
+ t_page = radix_tree_lookup(root, sect >> PAGE_SECTORS_SHIFT);
+ if (!t_page)
+ return;
+
+ offset = (sect & SECTOR_MASK) << SECTOR_SHIFT;
+ dest = kmap_atomic(t_page->page);
+ memset(dest + offset, 0, SECTOR_SIZE * nr_sects);
+ kunmap_atomic(dest);
+}
+
static struct nullb_page *null_radix_tree_insert(struct nullb *nullb, u64 idx,
struct nullb_page *t_page, bool is_cache)
{
@@ -1026,6 +1044,25 @@ static void null_handle_discard(struct nullb *nullb, sector_t sector, size_t n)
spin_unlock_irq(&nullb->lock);
}
+static void null_handle_write_zeroes(struct nullb *nullb, sector_t sector,
+ unsigned int bytes_left)
+{
+ sector_t nr_sectors;
+ size_t curr_bytes;
+
+ spin_lock_irq(&nullb->lock);
+ while (bytes_left > 0) {
+ curr_bytes = min_t(size_t, bytes_left, nullb->dev->blocksize);
+ nr_sectors = curr_bytes >> SECTOR_SHIFT;
+ null_zero_sector(nullb->dev, sector, nr_sectors, false);
+ if (null_cache_active(nullb))
+ null_zero_sector(nullb->dev, sector, nr_sectors, true);
+ sector += nr_sectors;
+ bytes_left -= curr_bytes;
+ }
+ spin_unlock_irq(&nullb->lock);
+}
+
static int null_handle_flush(struct nullb *nullb)
{
int err;
@@ -1075,9 +1112,15 @@ static int null_handle_rq(struct nullb_cmd *cmd)
sector = blk_rq_pos(rq);
- if (req_op(rq) == REQ_OP_DISCARD) {
+ switch (req_op(rq)) {
+ case REQ_OP_DISCARD:
null_handle_discard(nullb, sector, blk_rq_bytes(rq));
return 0;
+ case REQ_OP_WRITE_ZEROES:
+ null_handle_write_zeroes(nullb, sector, blk_rq_bytes(rq));
+ return 0;
+ default:
+ break;
}
spin_lock_irq(&nullb->lock);
--
2.17.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 4/8] null_blk: allow memory-backed write-zeroes-req
2019-07-11 17:53 ` [PATCH 4/8] null_blk: allow memory-backed write-zeroes-req Chaitanya Kulkarni
@ 2019-07-28 6:11 ` Minwoo Im
0 siblings, 0 replies; 16+ messages in thread
From: Minwoo Im @ 2019-07-28 6:11 UTC (permalink / raw)
To: Chaitanya Kulkarni; +Cc: linux-block, axboe, hch, Minwoo Im
On 19-07-11 10:53:24, Chaitanya Kulkarni wrote:
> This patch adds support for memory backed REQ_OP_WRITE_ZEROES
> operations for the null_blk request mode. We introduce two new
> functions where we zeroout the sector(s) using memset which are part
> of the payloadless write-zeroes request.
>
> Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
> ---
> drivers/block/null_blk_main.c | 45 ++++++++++++++++++++++++++++++++++-
> 1 file changed, 44 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
> index 65da7c2d93b9..fca011a05277 100644
> --- a/drivers/block/null_blk_main.c
> +++ b/drivers/block/null_blk_main.c
> @@ -725,6 +725,24 @@ static void null_free_sector(struct nullb *nullb, sector_t sector,
> }
> }
>
> +static void null_zero_sector(struct nullb_device *d, sector_t sect,
> + sector_t nr_sects, bool cache)
> +{
> + struct radix_tree_root *root = cache ? &d->cache : &d->data;
> + struct nullb_page *t_page;
> + unsigned int offset;
> + void *dest;
> +
> + t_page = radix_tree_lookup(root, sect >> PAGE_SECTORS_SHIFT);
> + if (!t_page)
> + return;
> +
> + offset = (sect & SECTOR_MASK) << SECTOR_SHIFT;
> + dest = kmap_atomic(t_page->page);
> + memset(dest + offset, 0, SECTOR_SIZE * nr_sects);
> + kunmap_atomic(dest);
> +}
> +
> static struct nullb_page *null_radix_tree_insert(struct nullb *nullb, u64 idx,
> struct nullb_page *t_page, bool is_cache)
> {
> @@ -1026,6 +1044,25 @@ static void null_handle_discard(struct nullb *nullb, sector_t sector, size_t n)
> spin_unlock_irq(&nullb->lock);
> }
>
> +static void null_handle_write_zeroes(struct nullb *nullb, sector_t sector,
> + unsigned int bytes_left)
> +{
> + sector_t nr_sectors;
> + size_t curr_bytes;
> +
> + spin_lock_irq(&nullb->lock);
> + while (bytes_left > 0) {
Hi Chaitanya,
Thanks for your support for this!
I have a simple query here. Is there any recommended rule about using
the function argument to be changed inside of that function like
_bytes_left_? I'm not against it, but I'd like to know if it's okay to
decrement inside of this function in code-style point-of-view.
Thanks!
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 5/8] null_blk: code cleaup
2019-07-11 17:53 [PATCH 0/8] null_blk: add missing write-zeroes and discard support Chaitanya Kulkarni
` (3 preceding siblings ...)
2019-07-11 17:53 ` [PATCH 4/8] null_blk: allow memory-backed write-zeroes-req Chaitanya Kulkarni
@ 2019-07-11 17:53 ` Chaitanya Kulkarni
2019-07-28 6:12 ` Minwoo Im
2019-07-11 17:53 ` [PATCH 6/8] null_blk: allow memory-backed write-zeroes-bio Chaitanya Kulkarni
` (2 subsequent siblings)
7 siblings, 1 reply; 16+ messages in thread
From: Chaitanya Kulkarni @ 2019-07-11 17:53 UTC (permalink / raw)
To: linux-block; +Cc: axboe, hch, Chaitanya Kulkarni
In the null_blk for different page and sector calculation we have
simple macros to make the code more redable.
Similar to that this is a purely code cleanup patch where we
introduce two new macros for calculating the page index from given
sector and index (offset) of the sector in the page.
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
drivers/block/null_blk_main.c | 37 ++++++++++++++++++++---------------
1 file changed, 21 insertions(+), 16 deletions(-)
diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
index fca011a05277..d463bde001b6 100644
--- a/drivers/block/null_blk_main.c
+++ b/drivers/block/null_blk_main.c
@@ -16,6 +16,11 @@
#define PAGE_SECTORS (1 << PAGE_SECTORS_SHIFT)
#define SECTOR_MASK (PAGE_SECTORS - 1)
+/* Gives page index for which this sector belongs to. */
+#define PAGE_IDX_FROM_SECT(sect) (sect >> PAGE_SECTORS_SHIFT)
+/* Gives index (offset) of the sector within page. */
+#define SECT_IDX_IN_PAGE(sect) ((sect & SECTOR_MASK) << SECTOR_SHIFT)
+
#define FREE_BATCH 16
#define TICKS_PER_SEC 50ULL
@@ -708,20 +713,20 @@ static void null_free_sector(struct nullb *nullb, sector_t sector,
struct radix_tree_root *root;
root = is_cache ? &nullb->dev->cache : &nullb->dev->data;
- idx = sector >> PAGE_SECTORS_SHIFT;
+ idx = PAGE_IDX_FROM_SECT(sector);
sector_bit = (sector & SECTOR_MASK);
t_page = radix_tree_lookup(root, idx);
- if (t_page) {
- __clear_bit(sector_bit, t_page->bitmap);
-
- if (null_page_empty(t_page)) {
- ret = radix_tree_delete_item(root, idx, t_page);
- WARN_ON(ret != t_page);
- null_free_page(ret);
- if (is_cache)
- nullb->dev->curr_cache -= PAGE_SIZE;
- }
+ if (!t_page)
+ return;
+ __clear_bit(sector_bit, t_page->bitmap);
+
+ if (null_page_empty(t_page)) {
+ ret = radix_tree_delete_item(root, idx, t_page);
+ WARN_ON(ret != t_page);
+ null_free_page(ret);
+ if (is_cache)
+ nullb->dev->curr_cache -= PAGE_SIZE;
}
}
@@ -733,11 +738,11 @@ static void null_zero_sector(struct nullb_device *d, sector_t sect,
unsigned int offset;
void *dest;
- t_page = radix_tree_lookup(root, sect >> PAGE_SECTORS_SHIFT);
+ t_page = radix_tree_lookup(root, PAGE_IDX_FROM_SECT(sect));
if (!t_page)
return;
- offset = (sect & SECTOR_MASK) << SECTOR_SHIFT;
+ offset = SECT_IDX_IN_PAGE(sect);
dest = kmap_atomic(t_page->page);
memset(dest + offset, 0, SECTOR_SIZE * nr_sects);
kunmap_atomic(dest);
@@ -797,7 +802,7 @@ static struct nullb_page *__null_lookup_page(struct nullb *nullb,
struct nullb_page *t_page;
struct radix_tree_root *root;
- idx = sector >> PAGE_SECTORS_SHIFT;
+ idx = PAGE_IDX_FROM_SECT(sector);
sector_bit = (sector & SECTOR_MASK);
root = is_cache ? &nullb->dev->cache : &nullb->dev->data;
@@ -973,7 +978,7 @@ static int copy_to_nullb(struct nullb *nullb, struct page *source,
if (null_cache_active(nullb) && !is_fua)
null_make_cache_space(nullb, PAGE_SIZE);
- offset = (sector & SECTOR_MASK) << SECTOR_SHIFT;
+ offset = SECT_IDX_IN_PAGE(sector);
t_page = null_insert_page(nullb, sector,
!null_cache_active(nullb) || is_fua);
if (!t_page)
@@ -1007,7 +1012,7 @@ static int copy_from_nullb(struct nullb *nullb, struct page *dest,
while (count < n) {
temp = min_t(size_t, nullb->dev->blocksize, n - count);
- offset = (sector & SECTOR_MASK) << SECTOR_SHIFT;
+ offset = SECT_IDX_IN_PAGE(sector);
t_page = null_lookup_page(nullb, sector, false,
!null_cache_active(nullb));
--
2.17.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 6/8] null_blk: allow memory-backed write-zeroes-bio
2019-07-11 17:53 [PATCH 0/8] null_blk: add missing write-zeroes and discard support Chaitanya Kulkarni
` (4 preceding siblings ...)
2019-07-11 17:53 ` [PATCH 5/8] null_blk: code cleaup Chaitanya Kulkarni
@ 2019-07-11 17:53 ` Chaitanya Kulkarni
2019-07-28 6:18 ` Minwoo Im
2019-07-11 17:53 ` [PATCH 7/8] null_blk: add support for configfs write_zeroes Chaitanya Kulkarni
2019-07-11 17:53 ` [PATCH 8/8] null_blk: adjusts the code with latest changes Chaitanya Kulkarni
7 siblings, 1 reply; 16+ messages in thread
From: Chaitanya Kulkarni @ 2019-07-11 17:53 UTC (permalink / raw)
To: linux-block; +Cc: axboe, hch, Chaitanya Kulkarni
This patch adds support for memory backed REQ_OP_WRITE_ZEROES
operations for the null_blk bio mode.
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
drivers/block/null_blk_main.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
index d463bde001b6..30cb90553167 100644
--- a/drivers/block/null_blk_main.c
+++ b/drivers/block/null_blk_main.c
@@ -1147,6 +1147,7 @@ static int null_handle_rq(struct nullb_cmd *cmd)
static int null_handle_bio(struct nullb_cmd *cmd)
{
+ unsigned int blk_bio_bytes = bio_sectors(cmd->bio) << SECTOR_SHIFT;
struct bio *bio = cmd->bio;
struct nullb *nullb = cmd->nq->dev->nullb;
int err;
@@ -1157,10 +1158,15 @@ static int null_handle_bio(struct nullb_cmd *cmd)
sector = bio->bi_iter.bi_sector;
- if (bio_op(bio) == REQ_OP_DISCARD) {
- null_handle_discard(nullb, sector,
- bio_sectors(bio) << SECTOR_SHIFT);
+ switch (bio_op(bio)) {
+ case REQ_OP_DISCARD:
+ null_handle_discard(nullb, sector, blk_bio_bytes);
+ return 0;
+ case REQ_OP_WRITE_ZEROES:
+ null_handle_write_zeroes(nullb, sector, blk_bio_bytes);
return 0;
+ default:
+ break;
}
spin_lock_irq(&nullb->lock);
--
2.17.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* Re: [PATCH 6/8] null_blk: allow memory-backed write-zeroes-bio
2019-07-11 17:53 ` [PATCH 6/8] null_blk: allow memory-backed write-zeroes-bio Chaitanya Kulkarni
@ 2019-07-28 6:18 ` Minwoo Im
0 siblings, 0 replies; 16+ messages in thread
From: Minwoo Im @ 2019-07-28 6:18 UTC (permalink / raw)
To: Chaitanya Kulkarni; +Cc: linux-block, axboe, hch, Minwoo Im
On 19-07-11 10:53:26, Chaitanya Kulkarni wrote:
> This patch adds support for memory backed REQ_OP_WRITE_ZEROES
> operations for the null_blk bio mode.
>
> Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Hi Chaitanya,
This patch looks like good to me merged with 4th patch which is about
the null_handle_rq(). I think it would be great if a commit covers the
actual callers for those introduced. But code looks good to me :)
Thanks!
^ permalink raw reply [flat|nested] 16+ messages in thread
* [PATCH 7/8] null_blk: add support for configfs write_zeroes
2019-07-11 17:53 [PATCH 0/8] null_blk: add missing write-zeroes and discard support Chaitanya Kulkarni
` (5 preceding siblings ...)
2019-07-11 17:53 ` [PATCH 6/8] null_blk: allow memory-backed write-zeroes-bio Chaitanya Kulkarni
@ 2019-07-11 17:53 ` Chaitanya Kulkarni
2019-07-11 17:53 ` [PATCH 8/8] null_blk: adjusts the code with latest changes Chaitanya Kulkarni
7 siblings, 0 replies; 16+ messages in thread
From: Chaitanya Kulkarni @ 2019-07-11 17:53 UTC (permalink / raw)
To: linux-block; +Cc: axboe, hch, Chaitanya Kulkarni
This patch adds a new configfs parameter to enable REQ_OP_WRITE_ZEROES
feature for null_blk similar to REQ_OP_DISCARD when device is memory
backed.
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
drivers/block/null_blk_main.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
index 30cb90553167..c734ddaa697f 100644
--- a/drivers/block/null_blk_main.c
+++ b/drivers/block/null_blk_main.c
@@ -308,6 +308,7 @@ NULLB_DEVICE_ATTR(blocking, bool);
NULLB_DEVICE_ATTR(use_per_node_hctx, bool);
NULLB_DEVICE_ATTR(memory_backed, bool);
NULLB_DEVICE_ATTR(discard, bool);
+NULLB_DEVICE_ATTR(write_zeroes, bool);
NULLB_DEVICE_ATTR(mbps, uint);
NULLB_DEVICE_ATTR(cache_size, ulong);
NULLB_DEVICE_ATTR(zoned, bool);
@@ -423,6 +424,7 @@ static struct configfs_attribute *nullb_device_attrs[] = {
&nullb_device_attr_power,
&nullb_device_attr_memory_backed,
&nullb_device_attr_discard,
+ &nullb_device_attr_write_zeroes,
&nullb_device_attr_mbps,
&nullb_device_attr_cache_size,
&nullb_device_attr_badblocks,
@@ -481,7 +483,7 @@ nullb_group_drop_item(struct config_group *group, struct config_item *item)
static ssize_t memb_group_features_show(struct config_item *item, char *page)
{
- return snprintf(page, PAGE_SIZE, "memory_backed,discard,bandwidth,cache,badblocks,zoned,zone_size\n");
+ return snprintf(page, PAGE_SIZE, "memory_backed,discard,write_zeroes,bandwidth,cache,badblocks,zoned,zone_size\n");
}
CONFIGFS_ATTR_RO(memb_group_, features);
--
2.17.0
^ permalink raw reply related [flat|nested] 16+ messages in thread
* [PATCH 8/8] null_blk: adjusts the code with latest changes
2019-07-11 17:53 [PATCH 0/8] null_blk: add missing write-zeroes and discard support Chaitanya Kulkarni
` (6 preceding siblings ...)
2019-07-11 17:53 ` [PATCH 7/8] null_blk: add support for configfs write_zeroes Chaitanya Kulkarni
@ 2019-07-11 17:53 ` Chaitanya Kulkarni
7 siblings, 0 replies; 16+ messages in thread
From: Chaitanya Kulkarni @ 2019-07-11 17:53 UTC (permalink / raw)
To: linux-block; +Cc: axboe, hch, Chaitanya Kulkarni
Now that we have support for more than on special operations
REQ_OP_DISCARD and REQ_OP_WRITE_ZEROES create a helper to isolate the
code common code.
Signed-off-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
---
drivers/block/null_blk_main.c | 41 +++++++++++++++++------------------
1 file changed, 20 insertions(+), 21 deletions(-)
diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c
index c734ddaa697f..f59a05bcf56f 100644
--- a/drivers/block/null_blk_main.c
+++ b/drivers/block/null_blk_main.c
@@ -1107,28 +1107,36 @@ static int null_transfer(struct nullb *nullb, struct page *page,
return err;
}
+static inline bool null_handle_special_op(struct nullb *nullb, sector_t sector,
+ unsigned int bytes, enum req_opf op)
+{
+ switch (op) {
+ case REQ_OP_DISCARD:
+ null_handle_discard(nullb, sector, bytes);
+ return true;
+ case REQ_OP_WRITE_ZEROES:
+ null_handle_write_zeroes(nullb, sector, bytes);
+ return true;
+ default:
+ break;
+ }
+ return false;
+}
+
static int null_handle_rq(struct nullb_cmd *cmd)
{
struct request *rq = cmd->rq;
struct nullb *nullb = cmd->nq->dev->nullb;
int err;
- unsigned int len;
+ unsigned int len = blk_rq_bytes(rq);
sector_t sector;
struct req_iterator iter;
struct bio_vec bvec;
sector = blk_rq_pos(rq);
- switch (req_op(rq)) {
- case REQ_OP_DISCARD:
- null_handle_discard(nullb, sector, blk_rq_bytes(rq));
+ if (null_handle_special_op(nullb, sector, len, req_op(rq)))
return 0;
- case REQ_OP_WRITE_ZEROES:
- null_handle_write_zeroes(nullb, sector, blk_rq_bytes(rq));
- return 0;
- default:
- break;
- }
spin_lock_irq(&nullb->lock);
rq_for_each_segment(bvec, rq, iter) {
@@ -1149,27 +1157,18 @@ static int null_handle_rq(struct nullb_cmd *cmd)
static int null_handle_bio(struct nullb_cmd *cmd)
{
- unsigned int blk_bio_bytes = bio_sectors(cmd->bio) << SECTOR_SHIFT;
+ unsigned int len = bio_sectors(cmd->bio) << SECTOR_SHIFT;
struct bio *bio = cmd->bio;
struct nullb *nullb = cmd->nq->dev->nullb;
int err;
- unsigned int len;
sector_t sector;
struct bio_vec bvec;
struct bvec_iter iter;
sector = bio->bi_iter.bi_sector;
- switch (bio_op(bio)) {
- case REQ_OP_DISCARD:
- null_handle_discard(nullb, sector, blk_bio_bytes);
+ if (null_handle_special_op(nullb, sector, len, bio_op(bio)))
return 0;
- case REQ_OP_WRITE_ZEROES:
- null_handle_write_zeroes(nullb, sector, blk_bio_bytes);
- return 0;
- default:
- break;
- }
spin_lock_irq(&nullb->lock);
bio_for_each_segment(bvec, bio, iter) {
--
2.17.0
^ permalink raw reply related [flat|nested] 16+ messages in thread