History

fscache: Implement cookie user counting and resource pinning

Provide a pair of functions to count the number of users of a cookie (open files, writeback, invalidation, resizing, reads, writes), to obtain and pin resources for the cookie and to prevent culling for the whilst there are users. The first function marks a cookie as being in use: void fscache_use_cookie(struct fscache_cookie *cookie, bool will_modify); The caller should indicate the cookie to use and whether or not the caller is in a context that may modify the cookie (e.g. a file open O_RDWR). If the cookie is not already resourced, fscache will ask the cache backend in the background to do whatever it needs to look up, create or otherwise obtain the resources necessary to access data. This is pinned to the cookie and may not be culled, though it may be withdrawn if the cache as a whole is withdrawn. The second function removes the in-use mark from a cookie and, optionally, updates the coherency data: void fscache_unuse_cookie(struct fscache_cookie *cookie, const void *aux_data, const loff_t *object_size); If non-NULL, the aux_data buffer and/or the object_size will be saved into the cookie and will be set on the backing store when the object is committed. If this removes the last usage on a cookie, the cookie is placed onto an LRU list from which it will be removed and closed after a couple of seconds if it doesn't get reused. This prevents resource overload in the cache - in particular it prevents it from holding too many files open. Changes ======= ver #2: - Fix fscache_unuse_cookie() to use atomic_dec_and_lock() to avoid a potential race if the cookie gets reused before it completes the unusement. - Added missing transition to LRU_DISCARDING state.

David Howells committed 5 years ago

Commit 12bb21a1 parent 5d00e425 files · +327 −2Browse files

Showing the changes to include/trace (1 of 5 files). Show all

Unified · Split

include/trace/events/fscache.h+12−0
@@ -51,13 +51,18 @@ enum fscache_cookie_trace { · 50 unmodified lines
51 fscache_cookie_discard,51 fscache_cookie_discard,
52 fscache_cookie_get_end_access,52 fscache_cookie_get_end_access,
53 fscache_cookie_get_hash_collision,53 fscache_cookie_get_hash_collision,
54 fscache_cookie_get_lru,
55 fscache_cookie_get_use_work,
54 fscache_cookie_new_acquire,56 fscache_cookie_new_acquire,
55 fscache_cookie_put_hash_collision,57 fscache_cookie_put_hash_collision,
58 fscache_cookie_put_lru,
56 fscache_cookie_put_over_queued,59 fscache_cookie_put_over_queued,
57 fscache_cookie_put_relinquish,60 fscache_cookie_put_relinquish,
58 fscache_cookie_put_withdrawn,61 fscache_cookie_put_withdrawn,
59 fscache_cookie_put_work,62 fscache_cookie_put_work,
60 fscache_cookie_see_active,63 fscache_cookie_see_active,
64 fscache_cookie_see_lru_discard,
65 fscache_cookie_see_lru_do_one,
61 fscache_cookie_see_relinquish,66 fscache_cookie_see_relinquish,
62 fscache_cookie_see_withdraw,67 fscache_cookie_see_withdraw,
63 fscache_cookie_see_work,68 fscache_cookie_see_work,
@@ -68,6 +73,7 @@ enum fscache_access_trace { · 4 unmodified lines
68 fscache_access_acquire_volume_end,73 fscache_access_acquire_volume_end,
69 fscache_access_cache_pin,74 fscache_access_cache_pin,
70 fscache_access_cache_unpin,75 fscache_access_cache_unpin,
76 fscache_access_lookup_cookie,
71 fscache_access_lookup_cookie_end,77 fscache_access_lookup_cookie_end,
72 fscache_access_lookup_cookie_end_failed,78 fscache_access_lookup_cookie_end_failed,
73 fscache_access_relinquish_volume,79 fscache_access_relinquish_volume,
@@ -110,13 +116,18 @@ enum fscache_access_trace { · 36 unmodified lines
110 EM(fscache_cookie_discard, "DISCARD ") \116 EM(fscache_cookie_discard, "DISCARD ") \
111 EM(fscache_cookie_get_hash_collision, "GET hcoll") \117 EM(fscache_cookie_get_hash_collision, "GET hcoll") \
112 EM(fscache_cookie_get_end_access, "GQ endac") \118 EM(fscache_cookie_get_end_access, "GQ endac") \
119 EM(fscache_cookie_get_lru, "GET lru ") \
120 EM(fscache_cookie_get_use_work, "GQ use ") \
113 EM(fscache_cookie_new_acquire, "NEW acq ") \121 EM(fscache_cookie_new_acquire, "NEW acq ") \
114 EM(fscache_cookie_put_hash_collision, "PUT hcoll") \122 EM(fscache_cookie_put_hash_collision, "PUT hcoll") \
123 EM(fscache_cookie_put_lru, "PUT lru ") \
115 EM(fscache_cookie_put_over_queued, "PQ overq") \124 EM(fscache_cookie_put_over_queued, "PQ overq") \
116 EM(fscache_cookie_put_relinquish, "PUT relnq") \125 EM(fscache_cookie_put_relinquish, "PUT relnq") \
117 EM(fscache_cookie_put_withdrawn, "PUT wthdn") \126 EM(fscache_cookie_put_withdrawn, "PUT wthdn") \
118 EM(fscache_cookie_put_work, "PQ work ") \127 EM(fscache_cookie_put_work, "PQ work ") \
119 EM(fscache_cookie_see_active, "- activ") \128 EM(fscache_cookie_see_active, "- activ") \
129 EM(fscache_cookie_see_lru_discard, "- x-lru") \
130 EM(fscache_cookie_see_lru_do_one, "- lrudo") \
120 EM(fscache_cookie_see_relinquish, "- x-rlq") \131 EM(fscache_cookie_see_relinquish, "- x-rlq") \
121 EM(fscache_cookie_see_withdraw, "- x-wth") \132 EM(fscache_cookie_see_withdraw, "- x-wth") \
122 E_(fscache_cookie_see_work, "- work ")133 E_(fscache_cookie_see_work, "- work ")
@@ -126,6 +137,7 @@ enum fscache_access_trace { · 3 unmodified lines
126 EM(fscache_access_acquire_volume_end, "END acq_vol") \137 EM(fscache_access_acquire_volume_end, "END acq_vol") \
127 EM(fscache_access_cache_pin, "PIN cache ") \138 EM(fscache_access_cache_pin, "PIN cache ") \
128 EM(fscache_access_cache_unpin, "UNPIN cache ") \139 EM(fscache_access_cache_unpin, "UNPIN cache ") \
140 EM(fscache_access_lookup_cookie, "BEGIN lookup ") \
129 EM(fscache_access_lookup_cookie_end, "END lookup ") \141 EM(fscache_access_lookup_cookie_end, "END lookup ") \
130 EM(fscache_access_lookup_cookie_end_failed,"END lookupf") \142 EM(fscache_access_lookup_cookie_end_failed,"END lookupf") \
131 EM(fscache_access_relinquish_volume, "BEGIN rlq_vol") \143 EM(fscache_access_relinquish_volume, "BEGIN rlq_vol") \

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t