Skip to content

Commit

Permalink
quota: avoid unnecessary dqget()/dqput() calls
Browse files Browse the repository at this point in the history
Avoid unnecessary dqget()/dqput() calls in __dquot_initialize(),
that will introduce global lock contention otherwise.

Signed-off-by: Lai Siyao <lai.siyao@intel.com>
Signed-off-by: Niu Yawei <yawei.niu@intel.com>
Signed-off-by: Jan Kara <jack@suse.cz>
  • Loading branch information
Niu Yawei authored and Jan Kara committed Jul 15, 2014
1 parent 606cdcc commit 1ea06be
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion fs/quota/dquot.c
Original file line number Diff line number Diff line change
Expand Up @@ -1402,7 +1402,7 @@ static int dquot_active(const struct inode *inode)
*/
static void __dquot_initialize(struct inode *inode, int type)
{
int cnt;
int cnt, init_needed = 0;
struct dquot *got[MAXQUOTAS];
struct super_block *sb = inode->i_sb;
qsize_t rsv;
Expand All @@ -1418,6 +1418,15 @@ static void __dquot_initialize(struct inode *inode, int type)
got[cnt] = NULL;
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:
qid = make_kqid_uid(inode->i_uid);
Expand All @@ -1429,6 +1438,10 @@ static void __dquot_initialize(struct inode *inode, int type)
got[cnt] = dqget(sb, qid);
}

/* All required i_dquot has been initialized */
if (!init_needed)
return;

down_write(&sb_dqopt(sb)->dqptr_sem);
if (IS_NOQUOTA(inode))
goto out_err;
Expand Down

0 comments on commit 1ea06be

Please sign in to comment.