Skip to contentSkip to conversation

block discard.

PATCH David Woodhouse 2 participants 5 messages Aug 8, 2008 Btrfs file system

lore
Share & tools
lore
#0 lore raw

Playing with the trim/punch/discard support, I tried the patch below. It see it getting invoked at times, but when I create a large file and then delete it, I don't see it getting invoked _enough_. And when I grep the block device for the contents of the file, they're still there.

I have a suspicion my added code is only getting invoked for metadata/tree extents, not the actual data extents. What'd I miss?

extent-tree.c +17 -0
index fff219e..e6908ad 100644
@@ -18,6 +18,7 @@
 #include <linux/sched.h>
 #include <linux/pagemap.h>
 #include <linux/writeback.h>
+#include <linux/blkdev.h>
 #include "hash.h"
 #include "crc32c.h"
 #include "ctree.h"
@@ -1743,6 +1744,22 @@ static int __free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
 		ret = update_block_group(trans, root, bytenr, num_bytes, 0,
 					 mark_free);
 		BUG_ON(ret);
+
+
+		u64 map_length = num_bytes;
+		struct btrfs_multi_bio *multi = NULL;
+		ret = btrfs_map_block(&root->fs_info->mapping_tree, READ,
+				      bytenr, &map_length, &multi, 0);
+		if (!ret) {
+			int i;
+			for (i=0; i< multi->num_stripes; i++) {
+				blkdev_issue_discard(multi->stripes[i].dev->bdev,
+						     multi->stripes[i].physical >> 9,
+						     min(map_length, num_bytes) >> 9,
+						     NULL);
+			}
+			kfree(multi);
+		}
 	}
 	btrfs_free_path(path);
 	finish_current_insert(trans, extent_root);
Signature · 2 lines
David Woodhouse                            Open Source Technology Centre
[email protected]                              Intel Corporation
#1 lore raw
Quoted 8 lines · David Woodhouse

Playing with the trim/punch/discard support, I tried the patch below. It see it getting invoked at times, but when I create a large file and then delete it, I don't see it getting invoked _enough_. And when I grep the block device for the contents of the file, they're still there.

I have a suspicion my added code is only getting invoked for metadata/tree extents, not the actual data extents. What'd I miss?

So you mkfs ; dd large file ; rm large file ; look for discards?

Try rm large file ; sync ; sync; look for discards

-chris

#2 lore raw
Quoted 3 lines · Chris Mason

So you mkfs ; dd large file ; rm large file ; look for discards?

Try rm large file ; sync ; sync; look for discards

Yeah, I did that. The actual data extent isn't getting removed.

[root@dyn-226 /]# modprobe mtdram total_size=280000 [root@dyn-226 /]# modprobe mtdchar
[root@dyn-226 /]# ftl_format /dev/mtd0
Partition size = 280000 kb, erase unit size = 128 kb, 1 transfer units Reserved 5%, formatted size = 262765 kb
Erasing all blocks...
+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+++++++*+
Writing erase unit headers...
format successful.
[root@dyn-226 /]# modprobe ftl
[root@dyn-226 /]# ~dwmw2/btrfs-progs-unstable/mkfs.btrfs /dev/ftla fs created label (null) on /dev/ftla

	nodesize 4096 leafsize 4096 sectorsize 4096 size 256.61MB

Btrfs Btrfs v0.15
[root@dyn-226 /]# mount -tbtrfs /dev/ftla /mnt/spare [root@dyn-226 /]# cd /mnt/spare
[root@dyn-226 spare]# cp /etc/services .
[root@dyn-226 spare]# sync
[root@dyn-226 spare]# hexdump -C /dev/ftla | grep /etc/services:
00c00000 23 20 2f 65 74 63 2f 73 65 72 76 69 63 65 73 3a |# /etc/services:| [root@dyn-226 spare]# dmesg -c > /dev/null
[root@dyn-226 spare]# rm services
[root@dyn-226 spare]# sync
[root@dyn-226 spare]# dmesg
num_bytes 4096, map_length 24576
Discard from stripe 0: 73808-8
FTL erase sector 73808 for 8 sectors
num_bytes 4096, map_length 12288
Discard from stripe 0: 73832-8
FTL erase sector 73832 for 8 sectors
num_bytes 4096, map_length 20480
Discard from stripe 0: 73816-8
FTL erase sector 73816 for 8 sectors
[root@dyn-226 spare]# hexdump -C /dev/ftla | grep /etc/services:
00c00000 23 20 2f 65 74 63 2f 73 65 72 76 69 63 65 73 3a |# /etc/services:| [root@dyn-226 spare]# echo $((0xc00000/512))
24576

Signature · 1 line
dwmw2
#3 lore raw
Quoted 6 lines · David Woodhouse
Quoted 3 lines · Chris Mason

So you mkfs ; dd large file ; rm large file ; look for discards?

Try rm large file ; sync ; sync; look for discards

Yeah, I did that. The actual data extent isn't getting removed.

Oh, you really did mean _two_ syncs. And then yes, I see why it isn't working; mea culpa.

__free_extent for 0xc00000-0xc65000
num_bytes 413696, map_length 8388608, stripes 1
Discard from stripe 0: 24576-808
bio too big device ftla (808 > 255)

Signature · 2 lines
David Woodhouse                            Open Source Technology Centre
[email protected]                              Intel Corporation
#4 lore raw
Quoted 11 lines · David Woodhouse
Quoted 6 lines · David Woodhouse
Quoted 3 lines · Chris Mason

So you mkfs ; dd large file ; rm large file ; look for discards?

Try rm large file ; sync ; sync; look for discards

Yeah, I did that. The actual data extent isn't getting removed.

Oh, you really did mean _two_ syncs. And then yes, I see why it isn't working; mea culpa.

The first sync commits the transaction and writes out the data. The second sync does the same thing, but this time it finds the old snapshot pending deletion and deletes it.

-chris