Whamcloud - gitweb
LU-3305 quota: avoid unnecessary dqget/dqput calls
[fs/lustre-release.git] / lustre / kernel_patches / patches / quota-avoid-dqget-calls.patch
1 Index: linux-2.6.32-358.0.1.el6/fs/quota/dquot.c
2 ===================================================================
3 --- linux-2.6.32-358.0.1.el6.orig/fs/quota/dquot.c
4 +++ linux-2.6.32-358.0.1.el6/fs/quota/dquot.c
5 @@ -1230,7 +1230,7 @@ static int info_bdq_free(struct dquot *d
6  int dquot_initialize(struct inode *inode, int type)
7  {
8         unsigned int id = 0;
9 -       int cnt, ret = 0;
10 +       int cnt, ret = 0, dq_get = 0;
11         struct dquot *got[MAXQUOTAS] = { NULL, NULL };
12         struct super_block *sb = inode->i_sb;
13         qsize_t rsv;
14 @@ -1240,7 +1240,14 @@ int dquot_initialize(struct inode *inode
15         if (IS_NOQUOTA(inode))
16                 return 0;
17  
18 -       /* First get references to structures we might need. */
19 +       /* In most case, the i_dquot should have been initialized, except
20 +        * the newly allocated one. We'd always try to skip the dqget() and
21 +        * dqput() calls to avoid unnecessary global lock contention. */
22 +       if (!(inode->i_state & I_NEW))
23 +               goto init_idquot;
24 +
25 +get_dquots:
26 +       dq_get = 1;
27         for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
28                 if (type != -1 && cnt != type)
29                         continue;
30 @@ -1254,7 +1261,7 @@ int dquot_initialize(struct inode *inode
31                 }
32                 got[cnt] = dqget(sb, id, cnt);
33         }
34 -
35 +init_idquot:
36         spin_lock(&inode->i_lock);
37         if (IS_NOQUOTA(inode))
38                 goto out_err;
39 @@ -1265,6 +1272,10 @@ int dquot_initialize(struct inode *inode
40                 if (!sb_has_quota_active(sb, cnt))
41                         continue;
42                 if (!inode->i_dquot[cnt]) {
43 +                       if (dq_get == 0) {
44 +                               spin_unlock(&inode->i_lock);
45 +                               goto get_dquots;
46 +                       }
47                         inode->i_dquot[cnt] = got[cnt];
48                         got[cnt] = NULL;
49                         /*
50 @@ -1272,7 +1283,7 @@ int dquot_initialize(struct inode *inode
51                          * did a write before quota was turned on
52                          */
53                         rsv = inode_get_rsv_space(inode);
54 -                       if (unlikely(rsv)) {
55 +                       if (unlikely(rsv) && likely(inode->i_dquot[cnt])) {
56                                 spin_lock(&dq_data_lock);
57                                 dquot_resv_space(inode->i_dquot[cnt], rsv);
58                                 spin_unlock(&dq_data_lock);