@@ -1865,12 +1865,19 @@ static int ext4_writepage(struct page *page,
if (ext4_walk_page_buffers(NULL, page_bufs, 0, len, NULL,
ext4_bh_delay_or_unwritten)) {
redirty_page_for_writepage(wbc, page);
- if (current->flags & PF_MEMALLOC) {
+ if ((current->flags & PF_MEMALLOC) ||
+ radix_tree_tag_get(&page->mapping->page_tree,
+ page->index, PAGECACHE_TAG_TOWRITE)) {
/*
* For memory cleaning there's no point in writing only
* some buffers. So just bail out. Warn if we came here
* from direct reclaim.
- */
+ * We should also bail out when a journal commit happen
+ * during an integrity sync operation because calling
+ * ext4_bio_write_page in this case will clear
+ * PAGECACHE_TAG_TOWRITE and we could end up with
+ * dirty pages even after completion of a sync call.
+ */
WARN_ON_ONCE((current->flags & (PF_MEMALLOC|PF_KSWAPD))
== PF_MEMALLOC);
unlock_page(page);