Whamcloud - gitweb
LU-12561 kernel: Remove 2.6 based SLES11 support
[fs/lustre-release.git] / lustre / kernel_patches / patches / quota-avoid-dqget-calls.patch
1 commit 1ea06bec78a128adc995ca32bd906a6c9bb9cf91
2 Author: Niu Yawei <yawei.niu@gmail.com>
3 Date:   Wed Jun 4 12:20:30 2014 +0800
4
5     quota: avoid unnecessary dqget()/dqput() calls
6
7     Avoid unnecessary dqget()/dqput() calls in __dquot_initialize(),
8     that will introduce global lock contention otherwise.
9
10     Signed-off-by: Lai Siyao <lai.siyao@intel.com>
11     Signed-off-by: Niu Yawei <yawei.niu@intel.com>
12     Signed-off-by: Jan Kara <jack@suse.cz>
13 Index: linux-2.6.32-431.5.1.el6/fs/quota/dquot.c
14 ===================================================================
15 --- linux-2.6.32-431.5.1.el6.orig/fs/quota/dquot.c
16 +++ linux-2.6.32-431.5.1.el6/fs/quota/dquot.c
17 @@ -1230,7 +1230,7 @@ static int info_bdq_free(struct dquot *d
18  int dquot_initialize(struct inode *inode, int type)
19  {
20         unsigned int id = 0;
21 -       int cnt, ret = 0;
22 +       int cnt, ret = 0, init_needed = 0;
23         struct dquot *got[MAXQUOTAS] = { NULL, NULL };
24         struct super_block *sb = inode->i_sb;
25         qsize_t rsv;
26 @@ -1244,6 +1244,15 @@ int dquot_initialize(struct inode *inode
27         for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
28                 if (type != -1 && cnt != type)
29                         continue;
30 +               /*
31 +                * The i_dquot should have been initialized in most cases,
32 +                * we check it without locking here to avoid unnecessary
33 +                * dqget()/dqput() calls.
34 +                */
35 +               if (inode->i_dquot[cnt])
36 +                       continue;
37 +               init_needed = 1;
38 +
39                 switch (cnt) {
40                 case USRQUOTA:
41                         id = inode->i_uid;
42 @@ -1255,6 +1264,10 @@ int dquot_initialize(struct inode *inode
43                 got[cnt] = dqget(sb, id, cnt);
44         }
45  
46 +       /* All required i_dquot has been initialized */
47 +       if (!init_needed)
48 +               return 0;
49 +
50         spin_lock(&inode->i_lock);
51         if (IS_NOQUOTA(inode))
52                 goto out_err;
53 @@ -1264,6 +1277,9 @@ int dquot_initialize(struct inode *inode
54                 /* Avoid races with quotaoff() */
55                 if (!sb_has_quota_active(sb, cnt))
56                         continue;
57 +               /* We could race with quotaon or dqget() could have failed */
58 +               if (!got[cnt])
59 +                       continue;
60                 if (!inode->i_dquot[cnt]) {
61                         inode->i_dquot[cnt] = got[cnt];
62                         got[cnt] = NULL;