Skip to content

Commit 966c4a8

Browse files
Jinshan Xionggregkh
authored andcommitted
staging/lustre/llite: define per open file cache for ll_cl_context
In ll_readpage and ll_write_begin, it needs to find out the cl_env and cl_io, a.k.a ll_cl_context, when the IO is initialized. It used to call cl_env_get() to figure it out but turned out to be contended if multiple threads are doing IO. In this patch, a per open file ll_cl_context cache is created. When IO type of CIT_READ, CIT_WRITE and CIR_FAULT is initialized, it will add a ll_cl_context into the cache maintained in ll_file_data. In this case, the ll_cl_context can be found in ll_readpage and ll_write_begin later. Signed-off-by: Jinshan Xiong <[email protected]> Reviewed-on: http://review.whamcloud.com/10503 Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5108 Reviewed-on: http://review.whamcloud.com/10955 Intel-bug-id: https://jira.hpdd.intel.com/browse/LU-5260 Reviewed-by: Lai Siyao <[email protected]> Reviewed-by: Bobi Jam <[email protected]> Signed-off-by: Oleg Drokin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ecd4df4 commit 966c4a8

File tree

5 files changed

+88
-97
lines changed

5 files changed

+88
-97
lines changed

drivers/staging/lustre/lustre/llite/file.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,11 @@ static int ll_local_open(struct file *file, struct lookup_intent *it,
519519
LUSTRE_FPRIVATE(file) = fd;
520520
ll_readahead_init(inode, &fd->fd_ras);
521521
fd->fd_omode = it->it_flags & (FMODE_READ | FMODE_WRITE | FMODE_EXEC);
522+
523+
/* ll_cl_context initialize */
524+
rwlock_init(&fd->fd_lock);
525+
INIT_LIST_HEAD(&fd->fd_lccs);
526+
522527
return 0;
523528
}
524529

@@ -1178,7 +1183,9 @@ ll_file_io_generic(const struct lu_env *env, struct vvp_io_args *args,
11781183
CERROR("Unknown IO type - %u\n", vio->vui_io_subtype);
11791184
LBUG();
11801185
}
1186+
ll_cl_add(file, env, io);
11811187
result = cl_io_loop(env, io);
1188+
ll_cl_remove(file, env);
11821189
if (args->via_io_subtype == IO_NORMAL)
11831190
up_read(&lli->lli_trunc_sem);
11841191
if (write_mutex_locked)

drivers/staging/lustre/lustre/llite/llite_internal.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,8 @@ struct ll_file_data {
640640
* false: unknown failure, should report.
641641
*/
642642
bool fd_write_failed;
643+
rwlock_t fd_lock; /* protect lcc list */
644+
struct list_head fd_lccs; /* list of ll_cl_context */
643645
};
644646

645647
struct lov_stripe_md;
@@ -715,8 +717,9 @@ void ll_readahead_init(struct inode *inode, struct ll_readahead_state *ras);
715717
int ll_readahead(const struct lu_env *env, struct cl_io *io,
716718
struct cl_page_list *queue, struct ll_readahead_state *ras,
717719
bool hit);
718-
struct ll_cl_context *ll_cl_init(struct file *file, struct page *vmpage);
719-
void ll_cl_fini(struct ll_cl_context *lcc);
720+
struct ll_cl_context *ll_cl_find(struct file *file);
721+
void ll_cl_add(struct file *file, const struct lu_env *env, struct cl_io *io);
722+
void ll_cl_remove(struct file *file, const struct lu_env *env);
720723

721724
extern const struct address_space_operations ll_aops;
722725

@@ -858,11 +861,11 @@ struct vvp_io_args {
858861
};
859862

860863
struct ll_cl_context {
864+
struct list_head lcc_list;
861865
void *lcc_cookie;
866+
const struct lu_env *lcc_env;
862867
struct cl_io *lcc_io;
863868
struct cl_page *lcc_page;
864-
struct lu_env *lcc_env;
865-
int lcc_refcheck;
866869
};
867870

868871
struct ll_thread_info {

drivers/staging/lustre/lustre/llite/llite_mmap.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,8 +315,13 @@ static int ll_fault0(struct vm_area_struct *vma, struct vm_fault *vmf)
315315
vio->u.fault.ft_flags = 0;
316316
vio->u.fault.ft_flags_valid = false;
317317

318+
/* May call ll_readpage() */
319+
ll_cl_add(vma->vm_file, env, io);
320+
318321
result = cl_io_loop(env, io);
319322

323+
ll_cl_remove(vma->vm_file, env);
324+
320325
/* ft_flags are only valid if we reached
321326
* the call to filemap_fault
322327
*/

drivers/staging/lustre/lustre/llite/rw.c

Lines changed: 60 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -59,84 +59,6 @@
5959
#include "llite_internal.h"
6060
#include "../include/linux/lustre_compat25.h"
6161

62-
/**
63-
* Finalizes cl-data before exiting typical address_space operation. Dual to
64-
* ll_cl_init().
65-
*/
66-
void ll_cl_fini(struct ll_cl_context *lcc)
67-
{
68-
struct lu_env *env = lcc->lcc_env;
69-
struct cl_io *io = lcc->lcc_io;
70-
struct cl_page *page = lcc->lcc_page;
71-
72-
LASSERT(lcc->lcc_cookie == current);
73-
LASSERT(env);
74-
75-
if (page) {
76-
lu_ref_del(&page->cp_reference, "cl_io", io);
77-
cl_page_put(env, page);
78-
}
79-
80-
cl_env_put(env, &lcc->lcc_refcheck);
81-
}
82-
83-
/**
84-
* Initializes common cl-data at the typical address_space operation entry
85-
* point.
86-
*/
87-
struct ll_cl_context *ll_cl_init(struct file *file, struct page *vmpage)
88-
{
89-
struct ll_cl_context *lcc;
90-
struct lu_env *env;
91-
struct cl_io *io;
92-
struct cl_object *clob;
93-
struct vvp_io *vio;
94-
95-
int refcheck;
96-
int result = 0;
97-
98-
clob = ll_i2info(file_inode(file))->lli_clob;
99-
LASSERT(clob);
100-
101-
env = cl_env_get(&refcheck);
102-
if (IS_ERR(env))
103-
return ERR_CAST(env);
104-
105-
lcc = &ll_env_info(env)->lti_io_ctx;
106-
memset(lcc, 0, sizeof(*lcc));
107-
lcc->lcc_env = env;
108-
lcc->lcc_refcheck = refcheck;
109-
lcc->lcc_cookie = current;
110-
111-
vio = vvp_env_io(env);
112-
io = vio->vui_cl.cis_io;
113-
lcc->lcc_io = io;
114-
if (!io)
115-
result = -EIO;
116-
117-
if (result == 0 && vmpage) {
118-
struct cl_page *page;
119-
120-
LASSERT(io->ci_state == CIS_IO_GOING);
121-
LASSERT(vio->vui_fd == LUSTRE_FPRIVATE(file));
122-
page = cl_page_find(env, clob, vmpage->index, vmpage,
123-
CPT_CACHEABLE);
124-
if (!IS_ERR(page)) {
125-
lcc->lcc_page = page;
126-
lu_ref_add(&page->cp_reference, "cl_io", io);
127-
result = 0;
128-
} else {
129-
result = PTR_ERR(page);
130-
}
131-
}
132-
if (result) {
133-
ll_cl_fini(lcc);
134-
lcc = ERR_PTR(result);
135-
}
136-
137-
return lcc;
138-
}
139-
14062
static void ll_ra_stats_inc_sbi(struct ll_sb_info *sbi, enum ra_stat which);
14163

14264
/**
@@ -1112,17 +1034,70 @@ int ll_writepages(struct address_space *mapping, struct writeback_control *wbc)
11121034
return result;
11131035
}
11141036

1037+
struct ll_cl_context *ll_cl_find(struct file *file)
1038+
{
1039+
struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1040+
struct ll_cl_context *lcc;
1041+
struct ll_cl_context *found = NULL;
1042+
1043+
read_lock(&fd->fd_lock);
1044+
list_for_each_entry(lcc, &fd->fd_lccs, lcc_list) {
1045+
if (lcc->lcc_cookie == current) {
1046+
found = lcc;
1047+
break;
1048+
}
1049+
}
1050+
read_unlock(&fd->fd_lock);
1051+
1052+
return found;
1053+
}
1054+
1055+
void ll_cl_add(struct file *file, const struct lu_env *env, struct cl_io *io)
1056+
{
1057+
struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1058+
struct ll_cl_context *lcc = &ll_env_info(env)->lti_io_ctx;
1059+
1060+
memset(lcc, 0, sizeof(*lcc));
1061+
INIT_LIST_HEAD(&lcc->lcc_list);
1062+
lcc->lcc_cookie = current;
1063+
lcc->lcc_env = env;
1064+
lcc->lcc_io = io;
1065+
1066+
write_lock(&fd->fd_lock);
1067+
list_add(&lcc->lcc_list, &fd->fd_lccs);
1068+
write_unlock(&fd->fd_lock);
1069+
}
1070+
1071+
void ll_cl_remove(struct file *file, const struct lu_env *env)
1072+
{
1073+
struct ll_file_data *fd = LUSTRE_FPRIVATE(file);
1074+
struct ll_cl_context *lcc = &ll_env_info(env)->lti_io_ctx;
1075+
1076+
write_lock(&fd->fd_lock);
1077+
list_del_init(&lcc->lcc_list);
1078+
write_unlock(&fd->fd_lock);
1079+
}
1080+
11151081
int ll_readpage(struct file *file, struct page *vmpage)
11161082
{
1083+
struct cl_object *clob = ll_i2info(file_inode(file))->lli_clob;
11171084
struct ll_cl_context *lcc;
1085+
const struct lu_env *env;
1086+
struct cl_io *io;
1087+
struct cl_page *page;
11181088
int result;
11191089

1120-
lcc = ll_cl_init(file, vmpage);
1121-
if (!IS_ERR(lcc)) {
1122-
struct lu_env *env = lcc->lcc_env;
1123-
struct cl_io *io = lcc->lcc_io;
1124-
struct cl_page *page = lcc->lcc_page;
1090+
lcc = ll_cl_find(file);
1091+
if (!lcc) {
1092+
unlock_page(vmpage);
1093+
return -EIO;
1094+
}
11251095

1096+
env = lcc->lcc_env;
1097+
io = lcc->lcc_io;
1098+
LASSERT(io->ci_state == CIS_IO_GOING);
1099+
page = cl_page_find(env, clob, vmpage->index, vmpage, CPT_CACHEABLE);
1100+
if (!IS_ERR(page)) {
11261101
LASSERT(page->cp_type == CPT_CACHEABLE);
11271102
if (likely(!PageUptodate(vmpage))) {
11281103
cl_page_assume(env, io, page);
@@ -1132,10 +1107,10 @@ int ll_readpage(struct file *file, struct page *vmpage)
11321107
unlock_page(vmpage);
11331108
result = 0;
11341109
}
1135-
ll_cl_fini(lcc);
1110+
cl_page_put(env, page);
11361111
} else {
11371112
unlock_page(vmpage);
1138-
result = PTR_ERR(lcc);
1113+
result = PTR_ERR(page);
11391114
}
11401115
return result;
11411116
}

drivers/staging/lustre/lustre/llite/rw26.c

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ static int ll_write_begin(struct file *file, struct address_space *mapping,
489489
struct page **pagep, void **fsdata)
490490
{
491491
struct ll_cl_context *lcc;
492-
struct lu_env *env;
492+
const struct lu_env *env;
493493
struct cl_io *io;
494494
struct cl_page *page;
495495
struct cl_object *clob = ll_i2info(mapping->host)->lli_clob;
@@ -501,9 +501,9 @@ static int ll_write_begin(struct file *file, struct address_space *mapping,
501501

502502
CDEBUG(D_VFSTRACE, "Writing %lu of %d to %d bytes\n", index, from, len);
503503

504-
lcc = ll_cl_init(file, NULL);
505-
if (IS_ERR(lcc)) {
506-
result = PTR_ERR(lcc);
504+
lcc = ll_cl_find(file);
505+
if (!lcc) {
506+
result = -EIO;
507507
goto out;
508508
}
509509

@@ -579,8 +579,6 @@ static int ll_write_begin(struct file *file, struct address_space *mapping,
579579
unlock_page(vmpage);
580580
put_page(vmpage);
581581
}
582-
if (!IS_ERR(lcc))
583-
ll_cl_fini(lcc);
584582
} else {
585583
*pagep = vmpage;
586584
*fsdata = lcc;
@@ -593,7 +591,7 @@ static int ll_write_end(struct file *file, struct address_space *mapping,
593591
struct page *vmpage, void *fsdata)
594592
{
595593
struct ll_cl_context *lcc = fsdata;
596-
struct lu_env *env;
594+
const struct lu_env *env;
597595
struct cl_io *io;
598596
struct vvp_io *vio;
599597
struct cl_page *page;
@@ -631,6 +629,10 @@ static int ll_write_end(struct file *file, struct address_space *mapping,
631629
} else {
632630
cl_page_disown(env, io, page);
633631

632+
lcc->lcc_page = NULL;
633+
lu_ref_del(&page->cp_reference, "cl_io", io);
634+
cl_page_put(env, page);
635+
634636
/* page list is not contiguous now, commit it now */
635637
unplug = true;
636638
}
@@ -639,7 +641,6 @@ static int ll_write_end(struct file *file, struct address_space *mapping,
639641
file->f_flags & O_SYNC || IS_SYNC(file_inode(file)))
640642
result = vvp_io_write_commit(env, io);
641643

642-
ll_cl_fini(lcc);
643644
return result >= 0 ? copied : result;
644645
}
645646

0 commit comments

Comments
 (0)