Skip to content

Commit 5753c44

Browse files
committed
FS-Cache: Permit cache retrieval ops to be interrupted in the initial wait phase
Permit the operations to retrieve data from the cache or to allocate space in the cache for future writes to be interrupted whilst they're waiting for permission for the operation to proceed. Typically this wait occurs whilst the cache object is being looked up on disk in the background. If an interruption occurs, and the operation has not yet been given the go-ahead to run, the operation is dequeued and cancelled, and control returns to the read operation of the netfs routine with none of the requested pages having been read or in any way marked as known by the cache. This means that the initial wait is done interruptibly rather than uninterruptibly. In addition, extra stats values are made available to show the number of ops cancelled and the number of cache space allocations interrupted. Signed-off-by: David Howells <dhowells@redhat.com>
1 parent b34df79 commit 5753c44

5 files changed

Lines changed: 115 additions & 39 deletions

File tree

‎Documentation/filesystems/caching/fscache.txt‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ proc files.
250250
ok=N Number of successful alloc reqs
251251
wt=N Number of alloc reqs that waited on lookup completion
252252
nbf=N Number of alloc reqs rejected -ENOBUFS
253+
int=N Number of alloc reqs aborted -ERESTARTSYS
253254
ops=N Number of alloc reqs submitted
254255
owt=N Number of alloc reqs waited for CPU time
255256
Retrvls n=N Number of retrieval (read) requests seen
@@ -271,6 +272,7 @@ proc files.
271272
Ops pend=N Number of times async ops added to pending queues
272273
run=N Number of times async ops given CPU time
273274
enq=N Number of times async ops queued for processing
275+
can=N Number of async ops cancelled
274276
dfr=N Number of async ops queued for deferred release
275277
rel=N Number of async ops released
276278
gc=N Number of deferred-release async ops garbage collected

‎fs/fscache/internal.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ extern int fscache_submit_exclusive_op(struct fscache_object *,
112112
struct fscache_operation *);
113113
extern int fscache_submit_op(struct fscache_object *,
114114
struct fscache_operation *);
115+
extern int fscache_cancel_op(struct fscache_operation *);
115116
extern void fscache_abort_object(struct fscache_object *);
116117
extern void fscache_start_operations(struct fscache_object *);
117118
extern void fscache_operation_gc(struct work_struct *);
@@ -140,6 +141,7 @@ extern atomic_t fscache_n_op_enqueue;
140141
extern atomic_t fscache_n_op_deferred_release;
141142
extern atomic_t fscache_n_op_release;
142143
extern atomic_t fscache_n_op_gc;
144+
extern atomic_t fscache_n_op_cancelled;
143145

144146
extern atomic_t fscache_n_attr_changed;
145147
extern atomic_t fscache_n_attr_changed_ok;
@@ -151,6 +153,7 @@ extern atomic_t fscache_n_allocs;
151153
extern atomic_t fscache_n_allocs_ok;
152154
extern atomic_t fscache_n_allocs_wait;
153155
extern atomic_t fscache_n_allocs_nobufs;
156+
extern atomic_t fscache_n_allocs_intr;
154157
extern atomic_t fscache_n_alloc_ops;
155158
extern atomic_t fscache_n_alloc_op_waits;
156159

‎fs/fscache/operation.c‎

Lines changed: 54 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -34,32 +34,31 @@ void fscache_enqueue_operation(struct fscache_operation *op)
3434

3535
fscache_set_op_state(op, "EnQ");
3636

37+
ASSERT(list_empty(&op->pend_link));
3738
ASSERT(op->processor != NULL);
3839
ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
3940
ASSERTCMP(atomic_read(&op->usage), >, 0);
4041

41-
if (list_empty(&op->pend_link)) {
42-
switch (op->flags & FSCACHE_OP_TYPE) {
43-
case FSCACHE_OP_FAST:
44-
_debug("queue fast");
45-
atomic_inc(&op->usage);
46-
if (!schedule_work(&op->fast_work))
47-
fscache_put_operation(op);
48-
break;
49-
case FSCACHE_OP_SLOW:
50-
_debug("queue slow");
51-
slow_work_enqueue(&op->slow_work);
52-
break;
53-
case FSCACHE_OP_MYTHREAD:
54-
_debug("queue for caller's attention");
55-
break;
56-
default:
57-
printk(KERN_ERR "FS-Cache: Unexpected op type %lx",
58-
op->flags);
59-
BUG();
60-
break;
61-
}
62-
fscache_stat(&fscache_n_op_enqueue);
42+
fscache_stat(&fscache_n_op_enqueue);
43+
switch (op->flags & FSCACHE_OP_TYPE) {
44+
case FSCACHE_OP_FAST:
45+
_debug("queue fast");
46+
atomic_inc(&op->usage);
47+
if (!schedule_work(&op->fast_work))
48+
fscache_put_operation(op);
49+
break;
50+
case FSCACHE_OP_SLOW:
51+
_debug("queue slow");
52+
slow_work_enqueue(&op->slow_work);
53+
break;
54+
case FSCACHE_OP_MYTHREAD:
55+
_debug("queue for caller's attention");
56+
break;
57+
default:
58+
printk(KERN_ERR "FS-Cache: Unexpected op type %lx",
59+
op->flags);
60+
BUG();
61+
break;
6362
}
6463
}
6564
EXPORT_SYMBOL(fscache_enqueue_operation);
@@ -97,6 +96,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
9796
spin_lock(&object->lock);
9897
ASSERTCMP(object->n_ops, >=, object->n_in_progress);
9998
ASSERTCMP(object->n_ops, >=, object->n_exclusive);
99+
ASSERT(list_empty(&op->pend_link));
100100

101101
ret = -ENOBUFS;
102102
if (fscache_object_is_active(object)) {
@@ -202,6 +202,7 @@ int fscache_submit_op(struct fscache_object *object,
202202
spin_lock(&object->lock);
203203
ASSERTCMP(object->n_ops, >=, object->n_in_progress);
204204
ASSERTCMP(object->n_ops, >=, object->n_exclusive);
205+
ASSERT(list_empty(&op->pend_link));
205206

206207
ostate = object->state;
207208
smp_rmb();
@@ -273,12 +274,7 @@ void fscache_start_operations(struct fscache_object *object)
273274
stop = true;
274275
}
275276
list_del_init(&op->pend_link);
276-
object->n_in_progress++;
277-
278-
if (test_and_clear_bit(FSCACHE_OP_WAITING, &op->flags))
279-
wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
280-
if (op->processor)
281-
fscache_enqueue_operation(op);
277+
fscache_run_op(object, op);
282278

283279
/* the pending queue was holding a ref on the object */
284280
fscache_put_operation(op);
@@ -290,6 +286,36 @@ void fscache_start_operations(struct fscache_object *object)
290286
object->n_in_progress, object->debug_id);
291287
}
292288

289+
/*
290+
* cancel an operation that's pending on an object
291+
*/
292+
int fscache_cancel_op(struct fscache_operation *op)
293+
{
294+
struct fscache_object *object = op->object;
295+
int ret;
296+
297+
_enter("OBJ%x OP%x}", op->object->debug_id, op->debug_id);
298+
299+
spin_lock(&object->lock);
300+
301+
ret = -EBUSY;
302+
if (!list_empty(&op->pend_link)) {
303+
fscache_stat(&fscache_n_op_cancelled);
304+
list_del_init(&op->pend_link);
305+
object->n_ops--;
306+
if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
307+
object->n_exclusive--;
308+
if (test_and_clear_bit(FSCACHE_OP_WAITING, &op->flags))
309+
wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
310+
fscache_put_operation(op);
311+
ret = 0;
312+
}
313+
314+
spin_unlock(&object->lock);
315+
_leave(" = %d", ret);
316+
return ret;
317+
}
318+
293319
/*
294320
* release an operation
295321
* - queues pending ops if this is the last in-progress op

‎fs/fscache/page.c‎

Lines changed: 48 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,20 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
295295
if (test_bit(FSCACHE_OP_WAITING, &op->op.flags)) {
296296
_debug(">>> WT");
297297
fscache_stat(&fscache_n_retrieval_op_waits);
298-
wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
299-
fscache_wait_bit, TASK_UNINTERRUPTIBLE);
298+
if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
299+
fscache_wait_bit_interruptible,
300+
TASK_INTERRUPTIBLE) < 0) {
301+
ret = fscache_cancel_op(&op->op);
302+
if (ret == 0) {
303+
ret = -ERESTARTSYS;
304+
goto error;
305+
}
306+
307+
/* it's been removed from the pending queue by another
308+
* party, so we should get to run shortly */
309+
wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
310+
fscache_wait_bit, TASK_UNINTERRUPTIBLE);
311+
}
300312
_debug("<<< GO");
301313
}
302314

@@ -313,6 +325,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
313325
fscache_stat_d(&fscache_n_cop_read_or_alloc_page);
314326
}
315327

328+
error:
316329
if (ret == -ENOMEM)
317330
fscache_stat(&fscache_n_retrievals_nomem);
318331
else if (ret == -ERESTARTSYS)
@@ -412,8 +425,20 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
412425
if (test_bit(FSCACHE_OP_WAITING, &op->op.flags)) {
413426
_debug(">>> WT");
414427
fscache_stat(&fscache_n_retrieval_op_waits);
415-
wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
416-
fscache_wait_bit, TASK_UNINTERRUPTIBLE);
428+
if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
429+
fscache_wait_bit_interruptible,
430+
TASK_INTERRUPTIBLE) < 0) {
431+
ret = fscache_cancel_op(&op->op);
432+
if (ret == 0) {
433+
ret = -ERESTARTSYS;
434+
goto error;
435+
}
436+
437+
/* it's been removed from the pending queue by another
438+
* party, so we should get to run shortly */
439+
wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
440+
fscache_wait_bit, TASK_UNINTERRUPTIBLE);
441+
}
417442
_debug("<<< GO");
418443
}
419444

@@ -430,6 +455,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
430455
fscache_stat_d(&fscache_n_cop_read_or_alloc_pages);
431456
}
432457

458+
error:
433459
if (ret == -ENOMEM)
434460
fscache_stat(&fscache_n_retrievals_nomem);
435461
else if (ret == -ERESTARTSYS)
@@ -505,8 +531,20 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
505531
if (test_bit(FSCACHE_OP_WAITING, &op->op.flags)) {
506532
_debug(">>> WT");
507533
fscache_stat(&fscache_n_alloc_op_waits);
508-
wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
509-
fscache_wait_bit, TASK_UNINTERRUPTIBLE);
534+
if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
535+
fscache_wait_bit_interruptible,
536+
TASK_INTERRUPTIBLE) < 0) {
537+
ret = fscache_cancel_op(&op->op);
538+
if (ret == 0) {
539+
ret = -ERESTARTSYS;
540+
goto error;
541+
}
542+
543+
/* it's been removed from the pending queue by another
544+
* party, so we should get to run shortly */
545+
wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
546+
fscache_wait_bit, TASK_UNINTERRUPTIBLE);
547+
}
510548
_debug("<<< GO");
511549
}
512550

@@ -515,7 +553,10 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
515553
ret = object->cache->ops->allocate_page(op, page, gfp);
516554
fscache_stat_d(&fscache_n_cop_allocate_page);
517555

518-
if (ret < 0)
556+
error:
557+
if (ret == -ERESTARTSYS)
558+
fscache_stat(&fscache_n_allocs_intr);
559+
else if (ret < 0)
519560
fscache_stat(&fscache_n_allocs_nobufs);
520561
else
521562
fscache_stat(&fscache_n_allocs_ok);

‎fs/fscache/stats.c‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ atomic_t fscache_n_op_requeue;
2525
atomic_t fscache_n_op_deferred_release;
2626
atomic_t fscache_n_op_release;
2727
atomic_t fscache_n_op_gc;
28+
atomic_t fscache_n_op_cancelled;
2829

2930
atomic_t fscache_n_attr_changed;
3031
atomic_t fscache_n_attr_changed_ok;
@@ -36,6 +37,7 @@ atomic_t fscache_n_allocs;
3637
atomic_t fscache_n_allocs_ok;
3738
atomic_t fscache_n_allocs_wait;
3839
atomic_t fscache_n_allocs_nobufs;
40+
atomic_t fscache_n_allocs_intr;
3941
atomic_t fscache_n_alloc_ops;
4042
atomic_t fscache_n_alloc_op_waits;
4143

@@ -169,11 +171,12 @@ static int fscache_stats_show(struct seq_file *m, void *v)
169171
atomic_read(&fscache_n_attr_changed_nomem),
170172
atomic_read(&fscache_n_attr_changed_calls));
171173

172-
seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u\n",
174+
seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
173175
atomic_read(&fscache_n_allocs),
174176
atomic_read(&fscache_n_allocs_ok),
175177
atomic_read(&fscache_n_allocs_wait),
176-
atomic_read(&fscache_n_allocs_nobufs));
178+
atomic_read(&fscache_n_allocs_nobufs),
179+
atomic_read(&fscache_n_allocs_intr));
177180
seq_printf(m, "Allocs : ops=%u owt=%u\n",
178181
atomic_read(&fscache_n_alloc_ops),
179182
atomic_read(&fscache_n_alloc_op_waits));
@@ -201,10 +204,11 @@ static int fscache_stats_show(struct seq_file *m, void *v)
201204
atomic_read(&fscache_n_store_ops),
202205
atomic_read(&fscache_n_store_calls));
203206

204-
seq_printf(m, "Ops : pend=%u run=%u enq=%u\n",
207+
seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u\n",
205208
atomic_read(&fscache_n_op_pend),
206209
atomic_read(&fscache_n_op_run),
207-
atomic_read(&fscache_n_op_enqueue));
210+
atomic_read(&fscache_n_op_enqueue),
211+
atomic_read(&fscache_n_op_cancelled));
208212
seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
209213
atomic_read(&fscache_n_op_deferred_release),
210214
atomic_read(&fscache_n_op_release),

0 commit comments

Comments
 (0)