----- Original Message -----
| ----- Original Message -----
| | Bearing in mind that the mutex is an exclusive lock and the glock
| | is
| | only a shared lock, do we have any other protection against the
| | rgrp
| | tree being updated simultaneously?
| |
| | Steve.
|
| Hi,
|
| Yes, I think you're right. The existing code should work most of the
| time but has the potential to leak rgrp memory if the timing is
| right.
| We could approach the solution two ways:
|
| (1) We could change the shared lock to an exclusive lock.
| (2) We could change function rgd_insert so that it returns an error
| if
| the rgrp was already in the rb_tree. That way, whoever gets the
| sd_rindex_spin spinlock first will call rgd_insert to insert the
| new
| rgrp into the rgrp tree, and when the second caller tries to
| insert
| its new rgrp into the rb_tree, it will find the entry already
| there,
| (inserted by the first caller), then take the error path and
| exit,
| freeing the rgrp it kmalloced.
|
| Regards,
|
| Bob Peterson
| Red Hat File Systems
Hi,
Here is a replacement patch that implements solution #2 as
described above:
Regards,
Bob Peterson
Red Hat File Systems
Signed-off-by: Bob Peterson <rpeterso@redhat.com>
--
GFS2: Eliminate sd_rindex_mutex
Over time, we've slowly eliminated the use of sd_rindex_mutex.
Up to this point, it was only used in two places: function
gfs2_ri_total (which totals the file system size by reading
and parsing the rindex file) and function gfs2_rindex_update
which updates the rgrps in memory. Both of these functions have
the rindex glock to protect them, so the rindex is unnecessary.
Since gfs2_grow writes to the rindex via the meta_fs, the mutex
is in the wrong order according to the normal rules. This patch
eliminates the mutex entirely to avoid the problem.
/* Read new copy from disk if we don't have the latest */
if (!sdp->sd_rindex_uptodate) {
- mutex_lock(&sdp->sd_rindex_mutex);
if (!gfs2_glock_is_locked_by_me(gl)) {
error = gfs2_glock_nq_init(gl, LM_ST_SHARED, 0, &ri_gh);
if (error)
- goto out_unlock;
+ return error;
unlock_required = 1;
}
if (!sdp->sd_rindex_uptodate)
error = gfs2_ri_update(ip);
if (unlock_required)
gfs2_glock_dq_uninit(&ri_gh);
-out_unlock:
- mutex_unlock(&sdp->sd_rindex_mutex);
}
-
return error;
}
03-05-2012, 01:20 PM
Bob Peterson
GFS2: Eliminate sd_rindex_mutex
----- Original Message -----
| Hi,
|
| Here is a replacement patch that implements solution #2 as
| described above:
|
| Regards,
|
| Bob Peterson
| Red Hat File Systems
|
| Signed-off-by: Bob Peterson <rpeterso@redhat.com>
Hi,
Ignore that last patch (try #2); I forgot to unlock the spin_lock in
the error case. This replacement patch simplifies the code a bit.
Regards,
Bob Peterson
Signed-off-by: Bob Peterson <rpeterso@redhat.com>
--
GFS2: Eliminate sd_rindex_mutex
Over time, we've slowly eliminated the use of sd_rindex_mutex.
Up to this point, it was only used in two places: function
gfs2_ri_total (which totals the file system size by reading
and parsing the rindex file) and function gfs2_rindex_update
which updates the rgrps in memory. Both of these functions have
the rindex glock to protect them, so the rindex is unnecessary.
Since gfs2_grow writes to the rindex via the meta_fs, the mutex
is in the wrong order according to the normal rules. This patch
eliminates the mutex entirely to avoid the problem.
/**
@@ -631,10 +631,12 @@ static int read_rindex_entry(struct gfs2_inode *ip,
if (rgd->rd_data > sdp->sd_max_rg_data)
sdp->sd_max_rg_data = rgd->rd_data;
spin_lock(&sdp->sd_rindex_spin);
- rgd_insert(rgd);
- sdp->sd_rgrps++;
+ error = rgd_insert(rgd);
spin_unlock(&sdp->sd_rindex_spin);
- return error;
+ if (!error)
+ return 0;
+
+ error = 0; /* someone else read in the rgrp; free it and ignore it */
fail:
kfree(rgd->rd_bits);
@@ -695,22 +697,18 @@ int gfs2_rindex_update(struct gfs2_sbd *sdp)
/* Read new copy from disk if we don't have the latest */
if (!sdp->sd_rindex_uptodate) {
- mutex_lock(&sdp->sd_rindex_mutex);
if (!gfs2_glock_is_locked_by_me(gl)) {
error = gfs2_glock_nq_init(gl, LM_ST_SHARED, 0, &ri_gh);
if (error)
- goto out_unlock;
+ return error;
unlock_required = 1;
}
if (!sdp->sd_rindex_uptodate)
error = gfs2_ri_update(ip);
if (unlock_required)
gfs2_glock_dq_uninit(&ri_gh);
-out_unlock:
- mutex_unlock(&sdp->sd_rindex_mutex);
}