Skip to content

Commit 2cde04e

Browse files
Kazuo ItoTrond Myklebust
authored andcommitted
pNFS: Avoid read/modify/write when it is not necessary
As the block and SCSI layouts can only read/write fixed-length blocks, we must perform read-modify-write when data to be written is not aligned to a block boundary or smaller than the block size. (612aa98 pnfs: add flag to force read-modify-write in ->write_begin) The current code tries to see if we have to do read-modify-write on block-oriented pNFS layouts by just checking !PageUptodate(page), but the same condition also applies for overwriting of any uncached potions of existing files, making such operations excessively slow even it is block-aligned. The change does not affect the optimization for modify-write-read cases (38c7304 NFS: read-modify-write page updating), because partial update of !PageUptodate() pages can only happen in layouts that can do arbitrary length read/write and never in block-based ones. Testing results: We ran fio on one of the pNFS clients running 4.20 kernel (vanilla and patched) in this configuration to read/write/overwrite files on the storage array, exported as pnfs share by the server. pNFS clients ---1G Ethernet--- pNFS server (HP DL360 G8) (HP DL360 G8) | | | | +------8G Fiber Channel--------+ | Storage Array (HP P6350) Throughput of overwrite (both buffered and O_SYNC) is noticeably improved. Ops. |block size| Throughput | | (KiB) | (MiB/s) | | | 4.20 | patched| ---------+----------+----------------+ buffered | 4| 21.3 | 232 | overwrite| 32| 22.2 | 256 | | 512| 22.4 | 260 | ---------+----------+----------------+ O_SYNC | 4| 3.84| 4.77| overwrite| 32| 12.2 | 32.0 | | 512| 18.5 | 152 | ---------+----------+----------------+ Read and write (buffered and O_SYNC) by the same client remain unchanged by the patch either negatively or positively, as they should do. Ops. |block size| Throughput | | (KiB) | (MiB/s) | | | 4.20 | patched| ---------+----------+----------------+ read | 4| 548 | 550 | | 32| 547 | 551 | | 512| 548 | 551 | ---------+----------+----------------+ buffered | 4| 237 | 244 | write | 32| 261 | 268 | | 512| 265 | 272 | ---------+----------+----------------+ O_SYNC | 4| 0.46| 0.46| write | 32| 3.60| 3.57| | 512| 105 | 106 | ---------+----------+----------------+ Signed-off-by: Kazuo Ito <ito_kazuo_g3@lab.ntt.co.jp> Tested-by: Hiroyuki Watanabe <watanabe.hiroyuki@lab.ntt.co.jp> Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com>
1 parent 97ae91b commit 2cde04e

File tree

1 file changed

+26
-14
lines changed

1 file changed

+26
-14
lines changed

fs/nfs/file.c

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,12 @@ EXPORT_SYMBOL_GPL(nfs_file_fsync);
276276
* then a modify/write/read cycle when writing to a page in the
277277
* page cache.
278278
*
279+
* Some pNFS layout drivers can only read/write at a certain block
280+
* granularity like all block devices and therefore we must perform
281+
* read/modify/write whenever a page hasn't read yet and the data
282+
* to be written there is not aligned to a block boundary and/or
283+
* smaller than the block size.
284+
*
279285
* The modify/write/read cycle may occur if a page is read before
280286
* being completely filled by the writer. In this situation, the
281287
* page must be completely written to stable storage on the server
@@ -291,26 +297,32 @@ EXPORT_SYMBOL_GPL(nfs_file_fsync);
291297
* and that the new data won't completely replace the old data in
292298
* that range of the file.
293299
*/
294-
static int nfs_want_read_modify_write(struct file *file, struct page *page,
295-
loff_t pos, unsigned len)
300+
static bool nfs_full_page_write(struct page *page, loff_t pos, unsigned int len)
296301
{
297302
unsigned int pglen = nfs_page_length(page);
298303
unsigned int offset = pos & (PAGE_SIZE - 1);
299304
unsigned int end = offset + len;
300305

301-
if (pnfs_ld_read_whole_page(file->f_mapping->host)) {
302-
if (!PageUptodate(page) && !PagePrivate(page))
303-
return 1;
304-
return 0;
305-
}
306+
return !pglen || (end >= pglen && !offset);
307+
}
306308

307-
if ((file->f_mode & FMODE_READ) && /* open for read? */
308-
!PageUptodate(page) && /* Uptodate? */
309-
!PagePrivate(page) && /* i/o request already? */
310-
pglen && /* valid bytes of file? */
311-
(end < pglen || offset)) /* replace all valid bytes? */
312-
return 1;
313-
return 0;
309+
static bool nfs_want_read_modify_write(struct file *file, struct page *page,
310+
loff_t pos, unsigned int len)
311+
{
312+
/*
313+
* Up-to-date pages, those with ongoing or full-page write
314+
* don't need read/modify/write
315+
*/
316+
if (PageUptodate(page) || PagePrivate(page) ||
317+
nfs_full_page_write(page, pos, len))
318+
return false;
319+
320+
if (pnfs_ld_read_whole_page(file->f_mapping->host))
321+
return true;
322+
/* Open for reading too? */
323+
if (file->f_mode & FMODE_READ)
324+
return true;
325+
return false;
314326
}
315327

316328
/*

0 commit comments

Comments
 (0)