Skip to contentSkip to conversation

gfs2: forcibly flush ail to relieve memory pressure

PATCH New Abhi Das 2 participants 2 messages Aug 4, 2017 GFS2 file system

lore
Share & tools
lore

Abhi Das

author
#0 lore raw

PATCH 1/1 gfs2: forcibly flush ail to relieve memory pressure

On systems with low memory, it is possible for gfs2 to infinitely loop in balance_dirty_pages() under heavy IO (creating sparse files).

balance_dirty_pages() attempts to write out the dirty pages via gfs2_writepages() but none are found because these dirty pages are being used by the journaling code in the ail. Normally, the journal has an upper threshold which when hit triggers an automatic flush of the ail. But this threshold can be higher than the number of allowable dirty pages and result in the ail never being flushed.

This patch forces an ail flush when gfs2_writepages() fails to write anything. This is a good indication that the ail might be holding some dirty pages.

Resolves: rhbz#1389079

---
 fs/gfs2/aops.c   | 14 +++++++++++++-
 fs/gfs2/incore.h |  1 +
 fs/gfs2/log.c    |  4 ++++
 3 files changed, 18 insertions(+), 1 deletion(-)
fs/gfs2/aops.c +13 -1
index ed7a2e2..68ed069 100644
@@ -234,7 +234,19 @@ static int gfs2_jdata_writepage(struct page *page, struct writeback_control *wbc
 static int gfs2_writepages(struct address_space *mapping,
 			   struct writeback_control *wbc)
 {
-	return mpage_writepages(mapping, wbc, gfs2_get_block_noalloc);
+	struct gfs2_sbd *sdp = gfs2_mapping2sbd(mapping);
+	int ret = mpage_writepages(mapping, wbc, gfs2_get_block_noalloc);
+
+	/*
+	 * Even if we didn't write any pages here, we might still be holding
+	 * dirty pages in the ail. We forcibly flush the ail because we don't
+	 * want balance_dirty_pages() to loop indefinitely trying to write out
+	 * pages held in the ail that it can't find.
+	 */
+	if (ret == 0)
+		set_bit(SDF_FORCE_AIL_FLUSH, &sdp->sd_flags);
+
+	return ret;
 }
 
 /**
fs/gfs2/incore.h +1 -0
index 73fce76..a7b0331 100644
@@ -606,6 +606,7 @@ enum {
 	SDF_NOJOURNALID		= 6,
 	SDF_RORECOVERY		= 7, /* read only recovery */
 	SDF_SKIP_DLM_UNLOCK	= 8,
+	SDF_FORCE_AIL_FLUSH     = 9,
 };
 
 enum gfs2_freeze_state {
fs/gfs2/log.c +4 -0
index 9a624f6..31585c2 100644
@@ -898,6 +898,10 @@ static inline int gfs2_jrnl_flush_reqd(struct gfs2_sbd *sdp)
 static inline int gfs2_ail_flush_reqd(struct gfs2_sbd *sdp)
 {
 	unsigned int used_blocks = sdp->sd_jdesc->jd_blocks - atomic_read(&sdp->sd_log_blks_free);
+
+	if (test_and_clear_bit(SDF_FORCE_AIL_FLUSH, &sdp->sd_flags))
+		return 1;
+
 	return used_blocks + atomic_read(&sdp->sd_log_blks_needed) >=
 		atomic_read(&sdp->sd_log_thresh2);
 }
Signature · 1 line
2.4.11
#1 lore raw

PATCH 1/1 gfs2: forcibly flush ail to relieve memory pressure

----- Original Message -----

| On systems with low memory, it is possible for gfs2 to infinitely
| loop in balance_dirty_pages() under heavy IO (creating sparse files).
| 
| balance_dirty_pages() attempts to write out the dirty pages via
| gfs2_writepages() but none are found because these dirty pages are
| being used by the journaling code in the ail. Normally, the journal
| has an upper threshold which when hit triggers an automatic flush
| of the ail. But this threshold can be higher than the number of
| allowable dirty pages and result in the ail never being flushed.
| 
| This patch forces an ail flush when gfs2_writepages() fails to write
| anything. This is a good indication that the ail might be holding
| some dirty pages.
| 
| Resolves: rhbz#1389079
| Signed-off-by: Abhi Das <[email protected]>
| ---
|  fs/gfs2/aops.c   | 14 +++++++++++++-
|  fs/gfs2/incore.h |  1 +
|  fs/gfs2/log.c    |  4 ++++
|  3 files changed, 18 insertions(+), 1 deletion(-)

Hi,

Looks good. This is now pushed to the for-next branch of the linux-gfs2 tree:
https://git.kernel.org/pub/scm/linux/kernel/git/gfs2/linux-gfs2.git/commit/fs/gfs2?h=for-next&id=9513f7bd924e64b4a75bdb99f6d85027b799e1ba

Regards,

Bob Peterson
Red Hat File Systems