History

fscache: Implement simple cookie state machine

Implement a very simple cookie state machine to handle lookup, invalidation, withdrawal, relinquishment and, to be added later, commit on LRU discard. Three cache methods are provided: ->lookup_cookie() to look up and, if necessary, create a data storage object; ->withdraw_cookie() to free the resources associated with that object and potentially delete it; and ->prepare_to_write(), to do prepare for changes to the cached data to be modified locally. Changes ======= ver #3: - Fix a race between LRU discard and relinquishment whereby the former would override the latter and thus the latter would never happen[1]. ver #2: - Don't hold n_accesses elevated whilst cache is bound to a cookie, but rather add a flag that prevents the state machine from being queued when n_accesses reaches 0.

David Howells committed 5 years ago

Commit 5d00e421 parent 29f18e73 files · +300 −44Browse files

Showing the changes to include (2 of 3 files). Show all

Unified · Split

2 files
  1. include/linux/fscache-cache.h +25 −2
  2. include/trace/events/fscache.h +4 −0
include/linux/fscache-cache.h+25−2
@@ -57,6 +57,15 @@ struct fscache_cache_ops { · 56 unmodified lines
5757
5858 /* Free the cache's data attached to a volume */
5959 void (*free_volume)(struct fscache_volume *volume);
60+
61+ /* Look up a cookie in the cache */
62+ bool (*lookup_cookie)(struct fscache_cookie *cookie);
63+
64+ /* Withdraw an object without any cookie access counts held */
65+ void (*withdraw_cookie)(struct fscache_cookie *cookie);
66+
67+ /* Prepare to write to a live cache object */
68+ void (*prepare_to_write)(struct fscache_cookie *cookie);
6069 };
6170
6271 extern struct workqueue_struct *fscache_wq;
@@ -72,6 +81,7 @@ extern int fscache_add_cache(struct fscache_cache *cache, · 9 unmodified lines
7281 void *cache_priv);
7382 extern void fscache_withdraw_cache(struct fscache_cache *cache);
7483 extern void fscache_withdraw_volume(struct fscache_volume *volume);
84+extern void fscache_withdraw_cookie(struct fscache_cookie *cookie);
7585
7686 extern void fscache_io_error(struct fscache_cache *cache);
7787
@@ -85,8 +95,21 @@ extern void fscache_put_cookie(struct fscache_cookie *cookie, · 7 unmodified lines
8595 enum fscache_cookie_trace where);
8696 extern void fscache_end_cookie_access(struct fscache_cookie *cookie,
8797 enum fscache_access_trace why);
88−extern void fscache_set_cookie_state(struct fscache_cookie *cookie,
89− enum fscache_cookie_state state);
98+extern void fscache_cookie_lookup_negative(struct fscache_cookie *cookie);
99+extern void fscache_caching_failed(struct fscache_cookie *cookie);
100+
101+/**
102+ * fscache_cookie_state - Read the state of a cookie
103+ * @cookie: The cookie to query
104+ *
105+ * Get the state of a cookie, imposing an ordering between the cookie contents
106+ * and the state value. Paired with fscache_set_cookie_state().
107+ */
108+static inline
109+enum fscache_cookie_state fscache_cookie_state(struct fscache_cookie *cookie)
110+{
111+ return smp_load_acquire(&cookie->state);
112+}
90113
91114 /**
92115 * fscache_get_key - Get a pointer to the cookie key
include/trace/events/fscache.h+4−0
@@ -68,6 +68,8 @@ enum fscache_access_trace { · 67 unmodified lines
6868 fscache_access_acquire_volume_end,
6969 fscache_access_cache_pin,
7070 fscache_access_cache_unpin,
71+ fscache_access_lookup_cookie_end,
72+ fscache_access_lookup_cookie_end_failed,
7173 fscache_access_relinquish_volume,
7274 fscache_access_relinquish_volume_end,
7375 fscache_access_unlive,
@@ -124,6 +126,8 @@ enum fscache_access_trace { · 50 unmodified lines
124126 EM(fscache_access_acquire_volume_end, "END acq_vol") \
125127 EM(fscache_access_cache_pin, "PIN cache ") \
126128 EM(fscache_access_cache_unpin, "UNPIN cache ") \
129+ EM(fscache_access_lookup_cookie_end, "END lookup ") \
130+ EM(fscache_access_lookup_cookie_end_failed,"END lookupf") \
127131 EM(fscache_access_relinquish_volume, "BEGIN rlq_vol") \
128132 EM(fscache_access_relinquish_volume_end,"END rlq_vol") \
129133 E_(fscache_access_unlive, "END unlive ")

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