Commit 0e0f2dfe authored by David Howells's avatar David Howells

netfs: Dispatch write requests to process a writeback slice

Dispatch one or more write reqeusts to process a writeback slice, where a
slice is tailored more to logical block divisions within the file (such as
crypto blocks, an object layout or cache granules) than the protocol RPC
maximum capacity.

The dispatch doesn't happen until throttling allows, at which point the
entire writeback slice is processed and queued.  A slice may be written to
multiple destinations (one or more servers and the local cache) and the
writes to each destination might be split up along different lines.

The writeback slice holds the required folios pinned.  An iov_iter is
provided in netfs_write_request that describes the buffer to be used.  This
may be part of the pagecache, may have auxiliary padding pages attached or
may be a bounce buffer resulting from crypto or compression.  Consequently,
the filesystem must not twiddle the folio markings directly.

The following API is available to the filesystem:

 (1) The ->create_write_requests() method is called to ask the filesystem
     to create the requests it needs.  This is passed the writeback slice
     to be processed.

 (2) The filesystem should then call netfs_create_write_request() to create
     the requests it needs.

 (3) Once a request is initialised, netfs_queue_write_request() can be
     called to dispatch it asynchronously, if not completed immediately.

 (4) netfs_write_request_completed() should be called to note the
     completion of a request.

 (5) netfs_get_write_request() and netfs_put_write_request() are provided
     to refcount a request.  These take constants from the netfs_wreq_trace
     enum for logging into ftrace.

 (6) The ->free_write_request is method is called to ask the filesystem to
     clean up a request.
Signed-off-by: default avatarDavid Howells <dhowells@redhat.com>
Reviewed-by: default avatarJeff Layton <jlayton@kernel.org>
cc: linux-cachefs@redhat.com
cc: linux-fsdevel@vger.kernel.org
cc: linux-mm@kvack.org
parent 9ebff83e
...@@ -7,7 +7,8 @@ netfs-y := \ ...@@ -7,7 +7,8 @@ netfs-y := \
locking.o \ locking.o \
main.o \ main.o \
misc.o \ misc.o \
objects.o objects.o \
output.o
netfs-$(CONFIG_NETFS_STATS) += stats.o netfs-$(CONFIG_NETFS_STATS) += stats.o
......
...@@ -88,6 +88,12 @@ static inline void netfs_see_request(struct netfs_io_request *rreq, ...@@ -88,6 +88,12 @@ static inline void netfs_see_request(struct netfs_io_request *rreq,
trace_netfs_rreq_ref(rreq->debug_id, refcount_read(&rreq->ref), what); trace_netfs_rreq_ref(rreq->debug_id, refcount_read(&rreq->ref), what);
} }
/*
* output.c
*/
int netfs_begin_write(struct netfs_io_request *wreq, bool may_wait,
enum netfs_write_trace what);
/* /*
* stats.c * stats.c
*/ */
......
This diff is collapsed.
...@@ -249,6 +249,7 @@ struct netfs_io_request { ...@@ -249,6 +249,7 @@ struct netfs_io_request {
struct bio_vec *direct_bv; /* DIO buffer list (when handling iovec-iter) */ struct bio_vec *direct_bv; /* DIO buffer list (when handling iovec-iter) */
unsigned int direct_bv_count; /* Number of elements in direct_bv[] */ unsigned int direct_bv_count; /* Number of elements in direct_bv[] */
unsigned int debug_id; unsigned int debug_id;
unsigned int wsize; /* Maximum write size (0 for none) */
unsigned int subreq_counter; /* Next subreq->debug_index */ unsigned int subreq_counter; /* Next subreq->debug_index */
atomic_t nr_outstanding; /* Number of ops in progress */ atomic_t nr_outstanding; /* Number of ops in progress */
atomic_t nr_copy_ops; /* Number of copy-to-cache ops in progress */ atomic_t nr_copy_ops; /* Number of copy-to-cache ops in progress */
...@@ -271,6 +272,7 @@ struct netfs_io_request { ...@@ -271,6 +272,7 @@ struct netfs_io_request {
#define NETFS_RREQ_WRITE_TO_CACHE 7 /* Need to write to the cache */ #define NETFS_RREQ_WRITE_TO_CACHE 7 /* Need to write to the cache */
#define NETFS_RREQ_UPLOAD_TO_SERVER 8 /* Need to write to the server */ #define NETFS_RREQ_UPLOAD_TO_SERVER 8 /* Need to write to the server */
const struct netfs_request_ops *netfs_ops; const struct netfs_request_ops *netfs_ops;
void (*cleanup)(struct netfs_io_request *req);
}; };
/* /*
...@@ -294,6 +296,11 @@ struct netfs_request_ops { ...@@ -294,6 +296,11 @@ struct netfs_request_ops {
/* Modification handling */ /* Modification handling */
void (*update_i_size)(struct inode *inode, loff_t i_size); void (*update_i_size)(struct inode *inode, loff_t i_size);
/* Write request handling */
void (*create_write_requests)(struct netfs_io_request *wreq,
loff_t start, size_t len);
void (*invalidate_cache)(struct netfs_io_request *wreq);
}; };
/* /*
...@@ -382,6 +389,12 @@ ssize_t netfs_extract_user_iter(struct iov_iter *orig, size_t orig_len, ...@@ -382,6 +389,12 @@ ssize_t netfs_extract_user_iter(struct iov_iter *orig, size_t orig_len,
iov_iter_extraction_t extraction_flags); iov_iter_extraction_t extraction_flags);
size_t netfs_limit_iter(const struct iov_iter *iter, size_t start_offset, size_t netfs_limit_iter(const struct iov_iter *iter, size_t start_offset,
size_t max_size, size_t max_segs); size_t max_size, size_t max_segs);
struct netfs_io_subrequest *netfs_create_write_request(
struct netfs_io_request *wreq, enum netfs_io_source dest,
loff_t start, size_t len, work_func_t worker);
void netfs_write_subrequest_terminated(void *_op, ssize_t transferred_or_error,
bool was_async);
void netfs_queue_write_request(struct netfs_io_subrequest *subreq);
int netfs_start_io_read(struct inode *inode); int netfs_start_io_read(struct inode *inode);
void netfs_end_io_read(struct inode *inode); void netfs_end_io_read(struct inode *inode);
......
...@@ -21,6 +21,11 @@ ...@@ -21,6 +21,11 @@
EM(netfs_read_trace_readpage, "READPAGE ") \ EM(netfs_read_trace_readpage, "READPAGE ") \
E_(netfs_read_trace_write_begin, "WRITEBEGN") E_(netfs_read_trace_write_begin, "WRITEBEGN")
#define netfs_write_traces \
EM(netfs_write_trace_dio_write, "DIO-WRITE") \
EM(netfs_write_trace_unbuffered_write, "UNB-WRITE") \
E_(netfs_write_trace_writeback, "WRITEBACK")
#define netfs_rreq_origins \ #define netfs_rreq_origins \
EM(NETFS_READAHEAD, "RA") \ EM(NETFS_READAHEAD, "RA") \
EM(NETFS_READPAGE, "RP") \ EM(NETFS_READPAGE, "RP") \
...@@ -32,11 +37,13 @@ ...@@ -32,11 +37,13 @@
EM(netfs_rreq_trace_copy, "COPY ") \ EM(netfs_rreq_trace_copy, "COPY ") \
EM(netfs_rreq_trace_done, "DONE ") \ EM(netfs_rreq_trace_done, "DONE ") \
EM(netfs_rreq_trace_free, "FREE ") \ EM(netfs_rreq_trace_free, "FREE ") \
EM(netfs_rreq_trace_redirty, "REDIRTY") \
EM(netfs_rreq_trace_resubmit, "RESUBMT") \ EM(netfs_rreq_trace_resubmit, "RESUBMT") \
EM(netfs_rreq_trace_unlock, "UNLOCK ") \ EM(netfs_rreq_trace_unlock, "UNLOCK ") \
EM(netfs_rreq_trace_unmark, "UNMARK ") \ EM(netfs_rreq_trace_unmark, "UNMARK ") \
EM(netfs_rreq_trace_wait_ip, "WAIT-IP") \ EM(netfs_rreq_trace_wait_ip, "WAIT-IP") \
E_(netfs_rreq_trace_wake_ip, "WAKE-IP") EM(netfs_rreq_trace_wake_ip, "WAKE-IP") \
E_(netfs_rreq_trace_write_done, "WR-DONE")
#define netfs_sreq_sources \ #define netfs_sreq_sources \
EM(NETFS_FILL_WITH_ZEROES, "ZERO") \ EM(NETFS_FILL_WITH_ZEROES, "ZERO") \
...@@ -64,7 +71,8 @@ ...@@ -64,7 +71,8 @@
EM(netfs_fail_copy_to_cache, "copy-to-cache") \ EM(netfs_fail_copy_to_cache, "copy-to-cache") \
EM(netfs_fail_read, "read") \ EM(netfs_fail_read, "read") \
EM(netfs_fail_short_read, "short-read") \ EM(netfs_fail_short_read, "short-read") \
E_(netfs_fail_prepare_write, "prep-write") EM(netfs_fail_prepare_write, "prep-write") \
E_(netfs_fail_write, "write")
#define netfs_rreq_ref_traces \ #define netfs_rreq_ref_traces \
EM(netfs_rreq_trace_get_for_outstanding,"GET OUTSTND") \ EM(netfs_rreq_trace_get_for_outstanding,"GET OUTSTND") \
...@@ -74,6 +82,8 @@ ...@@ -74,6 +82,8 @@
EM(netfs_rreq_trace_put_failed, "PUT FAILED ") \ EM(netfs_rreq_trace_put_failed, "PUT FAILED ") \
EM(netfs_rreq_trace_put_return, "PUT RETURN ") \ EM(netfs_rreq_trace_put_return, "PUT RETURN ") \
EM(netfs_rreq_trace_put_subreq, "PUT SUBREQ ") \ EM(netfs_rreq_trace_put_subreq, "PUT SUBREQ ") \
EM(netfs_rreq_trace_put_work, "PUT WORK ") \
EM(netfs_rreq_trace_see_work, "SEE WORK ") \
E_(netfs_rreq_trace_new, "NEW ") E_(netfs_rreq_trace_new, "NEW ")
#define netfs_sreq_ref_traces \ #define netfs_sreq_ref_traces \
...@@ -82,9 +92,12 @@ ...@@ -82,9 +92,12 @@
EM(netfs_sreq_trace_get_short_read, "GET SHORTRD") \ EM(netfs_sreq_trace_get_short_read, "GET SHORTRD") \
EM(netfs_sreq_trace_new, "NEW ") \ EM(netfs_sreq_trace_new, "NEW ") \
EM(netfs_sreq_trace_put_clear, "PUT CLEAR ") \ EM(netfs_sreq_trace_put_clear, "PUT CLEAR ") \
EM(netfs_sreq_trace_put_discard, "PUT DISCARD") \
EM(netfs_sreq_trace_put_failed, "PUT FAILED ") \ EM(netfs_sreq_trace_put_failed, "PUT FAILED ") \
EM(netfs_sreq_trace_put_merged, "PUT MERGED ") \ EM(netfs_sreq_trace_put_merged, "PUT MERGED ") \
EM(netfs_sreq_trace_put_no_copy, "PUT NO COPY") \ EM(netfs_sreq_trace_put_no_copy, "PUT NO COPY") \
EM(netfs_sreq_trace_put_wip, "PUT WIP ") \
EM(netfs_sreq_trace_put_work, "PUT WORK ") \
E_(netfs_sreq_trace_put_terminated, "PUT TERM ") E_(netfs_sreq_trace_put_terminated, "PUT TERM ")
#ifndef __NETFS_DECLARE_TRACE_ENUMS_ONCE_ONLY #ifndef __NETFS_DECLARE_TRACE_ENUMS_ONCE_ONLY
...@@ -96,6 +109,7 @@ ...@@ -96,6 +109,7 @@
#define E_(a, b) a #define E_(a, b) a
enum netfs_read_trace { netfs_read_traces } __mode(byte); enum netfs_read_trace { netfs_read_traces } __mode(byte);
enum netfs_write_trace { netfs_write_traces } __mode(byte);
enum netfs_rreq_trace { netfs_rreq_traces } __mode(byte); enum netfs_rreq_trace { netfs_rreq_traces } __mode(byte);
enum netfs_sreq_trace { netfs_sreq_traces } __mode(byte); enum netfs_sreq_trace { netfs_sreq_traces } __mode(byte);
enum netfs_failure { netfs_failures } __mode(byte); enum netfs_failure { netfs_failures } __mode(byte);
...@@ -113,6 +127,7 @@ enum netfs_sreq_ref_trace { netfs_sreq_ref_traces } __mode(byte); ...@@ -113,6 +127,7 @@ enum netfs_sreq_ref_trace { netfs_sreq_ref_traces } __mode(byte);
#define E_(a, b) TRACE_DEFINE_ENUM(a); #define E_(a, b) TRACE_DEFINE_ENUM(a);
netfs_read_traces; netfs_read_traces;
netfs_write_traces;
netfs_rreq_origins; netfs_rreq_origins;
netfs_rreq_traces; netfs_rreq_traces;
netfs_sreq_sources; netfs_sreq_sources;
...@@ -320,6 +335,37 @@ TRACE_EVENT(netfs_sreq_ref, ...@@ -320,6 +335,37 @@ TRACE_EVENT(netfs_sreq_ref,
__entry->ref) __entry->ref)
); );
TRACE_EVENT(netfs_write,
TP_PROTO(const struct netfs_io_request *wreq,
enum netfs_write_trace what),
TP_ARGS(wreq, what),
TP_STRUCT__entry(
__field(unsigned int, wreq )
__field(unsigned int, cookie )
__field(enum netfs_write_trace, what )
__field(unsigned long long, start )
__field(size_t, len )
),
TP_fast_assign(
struct netfs_inode *__ctx = netfs_inode(wreq->inode);
struct fscache_cookie *__cookie = netfs_i_cookie(__ctx);
__entry->wreq = wreq->debug_id;
__entry->cookie = __cookie ? __cookie->debug_id : 0;
__entry->what = what;
__entry->start = wreq->start;
__entry->len = wreq->len;
),
TP_printk("R=%08x %s c=%08x by=%llx-%llx",
__entry->wreq,
__print_symbolic(__entry->what, netfs_write_traces),
__entry->cookie,
__entry->start, __entry->start + __entry->len - 1)
);
#undef EM #undef EM
#undef E_ #undef E_
#endif /* _TRACE_NETFS_H */ #endif /* _TRACE_NETFS_H */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment