Skip to content

Commit 60d543c

Browse files
committed
FS-Cache: Start processing an object's operations on that object's death
Start processing an object's operations when that object moves into the DYING state as the object cannot be destroyed until all its outstanding operations have completed. Furthermore, make sure that read and allocation operations handle being woken up on a dead object. Such events are recorded in the Allocs.abt and Retrvls.abt statistics as viewable through /proc/fs/fscache/stats. The code for waiting for object activation for the read and allocation operations is also extracted into its own function as it is much the same in all cases, differing only in the stats incremented. Signed-off-by: David Howells <dhowells@redhat.com>
1 parent d461d26 commit 60d543c

6 files changed

Lines changed: 75 additions & 61 deletions

File tree

‎Documentation/filesystems/caching/fscache.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ proc files.
253253
int=N Number of alloc reqs aborted -ERESTARTSYS
254254
ops=N Number of alloc reqs submitted
255255
owt=N Number of alloc reqs waited for CPU time
256+
abt=N Number of alloc reqs aborted due to object death
256257
Retrvls n=N Number of retrieval (read) requests seen
257258
ok=N Number of successful retr reqs
258259
wt=N Number of retr reqs that waited on lookup completion
@@ -262,6 +263,7 @@ proc files.
262263
oom=N Number of retr reqs failed -ENOMEM
263264
ops=N Number of retr reqs submitted
264265
owt=N Number of retr reqs waited for CPU time
266+
abt=N Number of retr reqs aborted due to object death
265267
Stores n=N Number of storage (write) requests seen
266268
ok=N Number of successful store reqs
267269
agn=N Number of store reqs on a page already pending storage

‎fs/fscache/internal.h‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ extern atomic_t fscache_n_allocs_ok;
156156
extern atomic_t fscache_n_allocs_wait;
157157
extern atomic_t fscache_n_allocs_nobufs;
158158
extern atomic_t fscache_n_allocs_intr;
159+
extern atomic_t fscache_n_allocs_object_dead;
159160
extern atomic_t fscache_n_alloc_ops;
160161
extern atomic_t fscache_n_alloc_op_waits;
161162

@@ -166,6 +167,7 @@ extern atomic_t fscache_n_retrievals_nodata;
166167
extern atomic_t fscache_n_retrievals_nobufs;
167168
extern atomic_t fscache_n_retrievals_intr;
168169
extern atomic_t fscache_n_retrievals_nomem;
170+
extern atomic_t fscache_n_retrievals_object_dead;
169171
extern atomic_t fscache_n_retrieval_ops;
170172
extern atomic_t fscache_n_retrieval_op_waits;
171173

@@ -249,9 +251,12 @@ static inline void fscache_stat_d(atomic_t *stat)
249251
atomic_dec(stat);
250252
}
251253

254+
#define __fscache_stat(stat) (stat)
255+
252256
extern const struct file_operations fscache_stats_fops;
253257
#else
254258

259+
#define __fscache_stat(stat) (NULL)
255260
#define fscache_stat(stat) do {} while (0)
256261
#endif
257262

‎fs/fscache/object.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
201201
}
202202
spin_unlock(&object->lock);
203203
fscache_enqueue_dependents(object);
204+
fscache_start_operations(object);
204205
goto terminal_transit;
205206

206207
/* handle an abort during initialisation */

‎fs/fscache/page.c‎

Lines changed: 55 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,43 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
313313
return 0;
314314
}
315315

316+
/*
317+
* wait for an object to become active (or dead)
318+
*/
319+
static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
320+
struct fscache_retrieval *op,
321+
atomic_t *stat_op_waits,
322+
atomic_t *stat_object_dead)
323+
{
324+
int ret;
325+
326+
if (!test_bit(FSCACHE_OP_WAITING, &op->op.flags))
327+
goto check_if_dead;
328+
329+
_debug(">>> WT");
330+
fscache_stat(stat_op_waits);
331+
if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
332+
fscache_wait_bit_interruptible,
333+
TASK_INTERRUPTIBLE) < 0) {
334+
ret = fscache_cancel_op(&op->op);
335+
if (ret == 0)
336+
return -ERESTARTSYS;
337+
338+
/* it's been removed from the pending queue by another party,
339+
* so we should get to run shortly */
340+
wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
341+
fscache_wait_bit, TASK_UNINTERRUPTIBLE);
342+
}
343+
_debug("<<< GO");
344+
345+
check_if_dead:
346+
if (unlikely(fscache_object_is_dead(object))) {
347+
fscache_stat(stat_object_dead);
348+
return -ENOBUFS;
349+
}
350+
return 0;
351+
}
352+
316353
/*
317354
* read a page from the cache or allocate a block in which to store it
318355
* - we return:
@@ -376,25 +413,12 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
376413

377414
/* we wait for the operation to become active, and then process it
378415
* *here*, in this thread, and not in the thread pool */
379-
if (test_bit(FSCACHE_OP_WAITING, &op->op.flags)) {
380-
_debug(">>> WT");
381-
fscache_stat(&fscache_n_retrieval_op_waits);
382-
if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
383-
fscache_wait_bit_interruptible,
384-
TASK_INTERRUPTIBLE) < 0) {
385-
ret = fscache_cancel_op(&op->op);
386-
if (ret == 0) {
387-
ret = -ERESTARTSYS;
388-
goto error;
389-
}
390-
391-
/* it's been removed from the pending queue by another
392-
* party, so we should get to run shortly */
393-
wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
394-
fscache_wait_bit, TASK_UNINTERRUPTIBLE);
395-
}
396-
_debug("<<< GO");
397-
}
416+
ret = fscache_wait_for_retrieval_activation(
417+
object, op,
418+
__fscache_stat(&fscache_n_retrieval_op_waits),
419+
__fscache_stat(&fscache_n_retrievals_object_dead));
420+
if (ret < 0)
421+
goto error;
398422

399423
/* ask the cache to honour the operation */
400424
if (test_bit(FSCACHE_COOKIE_NO_DATA_YET, &object->cookie->flags)) {
@@ -506,25 +530,12 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
506530

507531
/* we wait for the operation to become active, and then process it
508532
* *here*, in this thread, and not in the thread pool */
509-
if (test_bit(FSCACHE_OP_WAITING, &op->op.flags)) {
510-
_debug(">>> WT");
511-
fscache_stat(&fscache_n_retrieval_op_waits);
512-
if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
513-
fscache_wait_bit_interruptible,
514-
TASK_INTERRUPTIBLE) < 0) {
515-
ret = fscache_cancel_op(&op->op);
516-
if (ret == 0) {
517-
ret = -ERESTARTSYS;
518-
goto error;
519-
}
520-
521-
/* it's been removed from the pending queue by another
522-
* party, so we should get to run shortly */
523-
wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
524-
fscache_wait_bit, TASK_UNINTERRUPTIBLE);
525-
}
526-
_debug("<<< GO");
527-
}
533+
ret = fscache_wait_for_retrieval_activation(
534+
object, op,
535+
__fscache_stat(&fscache_n_retrieval_op_waits),
536+
__fscache_stat(&fscache_n_retrievals_object_dead));
537+
if (ret < 0)
538+
goto error;
528539

529540
/* ask the cache to honour the operation */
530541
if (test_bit(FSCACHE_COOKIE_NO_DATA_YET, &object->cookie->flags)) {
@@ -612,25 +623,12 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
612623

613624
fscache_stat(&fscache_n_alloc_ops);
614625

615-
if (test_bit(FSCACHE_OP_WAITING, &op->op.flags)) {
616-
_debug(">>> WT");
617-
fscache_stat(&fscache_n_alloc_op_waits);
618-
if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
619-
fscache_wait_bit_interruptible,
620-
TASK_INTERRUPTIBLE) < 0) {
621-
ret = fscache_cancel_op(&op->op);
622-
if (ret == 0) {
623-
ret = -ERESTARTSYS;
624-
goto error;
625-
}
626-
627-
/* it's been removed from the pending queue by another
628-
* party, so we should get to run shortly */
629-
wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
630-
fscache_wait_bit, TASK_UNINTERRUPTIBLE);
631-
}
632-
_debug("<<< GO");
633-
}
626+
ret = fscache_wait_for_retrieval_activation(
627+
object, op,
628+
__fscache_stat(&fscache_n_alloc_op_waits),
629+
__fscache_stat(&fscache_n_allocs_object_dead));
630+
if (ret < 0)
631+
goto error;
634632

635633
/* ask the cache to honour the operation */
636634
fscache_stat(&fscache_n_cop_allocate_page);

‎fs/fscache/stats.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ atomic_t fscache_n_allocs_ok;
3939
atomic_t fscache_n_allocs_wait;
4040
atomic_t fscache_n_allocs_nobufs;
4141
atomic_t fscache_n_allocs_intr;
42+
atomic_t fscache_n_allocs_object_dead;
4243
atomic_t fscache_n_alloc_ops;
4344
atomic_t fscache_n_alloc_op_waits;
4445

@@ -49,6 +50,7 @@ atomic_t fscache_n_retrievals_nodata;
4950
atomic_t fscache_n_retrievals_nobufs;
5051
atomic_t fscache_n_retrievals_intr;
5152
atomic_t fscache_n_retrievals_nomem;
53+
atomic_t fscache_n_retrievals_object_dead;
5254
atomic_t fscache_n_retrieval_ops;
5355
atomic_t fscache_n_retrieval_op_waits;
5456

@@ -188,9 +190,10 @@ static int fscache_stats_show(struct seq_file *m, void *v)
188190
atomic_read(&fscache_n_allocs_wait),
189191
atomic_read(&fscache_n_allocs_nobufs),
190192
atomic_read(&fscache_n_allocs_intr));
191-
seq_printf(m, "Allocs : ops=%u owt=%u\n",
193+
seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
192194
atomic_read(&fscache_n_alloc_ops),
193-
atomic_read(&fscache_n_alloc_op_waits));
195+
atomic_read(&fscache_n_alloc_op_waits),
196+
atomic_read(&fscache_n_allocs_object_dead));
194197

195198
seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
196199
" int=%u oom=%u\n",
@@ -201,9 +204,10 @@ static int fscache_stats_show(struct seq_file *m, void *v)
201204
atomic_read(&fscache_n_retrievals_nobufs),
202205
atomic_read(&fscache_n_retrievals_intr),
203206
atomic_read(&fscache_n_retrievals_nomem));
204-
seq_printf(m, "Retrvls: ops=%u owt=%u\n",
207+
seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
205208
atomic_read(&fscache_n_retrieval_ops),
206-
atomic_read(&fscache_n_retrieval_op_waits));
209+
atomic_read(&fscache_n_retrieval_op_waits),
210+
atomic_read(&fscache_n_retrievals_object_dead));
207211

208212
seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
209213
atomic_read(&fscache_n_stores),

‎include/linux/fscache-cache.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,10 @@ extern const char *fscache_object_states[];
404404
(obj)->state >= FSCACHE_OBJECT_AVAILABLE && \
405405
(obj)->state < FSCACHE_OBJECT_DYING)
406406

407+
#define fscache_object_is_dead(obj) \
408+
(test_bit(FSCACHE_IOERROR, &(obj)->cache->flags) && \
409+
(obj)->state >= FSCACHE_OBJECT_DYING)
410+
407411
extern const struct slow_work_ops fscache_object_slow_work_ops;
408412

409413
/**

0 commit comments

Comments
 (0)