Commit 60d543ca authored by David Howells's avatar David Howells

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: default avatarDavid Howells <dhowells@redhat.com>
parent d461d26d
...@@ -253,6 +253,7 @@ proc files. ...@@ -253,6 +253,7 @@ proc files.
int=N Number of alloc reqs aborted -ERESTARTSYS 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
abt=N Number of alloc reqs aborted due to object death
Retrvls n=N Number of retrieval (read) requests seen Retrvls n=N Number of retrieval (read) requests seen
ok=N Number of successful retr reqs ok=N Number of successful retr reqs
wt=N Number of retr reqs that waited on lookup completion wt=N Number of retr reqs that waited on lookup completion
...@@ -262,6 +263,7 @@ proc files. ...@@ -262,6 +263,7 @@ proc files.
oom=N Number of retr reqs failed -ENOMEM oom=N Number of retr reqs failed -ENOMEM
ops=N Number of retr reqs submitted ops=N Number of retr reqs submitted
owt=N Number of retr reqs waited for CPU time owt=N Number of retr reqs waited for CPU time
abt=N Number of retr reqs aborted due to object death
Stores n=N Number of storage (write) requests seen Stores n=N Number of storage (write) requests seen
ok=N Number of successful store reqs ok=N Number of successful store reqs
agn=N Number of store reqs on a page already pending storage agn=N Number of store reqs on a page already pending storage
......
...@@ -156,6 +156,7 @@ extern atomic_t fscache_n_allocs_ok; ...@@ -156,6 +156,7 @@ 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_allocs_intr;
extern atomic_t fscache_n_allocs_object_dead;
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;
...@@ -166,6 +167,7 @@ extern atomic_t fscache_n_retrievals_nodata; ...@@ -166,6 +167,7 @@ extern atomic_t fscache_n_retrievals_nodata;
extern atomic_t fscache_n_retrievals_nobufs; extern atomic_t fscache_n_retrievals_nobufs;
extern atomic_t fscache_n_retrievals_intr; extern atomic_t fscache_n_retrievals_intr;
extern atomic_t fscache_n_retrievals_nomem; extern atomic_t fscache_n_retrievals_nomem;
extern atomic_t fscache_n_retrievals_object_dead;
extern atomic_t fscache_n_retrieval_ops; extern atomic_t fscache_n_retrieval_ops;
extern atomic_t fscache_n_retrieval_op_waits; extern atomic_t fscache_n_retrieval_op_waits;
...@@ -249,9 +251,12 @@ static inline void fscache_stat_d(atomic_t *stat) ...@@ -249,9 +251,12 @@ static inline void fscache_stat_d(atomic_t *stat)
atomic_dec(stat); atomic_dec(stat);
} }
#define __fscache_stat(stat) (stat)
extern const struct file_operations fscache_stats_fops; extern const struct file_operations fscache_stats_fops;
#else #else
#define __fscache_stat(stat) (NULL)
#define fscache_stat(stat) do {} while (0) #define fscache_stat(stat) do {} while (0)
#endif #endif
......
...@@ -201,6 +201,7 @@ static void fscache_object_state_machine(struct fscache_object *object) ...@@ -201,6 +201,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
} }
spin_unlock(&object->lock); spin_unlock(&object->lock);
fscache_enqueue_dependents(object); fscache_enqueue_dependents(object);
fscache_start_operations(object);
goto terminal_transit; goto terminal_transit;
/* handle an abort during initialisation */ /* handle an abort during initialisation */
......
...@@ -313,6 +313,43 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie) ...@@ -313,6 +313,43 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
return 0; return 0;
} }
/*
* wait for an object to become active (or dead)
*/
static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
struct fscache_retrieval *op,
atomic_t *stat_op_waits,
atomic_t *stat_object_dead)
{
int ret;
if (!test_bit(FSCACHE_OP_WAITING, &op->op.flags))
goto check_if_dead;
_debug(">>> WT");
fscache_stat(stat_op_waits);
if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
fscache_wait_bit_interruptible,
TASK_INTERRUPTIBLE) < 0) {
ret = fscache_cancel_op(&op->op);
if (ret == 0)
return -ERESTARTSYS;
/* 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");
check_if_dead:
if (unlikely(fscache_object_is_dead(object))) {
fscache_stat(stat_object_dead);
return -ENOBUFS;
}
return 0;
}
/* /*
* read a page from the cache or allocate a block in which to store it * read a page from the cache or allocate a block in which to store it
* - we return: * - we return:
...@@ -376,25 +413,12 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie, ...@@ -376,25 +413,12 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
/* we wait for the operation to become active, and then process it /* we wait for the operation to become active, and then process it
* *here*, in this thread, and not in the thread pool */ * *here*, in this thread, and not in the thread pool */
if (test_bit(FSCACHE_OP_WAITING, &op->op.flags)) { ret = fscache_wait_for_retrieval_activation(
_debug(">>> WT"); object, op,
fscache_stat(&fscache_n_retrieval_op_waits); __fscache_stat(&fscache_n_retrieval_op_waits),
if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING, __fscache_stat(&fscache_n_retrievals_object_dead));
fscache_wait_bit_interruptible, if (ret < 0)
TASK_INTERRUPTIBLE) < 0) {
ret = fscache_cancel_op(&op->op);
if (ret == 0) {
ret = -ERESTARTSYS;
goto error; 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");
}
/* ask the cache to honour the operation */ /* ask the cache to honour the operation */
if (test_bit(FSCACHE_COOKIE_NO_DATA_YET, &object->cookie->flags)) { 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, ...@@ -506,25 +530,12 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
/* we wait for the operation to become active, and then process it /* we wait for the operation to become active, and then process it
* *here*, in this thread, and not in the thread pool */ * *here*, in this thread, and not in the thread pool */
if (test_bit(FSCACHE_OP_WAITING, &op->op.flags)) { ret = fscache_wait_for_retrieval_activation(
_debug(">>> WT"); object, op,
fscache_stat(&fscache_n_retrieval_op_waits); __fscache_stat(&fscache_n_retrieval_op_waits),
if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING, __fscache_stat(&fscache_n_retrievals_object_dead));
fscache_wait_bit_interruptible, if (ret < 0)
TASK_INTERRUPTIBLE) < 0) {
ret = fscache_cancel_op(&op->op);
if (ret == 0) {
ret = -ERESTARTSYS;
goto error; 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");
}
/* ask the cache to honour the operation */ /* ask the cache to honour the operation */
if (test_bit(FSCACHE_COOKIE_NO_DATA_YET, &object->cookie->flags)) { if (test_bit(FSCACHE_COOKIE_NO_DATA_YET, &object->cookie->flags)) {
...@@ -612,25 +623,12 @@ int __fscache_alloc_page(struct fscache_cookie *cookie, ...@@ -612,25 +623,12 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
fscache_stat(&fscache_n_alloc_ops); fscache_stat(&fscache_n_alloc_ops);
if (test_bit(FSCACHE_OP_WAITING, &op->op.flags)) { ret = fscache_wait_for_retrieval_activation(
_debug(">>> WT"); object, op,
fscache_stat(&fscache_n_alloc_op_waits); __fscache_stat(&fscache_n_alloc_op_waits),
if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING, __fscache_stat(&fscache_n_allocs_object_dead));
fscache_wait_bit_interruptible, if (ret < 0)
TASK_INTERRUPTIBLE) < 0) {
ret = fscache_cancel_op(&op->op);
if (ret == 0) {
ret = -ERESTARTSYS;
goto error; 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");
}
/* ask the cache to honour the operation */ /* ask the cache to honour the operation */
fscache_stat(&fscache_n_cop_allocate_page); fscache_stat(&fscache_n_cop_allocate_page);
......
...@@ -39,6 +39,7 @@ atomic_t fscache_n_allocs_ok; ...@@ -39,6 +39,7 @@ 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_allocs_intr;
atomic_t fscache_n_allocs_object_dead;
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;
...@@ -49,6 +50,7 @@ atomic_t fscache_n_retrievals_nodata; ...@@ -49,6 +50,7 @@ atomic_t fscache_n_retrievals_nodata;
atomic_t fscache_n_retrievals_nobufs; atomic_t fscache_n_retrievals_nobufs;
atomic_t fscache_n_retrievals_intr; atomic_t fscache_n_retrievals_intr;
atomic_t fscache_n_retrievals_nomem; atomic_t fscache_n_retrievals_nomem;
atomic_t fscache_n_retrievals_object_dead;
atomic_t fscache_n_retrieval_ops; atomic_t fscache_n_retrieval_ops;
atomic_t fscache_n_retrieval_op_waits; atomic_t fscache_n_retrieval_op_waits;
...@@ -188,9 +190,10 @@ static int fscache_stats_show(struct seq_file *m, void *v) ...@@ -188,9 +190,10 @@ static int fscache_stats_show(struct seq_file *m, void *v)
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)); atomic_read(&fscache_n_allocs_intr));
seq_printf(m, "Allocs : ops=%u owt=%u\n", seq_printf(m, "Allocs : ops=%u owt=%u abt=%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),
atomic_read(&fscache_n_allocs_object_dead));
seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u" seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
" int=%u oom=%u\n", " int=%u oom=%u\n",
...@@ -201,9 +204,10 @@ static int fscache_stats_show(struct seq_file *m, void *v) ...@@ -201,9 +204,10 @@ static int fscache_stats_show(struct seq_file *m, void *v)
atomic_read(&fscache_n_retrievals_nobufs), atomic_read(&fscache_n_retrievals_nobufs),
atomic_read(&fscache_n_retrievals_intr), atomic_read(&fscache_n_retrievals_intr),
atomic_read(&fscache_n_retrievals_nomem)); atomic_read(&fscache_n_retrievals_nomem));
seq_printf(m, "Retrvls: ops=%u owt=%u\n", seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
atomic_read(&fscache_n_retrieval_ops), atomic_read(&fscache_n_retrieval_ops),
atomic_read(&fscache_n_retrieval_op_waits)); atomic_read(&fscache_n_retrieval_op_waits),
atomic_read(&fscache_n_retrievals_object_dead));
seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n", seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
atomic_read(&fscache_n_stores), atomic_read(&fscache_n_stores),
......
...@@ -404,6 +404,10 @@ extern const char *fscache_object_states[]; ...@@ -404,6 +404,10 @@ extern const char *fscache_object_states[];
(obj)->state >= FSCACHE_OBJECT_AVAILABLE && \ (obj)->state >= FSCACHE_OBJECT_AVAILABLE && \
(obj)->state < FSCACHE_OBJECT_DYING) (obj)->state < FSCACHE_OBJECT_DYING)
#define fscache_object_is_dead(obj) \
(test_bit(FSCACHE_IOERROR, &(obj)->cache->flags) && \
(obj)->state >= FSCACHE_OBJECT_DYING)
extern const struct slow_work_ops fscache_object_slow_work_ops; extern const struct slow_work_ops fscache_object_slow_work_ops;
/** /**
......
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