Skip to content

Commit faa794d

Browse files
hansendcMiklos Szeredi
authored andcommitted
fuse: Move prefaulting out of hot write path
Prefaulting the write source buffer incurs an extra userspace access in the common fast path. Make fuse_fill_write_pages() consistent with generic_perform_write(): only touch userspace an extra time when copy_folio_from_iter_atomic() has failed to make progress. Signed-off-by: Dave Hansen <[email protected]> Signed-off-by: Miklos Szeredi <[email protected]>
1 parent 0486b18 commit faa794d

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

fs/fuse/file.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,10 +1243,6 @@ static ssize_t fuse_fill_write_pages(struct fuse_io_args *ia,
12431243
bytes = min_t(size_t, bytes, fc->max_write - count);
12441244

12451245
again:
1246-
err = -EFAULT;
1247-
if (fault_in_iov_iter_readable(ii, bytes))
1248-
break;
1249-
12501246
folio = __filemap_get_folio(mapping, index, FGP_WRITEBEGIN,
12511247
mapping_gfp_mask(mapping));
12521248
if (IS_ERR(folio)) {
@@ -1263,6 +1259,16 @@ static ssize_t fuse_fill_write_pages(struct fuse_io_args *ia,
12631259
if (!tmp) {
12641260
folio_unlock(folio);
12651261
folio_put(folio);
1262+
1263+
/*
1264+
* Ensure forward progress by faulting in
1265+
* while not holding the folio lock:
1266+
*/
1267+
if (fault_in_iov_iter_readable(ii, bytes)) {
1268+
err = -EFAULT;
1269+
break;
1270+
}
1271+
12661272
goto again;
12671273
}
12681274

0 commit comments

Comments
 (0)