2023-06-26 12:31:44

by Li Lingfeng

[permalink] [raw]
Subject: [Question] Can DATA_DEV_BLOCK_SIZE_MIN_SECTORS be set to a smaller value

Hello:

Recently, I found that the used space of the thin-pool will keep rising
if I use dm-thin as follow:

// create dm-thin
dmsetup create linear_1 --table "0 2097152 linear /dev/sdc 0"
dmsetup create linear_2 --table "0 16777216  linear /dev/sdc 2097153"
dd if=/dev/zero of=/dev/mapper/linear_1 bs=4096 count=1
dmsetup create pool --table "0 16777216 thin-pool /dev/mapper/linear_1
/dev/mapper/linear_2 128 0 1 skip_block_zeroing"
dmsetup message /dev/mapper/pool 0 "create_thin 0"
dmsetup create thin --table "0 14680064 thin /dev/mapper/pool 0"

// mkfs and mount with discard
mkfs.ext4 /dev/mapper/thin
mount /dev/mapper/thin /mnt/test -o discard
cd /mnt/test

// create a file(17KB)
dd if=/dev/random of=testfile bs=1k count=17 oflag=direct
sync

// truncate the file and write it for many times
dd if=/dev/random of=testfile bs=1k count=17 oflag=direct
sync
...

Ext4 will issue discard IO to dm-thin when truncating file. However,
DATA_DEV_BLOCK_SIZE_MIN_SECTORS is set as 64KB which means the discard
covers less than a block when I truncating a 17KB file. As the result of
it, discard bio will end in process_discard_bio(), and more and more
blocks will leak.

I'm curious about the reason behind setting
DATA_DEV_BLOCK_SIZE_MIN_SECTORS to 64KB. Is there any specific
consideration for this? Would it be possible to set this minimum limit
to a smaller value, such as 4KB?



2023-06-26 12:46:35

by Zdenek Kabelac

[permalink] [raw]
Subject: Re: [dm-devel] [Question] Can DATA_DEV_BLOCK_SIZE_MIN_SECTORS be set to a smaller value

Dne 26. 06. 23 v 14:19 Li Lingfeng napsal(a):
> Hello:
>
> Recently, I found that the used space of the thin-pool will keep rising if I
> use dm-thin as follow:
>
> // create dm-thin
> dmsetup create linear_1 --table "0 2097152 linear /dev/sdc 0"
> dmsetup create linear_2 --table "0 16777216  linear /dev/sdc 2097153"
> dd if=/dev/zero of=/dev/mapper/linear_1 bs=4096 count=1
> dmsetup create pool --table "0 16777216 thin-pool /dev/mapper/linear_1
> /dev/mapper/linear_2 128 0 1 skip_block_zeroing"
> dmsetup message /dev/mapper/pool 0 "create_thin 0"
> dmsetup create thin --table "0 14680064 thin /dev/mapper/pool 0"
>
> // mkfs and mount with discard
> mkfs.ext4 /dev/mapper/thin
> mount /dev/mapper/thin /mnt/test -o discard
> cd /mnt/test
>
> // create a file(17KB)
> dd if=/dev/random of=testfile bs=1k count=17 oflag=direct
> sync
>
> // truncate the file and write it for many times
> dd if=/dev/random of=testfile bs=1k count=17 oflag=direct
> sync
> ...
>
> Ext4 will issue discard IO to dm-thin when truncating file. However,
> DATA_DEV_BLOCK_SIZE_MIN_SECTORS is set as 64KB which means the discard
> covers less than a block when I truncating a 17KB file. As the result of it,
> discard bio will end in process_discard_bio(), and more and more blocks will
> leak.
>
> I'm curious about the reason behind setting DATA_DEV_BLOCK_SIZE_MIN_SECTORS
> to 64KB. Is there any specific consideration for this? Would it be possible
> to set this minimum limit to a smaller value, such as 4KB?


Hi


The minimal chunksize for thin-pool was selected to  64K - smaller value would
cause major expansion in the used 'metadata' size and further slowdown of
metadata manipulation - so the 64K was set as minimal size.

Regards


Zdenek