Commit 5753c441 authored by David Howells's avatar David Howells

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: default avatarDavid Howells <dhowells@redhat.com>
parent b34df792
...@@ -250,6 +250,7 @@ proc files. ...@@ -250,6 +250,7 @@ proc files.
ok=N Number of successful alloc reqs ok=N Number of successful alloc reqs
wt=N Number of alloc reqs that waited on lookup completion wt=N Number of alloc reqs that waited on lookup completion
nbf=N Number of alloc reqs rejected -ENOBUFS nbf=N Number of alloc reqs rejected -ENOBUFS
int=N Number of alloc reqs aborted -ERESTARTSYS
ops=N Number of alloc reqs submitted ops=N Number of alloc reqs submitted
owt=N Number of alloc reqs waited for CPU time owt=N Number of alloc reqs waited for CPU time
Retrvls n=N Number of retrieval (read) requests seen Retrvls n=N Number of retrieval (read) requests seen
...@@ -271,6 +272,7 @@ proc files. ...@@ -271,6 +272,7 @@ proc files.
Ops pend=N Number of times async ops added to pending queues Ops pend=N Number of times async ops added to pending queues
run=N Number of times async ops given CPU time run=N Number of times async ops given CPU time
enq=N Number of times async ops queued for processing enq=N Number of times async ops queued for processing
can=N Number of async ops cancelled
dfr=N Number of async ops queued for deferred release dfr=N Number of async ops queued for deferred release
rel=N Number of async ops released rel=N Number of async ops released
gc=N Number of deferred-release async ops garbage collected gc=N Number of deferred-release async ops garbage collected
......
...@@ -112,6 +112,7 @@ extern int fscache_submit_exclusive_op(struct fscache_object *, ...@@ -112,6 +112,7 @@ extern int fscache_submit_exclusive_op(struct fscache_object *,
struct fscache_operation *); struct fscache_operation *);
extern int fscache_submit_op(struct fscache_object *, extern int fscache_submit_op(struct fscache_object *,
struct fscache_operation *); struct fscache_operation *);
extern int fscache_cancel_op(struct fscache_operation *);
extern void fscache_abort_object(struct fscache_object *); extern void fscache_abort_object(struct fscache_object *);
extern void fscache_start_operations(struct fscache_object *); extern void fscache_start_operations(struct fscache_object *);
extern void fscache_operation_gc(struct work_struct *); extern void fscache_operation_gc(struct work_struct *);
...@@ -140,6 +141,7 @@ extern atomic_t fscache_n_op_enqueue; ...@@ -140,6 +141,7 @@ extern atomic_t fscache_n_op_enqueue;
extern atomic_t fscache_n_op_deferred_release; extern atomic_t fscache_n_op_deferred_release;
extern atomic_t fscache_n_op_release; extern atomic_t fscache_n_op_release;
extern atomic_t fscache_n_op_gc; extern atomic_t fscache_n_op_gc;
extern atomic_t fscache_n_op_cancelled;
extern atomic_t fscache_n_attr_changed; extern atomic_t fscache_n_attr_changed;
extern atomic_t fscache_n_attr_changed_ok; extern atomic_t fscache_n_attr_changed_ok;
...@@ -151,6 +153,7 @@ extern atomic_t fscache_n_allocs; ...@@ -151,6 +153,7 @@ extern atomic_t fscache_n_allocs;
extern atomic_t fscache_n_allocs_ok; extern atomic_t fscache_n_allocs_ok;
extern atomic_t fscache_n_allocs_wait; extern atomic_t fscache_n_allocs_wait;
extern atomic_t fscache_n_allocs_nobufs; extern atomic_t fscache_n_allocs_nobufs;
extern atomic_t fscache_n_allocs_intr;
extern atomic_t fscache_n_alloc_ops; extern atomic_t fscache_n_alloc_ops;
extern atomic_t fscache_n_alloc_op_waits; extern atomic_t fscache_n_alloc_op_waits;
......
...@@ -34,32 +34,31 @@ void fscache_enqueue_operation(struct fscache_operation *op) ...@@ -34,32 +34,31 @@ void fscache_enqueue_operation(struct fscache_operation *op)
fscache_set_op_state(op, "EnQ"); fscache_set_op_state(op, "EnQ");
ASSERT(list_empty(&op->pend_link));
ASSERT(op->processor != NULL); ASSERT(op->processor != NULL);
ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE); ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
ASSERTCMP(atomic_read(&op->usage), >, 0); ASSERTCMP(atomic_read(&op->usage), >, 0);
if (list_empty(&op->pend_link)) { fscache_stat(&fscache_n_op_enqueue);
switch (op->flags & FSCACHE_OP_TYPE) { switch (op->flags & FSCACHE_OP_TYPE) {
case FSCACHE_OP_FAST: case FSCACHE_OP_FAST:
_debug("queue fast"); _debug("queue fast");
atomic_inc(&op->usage); atomic_inc(&op->usage);
if (!schedule_work(&op->fast_work)) if (!schedule_work(&op->fast_work))
fscache_put_operation(op); fscache_put_operation(op);
break; break;
case FSCACHE_OP_SLOW: case FSCACHE_OP_SLOW:
_debug("queue slow"); _debug("queue slow");
slow_work_enqueue(&op->slow_work); slow_work_enqueue(&op->slow_work);
break; break;
case FSCACHE_OP_MYTHREAD: case FSCACHE_OP_MYTHREAD:
_debug("queue for caller's attention"); _debug("queue for caller's attention");
break; break;
default: default:
printk(KERN_ERR "FS-Cache: Unexpected op type %lx", printk(KERN_ERR "FS-Cache: Unexpected op type %lx",
op->flags); op->flags);
BUG(); BUG();
break; break;
}
fscache_stat(&fscache_n_op_enqueue);
} }
} }
EXPORT_SYMBOL(fscache_enqueue_operation); EXPORT_SYMBOL(fscache_enqueue_operation);
...@@ -97,6 +96,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object, ...@@ -97,6 +96,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
spin_lock(&object->lock); spin_lock(&object->lock);
ASSERTCMP(object->n_ops, >=, object->n_in_progress); ASSERTCMP(object->n_ops, >=, object->n_in_progress);
ASSERTCMP(object->n_ops, >=, object->n_exclusive); ASSERTCMP(object->n_ops, >=, object->n_exclusive);
ASSERT(list_empty(&op->pend_link));
ret = -ENOBUFS; ret = -ENOBUFS;
if (fscache_object_is_active(object)) { if (fscache_object_is_active(object)) {
...@@ -202,6 +202,7 @@ int fscache_submit_op(struct fscache_object *object, ...@@ -202,6 +202,7 @@ int fscache_submit_op(struct fscache_object *object,
spin_lock(&object->lock); spin_lock(&object->lock);
ASSERTCMP(object->n_ops, >=, object->n_in_progress); ASSERTCMP(object->n_ops, >=, object->n_in_progress);
ASSERTCMP(object->n_ops, >=, object->n_exclusive); ASSERTCMP(object->n_ops, >=, object->n_exclusive);
ASSERT(list_empty(&op->pend_link));
ostate = object->state; ostate = object->state;
smp_rmb(); smp_rmb();
...@@ -273,12 +274,7 @@ void fscache_start_operations(struct fscache_object *object) ...@@ -273,12 +274,7 @@ void fscache_start_operations(struct fscache_object *object)
stop = true; stop = true;
} }
list_del_init(&op->pend_link); list_del_init(&op->pend_link);
object->n_in_progress++; fscache_run_op(object, op);
if (test_and_clear_bit(FSCACHE_OP_WAITING, &op->flags))
wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
if (op->processor)
fscache_enqueue_operation(op);
/* the pending queue was holding a ref on the object */ /* the pending queue was holding a ref on the object */
fscache_put_operation(op); fscache_put_operation(op);
...@@ -290,6 +286,36 @@ void fscache_start_operations(struct fscache_object *object) ...@@ -290,6 +286,36 @@ void fscache_start_operations(struct fscache_object *object)
object->n_in_progress, object->debug_id); object->n_in_progress, object->debug_id);
} }
/*
* cancel an operation that's pending on an object
*/
int fscache_cancel_op(struct fscache_operation *op)
{
struct fscache_object *object = op->object;
int ret;
_enter("OBJ%x OP%x}", op->object->debug_id, op->debug_id);
spin_lock(&object->lock);
ret = -EBUSY;
if (!list_empty(&op->pend_link)) {
fscache_stat(&fscache_n_op_cancelled);
list_del_init(&op->pend_link);
object->n_ops--;
if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
object->n_exclusive--;
if (test_and_clear_bit(FSCACHE_OP_WAITING, &op->flags))
wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
fscache_put_operation(op);
ret = 0;
}
spin_unlock(&object->lock);
_leave(" = %d", ret);
return ret;
}
/* /*
* release an operation * release an operation
* - queues pending ops if this is the last in-progress op * - queues pending ops if this is the last in-progress op
......
...@@ -295,8 +295,20 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie, ...@@ -295,8 +295,20 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
if (test_bit(FSCACHE_OP_WAITING, &op->op.flags)) { if (test_bit(FSCACHE_OP_WAITING, &op->op.flags)) {
_debug(">>> WT"); _debug(">>> WT");
fscache_stat(&fscache_n_retrieval_op_waits); fscache_stat(&fscache_n_retrieval_op_waits);
wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING, if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
fscache_wait_bit, TASK_UNINTERRUPTIBLE); fscache_wait_bit_interruptible,
TASK_INTERRUPTIBLE) < 0) {
ret = fscache_cancel_op(&op->op);
if (ret == 0) {
ret = -ERESTARTSYS;
goto error;
}
/* it's been removed from the pending queue by another
* party, so we should get to run shortly */
wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
fscache_wait_bit, TASK_UNINTERRUPTIBLE);
}
_debug("<<< GO"); _debug("<<< GO");
} }
...@@ -313,6 +325,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie, ...@@ -313,6 +325,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
fscache_stat_d(&fscache_n_cop_read_or_alloc_page); fscache_stat_d(&fscache_n_cop_read_or_alloc_page);
} }
error:
if (ret == -ENOMEM) if (ret == -ENOMEM)
fscache_stat(&fscache_n_retrievals_nomem); fscache_stat(&fscache_n_retrievals_nomem);
else if (ret == -ERESTARTSYS) else if (ret == -ERESTARTSYS)
...@@ -412,8 +425,20 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie, ...@@ -412,8 +425,20 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
if (test_bit(FSCACHE_OP_WAITING, &op->op.flags)) { if (test_bit(FSCACHE_OP_WAITING, &op->op.flags)) {
_debug(">>> WT"); _debug(">>> WT");
fscache_stat(&fscache_n_retrieval_op_waits); fscache_stat(&fscache_n_retrieval_op_waits);
wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING, if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
fscache_wait_bit, TASK_UNINTERRUPTIBLE); fscache_wait_bit_interruptible,
TASK_INTERRUPTIBLE) < 0) {
ret = fscache_cancel_op(&op->op);
if (ret == 0) {
ret = -ERESTARTSYS;
goto error;
}
/* it's been removed from the pending queue by another
* party, so we should get to run shortly */
wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
fscache_wait_bit, TASK_UNINTERRUPTIBLE);
}
_debug("<<< GO"); _debug("<<< GO");
} }
...@@ -430,6 +455,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie, ...@@ -430,6 +455,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
fscache_stat_d(&fscache_n_cop_read_or_alloc_pages); fscache_stat_d(&fscache_n_cop_read_or_alloc_pages);
} }
error:
if (ret == -ENOMEM) if (ret == -ENOMEM)
fscache_stat(&fscache_n_retrievals_nomem); fscache_stat(&fscache_n_retrievals_nomem);
else if (ret == -ERESTARTSYS) else if (ret == -ERESTARTSYS)
...@@ -505,8 +531,20 @@ int __fscache_alloc_page(struct fscache_cookie *cookie, ...@@ -505,8 +531,20 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
if (test_bit(FSCACHE_OP_WAITING, &op->op.flags)) { if (test_bit(FSCACHE_OP_WAITING, &op->op.flags)) {
_debug(">>> WT"); _debug(">>> WT");
fscache_stat(&fscache_n_alloc_op_waits); fscache_stat(&fscache_n_alloc_op_waits);
wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING, if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
fscache_wait_bit, TASK_UNINTERRUPTIBLE); fscache_wait_bit_interruptible,
TASK_INTERRUPTIBLE) < 0) {
ret = fscache_cancel_op(&op->op);
if (ret == 0) {
ret = -ERESTARTSYS;
goto error;
}
/* it's been removed from the pending queue by another
* party, so we should get to run shortly */
wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
fscache_wait_bit, TASK_UNINTERRUPTIBLE);
}
_debug("<<< GO"); _debug("<<< GO");
} }
...@@ -515,7 +553,10 @@ int __fscache_alloc_page(struct fscache_cookie *cookie, ...@@ -515,7 +553,10 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
ret = object->cache->ops->allocate_page(op, page, gfp); ret = object->cache->ops->allocate_page(op, page, gfp);
fscache_stat_d(&fscache_n_cop_allocate_page); fscache_stat_d(&fscache_n_cop_allocate_page);
if (ret < 0) error:
if (ret == -ERESTARTSYS)
fscache_stat(&fscache_n_allocs_intr);
else if (ret < 0)
fscache_stat(&fscache_n_allocs_nobufs); fscache_stat(&fscache_n_allocs_nobufs);
else else
fscache_stat(&fscache_n_allocs_ok); fscache_stat(&fscache_n_allocs_ok);
......
...@@ -25,6 +25,7 @@ atomic_t fscache_n_op_requeue; ...@@ -25,6 +25,7 @@ atomic_t fscache_n_op_requeue;
atomic_t fscache_n_op_deferred_release; atomic_t fscache_n_op_deferred_release;
atomic_t fscache_n_op_release; atomic_t fscache_n_op_release;
atomic_t fscache_n_op_gc; atomic_t fscache_n_op_gc;
atomic_t fscache_n_op_cancelled;
atomic_t fscache_n_attr_changed; atomic_t fscache_n_attr_changed;
atomic_t fscache_n_attr_changed_ok; atomic_t fscache_n_attr_changed_ok;
...@@ -36,6 +37,7 @@ atomic_t fscache_n_allocs; ...@@ -36,6 +37,7 @@ atomic_t fscache_n_allocs;
atomic_t fscache_n_allocs_ok; atomic_t fscache_n_allocs_ok;
atomic_t fscache_n_allocs_wait; atomic_t fscache_n_allocs_wait;
atomic_t fscache_n_allocs_nobufs; atomic_t fscache_n_allocs_nobufs;
atomic_t fscache_n_allocs_intr;
atomic_t fscache_n_alloc_ops; atomic_t fscache_n_alloc_ops;
atomic_t fscache_n_alloc_op_waits; atomic_t fscache_n_alloc_op_waits;
...@@ -169,11 +171,12 @@ static int fscache_stats_show(struct seq_file *m, void *v) ...@@ -169,11 +171,12 @@ static int fscache_stats_show(struct seq_file *m, void *v)
atomic_read(&fscache_n_attr_changed_nomem), atomic_read(&fscache_n_attr_changed_nomem),
atomic_read(&fscache_n_attr_changed_calls)); atomic_read(&fscache_n_attr_changed_calls));
seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u\n", seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
atomic_read(&fscache_n_allocs), atomic_read(&fscache_n_allocs),
atomic_read(&fscache_n_allocs_ok), atomic_read(&fscache_n_allocs_ok),
atomic_read(&fscache_n_allocs_wait), atomic_read(&fscache_n_allocs_wait),
atomic_read(&fscache_n_allocs_nobufs)); atomic_read(&fscache_n_allocs_nobufs),
atomic_read(&fscache_n_allocs_intr));
seq_printf(m, "Allocs : ops=%u owt=%u\n", seq_printf(m, "Allocs : ops=%u owt=%u\n",
atomic_read(&fscache_n_alloc_ops), atomic_read(&fscache_n_alloc_ops),
atomic_read(&fscache_n_alloc_op_waits)); atomic_read(&fscache_n_alloc_op_waits));
...@@ -201,10 +204,11 @@ static int fscache_stats_show(struct seq_file *m, void *v) ...@@ -201,10 +204,11 @@ static int fscache_stats_show(struct seq_file *m, void *v)
atomic_read(&fscache_n_store_ops), atomic_read(&fscache_n_store_ops),
atomic_read(&fscache_n_store_calls)); atomic_read(&fscache_n_store_calls));
seq_printf(m, "Ops : pend=%u run=%u enq=%u\n", seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u\n",
atomic_read(&fscache_n_op_pend), atomic_read(&fscache_n_op_pend),
atomic_read(&fscache_n_op_run), atomic_read(&fscache_n_op_run),
atomic_read(&fscache_n_op_enqueue)); atomic_read(&fscache_n_op_enqueue),
atomic_read(&fscache_n_op_cancelled));
seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n", seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
atomic_read(&fscache_n_op_deferred_release), atomic_read(&fscache_n_op_deferred_release),
atomic_read(&fscache_n_op_release), atomic_read(&fscache_n_op_release),
......
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