diff options
author | David Howells <dhowells@redhat.com> | 2012-12-20 16:52:35 -0500 |
---|---|---|
committer | David Howells <dhowells@redhat.com> | 2012-12-20 16:58:26 -0500 |
commit | 9f10523f891928330b7529da54c1a3cc65180b1a (patch) | |
tree | 014731e89d44d1ca86cc665f4d39d8d2c25c69bf /include/linux | |
parent | ef46ed888efb1e8da33be5d33c9b54476289a43b (diff) |
FS-Cache: Fix operation state management and accounting
Fix the state management of internal fscache operations and the accounting of
what operations are in what states.
This is done by:
(1) Give struct fscache_operation a enum variable that directly represents the
state it's currently in, rather than spreading this knowledge over a bunch
of flags, who's processing the operation at the moment and whether it is
queued or not.
This makes it easier to write assertions to check the state at various
points and to prevent invalid state transitions.
(2) Add an 'operation complete' state and supply a function to indicate the
completion of an operation (fscache_op_complete()) and make things call
it. The final call to fscache_put_operation() can then check that an op
in the appropriate state (complete or cancelled).
(3) Adjust the use of object->n_ops, ->n_in_progress, ->n_exclusive to better
govern the state of an object:
(a) The ->n_ops is now the number of extant operations on the object
and is now decremented by fscache_put_operation() only.
(b) The ->n_in_progress is simply the number of objects that have been
taken off of the object's pending queue for the purposes of being
run. This is decremented by fscache_op_complete() only.
(c) The ->n_exclusive is the number of exclusive ops that have been
submitted and queued or are in progress. It is decremented by
fscache_op_complete() and by fscache_cancel_op().
fscache_put_operation() and fscache_operation_gc() now no longer try to
clean up ->n_exclusive and ->n_in_progress. That was leading to double
decrements against fscache_cancel_op().
fscache_cancel_op() now no longer decrements ->n_ops. That was leading to
double decrements against fscache_put_operation().
fscache_submit_exclusive_op() now decides whether it has to queue an op
based on ->n_in_progress being > 0 rather than ->n_ops > 0 as the latter
will persist in being true even after all preceding operations have been
cancelled or completed. Furthermore, if an object is active and there are
runnable ops against it, there must be at least one op running.
(4) Add a remaining-pages counter (n_pages) to struct fscache_retrieval and
provide a function to record completion of the pages as they complete.
When n_pages reaches 0, the operation is deemed to be complete and
fscache_op_complete() is called.
Add calls to fscache_retrieval_complete() anywhere we've finished with a
page we've been given to read or allocate for. This includes places where
we just return pages to the netfs for reading from the server and where
accessing the cache fails and we discard the proposed netfs page.
The bugs in the unfixed state management manifest themselves as oopses like the
following where the operation completion gets out of sync with return of the
cookie by the netfs. This is possible because the cache unlocks and returns
all the netfs pages before recording its completion - which means that there's
nothing to stop the netfs discarding them and returning the cookie.
FS-Cache: Cookie 'NFS.fh' still has outstanding reads
------------[ cut here ]------------
kernel BUG at fs/fscache/cookie.c:519!
invalid opcode: 0000 [#1] SMP
CPU 1
Modules linked in: cachefiles nfs fscache auth_rpcgss nfs_acl lockd sunrpc
Pid: 400, comm: kswapd0 Not tainted 3.1.0-rc7-fsdevel+ #1090 /DG965RY
RIP: 0010:[<ffffffffa007050a>] [<ffffffffa007050a>] __fscache_relinquish_cookie+0x170/0x343 [fscache]
RSP: 0018:ffff8800368cfb00 EFLAGS: 00010282
RAX: 000000000000003c RBX: ffff880023cc8790 RCX: 0000000000000000
RDX: 0000000000002f2e RSI: 0000000000000001 RDI: ffffffff813ab86c
RBP: ffff8800368cfb50 R08: 0000000000000002 R09: 0000000000000000
R10: ffff88003a1b7890 R11: ffff88001df6e488 R12: ffff880023d8ed98
R13: ffff880023cc8798 R14: 0000000000000004 R15: ffff88003b8bf370
FS: 0000000000000000(0000) GS:ffff88003bd00000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 000000008005003b
CR2: 00000000008ba008 CR3: 0000000023d93000 CR4: 00000000000006e0
DR0: 0000000000000000 DR1: 0000000000000000 DR2: 0000000000000000
DR3: 0000000000000000 DR6: 00000000ffff0ff0 DR7: 0000000000000400
Process kswapd0 (pid: 400, threadinfo ffff8800368ce000, task ffff88003b8bf040)
Stack:
ffff88003b8bf040 ffff88001df6e528 ffff88001df6e528 ffffffffa00b46b0
ffff88003b8bf040 ffff88001df6e488 ffff88001df6e620 ffffffffa00b46b0
ffff88001ebd04c8 0000000000000004 ffff8800368cfb70 ffffffffa00b2c91
Call Trace:
[<ffffffffa00b2c91>] nfs_fscache_release_inode_cookie+0x3b/0x47 [nfs]
[<ffffffffa008f25f>] nfs_clear_inode+0x3c/0x41 [nfs]
[<ffffffffa0090df1>] nfs4_evict_inode+0x2f/0x33 [nfs]
[<ffffffff810d8d47>] evict+0xa1/0x15c
[<ffffffff810d8e2e>] dispose_list+0x2c/0x38
[<ffffffff810d9ebd>] prune_icache_sb+0x28c/0x29b
[<ffffffff810c56b7>] prune_super+0xd5/0x140
[<ffffffff8109b615>] shrink_slab+0x102/0x1ab
[<ffffffff8109d690>] balance_pgdat+0x2f2/0x595
[<ffffffff8103e009>] ? process_timeout+0xb/0xb
[<ffffffff8109dba3>] kswapd+0x270/0x289
[<ffffffff8104c5ea>] ? __init_waitqueue_head+0x46/0x46
[<ffffffff8109d933>] ? balance_pgdat+0x595/0x595
[<ffffffff8104bf7a>] kthread+0x7f/0x87
[<ffffffff813ad6b4>] kernel_thread_helper+0x4/0x10
[<ffffffff81026b98>] ? finish_task_switch+0x45/0xc0
[<ffffffff813abcdd>] ? retint_restore_args+0xe/0xe
[<ffffffff8104befb>] ? __init_kthread_worker+0x53/0x53
[<ffffffff813ad6b0>] ? gs_change+0xb/0xb
Signed-off-by: David Howells <dhowells@redhat.com>
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/fscache-cache.h | 37 |
1 files changed, 32 insertions, 5 deletions
diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h index e3d6d939d959..f5facd1d333f 100644 --- a/include/linux/fscache-cache.h +++ b/include/linux/fscache-cache.h | |||
@@ -75,6 +75,16 @@ extern wait_queue_head_t fscache_cache_cleared_wq; | |||
75 | typedef void (*fscache_operation_release_t)(struct fscache_operation *op); | 75 | typedef void (*fscache_operation_release_t)(struct fscache_operation *op); |
76 | typedef void (*fscache_operation_processor_t)(struct fscache_operation *op); | 76 | typedef void (*fscache_operation_processor_t)(struct fscache_operation *op); |
77 | 77 | ||
78 | enum fscache_operation_state { | ||
79 | FSCACHE_OP_ST_BLANK, /* Op is not yet submitted */ | ||
80 | FSCACHE_OP_ST_INITIALISED, /* Op is initialised */ | ||
81 | FSCACHE_OP_ST_PENDING, /* Op is blocked from running */ | ||
82 | FSCACHE_OP_ST_IN_PROGRESS, /* Op is in progress */ | ||
83 | FSCACHE_OP_ST_COMPLETE, /* Op is complete */ | ||
84 | FSCACHE_OP_ST_CANCELLED, /* Op has been cancelled */ | ||
85 | FSCACHE_OP_ST_DEAD /* Op is now dead */ | ||
86 | }; | ||
87 | |||
78 | struct fscache_operation { | 88 | struct fscache_operation { |
79 | struct work_struct work; /* record for async ops */ | 89 | struct work_struct work; /* record for async ops */ |
80 | struct list_head pend_link; /* link in object->pending_ops */ | 90 | struct list_head pend_link; /* link in object->pending_ops */ |
@@ -86,10 +96,10 @@ struct fscache_operation { | |||
86 | #define FSCACHE_OP_MYTHREAD 0x0002 /* - processing is done be issuing thread, not pool */ | 96 | #define FSCACHE_OP_MYTHREAD 0x0002 /* - processing is done be issuing thread, not pool */ |
87 | #define FSCACHE_OP_WAITING 4 /* cleared when op is woken */ | 97 | #define FSCACHE_OP_WAITING 4 /* cleared when op is woken */ |
88 | #define FSCACHE_OP_EXCLUSIVE 5 /* exclusive op, other ops must wait */ | 98 | #define FSCACHE_OP_EXCLUSIVE 5 /* exclusive op, other ops must wait */ |
89 | #define FSCACHE_OP_DEAD 6 /* op is now dead */ | 99 | #define FSCACHE_OP_DEC_READ_CNT 6 /* decrement object->n_reads on destruction */ |
90 | #define FSCACHE_OP_DEC_READ_CNT 7 /* decrement object->n_reads on destruction */ | 100 | #define FSCACHE_OP_KEEP_FLAGS 0x0070 /* flags to keep when repurposing an op */ |
91 | #define FSCACHE_OP_KEEP_FLAGS 0xc0 /* flags to keep when repurposing an op */ | ||
92 | 101 | ||
102 | enum fscache_operation_state state; | ||
93 | atomic_t usage; | 103 | atomic_t usage; |
94 | unsigned debug_id; /* debugging ID */ | 104 | unsigned debug_id; /* debugging ID */ |
95 | 105 | ||
@@ -106,6 +116,7 @@ extern atomic_t fscache_op_debug_id; | |||
106 | extern void fscache_op_work_func(struct work_struct *work); | 116 | extern void fscache_op_work_func(struct work_struct *work); |
107 | 117 | ||
108 | extern void fscache_enqueue_operation(struct fscache_operation *); | 118 | extern void fscache_enqueue_operation(struct fscache_operation *); |
119 | extern void fscache_op_complete(struct fscache_operation *); | ||
109 | extern void fscache_put_operation(struct fscache_operation *); | 120 | extern void fscache_put_operation(struct fscache_operation *); |
110 | 121 | ||
111 | /** | 122 | /** |
@@ -122,6 +133,7 @@ static inline void fscache_operation_init(struct fscache_operation *op, | |||
122 | { | 133 | { |
123 | INIT_WORK(&op->work, fscache_op_work_func); | 134 | INIT_WORK(&op->work, fscache_op_work_func); |
124 | atomic_set(&op->usage, 1); | 135 | atomic_set(&op->usage, 1); |
136 | op->state = FSCACHE_OP_ST_INITIALISED; | ||
125 | op->debug_id = atomic_inc_return(&fscache_op_debug_id); | 137 | op->debug_id = atomic_inc_return(&fscache_op_debug_id); |
126 | op->processor = processor; | 138 | op->processor = processor; |
127 | op->release = release; | 139 | op->release = release; |
@@ -138,6 +150,7 @@ struct fscache_retrieval { | |||
138 | void *context; /* netfs read context (pinned) */ | 150 | void *context; /* netfs read context (pinned) */ |
139 | struct list_head to_do; /* list of things to be done by the backend */ | 151 | struct list_head to_do; /* list of things to be done by the backend */ |
140 | unsigned long start_time; /* time at which retrieval started */ | 152 | unsigned long start_time; /* time at which retrieval started */ |
153 | unsigned n_pages; /* number of pages to be retrieved */ | ||
141 | }; | 154 | }; |
142 | 155 | ||
143 | typedef int (*fscache_page_retrieval_func_t)(struct fscache_retrieval *op, | 156 | typedef int (*fscache_page_retrieval_func_t)(struct fscache_retrieval *op, |
@@ -174,8 +187,22 @@ static inline void fscache_enqueue_retrieval(struct fscache_retrieval *op) | |||
174 | } | 187 | } |
175 | 188 | ||
176 | /** | 189 | /** |
190 | * fscache_retrieval_complete - Record (partial) completion of a retrieval | ||
191 | * @op: The retrieval operation affected | ||
192 | * @n_pages: The number of pages to account for | ||
193 | */ | ||
194 | static inline void fscache_retrieval_complete(struct fscache_retrieval *op, | ||
195 | int n_pages) | ||
196 | { | ||
197 | op->n_pages -= n_pages; | ||
198 | if (op->n_pages <= 0) | ||
199 | fscache_op_complete(&op->op); | ||
200 | } | ||
201 | |||
202 | /** | ||
177 | * fscache_put_retrieval - Drop a reference to a retrieval operation | 203 | * fscache_put_retrieval - Drop a reference to a retrieval operation |
178 | * @op: The retrieval operation affected | 204 | * @op: The retrieval operation affected |
205 | * @n_pages: The number of pages to account for | ||
179 | * | 206 | * |
180 | * Drop a reference to a retrieval operation. | 207 | * Drop a reference to a retrieval operation. |
181 | */ | 208 | */ |
@@ -333,10 +360,10 @@ struct fscache_object { | |||
333 | 360 | ||
334 | int debug_id; /* debugging ID */ | 361 | int debug_id; /* debugging ID */ |
335 | int n_children; /* number of child objects */ | 362 | int n_children; /* number of child objects */ |
336 | int n_ops; /* number of ops outstanding on object */ | 363 | int n_ops; /* number of extant ops on object */ |
337 | int n_obj_ops; /* number of object ops outstanding on object */ | 364 | int n_obj_ops; /* number of object ops outstanding on object */ |
338 | int n_in_progress; /* number of ops in progress */ | 365 | int n_in_progress; /* number of ops in progress */ |
339 | int n_exclusive; /* number of exclusive ops queued */ | 366 | int n_exclusive; /* number of exclusive ops queued or in progress */ |
340 | atomic_t n_reads; /* number of read ops in progress */ | 367 | atomic_t n_reads; /* number of read ops in progress */ |
341 | spinlock_t lock; /* state and operations lock */ | 368 | spinlock_t lock; /* state and operations lock */ |
342 | 369 | ||