From: fengnan chang <fengnanchang@gmail.com>
To: Guoqing Jiang <guoqing.jiang@linux.dev>
Cc: Fengnan Chang <changfengnan@bytedance.com>,
adilger.kernel@dilger.ca, tytso@mit.edu,
linux-ext4@vger.kernel.org,
kernel test robot <oliver.sang@intel.com>
Subject: Re: [PATCH v2] ext4: improve discard efficiency
Date: Mon, 24 Jul 2023 15:22:34 +0800 [thread overview]
Message-ID: <CALWNXx-6y0=ZDBMicv2qng9pKHWcpJbCvUm9TaRBwg81WzWkWQ@mail.gmail.com> (raw)
In-Reply-To: <7aec48ca-c7fa-df42-8a09-5dea9c762c2e@linux.dev>
[-- Attachment #1: Type: text/plain, Size: 1772 bytes --]
On Mon, Jul 24, 2023 at 11:42 AM Guoqing Jiang <guoqing.jiang@linux.dev> wrote:
>
> Hi,
>
> On 7/19/23 17:36, Fengnan Chang wrote:
> > In commit a015434480dc("ext4: send parallel discards on commit
> > completions"), issue all discard commands in parallel make all
> > bios could merged into one request, so lowlevel drive can issue
> > multi segments in one time which is more efficiency, but commit
> > 55cdd0af2bc5 ("ext4: get discard out of jbd2 commit kthread contex")
> > seems broke this way, let's fix it.
> > In my test, the time of fstrim fs with multi big sparse file
> > reduce from 6.7s to 1.3s.
>
> I tried with a 20T sparse file with latest kernel (6.5-rc2+ commit
> f7e3a1baf).
>
> truncate -s 20T sparse1.img
> mkfs.ext4 sparse1.img
> mount -o discard sparse1.img /mnt/
> time fstrim /mnt
>
> 1. without the patch
>
> [root@localhost ~]# time fstrim /mnt
>
> real 0m13.496s
> user 0m0.002s
> sys 0m5.202s
>
> 2. with the patch
>
> [root@localhost ~]# time fstrim /mnt
>
> real 0m15.956s
> user 0m0.000s
> sys 0m7.251s
>
> The result is different from your side, could you share your test?
Here are my test steps:
1. create 10 normal files, each file size is 10G.
2. deallocate file:punch holes every 16k. The attached file includes step 1&2.
3. trim all fs.
So why does trim a new fs become slow? because with my patch, in
ext4_try_to_trim_range
we need do alloc and free memory, this might cause 9us cost in
addition. So in current
version, benefits can only be gained if there are multiple
discontinuous segments that
need to be trimmed in ext4_try_to_trim_range.
This problem needs to be fixed, so I'll send another version.
Thanks.
Fengnan
>
> Thanks,
> Guoqing
[-- Attachment #2: makefrag.c --]
[-- Type: application/octet-stream, Size: 1707 bytes --]
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <sys/stat.h>
#include <linux/falloc.h>
#define _GNU_SOURCE
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/fs.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <time.h>
int deallocate_block_range(int fd, int start_block, int count)
{
unsigned long start = start_block * 4096; // 以字节为单位描述块的范围
unsigned long len = count * 4096; // 以字节为单位描述块的范围
if (fallocate(fd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE,
start, len) == -1) {
perror("fallocate");
exit(EXIT_FAILURE);
}
return 0;
}
int create_file(char *file) {
int fd = open(file, O_WRONLY | O_CREAT | O_TRUNC, 0666);
// 打开文件,以写入方式打开,若不存在则创建,权限为666,文件长度为0
if (fd == -1) {
printf("Fail to create file!\n");
return -1;
}
unsigned long file_s = 10*1024*1024*1024;
unsigned long block_size= 1024*1024;
unsigned long count = file_s / (64* 1024);
char* block = calloc(1, block_size); // 用'A'填充每个块
memset(block, 0x3f, block_size);
for (int i = 0; i < file_s/block_size; i++) {
write(fd, block, block_size); // 写入一个块
}
fsync(fd); // 将缓存中的数据刷新到磁盘
int off = 0;
for (int i = 0; i < count; i++) {
deallocate_block_range(fd, off, 8);
off += 16;
}
close(fd); // 关闭文件
return 0;
}
int
main(int argc, char **argv)
{
for(int i = 0; i < 10; i++) {
char name[128];
sprintf(name, "testfile_%d",i);
create_file(name);
}
return 0;
}
prev parent reply other threads:[~2023-07-24 7:22 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-19 9:36 [PATCH v2] ext4: improve discard efficiency Fengnan Chang
2023-07-24 3:16 ` Guoqing Jiang
2023-07-24 7:22 ` fengnan chang [this message]
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='CALWNXx-6y0=ZDBMicv2qng9pKHWcpJbCvUm9TaRBwg81WzWkWQ@mail.gmail.com' \
--to=fengnanchang@gmail.com \
--cc=adilger.kernel@dilger.ca \
--cc=changfengnan@bytedance.com \
--cc=guoqing.jiang@linux.dev \
--cc=linux-ext4@vger.kernel.org \
--cc=oliver.sang@intel.com \
--cc=tytso@mit.edu \
/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).