commit 1ea06bec78a128adc995ca32bd906a6c9bb9cf91 Author: Niu Yawei Date: Wed Jun 4 12:20:30 2014 +0800 quota: avoid unnecessary dqget()/dqput() calls Avoid unnecessary dqget()/dqput() calls in __dquot_initialize(), that will introduce global lock contention otherwise. Signed-off-by: Lai Siyao Signed-off-by: Niu Yawei Signed-off-by: Jan Kara Index: linux-2.6.32-431.5.1.el6/fs/quota/dquot.c =================================================================== --- linux-2.6.32-431.5.1.el6.orig/fs/quota/dquot.c +++ linux-2.6.32-431.5.1.el6/fs/quota/dquot.c @@ -1230,7 +1230,7 @@ static int info_bdq_free(struct dquot *d int dquot_initialize(struct inode *inode, int type) { unsigned int id = 0; - int cnt, ret = 0; + int cnt, ret = 0, init_needed = 0; struct dquot *got[MAXQUOTAS] = { NULL, NULL }; struct super_block *sb = inode->i_sb; qsize_t rsv; @@ -1244,6 +1244,15 @@ int dquot_initialize(struct inode *inode for (cnt = 0; cnt < MAXQUOTAS; cnt++) { if (type != -1 && cnt != type) continue; + /* + * The i_dquot should have been initialized in most cases, + * we check it without locking here to avoid unnecessary + * dqget()/dqput() calls. + */ + if (inode->i_dquot[cnt]) + continue; + init_needed = 1; + switch (cnt) { case USRQUOTA: id = inode->i_uid; @@ -1255,6 +1264,10 @@ int dquot_initialize(struct inode *inode got[cnt] = dqget(sb, id, cnt); } + /* All required i_dquot has been initialized */ + if (!init_needed) + return 0; + spin_lock(&inode->i_lock); if (IS_NOQUOTA(inode)) goto out_err; @@ -1264,6 +1277,9 @@ int dquot_initialize(struct inode *inode /* Avoid races with quotaoff() */ if (!sb_has_quota_active(sb, cnt)) continue; + /* We could race with quotaon or dqget() could have failed */ + if (!got[cnt]) + continue; if (!inode->i_dquot[cnt]) { inode->i_dquot[cnt] = got[cnt]; got[cnt] = NULL;