fuse: make foffset alignment opt-in for optimum backend performance
Subsystems (2)
PATCH 1/1 fuse: make foffset alignment opt-in for optimum backend performance
Sometimes the file offset alignment needs to be opt-in to achieve the optimum performance at the backend store.
For example when ErasureCode [1] is used at the backend store, the optimum write performance is achieved when the WRITE request is aligned with the stripe size of ErasureCode. Otherwise a non-aligned WRITE request needs to be split at the stripe size boundary. It is quite costly to handle these split partial requests, as firstly the whole stripe to which the split partial request belongs needs to be read out, then overwrite the read stripe buffer with the request, and finally write the whole stripe back to the persistent storage.
Thus the backend store can suffer severe performance degradation when WRITE requests can not fit into one stripe exactly. The write performance can be 10x slower when the request is 256KB in size given 4MB stripe size. Also there can be 50% performance degradation in theory if the request is not stripe boundary aligned.
Besides, the conveyed test indicates that, the non-alignment issue becomes more severe when decreasing fuse's max_ratio, maybe partly because the background writeback now is more likely to run parallelly with the dirtier.
fuse's max_ratio ratio of aligned WRITE requests
---------------- -------------------------------
70 99.9%
40 74%
20 45%
10 20%
With the patched version, which makes the alignment constraint opt-in when constructing WRITE requests, the ratio of aligned WRITE requests increases to 98% (previously 20%) when fuse's max_ratio is 10.
[1] https://lore.kernel.org/linux-fsdevel/[email protected]/T/#m9bce469998ea6e4f911555c6f7be1e077ce3d8b4
--- fs/fuse/file.c | 4 ++++ fs/fuse/fuse_i.h | 6 ++++++ fs/fuse/inode.c | 9 +++++++++ include/uapi/linux/fuse.h | 9 ++++++++- 4 files changed, 27 insertions(+), 1 deletion(-)
fs/fuse/file.c +4 -0
@@ -2246,6 +2246,10 @@ static bool fuse_writepage_need_send(struct fuse_conn *fc, struct page *page,if (ap->num_pages == data->max_pages && !fuse_pages_realloc (data))return true; +/* Reached alignment */ +if (fc->opt_alignment && !(page->index % fc->opt_alignment_pages)) +return true; +return false; }
fs/fuse/fuse_i.h +6 -0
@@ -860,6 +860,9 @@ struct fuse_conn {/** Passthrough support for read/write IO */ unsigned int passthrough:1; +/* Foffset alignment required for optimum performance */ + unsigned int opt_alignment:1; +/** Maximum stack depth for passthrough backing files */ int max_stack_depth;
@@ -917,6 +920,9 @@ struct fuse_conn {/** IDR for backing files ids */ struct idr backing_files_map;#endif + +/* The foffset alignment in PAGE_SIZE */ +unsigned int opt_alignment_pages; };/*
fs/fuse/inode.c +9 -0
@@ -1331,6 +1331,15 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args, }if (flags &FUSE_NO_EXPORT_SUPPORT ) fm->sb->s_export_op = &fuse_export_fid_operations; + +/* fallback to default if opt_alignment <= PAGE_SHIFT */ +if (flags &FUSE_OPT_ALIGNMENT ) { +if (arg->opt_alignment >PAGE_SHIFT ) { + fc->opt_alignment =1 ; + fc->opt_alignment_pages =1 << + (arg->opt_alignment -PAGE_SHIFT ); + } + } }else { ra_pages = fc->max_read /PAGE_SIZE ; fc->no_lock =1 ;
include/uapi/linux/fuse.h +8 -1
@@ -217,6 +217,9 @@* - add backing_id to fuse_open_out, add FOPEN_PASSTHROUGH open flag * - add FUSE_NO_EXPORT_SUPPORT init flag * - add FUSE_NOTIFY_RESEND, add FUSE_HAS_RESEND init flag +* +* 7.41 +* - add opt_alignment to fuse_init_out, add FUSE_OPT_ALIGNMENT init flag */ #ifndef _LINUX_FUSE_H
@@ -421,6 +424,8 @@ struct fuse_file_lock {* FUSE_NO_EXPORT_SUPPORT: explicitly disable export support * FUSE_HAS_RESEND: kernel supports resending pending requests, and the high bit * of the request ID indicates resend requests +* FUSE_OPT_ALIGNMENT: init_out.opt_alignment contains log2(byte alignment) for +* foffset alignment for optimum write performance */ #define FUSE_ASYNC_READ (1 << 0)#define FUSE_POSIX_LOCKS (1 << 1)
@@ -463,6 +468,7 @@ struct fuse_file_lock {#define FUSE_PASSTHROUGH (1ULL << 37)#define FUSE_NO_EXPORT_SUPPORT (1ULL << 38)#define FUSE_HAS_RESEND (1ULL << 39) +#define FUSE_OPT_ALIGNMENT (1ULL << 40)/* Obsolete alias for FUSE_DIRECT_IO_ALLOW_MMAP */ #define FUSE_DIRECT_IO_RELAX FUSE_DIRECT_IO_ALLOW_MMAP
@@ -893,7 +899,8 @@ struct fuse_init_out {uint16_t map_alignment;uint32_t flags2;uint32_t max_stack_depth; -uint32_t unused[6 ]; +uint32_t opt_alignment; +uint32_t unused[5 ]; };#define CUSE_INIT_INFO_MAX 4096
Signature · 1 line
2.19.1.6.gb485710b
Quoted 50 lines · Jingbo Xu
Sometimes the file offset alignment needs to be opt-in to achieve the optimum performance at the backend store.
For example when ErasureCode [1] is used at the backend store, the optimum write performance is achieved when the WRITE request is aligned with the stripe size of ErasureCode. Otherwise a non-aligned WRITE request needs to be split at the stripe size boundary. It is quite costly to handle these split partial requests, as firstly the whole stripe to which the split partial request belongs needs to be read out, then overwrite the read stripe buffer with the request, and finally write the whole stripe back to the persistent storage.
Thus the backend store can suffer severe performance degradation when WRITE requests can not fit into one stripe exactly. The write performance can be 10x slower when the request is 256KB in size given 4MB stripe size. Also there can be 50% performance degradation in theory if the request is not stripe boundary aligned.
Besides, the conveyed test indicates that, the non-alignment issue becomes more severe when decreasing fuse's
max_ratio, maybe partly because the background writeback now is more likely to run parallelly with the dirtier.fuse's
max_ratioratio of aligned WRITE requests
---------------- -------------------------------
70 99.9%
40 74%
20 45%
10 20%With the patched version, which makes the alignment constraint opt-in when constructing WRITE requests, the ratio of aligned WRITE requests increases to 98% (previously 20%) when fuse's
max_ratiois 10.[1] https://lore.kernel.org/linux-fsdevel/[email protected]/T/#m9bce469998ea6e4f911555c6f7be1e077ce3d8b4
Signed-off-by Jingbo Xu <[email protected]>Signed-off-by Jingbo Xu <[email protected]>--- fs/fuse/file.c | 4 ++++ fs/fuse/fuse_i.h | 6 ++++++ fs/fuse/inode.c | 9 +++++++++ include/uapi/linux/fuse.h | 9 ++++++++- 4 files changed, 27 insertions(+), 1 deletion(-)fs/fuse/file.c +0
-0
fs/fuse/file.c static bool fuse_writepage_need_send(struct fuse_conn *fc, struct page *page, · line 2251
Quoted 6 lines
fs/fuse/file.c +3
-0@@ -2246,6 +2246,10 @@ static bool fuse_writepage_need_send(struct fuse_conn *fc, struct page *page,if (ap->num_pages == data->max_pages && !fuse_pages_realloc (data))return true; +/* Reached alignment */ +if (fc->opt_alignment && !(page->index % fc->opt_alignment_pages)) +return true;
I link the idea, but couldn't it just do that with fc->max_pages? I'm asking because fc->opt_alignment_pages takes another uint32_t in fuse_init_out and there is not so much space left anymore.
Quoted 33 lines
fs/fuse/file.c +1
-0+return false; }fs/fuse/fuse_i.h +6
-0@@ -860,6 +860,9 @@ struct fuse_conn {/** Passthrough support for read/write IO */ unsigned int passthrough:1; +/* Foffset alignment required for optimum performance */ + unsigned int opt_alignment:1; +/** Maximum stack depth for passthrough backing files */ int max_stack_depth;@@ -917,6 +920,9 @@ struct fuse_conn {/** IDR for backing files ids */ struct idr backing_files_map;#endif + +/* The foffset alignment in PAGE_SIZE */ +unsigned int opt_alignment_pages; };/* fs/fuse/inode.c +0
-0
fs/fuse/inode.c static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args, · line 1340
Quoted 10 lines
fs/fuse/inode.c +7
-0@@ -1331,6 +1331,15 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args, }if (flags &FUSE_NO_EXPORT_SUPPORT ) fm->sb->s_export_op = &fuse_export_fid_operations; + +/* fallback to default if opt_alignment <= PAGE_SHIFT */ +if (flags &FUSE_OPT_ALIGNMENT ) { +if (arg->opt_alignment >PAGE_SHIFT ) { + fc->opt_alignment =1 ; + fc->opt_alignment_pages =1 << + (arg->opt_alignment -PAGE_SHIFT );
opt_alignment is the number of bits required for alignment? Not very user friendly, from my point of view would be better to have this in a byte or kb unit.
Thanks,
Bernd
Quoted 46 lines
fs/fuse/inode.c +2
-0+ } + } }else { ra_pages = fc->max_read /PAGE_SIZE ; fc->no_lock =1 ;include/uapi/linux/fuse.h +8
-1@@ -217,6 +217,9 @@* - add backing_id to fuse_open_out, add FOPEN_PASSTHROUGH open flag * - add FUSE_NO_EXPORT_SUPPORT init flag * - add FUSE_NOTIFY_RESEND, add FUSE_HAS_RESEND init flag +* +* 7.41 +* - add opt_alignment to fuse_init_out, add FUSE_OPT_ALIGNMENT init flag */ #ifndef _LINUX_FUSE_H@@ -421,6 +424,8 @@ struct fuse_file_lock {* FUSE_NO_EXPORT_SUPPORT: explicitly disable export support * FUSE_HAS_RESEND: kernel supports resending pending requests, and the high bit * of the request ID indicates resend requests +* FUSE_OPT_ALIGNMENT: init_out.opt_alignment contains log2(byte alignment) for +* foffset alignment for optimum write performance */ #define FUSE_ASYNC_READ (1 << 0)#define FUSE_POSIX_LOCKS (1 << 1)@@ -463,6 +468,7 @@ struct fuse_file_lock {#define FUSE_PASSTHROUGH (1ULL << 37)#define FUSE_NO_EXPORT_SUPPORT (1ULL << 38)#define FUSE_HAS_RESEND (1ULL << 39) +#define FUSE_OPT_ALIGNMENT (1ULL << 40)/* Obsolete alias for FUSE_DIRECT_IO_ALLOW_MMAP */ #define FUSE_DIRECT_IO_RELAX FUSE_DIRECT_IO_ALLOW_MMAP@@ -893,7 +899,8 @@ struct fuse_init_out {uint16_t map_alignment;uint32_t flags2;uint32_t max_stack_depth; -uint32_t unused[6 ]; +uint32_t opt_alignment; +uint32_t unused[5 ]; };#define CUSE_INIT_INFO_MAX 4096
Hi Bernd,
Thanks for the comment.
Quoted 56 lines · Bernd Schubert
Quoted 53 lines · Jingbo Xu
Sometimes the file offset alignment needs to be opt-in to achieve the optimum performance at the backend store.
For example when ErasureCode [1] is used at the backend store, the optimum write performance is achieved when the WRITE request is aligned with the stripe size of ErasureCode. Otherwise a non-aligned WRITE request needs to be split at the stripe size boundary. It is quite costly to handle these split partial requests, as firstly the whole stripe to which the split partial request belongs needs to be read out, then overwrite the read stripe buffer with the request, and finally write the whole stripe back to the persistent storage.
Thus the backend store can suffer severe performance degradation when WRITE requests can not fit into one stripe exactly. The write performance can be 10x slower when the request is 256KB in size given 4MB stripe size. Also there can be 50% performance degradation in theory if the request is not stripe boundary aligned.
Besides, the conveyed test indicates that, the non-alignment issue becomes more severe when decreasing fuse's
max_ratio, maybe partly because the background writeback now is more likely to run parallelly with the dirtier.fuse's
max_ratioratio of aligned WRITE requests
---------------- -------------------------------
70 99.9%
40 74%
20 45%
10 20%With the patched version, which makes the alignment constraint opt-in when constructing WRITE requests, the ratio of aligned WRITE requests increases to 98% (previously 20%) when fuse's
max_ratiois 10.[1] https://lore.kernel.org/linux-fsdevel/[email protected]/T/#m9bce469998ea6e4f911555c6f7be1e077ce3d8b4
Signed-off-by Jingbo Xu <[email protected]>Signed-off-by Jingbo Xu <[email protected]>--- fs/fuse/file.c | 4 ++++ fs/fuse/fuse_i.h | 6 ++++++ fs/fuse/inode.c | 9 +++++++++ include/uapi/linux/fuse.h | 9 ++++++++- 4 files changed, 27 insertions(+), 1 deletion(-)fs/fuse/file.c +0
-0@@ -2246,6 +2246,10 @@ static bool fuse_writepage_need_send(struct fuse_conn *fc, struct page *page,if (ap->num_pages == data->max_pages && !fuse_pages_realloc (data))return true;
Quoted 8 lines
fs/fuse/file.c static bool fuse_writepage_need_send(struct fuse_conn *fc, struct page *page, · line 2251
Quoted 3 lines
fs/fuse/file.c +3
-0+/* Reached alignment */ +if (fc->opt_alignment && !(page->index % fc->opt_alignment_pages)) +return true;I link the idea, but couldn't it just do that with
fc->max_pages? I'm asking becausefc->opt_alignment_pagestakes anotheruint32_tinfuse_init_outand there is not so much space left anymore.
I'm okay with resuing max_pages as the alignment constraint. They are the same in our internal scenarios. But I'm not sure if it is the case in other scenarios.
Quoted 12 lines
Quoted 12 lines
fs/fuse/file.c +0
-0/* fs/fuse/inode.c +3
-0@@ -1331,6 +1331,15 @@ static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args, }if (flags &FUSE_NO_EXPORT_SUPPORT ) fm->sb->s_export_op = &fuse_export_fid_operations; + +/* fallback to default if opt_alignment <= PAGE_SHIFT */ +if (flags &FUSE_OPT_ALIGNMENT ) {
Quoted 9 lines
fs/fuse/inode.c static void process_init_reply(struct fuse_mount *fm, struct fuse_args *args, · line 1340
Quoted 4 lines
fs/fuse/inode.c +4
-0+if (arg->opt_alignment >PAGE_SHIFT ) { + fc->opt_alignment =1 ; + fc->opt_alignment_pages =1 << + (arg->opt_alignment -PAGE_SHIFT );
opt_alignmentis the number of bits required for alignment? Not very user friendly, from my point of view would be better to have this in a byte or kb unit.
Actually I referred to fuse_init_out.map_alignment, which is also log2(byte alignment). Anyway I'm okay making it a more understandable name.
Signature · 2 lines
Thanks, Jingbo
Miklos Szeredi
maintainerQuoted 3 lines · Jingbo Xu
I'm okay with resuing
max_pagesas the alignment constraint. They are the same in our internal scenarios. But I'm not sure if it is the case in other scenarios.
max_pages < alignment makes little sense.
max_pages = n * alignment could make sense, i.e. allow writes that are whole multiples of the alignment.
I'm not against adding a separate alignment, but it could be justuint8_t to take up less space in init_out. We could have done that
with max_stack_depth too. Oh well...
Thanks,
Miklos
Quoted 9 lines · Miklos Szeredi
Quoted 3 lines · Jingbo Xu
I'm okay with resuing
max_pagesas the alignment constraint. They are the same in our internal scenarios. But I'm not sure if it is the case in other scenarios.
max_pages< alignment makes little sense.
max_pages= n * alignment could make sense, i.e. allow writes that are whole multiples of the alignment.
Agreed.
Quoted 4 lines
I'm not against adding a separate alignment, but it could be just
uint8_tto take up less space ininit_out. We could have done that
withmax_stack_depthtoo. Oh well...
Make sense, as the new added fuse_init_out.opt_alignment is already log2(byte alignment). I think uint8_t is already adequate in this case. (Actually I'm going to rename @opt_alignment field of fuse_init_out to something like @log_opt_align to indicate it's actually a log2() value as Berned previously suggested)
Besides, I'm not sure if it's worth adding a new init flag, i.e. FUSE_OPT_ALIGNMENT, as the init flag bits are continually consumed. Maybe we could stipulate that a zero log_opt_align indicates no alignment constraint (the default behavior), while a non-zero log_opt_align indicates an alignment constraint. However IIUC the user daemon may or may not zero the unused fields of fuse_init_out. Thus if a fuse server not supporting opt_alignment doesn't zero fuse_init_out.unused, then the kernel side will enforce an alignment constraint unexpectedly.
Signature · 2 lines
Thanks, Jingbo