History

fscache: Provide a function to resize a cookie

Provide a function to change the size of the storage attached to a cookie, to match the size of the file being cached when it's changed by truncate or fallocate: void fscache_resize_cookie(struct fscache_cookie *cookie, loff_t new_size); This acts synchronously and is expected to run under the inode lock of the caller.

David Howells committed 5 years ago

Commit 16a96bd1 parent 1f67e6d6 files · +82 −2Browse files

Unified · Split

6 files
  1. fs/fscache/internal.h +3 −0
  2. fs/fscache/io.c +25 −0
  3. fs/fscache/stats.c +7 −2
  4. include/linux/fscache-cache.h +4 −0
  5. include/linux/fscache.h +18 −0
  6. include/trace/events/fscache.h +25 −0
fs/fscache/internal.h+3−0
@@ -122,6 +122,9 @@ extern atomic_t fscache_n_relinquishes; · 121 unmodified lines
122extern atomic_t fscache_n_relinquishes_retire;122extern atomic_t fscache_n_relinquishes_retire;
123extern atomic_t fscache_n_relinquishes_dropped;123extern atomic_t fscache_n_relinquishes_dropped;
124 124
125extern atomic_t fscache_n_resizes;
126extern atomic_t fscache_n_resizes_null;
127
125static inline void fscache_stat(atomic_t *stat)128static inline void fscache_stat(atomic_t *stat)
126{129{
127 atomic_inc(stat);130 atomic_inc(stat);
fs/fscache/io.c+25−0
@@ -291,3 +291,28 @@ abandon: · 290 unmodified lines
291 term_func(term_func_priv, ret, false);291 term_func(term_func_priv, ret, false);
292}292}
293EXPORT_SYMBOL(__fscache_write_to_cache);293EXPORT_SYMBOL(__fscache_write_to_cache);
294
295/*
296 * Change the size of a backing object.
297 */
298void __fscache_resize_cookie(struct fscache_cookie *cookie, loff_t new_size)
299{
300 struct netfs_cache_resources cres;
301
302 trace_fscache_resize(cookie, new_size);
303 if (fscache_begin_operation(&cres, cookie, FSCACHE_WANT_WRITE,
304 fscache_access_io_resize) == 0) {
305 fscache_stat(&fscache_n_resizes);
306 set_bit(FSCACHE_COOKIE_NEEDS_UPDATE, &cookie->flags);
307
308 /* We cannot defer a resize as we need to do it inside the
309 * netfs's inode lock so that we're serialised with respect to
310 * writes.
311 */
312 cookie->volume->cache->ops->resize_cookie(&cres, new_size);
313 fscache_end_operation(&cres);
314 } else {
315 fscache_stat(&fscache_n_resizes_null);
316 }
317}
318EXPORT_SYMBOL(__fscache_resize_cookie);
fs/fscache/stats.c+7−2
@@ -35,6 +35,9 @@ atomic_t fscache_n_relinquishes; · 34 unmodified lines
35atomic_t fscache_n_relinquishes_retire;35atomic_t fscache_n_relinquishes_retire;
36atomic_t fscache_n_relinquishes_dropped;36atomic_t fscache_n_relinquishes_dropped;
37 37
38atomic_t fscache_n_resizes;
39atomic_t fscache_n_resizes_null;
40
38atomic_t fscache_n_read;41atomic_t fscache_n_read;
39EXPORT_SYMBOL(fscache_n_read);42EXPORT_SYMBOL(fscache_n_read);
40atomic_t fscache_n_write;43atomic_t fscache_n_write;
@@ -69,8 +72,10 @@ int fscache_stats_show(struct seq_file *m, void *v) · 28 unmodified lines
69 seq_printf(m, "Invals : n=%u\n",72 seq_printf(m, "Invals : n=%u\n",
70 atomic_read(&fscache_n_invalidates));73 atomic_read(&fscache_n_invalidates));
71 74
72 seq_printf(m, "Updates: n=%u\n",75 seq_printf(m, "Updates: n=%u rsz=%u rsn=%u\n",
73 atomic_read(&fscache_n_updates));76 atomic_read(&fscache_n_updates),
77 atomic_read(&fscache_n_resizes),
78 atomic_read(&fscache_n_resizes_null));
74 79
75 seq_printf(m, "Relinqs: n=%u rtr=%u drop=%u\n",80 seq_printf(m, "Relinqs: n=%u rtr=%u drop=%u\n",
76 atomic_read(&fscache_n_relinquishes),81 atomic_read(&fscache_n_relinquishes),
include/linux/fscache-cache.h+4−0
@@ -64,6 +64,10 @@ struct fscache_cache_ops { · 63 unmodified lines
64 /* Withdraw an object without any cookie access counts held */64 /* Withdraw an object without any cookie access counts held */
65 void (*withdraw_cookie)(struct fscache_cookie *cookie);65 void (*withdraw_cookie)(struct fscache_cookie *cookie);
66 66
67 /* Change the size of a data object */
68 void (*resize_cookie)(struct netfs_cache_resources *cres,
69 loff_t new_size);
70
67 /* Invalidate an object */71 /* Invalidate an object */
68 bool (*invalidate_cookie)(struct fscache_cookie *cookie);72 bool (*invalidate_cookie)(struct fscache_cookie *cookie);
69 73
include/linux/fscache.h+18−0
@@ -163,6 +163,7 @@ extern struct fscache_cookie *__fscache_acquire_cookie( · 162 unmodified lines
163extern void __fscache_use_cookie(struct fscache_cookie *, bool);163extern void __fscache_use_cookie(struct fscache_cookie *, bool);
164extern void __fscache_unuse_cookie(struct fscache_cookie *, const void *, const loff_t *);164extern void __fscache_unuse_cookie(struct fscache_cookie *, const void *, const loff_t *);
165extern void __fscache_relinquish_cookie(struct fscache_cookie *, bool);165extern void __fscache_relinquish_cookie(struct fscache_cookie *, bool);
166extern void __fscache_resize_cookie(struct fscache_cookie *, loff_t);
166extern void __fscache_invalidate(struct fscache_cookie *, const void *, loff_t, unsigned int);167extern void __fscache_invalidate(struct fscache_cookie *, const void *, loff_t, unsigned int);
167extern int __fscache_begin_read_operation(struct netfs_cache_resources *, struct fscache_cookie *);168extern int __fscache_begin_read_operation(struct netfs_cache_resources *, struct fscache_cookie *);
168 169
@@ -366,6 +367,23 @@ void fscache_update_cookie(struct fscache_cookie *cookie, const void *aux_data, · 197 unmodified lines
366 __fscache_update_cookie(cookie, aux_data, object_size);367 __fscache_update_cookie(cookie, aux_data, object_size);
367}368}
368 369
370/**
371 * fscache_resize_cookie - Request that a cache object be resized
372 * @cookie: The cookie representing the cache object
373 * @new_size: The new size of the object (may be NULL)
374 *
375 * Request that the size of an object be changed.
376 *
377 * See Documentation/filesystems/caching/netfs-api.txt for a complete
378 * description.
379 */
380static inline
381void fscache_resize_cookie(struct fscache_cookie *cookie, loff_t new_size)
382{
383 if (fscache_cookie_enabled(cookie))
384 __fscache_resize_cookie(cookie, new_size);
385}
386
369/**387/**
370 * fscache_invalidate - Notify cache that an object needs invalidation388 * fscache_invalidate - Notify cache that an object needs invalidation
371 * @cookie: The cookie representing the cache object389 * @cookie: The cookie representing the cache object
include/trace/events/fscache.h+25−0
@@ -78,6 +78,7 @@ enum fscache_access_trace { · 77 unmodified lines
78 fscache_access_invalidate_cookie_end,78 fscache_access_invalidate_cookie_end,
79 fscache_access_io_not_live,79 fscache_access_io_not_live,
80 fscache_access_io_read,80 fscache_access_io_read,
81 fscache_access_io_resize,
81 fscache_access_io_wait,82 fscache_access_io_wait,
82 fscache_access_io_write,83 fscache_access_io_write,
83 fscache_access_lookup_cookie,84 fscache_access_lookup_cookie,
@@ -149,6 +150,7 @@ enum fscache_access_trace { · 65 unmodified lines
149 EM(fscache_access_invalidate_cookie_end,"END inval ") \150 EM(fscache_access_invalidate_cookie_end,"END inval ") \
150 EM(fscache_access_io_not_live, "END io_notl") \151 EM(fscache_access_io_not_live, "END io_notl") \
151 EM(fscache_access_io_read, "BEGIN io_read") \152 EM(fscache_access_io_read, "BEGIN io_read") \
153 EM(fscache_access_io_resize, "BEGIN io_resz") \
152 EM(fscache_access_io_wait, "WAIT io ") \154 EM(fscache_access_io_wait, "WAIT io ") \
153 EM(fscache_access_io_write, "BEGIN io_writ") \155 EM(fscache_access_io_write, "BEGIN io_writ") \
154 EM(fscache_access_lookup_cookie, "BEGIN lookup ") \156 EM(fscache_access_lookup_cookie, "BEGIN lookup ") \
@@ -418,6 +420,29 @@ TRACE_EVENT(fscache_invalidate, · 263 unmodified lines
418 __entry->cookie, __entry->new_size)420 __entry->cookie, __entry->new_size)
419 );421 );
420 422
423TRACE_EVENT(fscache_resize,
424 TP_PROTO(struct fscache_cookie *cookie, loff_t new_size),
425
426 TP_ARGS(cookie, new_size),
427
428 TP_STRUCT__entry(
429 __field(unsigned int, cookie )
430 __field(loff_t, old_size )
431 __field(loff_t, new_size )
432 ),
433
434 TP_fast_assign(
435 __entry->cookie = cookie->debug_id;
436 __entry->old_size = cookie->object_size;
437 __entry->new_size = new_size;
438 ),
439
440 TP_printk("c=%08x os=%08llx sz=%08llx",
441 __entry->cookie,
442 __entry->old_size,
443 __entry->new_size)
444 );
445
421#endif /* _TRACE_FSCACHE_H */446#endif /* _TRACE_FSCACHE_H */
422 447
423/* This part must be outside protection */448/* This part must be outside protection */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t