1 In dquot_initialize(), we'd call dqget() only when i_dquot not
2 initialized, which can avoid 2 pair of dqget()/dqput() in most
3 case. It could relieve the global locks contenion caused by
5 Index: linux-2.6.32-358.0.1.el6/fs/quota/dquot.c
6 ===================================================================
7 --- linux-2.6.32-358.0.1.el6.orig/fs/quota/dquot.c
8 +++ linux-2.6.32-358.0.1.el6/fs/quota/dquot.c
9 @@ -1230,7 +1230,7 @@ static int info_bdq_free(struct dquot *d
10 int dquot_initialize(struct inode *inode, int type)
14 + int cnt, ret = 0, dq_get = 0;
15 struct dquot *got[MAXQUOTAS] = { NULL, NULL };
16 struct super_block *sb = inode->i_sb;
18 @@ -1240,7 +1240,14 @@ int dquot_initialize(struct inode *inode
19 if (IS_NOQUOTA(inode))
22 - /* First get references to structures we might need. */
23 + /* In most case, the i_dquot should have been initialized, except
24 + * the newly allocated one. We'd always try to skip the dqget() and
25 + * dqput() calls to avoid unnecessary global lock contention. */
26 + if (!(inode->i_state & I_NEW))
31 for (cnt = 0; cnt < MAXQUOTAS; cnt++) {
32 if (type != -1 && cnt != type)
34 @@ -1254,7 +1261,7 @@ int dquot_initialize(struct inode *inode
36 got[cnt] = dqget(sb, id, cnt);
40 spin_lock(&inode->i_lock);
41 if (IS_NOQUOTA(inode))
43 @@ -1265,6 +1272,10 @@ int dquot_initialize(struct inode *inode
44 if (!sb_has_quota_active(sb, cnt))
46 if (!inode->i_dquot[cnt]) {
48 + spin_unlock(&inode->i_lock);
51 inode->i_dquot[cnt] = got[cnt];
54 @@ -1272,7 +1283,7 @@ int dquot_initialize(struct inode *inode
55 * did a write before quota was turned on
57 rsv = inode_get_rsv_space(inode);
58 - if (unlikely(rsv)) {
59 + if (unlikely(rsv) && likely(inode->i_dquot[cnt])) {
60 spin_lock(&dq_data_lock);
61 dquot_resv_space(inode->i_dquot[cnt], rsv);
62 spin_unlock(&dq_data_lock);