Skip to content

Commit 502be2a

Browse files
AstralBobswhiteho
authored andcommitted
GFS2: Fix slab memory leak in gfs2_bufdata
This patch fixes a slab memory leak that sometimes can occur for files with a very short lifespan. The problem occurs when a dinode is deleted before it has gotten to the journal properly. In the leak scenario, the bd object is pinned for journal committment (queued to the metadata buffers queue: sd_log_le_buf) but is subsequently unpinned and dequeued before it finds its way to the ail or the revoke queue. In this rare circumstance, the bd object needs to be freed from slab memory, or it is forgotten. We have to be very careful how we do it, though, because multiple processes can call gfs2_remove_from_journal. In order to avoid double-frees, only the process that does the unpinning is allowed to free the bd. Signed-off-by: Bob Peterson <rpeterso@redhat.com> Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
1 parent 9290a9a commit 502be2a

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

‎fs/gfs2/meta_io.c‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,7 @@ void gfs2_remove_from_journal(struct buffer_head *bh, struct gfs2_trans *tr, int
258258
struct address_space *mapping = bh->b_page->mapping;
259259
struct gfs2_sbd *sdp = gfs2_mapping2sbd(mapping);
260260
struct gfs2_bufdata *bd = bh->b_private;
261+
int was_pinned = 0;
261262

262263
if (test_clear_buffer_pinned(bh)) {
263264
trace_gfs2_pin(bd, 0);
@@ -273,12 +274,16 @@ void gfs2_remove_from_journal(struct buffer_head *bh, struct gfs2_trans *tr, int
273274
tr->tr_num_databuf_rm++;
274275
}
275276
tr->tr_touched = 1;
277+
was_pinned = 1;
276278
brelse(bh);
277279
}
278280
if (bd) {
279281
spin_lock(&sdp->sd_ail_lock);
280282
if (bd->bd_tr) {
281283
gfs2_trans_add_revoke(sdp, bd);
284+
} else if (was_pinned) {
285+
bh->b_private = NULL;
286+
kmem_cache_free(gfs2_bufdata_cachep, bd);
282287
}
283288
spin_unlock(&sdp->sd_ail_lock);
284289
}

0 commit comments

Comments
 (0)