From 24127888625f029e908f9af4210b438c975ebc42 Mon Sep 17 00:00:00 2001 From: liuzerun Date: Fri, 29 Dec 2023 10:02:40 +0000 Subject: [PATCH 1/4] change_cred Signed-off-by: liuzerun --- fs/hmdfs/file_cloud.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fs/hmdfs/file_cloud.c b/fs/hmdfs/file_cloud.c index b7386be449d4..d0d567f99dbc 100644 --- a/fs/hmdfs/file_cloud.c +++ b/fs/hmdfs/file_cloud.c @@ -35,6 +35,7 @@ struct cloud_readpages_work { struct file *filp; loff_t pos; int cnt; + struct cred *cred; struct work_struct work; struct page *pages[0]; }; @@ -163,11 +164,13 @@ static void cloud_readpages_work_func(struct work_struct *work) void *pages_buf; int idx, ret; ssize_t read_len; + const struct cred *old_cred; struct cloud_readpages_work *cr_work; cr_work = container_of(work, struct cloud_readpages_work, work); read_len = cr_work->cnt * HMDFS_PAGE_SIZE; + old_cred = override_creds(cr_work->cred); pages_buf = vmap(cr_work->pages, cr_work->cnt, VM_MAP, PAGE_KERNEL); if (!pages_buf) goto out; @@ -186,6 +189,7 @@ static void cloud_readpages_work_func(struct work_struct *work) SetPageUptodate(cr_work->pages[idx]); unlock_page(cr_work->pages[idx]); } + revert_creds(old_cred); kfree(cr_work); } @@ -194,6 +198,7 @@ static int prepare_cloud_readpage_work(struct file *filp, int cnt, { struct cloud_readpages_work *cr_work; struct hmdfs_file_info *gfi = filp->private_data; + struct cred *cred = NULL; cr_work = kzalloc(sizeof(*cr_work) + sizeof(cr_work->pages[0]) * cnt, @@ -207,6 +212,11 @@ static int prepare_cloud_readpage_work(struct file *filp, int cnt, cr_work->filp = gfi->lower_file; else cr_work->filp = filp; + + cred = prepare_creds(); + if (!cred) + return -ENOMEM; + cr_work->cred = cred; cr_work->pos = (loff_t)(vec[0]->index) << HMDFS_PAGE_OFFSET; cr_work->cnt = cnt; memcpy(cr_work->pages, vec, cnt * sizeof(*vec)); -- Gitee From 8b5573da53c5e5ef9ce939d008616e5b6107aba3 Mon Sep 17 00:00:00 2001 From: liuzerun Date: Fri, 29 Dec 2023 17:04:19 +0000 Subject: [PATCH 2/4] read_pages optimize Signed-off-by: liuzerun --- fs/hmdfs/file_cloud.c | 11 +++++++--- fs/hmdfs/file_local.c | 13 +++++++++--- fs/hmdfs/hmdfs_trace.h | 40 ++++++++++++++++++++++++++++++++++++ fs/hmdfs/inode_cloud_merge.c | 1 + 4 files changed, 59 insertions(+), 6 deletions(-) diff --git a/fs/hmdfs/file_cloud.c b/fs/hmdfs/file_cloud.c index d0d567f99dbc..8c98656f8655 100644 --- a/fs/hmdfs/file_cloud.c +++ b/fs/hmdfs/file_cloud.c @@ -92,7 +92,7 @@ int hmdfs_file_open_cloud(struct inode *inode, struct file *file) } lower_file = file_open_root(&root_path, dir_path, - file->f_flags, file->f_mode); + file->f_flags | O_DIRECT, file->f_mode); path_put(&root_path); if (IS_ERR(lower_file)) { hmdfs_info("file_open_root failed: %ld", PTR_ERR(lower_file)); @@ -175,7 +175,9 @@ static void cloud_readpages_work_func(struct work_struct *work) if (!pages_buf) goto out; + trace_hmdfs_readpages_cloud_work_begin(cr_work->cnt, cr_work->pos); ret = kernel_read(cr_work->filp, pages_buf, read_len, &cr_work->pos); + trace_hmdfs_readpages_cloud_work_end(cr_work->cnt, cr_work->pos); if (ret < 0) goto out_vunmap; @@ -211,11 +213,11 @@ static int prepare_cloud_readpage_work(struct file *filp, int cnt, if (gfi) cr_work->filp = gfi->lower_file; else - cr_work->filp = filp; + goto out; cred = prepare_creds(); if (!cred) - return -ENOMEM; + goto out; cr_work->cred = cred; cr_work->pos = (loff_t)(vec[0]->index) << HMDFS_PAGE_OFFSET; cr_work->cnt = cnt; @@ -224,6 +226,9 @@ static int prepare_cloud_readpage_work(struct file *filp, int cnt, INIT_WORK(&cr_work->work, cloud_readpages_work_func); schedule_work(&cr_work->work); return 0; +out: + kfree(cr_work); + return -ENOMEM; } static int hmdfs_readpages_cloud(struct file *filp, diff --git a/fs/hmdfs/file_local.c b/fs/hmdfs/file_local.c index c9aaaaa9ebc9..547a4a9f8349 100644 --- a/fs/hmdfs/file_local.c +++ b/fs/hmdfs/file_local.c @@ -36,7 +36,12 @@ int hmdfs_file_open_local(struct inode *inode, struct file *file) } hmdfs_get_lower_path(file->f_path.dentry, &lower_path); - lower_file = dentry_open(&lower_path, file->f_flags, cred); + if (inode->imapping != NULL && + inode->imapping->a_ops == &hmdfs_aops_cloud) + lower_file = dentry_open(&lower_path, file->f_flags | O_DIRECT, + cred); + else + lower_file = dentry_open(&lower_path, file->f_flags, cred); hmdfs_put_lower_path(&lower_path); if (IS_ERR(lower_file)) { err = PTR_ERR(lower_file); @@ -86,11 +91,13 @@ ssize_t hmdfs_do_read_iter(struct file *file, struct iov_iter *iter, if (!iov_iter_count(iter)) return 0; - if (file->f_inode->i_mapping->a_ops == &hmdfs_aops_cloud) { + if (inode->imapping != NULL && + inode->imapping->a_ops == &hmdfs_aops_cloud) { iocb = container_of(ppos, struct kiocb, ki_pos); ret = generic_file_read_iter(iocb, iter); - } else + } else { ret = vfs_iter_read(lower_file, iter, ppos, 0); + } hmdfs_file_accessed(file); return ret; diff --git a/fs/hmdfs/hmdfs_trace.h b/fs/hmdfs/hmdfs_trace.h index 15bedbaa5cfa..6b26662ccd2e 100644 --- a/fs/hmdfs/hmdfs_trace.h +++ b/fs/hmdfs/hmdfs_trace.h @@ -546,6 +546,46 @@ TRACE_EVENT(hmdfs_readpages_cloud, __entry->nr_pages, __entry->err) ); +TRACE_EVENT(hmdfs_readpages_cloud_work_begin, + + TP_PROTO(int cnt, loff_t pos), + + TP_ARGS(cnt, pos), + + TP_STRUCT__entry( + __field(int, cnt) + __field(loff_t, pos) + ), + + TP_fast_assign( + __entry->cnt = cnt; + __entry->pos = pos; + ), + + TP_printk("cnt:%d, pos:%llx", + __entry->cnt, __entry->pos) +); + +TRACE_EVENT(hmdfs_readpages_cloud_work_end, + + TP_PROTO(int cnt, loff_t pos), + + TP_ARGS(cnt, pos), + + TP_STRUCT__entry( + __field(int, cnt) + __field(loff_t, pos) + ), + + TP_fast_assign( + __entry->cnt = cnt; + __entry->pos = pos; + ), + + TP_printk("cnt:%d, pos:%llx", + __entry->cnt, __entry->pos) +); + TRACE_EVENT(hmdfs_client_recv_readpage, TP_PROTO(struct hmdfs_peer *con, unsigned long long remote_ino, diff --git a/fs/hmdfs/inode_cloud_merge.c b/fs/hmdfs/inode_cloud_merge.c index d0b5e58f9fbe..b3139fbf0da0 100644 --- a/fs/hmdfs/inode_cloud_merge.c +++ b/fs/hmdfs/inode_cloud_merge.c @@ -79,6 +79,7 @@ static struct inode *fill_inode_merge(struct super_block *sb, goto bad_inode; } + inode->i_mapping->a_ops = &hmdfs_aops_cloud; unlock_new_inode(inode); out: dput(fst_lo_d); -- Gitee From 2c68a6bb8b90cd80e239b8bd6fc46400b41fd032 Mon Sep 17 00:00:00 2001 From: liuzerun Date: Fri, 29 Dec 2023 17:07:36 +0000 Subject: [PATCH 3/4] read_pages optimize Signed-off-by: liuzerun --- fs/hmdfs/file_local.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/hmdfs/file_local.c b/fs/hmdfs/file_local.c index 547a4a9f8349..6e738dc55783 100644 --- a/fs/hmdfs/file_local.c +++ b/fs/hmdfs/file_local.c @@ -36,8 +36,8 @@ int hmdfs_file_open_local(struct inode *inode, struct file *file) } hmdfs_get_lower_path(file->f_path.dentry, &lower_path); - if (inode->imapping != NULL && - inode->imapping->a_ops == &hmdfs_aops_cloud) + if (inode->i_mapping != NULL && + inode->i_mapping->a_ops == &hmdfs_aops_cloud) lower_file = dentry_open(&lower_path, file->f_flags | O_DIRECT, cred); else @@ -91,8 +91,8 @@ ssize_t hmdfs_do_read_iter(struct file *file, struct iov_iter *iter, if (!iov_iter_count(iter)) return 0; - if (inode->imapping != NULL && - inode->imapping->a_ops == &hmdfs_aops_cloud) { + if (inode->i_mapping != NULL && + inode->i_mapping->a_ops == &hmdfs_aops_cloud) { iocb = container_of(ppos, struct kiocb, ki_pos); ret = generic_file_read_iter(iocb, iter); } else { -- Gitee From dba926e20f43e9e90ef882704a5efa1303e17f76 Mon Sep 17 00:00:00 2001 From: liuzerun Date: Fri, 29 Dec 2023 17:30:43 +0000 Subject: [PATCH 4/4] read_pages optimize Signed-off-by: liuzerun --- fs/hmdfs/file_local.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/hmdfs/file_local.c b/fs/hmdfs/file_local.c index 6e738dc55783..c563ea44ade1 100644 --- a/fs/hmdfs/file_local.c +++ b/fs/hmdfs/file_local.c @@ -91,8 +91,8 @@ ssize_t hmdfs_do_read_iter(struct file *file, struct iov_iter *iter, if (!iov_iter_count(iter)) return 0; - if (inode->i_mapping != NULL && - inode->i_mapping->a_ops == &hmdfs_aops_cloud) { + if (file->f_inode->i_mapping != NULL && + file->f_inode->i_mapping->a_ops == &hmdfs_aops_cloud) { iocb = container_of(ppos, struct kiocb, ki_pos); ret = generic_file_read_iter(iocb, iter); } else { -- Gitee