The problem appears to be here: if (folio_mapping(folio) != mapping || !folio_test_dirty(folio)) { folio_unlock(folio); goto skip_write; } in my version it's: if (folio->mapping != mapping || !folio_test_dirty(folio)) { start += folio_size(folio); folio_unlock(folio); continue; } In your version, skip_write doesn't advance start if it too many skips occur. Changing your version to match fixes the problem - or, at least, the symptoms. I'm not sure exactly why it's occurring, but the -EBADF (-9) is coming from cifs_get_writable_file() not finding an open file. I think this is a Steve question. With Vishal's change to use filemap_get_folios_tag() instead of find_get_pages_range_tag(), the most common file write case (open, write, write, ..., write, close) in which all the data is added to the pagecache in one contiguous lump without seeking, hits this a lot. Unfortunately, unlike find_get_pages_range_tag(), filemap_get_folios_tag() doesn't allow you to set a limit on the number of pages it will return. David