Skip to contentSkip to conversation

block: unmap (discard) blocks only if discard_zeros flag is true

PATCH In review luzhipeng 2 participants 3 messages Sep 23, 2022 Block layer

lore
Share & tools
lore

luzhipeng

author
#0 lore raw

PATCH 1/1 block: unmap (discard) blocks only if discard_zeros flag is true

From: lu zhipeng <[email protected]>

we can unmap(discard) blocks for block devices of supporting discard zeros or regular file.

---
 block/file-posix.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
block/file-posix.c +2 -1
index 48cd096624..c35dbc0d88 100644
@@ -799,7 +799,8 @@ static int raw_open_common(BlockDriverState *bs, QDict *options,
 #endif
     s->needs_alignment = raw_needs_alignment(bs);
 
-    bs->supported_zero_flags = BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK;
+    bs->supported_zero_flags = s->discard_zeroes ?
+                               BDRV_REQ_MAY_UNMAP | BDRV_REQ_NO_FALLBACK : 0;
     if (S_ISREG(st.st_mode)) {
         /* When extending regular files, we get zeros from the OS */
         bs->supported_truncate_flags = BDRV_REQ_ZERO_WRITE;
Signature · 1 line
2.31.1
#1 lore raw

Am 23.09.2022 um 12:02 hat luzhipeng geschrieben:

Quoted 6 lines

From: lu zhipeng <[email protected]>

we can unmap(discard) blocks for block devices of supporting discard zeros or regular file.

This more or less restores the state before commit 34fa110e. The commit message there explains that s->discard_zeroes is unreliable (in particular, it is false on block devices on recent kernels even though they may support zeroing by discard just fine).

We should instead remove s->discard_zeroes because it is currently unused. I'll send a patch.

Kevin

author
#2 lore raw
Quoted 13 lines · Kevin Wolf

Am 23.09.2022 um 12:02 hat luzhipeng geschrieben:

Quoted 6 lines

From: lu zhipeng <[email protected]>

we can unmap(discard) blocks for block devices of supporting discard zeros or regular file.

This more or less restores the state before commit 34fa110e. The commit message there explains that s->discard_zeroes is unreliable (in particular, it is false on block devices on recent kernels even though they may support zeroing by discard just fine).

Quoted 7 lines

We should instead remove s->discard_zeroes because it is currently unused. I'll send a patch.

Kevin

OK