Skip to contentSkip to conversation

The mapping->invalidate_lock, copy-offload and cifs

DISCUSSION David Howells 2 participants 2 messages Aug 27, 2024 – Aug 28, 2024

Subsystems (5)
lore
Share & tools
lore

David Howells

author maintainer
#0 lore raw

Hi Jann,

I'm looking at trying to fix cifs_file_copychunk_range(). Currently, it invalidates the destination range, apart from a partial folio at either end which will be flushed, and then tries the copy. But if the copy fails or can only be partially completed (eg. ENOSPC), we lose any data in the destination region, so I think it needs to be flushed and invalidated rather than just being invalidated.

Now, we have filemap_invalidate_inode() which I can use to flush back and invalidate the folios under the invalidate_lock (thereby avoiding the need for launder_folio). However, that doesn't prevent mmap from reinstating the destination folios with modifications whilst the copy is ongoing the moment the invalidate_lock is dropped.

Question is: would it be reasonable to do the copy offload whilst holding the invalidate_lock for the duration?

Thanks,
David

reviewer
#1 lore raw

Hi David!

Quoted 7 lines · David Howells

I'm looking at trying to fix cifs_file_copychunk_range(). Currently, it invalidates the destination range, apart from a partial folio at either end which will be flushed, and then tries the copy. But if the copy fails or can only be partially completed (eg. ENOSPC), we lose any data in the destination region, so I think it needs to be flushed and invalidated rather than just being invalidated.

Quoted 8 lines

Now, we have filemap_invalidate_inode() which I can use to flush back and invalidate the folios under the invalidate_lock (thereby avoiding the need for launder_folio). However, that doesn't prevent mmap from reinstating the destination folios with modifications whilst the copy is ongoing the moment the invalidate_lock is dropped.

Question is: would it be reasonable to do the copy offload whilst holding the invalidate_lock for the duration?

FWIW yes, I'd expect cifs_file_copychunk_range() to take invalidate_lock on the target file to avoid possible races with page faults. We do it this already for similar operations such as reflink or various fallocate operations...

Honza

Quoted 4 lines

Thanks,
David

Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR