Skip to content

Commit b31268a

Browse files
Trond MyklebustTrond Myklebust
authored andcommitted
FS: Use stable writes when not doing a bulk flush
If we're only doing a single write, and there are no other unstable writes being queued up, we might want to just flip to using a stable write RPC call. Reviewed-by: NeilBrown <neilb@suse.de> Signed-off-by: Trond Myklebust <Trond.Myklebust@netapp.com>
1 parent 8e26de2 commit b31268a

File tree

4 files changed

+19
-3
lines changed

4 files changed

+19
-3
lines changed

fs/nfs/pagelist.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ void nfs_pageio_init(struct nfs_pageio_descriptor *desc,
223223
desc->pg_count = 0;
224224
desc->pg_bsize = bsize;
225225
desc->pg_base = 0;
226+
desc->pg_moreio = 0;
226227
desc->pg_inode = inode;
227228
desc->pg_doio = doio;
228229
desc->pg_ioflags = io_flags;
@@ -335,9 +336,11 @@ int nfs_pageio_add_request(struct nfs_pageio_descriptor *desc,
335336
struct nfs_page *req)
336337
{
337338
while (!nfs_pageio_do_add_request(desc, req)) {
339+
desc->pg_moreio = 1;
338340
nfs_pageio_doio(desc);
339341
if (desc->pg_error < 0)
340342
return 0;
343+
desc->pg_moreio = 0;
341344
}
342345
return 1;
343346
}

fs/nfs/write.c

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,8 +179,8 @@ static int wb_priority(struct writeback_control *wbc)
179179
if (wbc->for_reclaim)
180180
return FLUSH_HIGHPRI | FLUSH_STABLE;
181181
if (wbc->for_kupdate || wbc->for_background)
182-
return FLUSH_LOWPRI;
183-
return 0;
182+
return FLUSH_LOWPRI | FLUSH_COND_STABLE;
183+
return FLUSH_COND_STABLE;
184184
}
185185

186186
/*
@@ -863,7 +863,7 @@ static int nfs_write_rpcsetup(struct nfs_page *req,
863863
data->args.context = get_nfs_open_context(req->wb_context);
864864
data->args.lock_context = req->wb_lock_context;
865865
data->args.stable = NFS_UNSTABLE;
866-
if (how & FLUSH_STABLE) {
866+
if (how & (FLUSH_STABLE | FLUSH_COND_STABLE)) {
867867
data->args.stable = NFS_DATA_SYNC;
868868
if (!nfs_need_commit(NFS_I(inode)))
869869
data->args.stable = NFS_FILE_SYNC;
@@ -912,6 +912,12 @@ static int nfs_flush_multi(struct nfs_pageio_descriptor *desc)
912912

913913
nfs_list_remove_request(req);
914914

915+
if ((desc->pg_ioflags & FLUSH_COND_STABLE) &&
916+
(desc->pg_moreio || NFS_I(desc->pg_inode)->ncommit ||
917+
desc->pg_count > wsize))
918+
desc->pg_ioflags &= ~FLUSH_COND_STABLE;
919+
920+
915921
nbytes = desc->pg_count;
916922
do {
917923
size_t len = min(nbytes, wsize);
@@ -1002,6 +1008,10 @@ static int nfs_flush_one(struct nfs_pageio_descriptor *desc)
10021008
if ((!lseg) && list_is_singular(&data->pages))
10031009
lseg = pnfs_update_layout(desc->pg_inode, req->wb_context, IOMODE_RW);
10041010

1011+
if ((desc->pg_ioflags & FLUSH_COND_STABLE) &&
1012+
(desc->pg_moreio || NFS_I(desc->pg_inode)->ncommit))
1013+
desc->pg_ioflags &= ~FLUSH_COND_STABLE;
1014+
10051015
/* Set up the argument struct */
10061016
ret = nfs_write_rpcsetup(req, data, &nfs_write_full_ops, desc->pg_count, 0, lseg, desc->pg_ioflags);
10071017
out:

include/linux/nfs_fs.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@
3333
#define FLUSH_STABLE 4 /* commit to stable storage */
3434
#define FLUSH_LOWPRI 8 /* low priority background flush */
3535
#define FLUSH_HIGHPRI 16 /* high priority memory reclaim flush */
36+
#define FLUSH_COND_STABLE 32 /* conditional stable write - only stable
37+
* if everything fits in one RPC */
3638

3739
#ifdef __KERNEL__
3840

include/linux/nfs_page.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ struct nfs_pageio_descriptor {
5757
size_t pg_count;
5858
size_t pg_bsize;
5959
unsigned int pg_base;
60+
char pg_moreio;
6061

6162
struct inode *pg_inode;
6263
int (*pg_doio)(struct nfs_pageio_descriptor *);

0 commit comments

Comments
 (0)