FAILED: patch "[PATCH] nilfs2: force clear dirty state when restoring from the shadow map" failed to apply to 5.15-stable tree
Subsystems (2)
Sasha Levin
maintainerThe patch below does not apply to the 5.15-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
To reproduce the conflict and resubmit, you may use the following commands:
git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y
git checkout FETCH_HEAD
git cherry-pick -x cb6702e63e0a16afd83875294e5ce53becdd1b1f
# <resolve conflicts, build, test, etc.>
git commit -s
git send-email --to '<[email protected]>' --in-reply-to '[email protected]' --subject-prefix 'PATCH 5.15.y' 'HEAD^..'
Thanks,
Sasha
------------------ original commit in Linus's tree ------------------
From cb6702e63e0a16afd83875294e5ce53becdd1b1f Mon Sep 17 00:00:00 2001
From: Jiaming Zhang <[email protected]>
Date: Wed, 2 Sep 2026 19:21:21 +0800
Subject: [PATCH] nilfs2: force clear dirty state when restoring from the
shadow map
When garbage collection fails, nilfs2 rolls the DAT metadata file's page cache back to a shadow copy taken before GC started. nilfs_clear_dirty_pages() drops the dirty state of the folios in the DAT cache, then nilfs_copy_back_pages() overwrites them with the saved contents and warns if one is still dirty:
/* overwrite existing folio in the destination cache */ WARN_ON(folio_test_dirty(dfolio));
nilfs_clear_dirty_pages() used to clear the dirty state unconditionally, which is safe here because the rollback runs with the log writer stopped, so nothing else can dirty the cache while it runs. The same helper is also used when writeback finds dirty folios after the filesystem has degraded to read-only, where it does run concurrently with the log writer, so commit ca76bb226bf4 ("nilfs2: do not force clear folio if buffer is referenced") made nilfs_clear_folio_dirty() skip a folio if any of its buffer heads is busy. The rollback caller shares that helper, so its clearing step can now return with a folio still dirty.
A DAT folio can hold a busy buffer head without anyone modifying the
folio: nilfs_mdt_read_block() submits read-ahead for the blocks following the one it was asked for and waits only for the first, so the read-ahead buffers are still locked when it returns. With a block size smaller than the page size, a locked read-ahead buffer can share a folio with a block that GC dirtied and keep the whole folio dirty past the clearing step.
Add a force flag to nilfs_clear_dirty_pages() and nilfs_clear_folio_dirty() that skips the busy buffer check, and set it in the two calls from nilfs_mdt_restore_from_shadow_map(). The read-only fallback callers keep passing false, so that commit still protects them and the WARN_ON() is left alone.
--- fs/nilfs2/inode.c | 2 +- fs/nilfs2/mdt.c | 6 +++--- fs/nilfs2/page.c | 50 +++++++++++++++++++++++++++-------------------- fs/nilfs2/page.h | 4 ++-- 4 files changed, 35 insertions(+), 27 deletions(-)
fs/nilfs2/inode.c +1 -1
@@ -163,7 +163,7 @@ static int nilfs_writepages(struct address_space *mapping,int err =0 ;if (sb_rdonly (inode->i_sb)) { -nilfs_clear_dirty_pages (mapping); +nilfs_clear_dirty_pages (mapping, false);return -EROFS ; }
fs/nilfs2/mdt.c +3 -3
@@ -405,7 +405,7 @@ static int nilfs_mdt_write_folio(struct folio *folio,* have dirty folios that try to be flushed in background. * So, here we simply discard this dirty folio. */ -nilfs_clear_folio_dirty (folio); +nilfs_clear_folio_dirty (folio, false);folio_unlock (folio);return -EROFS ; }
@@ -648,10 +648,10 @@ void nilfs_mdt_restore_from_shadow_map(struct inode *inode)if (mi->mi_palloc_cache)nilfs_palloc_clear_cache (inode); -nilfs_clear_dirty_pages (inode->i_mapping); +nilfs_clear_dirty_pages (inode->i_mapping, true);nilfs_copy_back_pages (inode->i_mapping, shadow->inode->i_mapping); -nilfs_clear_dirty_pages (ii->i_assoc_inode->i_mapping); +nilfs_clear_dirty_pages (ii->i_assoc_inode->i_mapping, true);nilfs_copy_back_pages (ii->i_assoc_inode->i_mapping,NILFS_I (shadow->inode)->i_assoc_inode->i_mapping);
fs/nilfs2/page.c +29 -21
81 lines not on this page · raw message
fs/nilfs2/page.h +2 -2
@@ -41,8 +41,8 @@ void nilfs_folio_bug(struct folio *);int nilfs_copy_dirty_pages (struct address_space *,struct address_space *);void nilfs_copy_back_pages (struct address_space *,struct address_space *); -void nilfs_clear_folio_dirty (struct folio *folio); -void nilfs_clear_dirty_pages (struct address_space *mapping); +void nilfs_clear_folio_dirty (struct folio *folio,bool force); +void nilfs_clear_dirty_pages (struct address_space *mapping,bool force);unsigned int nilfs_page_count_clean_buffers (struct folio *folio,unsigned int from,unsigned int to); unsigned long nilfs_find_uncommitted_extent(struct inode *inode,
Signature · 1 line
2.53.0
Sasha Levin
maintainerPATCH 1/1 nilfs2: force clear dirty state when restoring from the shadow map
From: Jiaming Zhang <[email protected]>
[ Upstream commit cb6702e63e0a16afd83875294e5ce53becdd1b1f ]
When garbage collection fails, nilfs2 rolls the DAT metadata file's page cache back to a shadow copy taken before GC started. nilfs_clear_dirty_pages() drops the dirty state of the folios in the DAT cache, then nilfs_copy_back_pages() overwrites them with the saved contents and warns if one is still dirty:
/* overwrite existing folio in the destination cache */ WARN_ON(folio_test_dirty(dfolio));
nilfs_clear_dirty_pages() used to clear the dirty state unconditionally, which is safe here because the rollback runs with the log writer stopped, so nothing else can dirty the cache while it runs. The same helper is also used when writeback finds dirty folios after the filesystem has degraded to read-only, where it does run concurrently with the log writer, so commit ca76bb226bf4 ("nilfs2: do not force clear folio if buffer is referenced") made nilfs_clear_folio_dirty() skip a folio if any of its buffer heads is busy. The rollback caller shares that helper, so its clearing step can now return with a folio still dirty.
A DAT folio can hold a busy buffer head without anyone modifying the
folio: nilfs_mdt_read_block() submits read-ahead for the blocks following the one it was asked for and waits only for the first, so the read-ahead buffers are still locked when it returns. With a block size smaller than the page size, a locked read-ahead buffer can share a folio with a block that GC dirtied and keep the whole folio dirty past the clearing step.
Add a force flag to nilfs_clear_dirty_pages() and nilfs_clear_folio_dirty() that skips the busy buffer check, and set it in the two calls from nilfs_mdt_restore_from_shadow_map(). The read-only fallback callers keep passing false, so that commit still protects them and the WARN_ON() is left alone.
--- fs/nilfs2/inode.c | 4 ++-- fs/nilfs2/mdt.c | 6 +++--- fs/nilfs2/page.c | 50 +++++++++++++++++++++++++++-------------------- fs/nilfs2/page.h | 4 ++-- 4 files changed, 36 insertions(+), 28 deletions(-)
fs/nilfs2/inode.c +2 -2
@@ -162,7 +162,7 @@ static int nilfs_writepages(struct address_space *mapping,int err =0 ;if (sb_rdonly (inode->i_sb)) { -nilfs_clear_dirty_pages (mapping); +nilfs_clear_dirty_pages (mapping, false);return -EROFS ; }
@@ -185,7 +185,7 @@ static int nilfs_writepage(struct page *page, struct writeback_control *wbc)* have dirty pages that try to be flushed in background. * So, here we simply discard this dirty page. */ -nilfs_clear_dirty_page (page); +nilfs_clear_dirty_page (page, false);unlock_page (page);return -EROFS ; }
fs/nilfs2/mdt.c +3 -3
@@ -410,7 +410,7 @@ nilfs_mdt_write_page(struct page *page, struct writeback_control *wbc)* have dirty pages that try to be flushed in background. * So, here we simply discard this dirty page. */ -nilfs_clear_dirty_page (page); +nilfs_clear_dirty_page (page, false);unlock_page (page);return -EROFS ; }
@@ -632,10 +632,10 @@ void nilfs_mdt_restore_from_shadow_map(struct inode *inode)if (mi->mi_palloc_cache)nilfs_palloc_clear_cache (inode); -nilfs_clear_dirty_pages (inode->i_mapping); +nilfs_clear_dirty_pages (inode->i_mapping, true);nilfs_copy_back_pages (inode->i_mapping, shadow->inode->i_mapping); -nilfs_clear_dirty_pages (ii->i_assoc_inode->i_mapping); +nilfs_clear_dirty_pages (ii->i_assoc_inode->i_mapping, true);nilfs_copy_back_pages (ii->i_assoc_inode->i_mapping,NILFS_I (shadow->inode)->i_assoc_inode->i_mapping);
fs/nilfs2/page.c +29 -21
81 lines not on this page · raw message
fs/nilfs2/page.h +2 -2
@@ -41,8 +41,8 @@ void nilfs_page_bug(struct page *);int nilfs_copy_dirty_pages (struct address_space *,struct address_space *);void nilfs_copy_back_pages (struct address_space *,struct address_space *); -void nilfs_clear_dirty_page (struct page *page); -void nilfs_clear_dirty_pages (struct address_space *mapping); +void nilfs_clear_dirty_page (struct page *page,bool force); +void nilfs_clear_dirty_pages (struct address_space *mapping,bool force);void nilfs_mapping_init (struct address_space *mapping,struct inode *inode);unsigned int nilfs_page_count_clean_buffers (struct page *,unsigned int ,unsigned int );
Signature · 1 line
2.53.0