Skip to content

Commit 1863d77

Browse files
trondmyJ. Bruce Fields
authored andcommitted
SUNRPC: Replace the cache_detail->hash_lock with a regular spinlock
Now that the reader functions are all RCU protected, use a regular spinlock rather than a reader/writer lock. Signed-off-by: Trond Myklebust <trond.myklebust@hammerspace.com> Signed-off-by: J. Bruce Fields <bfields@redhat.com>
1 parent d48cf35 commit 1863d77

File tree

2 files changed

+24
-24
lines changed

2 files changed

+24
-24
lines changed

include/linux/sunrpc/cache.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ struct cache_detail {
6767
struct module * owner;
6868
int hash_size;
6969
struct hlist_head * hash_table;
70-
rwlock_t hash_lock;
70+
spinlock_t hash_lock;
7171

7272
char *name;
7373
void (*cache_put)(struct kref *);

net/sunrpc/cache.c

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail,
9292
cache_init(new, detail);
9393
detail->init(new, key);
9494

95-
write_lock(&detail->hash_lock);
95+
spin_lock(&detail->hash_lock);
9696

9797
/* check if entry appeared while we slept */
9898
hlist_for_each_entry_rcu(tmp, head, cache_list) {
@@ -104,7 +104,7 @@ static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail,
104104
break;
105105
}
106106
cache_get(tmp);
107-
write_unlock(&detail->hash_lock);
107+
spin_unlock(&detail->hash_lock);
108108
cache_put(new, detail);
109109
return tmp;
110110
}
@@ -113,7 +113,7 @@ static struct cache_head *sunrpc_cache_add_entry(struct cache_detail *detail,
113113
hlist_add_head_rcu(&new->cache_list, head);
114114
detail->entries++;
115115
cache_get(new);
116-
write_unlock(&detail->hash_lock);
116+
spin_unlock(&detail->hash_lock);
117117

118118
if (freeme)
119119
cache_put(freeme, detail);
@@ -167,18 +167,18 @@ struct cache_head *sunrpc_cache_update(struct cache_detail *detail,
167167
struct cache_head *tmp;
168168

169169
if (!test_bit(CACHE_VALID, &old->flags)) {
170-
write_lock(&detail->hash_lock);
170+
spin_lock(&detail->hash_lock);
171171
if (!test_bit(CACHE_VALID, &old->flags)) {
172172
if (test_bit(CACHE_NEGATIVE, &new->flags))
173173
set_bit(CACHE_NEGATIVE, &old->flags);
174174
else
175175
detail->update(old, new);
176176
cache_fresh_locked(old, new->expiry_time, detail);
177-
write_unlock(&detail->hash_lock);
177+
spin_unlock(&detail->hash_lock);
178178
cache_fresh_unlocked(old, detail);
179179
return old;
180180
}
181-
write_unlock(&detail->hash_lock);
181+
spin_unlock(&detail->hash_lock);
182182
}
183183
/* We need to insert a new entry */
184184
tmp = detail->alloc();
@@ -189,7 +189,7 @@ struct cache_head *sunrpc_cache_update(struct cache_detail *detail,
189189
cache_init(tmp, detail);
190190
detail->init(tmp, old);
191191

192-
write_lock(&detail->hash_lock);
192+
spin_lock(&detail->hash_lock);
193193
if (test_bit(CACHE_NEGATIVE, &new->flags))
194194
set_bit(CACHE_NEGATIVE, &tmp->flags);
195195
else
@@ -199,7 +199,7 @@ struct cache_head *sunrpc_cache_update(struct cache_detail *detail,
199199
cache_get(tmp);
200200
cache_fresh_locked(tmp, new->expiry_time, detail);
201201
cache_fresh_locked(old, 0, detail);
202-
write_unlock(&detail->hash_lock);
202+
spin_unlock(&detail->hash_lock);
203203
cache_fresh_unlocked(tmp, detail);
204204
cache_fresh_unlocked(old, detail);
205205
cache_put(old, detail);
@@ -239,15 +239,15 @@ static int try_to_negate_entry(struct cache_detail *detail, struct cache_head *h
239239
{
240240
int rv;
241241

242-
write_lock(&detail->hash_lock);
242+
spin_lock(&detail->hash_lock);
243243
rv = cache_is_valid(h);
244244
if (rv == -EAGAIN) {
245245
set_bit(CACHE_NEGATIVE, &h->flags);
246246
cache_fresh_locked(h, seconds_since_boot()+CACHE_NEW_EXPIRY,
247247
detail);
248248
rv = -ENOENT;
249249
}
250-
write_unlock(&detail->hash_lock);
250+
spin_unlock(&detail->hash_lock);
251251
cache_fresh_unlocked(h, detail);
252252
return rv;
253253
}
@@ -357,7 +357,7 @@ static struct delayed_work cache_cleaner;
357357

358358
void sunrpc_init_cache_detail(struct cache_detail *cd)
359359
{
360-
rwlock_init(&cd->hash_lock);
360+
spin_lock_init(&cd->hash_lock);
361361
INIT_LIST_HEAD(&cd->queue);
362362
spin_lock(&cache_list_lock);
363363
cd->nextcheck = 0;
@@ -377,11 +377,11 @@ void sunrpc_destroy_cache_detail(struct cache_detail *cd)
377377
{
378378
cache_purge(cd);
379379
spin_lock(&cache_list_lock);
380-
write_lock(&cd->hash_lock);
380+
spin_lock(&cd->hash_lock);
381381
if (current_detail == cd)
382382
current_detail = NULL;
383383
list_del_init(&cd->others);
384-
write_unlock(&cd->hash_lock);
384+
spin_unlock(&cd->hash_lock);
385385
spin_unlock(&cache_list_lock);
386386
if (list_empty(&cache_list)) {
387387
/* module must be being unloaded so its safe to kill the worker */
@@ -438,7 +438,7 @@ static int cache_clean(void)
438438
struct hlist_head *head;
439439
struct hlist_node *tmp;
440440

441-
write_lock(&current_detail->hash_lock);
441+
spin_lock(&current_detail->hash_lock);
442442

443443
/* Ok, now to clean this strand */
444444

@@ -455,7 +455,7 @@ static int cache_clean(void)
455455
break;
456456
}
457457

458-
write_unlock(&current_detail->hash_lock);
458+
spin_unlock(&current_detail->hash_lock);
459459
d = current_detail;
460460
if (!ch)
461461
current_index ++;
@@ -510,9 +510,9 @@ void cache_purge(struct cache_detail *detail)
510510
struct hlist_node *tmp = NULL;
511511
int i = 0;
512512

513-
write_lock(&detail->hash_lock);
513+
spin_lock(&detail->hash_lock);
514514
if (!detail->entries) {
515-
write_unlock(&detail->hash_lock);
515+
spin_unlock(&detail->hash_lock);
516516
return;
517517
}
518518

@@ -524,13 +524,13 @@ void cache_purge(struct cache_detail *detail)
524524
detail->entries--;
525525

526526
set_bit(CACHE_CLEANED, &ch->flags);
527-
write_unlock(&detail->hash_lock);
527+
spin_unlock(&detail->hash_lock);
528528
cache_fresh_unlocked(ch, detail);
529529
cache_put(ch, detail);
530-
write_lock(&detail->hash_lock);
530+
spin_lock(&detail->hash_lock);
531531
}
532532
}
533-
write_unlock(&detail->hash_lock);
533+
spin_unlock(&detail->hash_lock);
534534
}
535535
EXPORT_SYMBOL_GPL(cache_purge);
536536

@@ -1873,13 +1873,13 @@ EXPORT_SYMBOL_GPL(sunrpc_cache_unregister_pipefs);
18731873

18741874
void sunrpc_cache_unhash(struct cache_detail *cd, struct cache_head *h)
18751875
{
1876-
write_lock(&cd->hash_lock);
1876+
spin_lock(&cd->hash_lock);
18771877
if (!hlist_unhashed(&h->cache_list)){
18781878
hlist_del_init_rcu(&h->cache_list);
18791879
cd->entries--;
1880-
write_unlock(&cd->hash_lock);
1880+
spin_unlock(&cd->hash_lock);
18811881
cache_put(h, cd);
18821882
} else
1883-
write_unlock(&cd->hash_lock);
1883+
spin_unlock(&cd->hash_lock);
18841884
}
18851885
EXPORT_SYMBOL_GPL(sunrpc_cache_unhash);

0 commit comments

Comments
 (0)