Release 4.11 net/sunrpc/cache.c
/*
* net/sunrpc/cache.c
*
* Generic code for various authentication-related caches
* used by sunrpc clients and servers.
*
* Copyright (C) 2002 Neil Brown <neilb@cse.unsw.edu.au>
*
* Released under terms in GPL version 2. See COPYING.
*
*/
#include <linux/types.h>
#include <linux/fs.h>
#include <linux/file.h>
#include <linux/slab.h>
#include <linux/signal.h>
#include <linux/sched.h>
#include <linux/kmod.h>
#include <linux/list.h>
#include <linux/module.h>
#include <linux/ctype.h>
#include <linux/string_helpers.h>
#include <linux/uaccess.h>
#include <linux/poll.h>
#include <linux/seq_file.h>
#include <linux/proc_fs.h>
#include <linux/net.h>
#include <linux/workqueue.h>
#include <linux/mutex.h>
#include <linux/pagemap.h>
#include <asm/ioctls.h>
#include <linux/sunrpc/types.h>
#include <linux/sunrpc/cache.h>
#include <linux/sunrpc/stats.h>
#include <linux/sunrpc/rpc_pipe_fs.h>
#include "netns.h"
#define RPCDBG_FACILITY RPCDBG_CACHE
static bool cache_defer_req(struct cache_req *req, struct cache_head *item);
static void cache_revisit_request(struct cache_head *item);
static void cache_init(struct cache_head *h, struct cache_detail *detail)
{
time_t now = seconds_since_boot();
INIT_HLIST_NODE(&h->cache_list);
h->flags = 0;
kref_init(&h->ref);
h->expiry_time = now + CACHE_NEW_EXPIRY;
if (now <= detail->flush_time)
/* ensure it isn't already expired */
now = detail->flush_time + 1;
h->last_refresh = now;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Neil Brown | 68 | 90.67% | 4 | 57.14% |
Kinglong Mee | 5 | 6.67% | 1 | 14.29% |
Andi Kleen | 1 | 1.33% | 1 | 14.29% |
Adrian Bunk | 1 | 1.33% | 1 | 14.29% |
Total | 75 | 100.00% | 7 | 100.00% |
struct cache_head *sunrpc_cache_lookup(struct cache_detail *detail,
struct cache_head *key, int hash)
{
struct cache_head *new = NULL, *freeme = NULL, *tmp = NULL;
struct hlist_head *head;
head = &detail->hash_table[hash];
read_lock(&detail->hash_lock);
hlist_for_each_entry(tmp, head, cache_list) {
if (detail->match(tmp, key)) {
if (cache_is_expired(detail, tmp))
/* This entry is expired, we will discard it. */
break;
cache_get(tmp);
read_unlock(&detail->hash_lock);
return tmp;
}
}
read_unlock(&detail->hash_lock);
/* Didn't find anything, insert an empty entry */
new = detail->alloc();
if (!new)
return NULL;
/* must fully initialise 'new', else
* we might get lose if we need to
* cache_put it soon.
*/
cache_init(new, detail);
detail->init(new, key);
write_lock(&detail->hash_lock);
/* check if entry appeared while we slept */
hlist_for_each_entry(tmp, head, cache_list) {
if (detail->match(tmp, key)) {
if (cache_is_expired(detail, tmp)) {
hlist_del_init(&tmp->cache_list);
detail->entries --;
freeme = tmp;
break;
}
cache_get(tmp);
write_unlock(&detail->hash_lock);
cache_put(new, detail);
return tmp;
}
}
hlist_add_head(&new->cache_list, head);
detail->entries++;
cache_get(new);
write_unlock(&detail->hash_lock);
if (freeme)
cache_put(freeme, detail);
return new;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Neil Brown | 240 | 86.64% | 4 | 80.00% |
Kinglong Mee | 37 | 13.36% | 1 | 20.00% |
Total | 277 | 100.00% | 5 | 100.00% |
EXPORT_SYMBOL_GPL(sunrpc_cache_lookup);
static void cache_dequeue(struct cache_detail *detail, struct cache_head *ch);
static void cache_fresh_locked(struct cache_head *head, time_t expiry,
struct cache_detail *detail)
{
time_t now = seconds_since_boot();
if (now <= detail->flush_time)
/* ensure it isn't immediately treated as expired */
now = detail->flush_time + 1;
head->expiry_time = expiry;
head->last_refresh = now;
smp_wmb(); /* paired with smp_rmb() in cache_is_valid() */
set_bit(CACHE_VALID, &head->flags);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Neil Brown | 64 | 94.12% | 3 | 75.00% |
J. Bruce Fields | 4 | 5.88% | 1 | 25.00% |
Total | 68 | 100.00% | 4 | 100.00% |
static void cache_fresh_unlocked(struct cache_head *head,
struct cache_detail *detail)
{
if (test_and_clear_bit(CACHE_PENDING, &head->flags)) {
cache_revisit_request(head);
cache_dequeue(detail, head);
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Neil Brown | 42 | 100.00% | 2 | 100.00% |
Total | 42 | 100.00% | 2 | 100.00% |
struct cache_head *sunrpc_cache_update(struct cache_detail *detail,
struct cache_head *new, struct cache_head *old, int hash)
{
/* The 'old' entry is to be replaced by 'new'.
* If 'old' is not VALID, we update it directly,
* otherwise we need to replace it
*/
struct cache_head *tmp;
if (!test_bit(CACHE_VALID, &old->flags)) {
write_lock(&detail->hash_lock);
if (!test_bit(CACHE_VALID, &old->flags)) {
if (test_bit(CACHE_NEGATIVE, &new->flags))
set_bit(CACHE_NEGATIVE, &old->flags);
else
detail->update(old, new);
cache_fresh_locked(old, new->expiry_time, detail);
write_unlock(&detail->hash_lock);
cache_fresh_unlocked(old, detail);
return old;
}
write_unlock(&detail->hash_lock);
}
/* We need to insert a new entry */
tmp = detail->alloc();
if (!tmp) {
cache_put(old, detail);
return NULL;
}
cache_init(tmp, detail);
detail->init(tmp, old);
write_lock(&detail->hash_lock);
if (test_bit(CACHE_NEGATIVE, &new->flags))
set_bit(CACHE_NEGATIVE, &tmp->flags);
else
detail->update(tmp, new);
hlist_add_head(&tmp->cache_list, &detail->hash_table[hash]);
detail->entries++;
cache_get(tmp);
cache_fresh_locked(tmp, new->expiry_time, detail);
cache_fresh_locked(old, 0, detail);
write_unlock(&detail->hash_lock);
cache_fresh_unlocked(tmp, detail);
cache_fresh_unlocked(old, detail);
cache_put(old, detail);
return tmp;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Neil Brown | 284 | 95.62% | 4 | 80.00% |
Kinglong Mee | 13 | 4.38% | 1 | 20.00% |
Total | 297 | 100.00% | 5 | 100.00% |
EXPORT_SYMBOL_GPL(sunrpc_cache_update);
static int cache_make_upcall(struct cache_detail *cd, struct cache_head *h)
{
if (cd->cache_upcall)
return cd->cache_upcall(cd, h);
return sunrpc_cache_pipe_upcall(cd, h);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Trond Myklebust | 19 | 47.50% | 1 | 33.33% |
Neil Brown | 13 | 32.50% | 1 | 33.33% |
Stanislav Kinsbursky | 8 | 20.00% | 1 | 33.33% |
Total | 40 | 100.00% | 3 | 100.00% |
static inline int cache_is_valid(struct cache_head *h)
{
if (!test_bit(CACHE_VALID, &h->flags))
return -EAGAIN;
else {
/* entry is valid */
if (test_bit(CACHE_NEGATIVE, &h->flags))
return -ENOENT;
else {
/*
* In combination with write barrier in
* sunrpc_cache_update, ensures that anyone
* using the cache entry after this sees the
* updated contents:
*/
smp_rmb();
return 0;
}
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Neil Brown | 53 | 89.83% | 2 | 66.67% |
J. Bruce Fields | 6 | 10.17% | 1 | 33.33% |
Total | 59 | 100.00% | 3 | 100.00% |
static int try_to_negate_entry(struct cache_detail *detail, struct cache_head *h)
{
int rv;
write_lock(&detail->hash_lock);
rv = cache_is_valid(h);
if (rv == -EAGAIN) {
set_bit(CACHE_NEGATIVE, &h->flags);
cache_fresh_locked(h, seconds_since_boot()+CACHE_NEW_EXPIRY,
detail);
rv = -ENOENT;
}
write_unlock(&detail->hash_lock);
cache_fresh_unlocked(h, detail);
return rv;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
J. Bruce Fields | 78 | 88.64% | 1 | 33.33% |
Neil Brown | 10 | 11.36% | 2 | 66.67% |
Total | 88 | 100.00% | 3 | 100.00% |
/*
* This is the generic cache management routine for all
* the authentication caches.
* It checks the currency of a cache item and will (later)
* initiate an upcall to fill it if needed.
*
*
* Returns 0 if the cache_head can be used, or cache_puts it and returns
* -EAGAIN if upcall is pending and request has been queued
* -ETIMEDOUT if upcall failed or request could not be queue or
* upcall completed but item is still invalid (implying that
* the cache item has been replaced with a newer one).
* -ENOENT if cache entry was negative
*/
int cache_check(struct cache_detail *detail,
struct cache_head *h, struct cache_req *rqstp)
{
int rv;
long refresh_age, age;
/* First decide return status as best we can */
rv = cache_is_valid(h);
/* now see if we want to start an upcall */
refresh_age = (h->expiry_time - h->last_refresh);
age = seconds_since_boot() - h->last_refresh;
if (rqstp == NULL) {
if (rv == -EAGAIN)
rv = -ENOENT;
} else if (rv == -EAGAIN ||
(h->expiry_time != 0 && age > refresh_age/2)) {
dprintk("RPC: Want update, refage=%ld, age=%ld\n",
refresh_age, age);
if (!test_and_set_bit(CACHE_PENDING, &h->flags)) {
switch (cache_make_upcall(detail, h)) {
case -EINVAL:
rv = try_to_negate_entry(detail, h);
break;
case -EAGAIN:
cache_fresh_unlocked(h, detail);
break;
}
}
}
if (rv == -EAGAIN) {
if (!cache_defer_req(rqstp, h)) {
/*
* Request was not deferred; handle it as best
* we can ourselves:
*/
rv = cache_is_valid(h);
if (rv == -EAGAIN)
rv = -ETIMEDOUT;
}
}
if (rv)
cache_put(h, detail);
return rv;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Neil Brown | 205 | 94.04% | 8 | 61.54% |
J. Bruce Fields | 11 | 5.05% | 3 | 23.08% |
Andi Kleen | 1 | 0.46% | 1 | 7.69% |
Chuck Lever | 1 | 0.46% | 1 | 7.69% |
Total | 218 | 100.00% | 13 | 100.00% |
EXPORT_SYMBOL_GPL(cache_check);
/*
* caches need to be periodically cleaned.
* For this we maintain a list of cache_detail and
* a current pointer into that list and into the table
* for that entry.
*
* Each time cache_clean is called it finds the next non-empty entry
* in the current table and walks the list in that entry
* looking for entries that can be removed.
*
* An entry gets removed if:
* - The expiry is before current time
* - The last_refresh time is before the flush_time for that cache
*
* later we might drop old entries with non-NEVER expiry if that table
* is getting 'full' for some definition of 'full'
*
* The question of "how often to scan a table" is an interesting one
* and is answered in part by the use of the "nextcheck" field in the
* cache_detail.
* When a scan of a table begins, the nextcheck field is set to a time
* that is well into the future.
* While scanning, if an expiry time is found that is earlier than the
* current nextcheck time, nextcheck is set to that expiry time.
* If the flush_time is ever set to a time earlier than the nextcheck
* time, the nextcheck time is then set to that flush_time.
*
* A table is then only scanned if the current time is at least
* the nextcheck time.
*
*/
static LIST_HEAD(cache_list);
static DEFINE_SPINLOCK(cache_list_lock);
static struct cache_detail *current_detail;
static int current_index;
static void do_cache_clean(struct work_struct *work);
static struct delayed_work cache_cleaner;
void sunrpc_init_cache_detail(struct cache_detail *cd)
{
rwlock_init(&cd->hash_lock);
INIT_LIST_HEAD(&cd->queue);
spin_lock(&cache_list_lock);
cd->nextcheck = 0;
cd->entries = 0;
atomic_set(&cd->readers, 0);
cd->last_close = 0;
cd->last_warn = -1;
list_add(&cd->others, &cache_list);
spin_unlock(&cache_list_lock);
/* start the cleaning process */
queue_delayed_work(system_power_efficient_wq, &cache_cleaner, 0);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Trond Myklebust | 55 | 57.89% | 1 | 20.00% |
J. Bruce Fields | 25 | 26.32% | 1 | 20.00% |
Neil Brown | 12 | 12.63% | 2 | 40.00% |
Ke Wang | 3 | 3.16% | 1 | 20.00% |
Total | 95 | 100.00% | 5 | 100.00% |
EXPORT_SYMBOL_GPL(sunrpc_init_cache_detail);
void sunrpc_destroy_cache_detail(struct cache_detail *cd)
{
cache_purge(cd);
spin_lock(&cache_list_lock);
write_lock(&cd->hash_lock);
if (current_detail == cd)
current_detail = NULL;
list_del_init(&cd->others);
write_unlock(&cd->hash_lock);
spin_unlock(&cache_list_lock);
if (list_empty(&cache_list)) {
/* module must be being unloaded so its safe to kill the worker */
cancel_delayed_work_sync(&cache_cleaner);
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Neil Brown | 43 | 55.13% | 5 | 45.45% |
J. Bruce Fields | 16 | 20.51% | 1 | 9.09% |
Trond Myklebust | 12 | 15.38% | 2 | 18.18% |
Wang Chen | 3 | 3.85% | 1 | 9.09% |
Andrew Morton | 3 | 3.85% | 1 | 9.09% |
Denis V. Lunev | 1 | 1.28% | 1 | 9.09% |
Total | 78 | 100.00% | 11 | 100.00% |
EXPORT_SYMBOL_GPL(sunrpc_destroy_cache_detail);
/* clean cache tries to find something to clean
* and cleans it.
* It returns 1 if it cleaned something,
* 0 if it didn't find anything this time
* -1 if it fell off the end of the list.
*/
static int cache_clean(void)
{
int rv = 0;
struct list_head *next;
spin_lock(&cache_list_lock);
/* find a suitable table if we don't already have one */
while (current_detail == NULL ||
current_index >= current_detail->hash_size) {
if (current_detail)
next = current_detail->others.next;
else
next = cache_list.next;
if (next == &cache_list) {
current_detail = NULL;
spin_unlock(&cache_list_lock);
return -1;
}
current_detail = list_entry(next, struct cache_detail, others);
if (current_detail->nextcheck > seconds_since_boot())
current_index = current_detail->hash_size;
else {
current_index = 0;
current_detail->nextcheck = seconds_since_boot()+30*60;
}
}
/* find a non-empty bucket in the table */
while (current_detail &&
current_index < current_detail->hash_size &&
hlist_empty(¤t_detail->hash_table[current_index]))
current_index++;
/* find a cleanable entry in the bucket and clean it, or set to next bucket */
if (current_detail && current_index < current_detail->hash_size) {
struct cache_head *ch = NULL;
struct cache_detail *d;
struct hlist_head *head;
struct hlist_node *tmp;
write_lock(¤t_detail->hash_lock);
/* Ok, now to clean this strand */
head = ¤t_detail->hash_table[current_index];
hlist_for_each_entry_safe(ch, tmp, head, cache_list) {
if (current_detail->nextcheck > ch->expiry_time)
current_detail->nextcheck = ch->expiry_time+1;
if (!cache_is_expired(current_detail, ch))
continue;
hlist_del_init(&ch->cache_list);
current_detail->entries--;
rv = 1;
break;
}
write_unlock(¤t_detail->hash_lock);
d = current_detail;
if (!ch)
current_index ++;
spin_unlock(&cache_list_lock);
if (ch) {
set_bit(CACHE_CLEANED, &ch->flags);
cache_fresh_unlocked(ch, d);
cache_put(ch, d);
}
} else
spin_unlock(&cache_list_lock);
return rv;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Neil Brown | 242 | 72.89% | 10 | 47.62% |
Kinglong Mee | 32 | 9.64% | 1 | 4.76% |
Andrew Morton | 29 | 8.73% | 3 | 14.29% |
J. Bruce Fields | 23 | 6.93% | 4 | 19.05% |
Trond Myklebust | 4 | 1.20% | 2 | 9.52% |
Andi Kleen | 2 | 0.60% | 1 | 4.76% |
Total | 332 | 100.00% | 21 | 100.00% |
/*
* We want to regularly clean the cache, so we need to schedule some work ...
*/
static void do_cache_clean(struct work_struct *work)
{
int delay = 5;
if (cache_clean() == -1)
delay = round_jiffies_relative(30*HZ);
if (list_empty(&cache_list))
delay = 0;
if (delay)
queue_delayed_work(system_power_efficient_wq,
&cache_cleaner, delay);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Neil Brown | 49 | 83.05% | 2 | 33.33% |
Ke Wang | 3 | 5.08% | 1 | 16.67% |
David Howells | 3 | 5.08% | 1 | 16.67% |
Anton Blanchard | 3 | 5.08% | 1 | 16.67% |
Adrian Bunk | 1 | 1.69% | 1 | 16.67% |
Total | 59 | 100.00% | 6 | 100.00% |
/*
* Clean all caches promptly. This just calls cache_clean
* repeatedly until we are sure that every cache has had a chance to
* be fully cleaned
*/
void cache_flush(void)
{
while (cache_clean() != -1)
cond_resched();
while (cache_clean() != -1)
cond_resched();
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Neil Brown | 29 | 100.00% | 1 | 100.00% |
Total | 29 | 100.00% | 1 | 100.00% |
EXPORT_SYMBOL_GPL(cache_flush);
void cache_purge(struct cache_detail *detail)
{
struct cache_head *ch = NULL;
struct hlist_head *head = NULL;
struct hlist_node *tmp = NULL;
int i = 0;
write_lock(&detail->hash_lock);
if (!detail->entries) {
write_unlock(&detail->hash_lock);
return;
}
dprintk("RPC: %d entries in %s cache\n", detail->entries, detail->name);
for (i = 0; i < detail->hash_size; i++) {
head = &detail->hash_table[i];
hlist_for_each_entry_safe(ch, tmp, head, cache_list) {
hlist_del_init(&ch->cache_list);
detail->entries--;
set_bit(CACHE_CLEANED, &ch->flags);
write_unlock(&detail->hash_lock);
cache_fresh_unlocked(ch, detail);
cache_put(ch, detail);
write_lock(&detail->hash_lock);
}
}
write_unlock(&detail->hash_lock);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Kinglong Mee | 146 | 83.43% | 1 | 33.33% |
Neil Brown | 29 | 16.57% | 2 | 66.67% |
Total | 175 | 100.00% | 3 | 100.00% |
EXPORT_SYMBOL_GPL(cache_purge);
/*
* Deferral and Revisiting of Requests.
*
* If a cache lookup finds a pending entry, we
* need to defer the request and revisit it later.
* All deferred requests are stored in a hash table,
* indexed by "struct cache_head *".
* As it may be wasteful to store a whole request
* structure, we allow the request to provide a
* deferred form, which must contain a
* 'struct cache_deferred_req'
* This cache_deferred_req contains a method to allow
* it to be revisited when cache info is available
*/
#define DFR_HASHSIZE (PAGE_SIZE/sizeof(struct list_head))
#define DFR_HASH(item) ((((long)item)>>4 ^ (((long)item)>>13)) % DFR_HASHSIZE)
#define DFR_MAX 300
/* ??? */
static DEFINE_SPINLOCK(cache_defer_lock);
static LIST_HEAD(cache_defer_list);
static struct hlist_head cache_defer_hash[DFR_HASHSIZE];
static int cache_defer_cnt;
static void __unhash_deferred_req(struct cache_deferred_req *dreq)
{
hlist_del_init(&dreq->hash);
if (!list_empty(&dreq->recent)) {
list_del_init(&dreq->recent);
cache_defer_cnt--;
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Neil Brown | 22 | 51.16% | 3 | 60.00% |
J. Bruce Fields | 20 | 46.51% | 1 | 20.00% |
Adrian Bunk | 1 | 2.33% | 1 | 20.00% |
Total | 43 | 100.00% | 5 | 100.00% |
static void __hash_deferred_req(struct cache_deferred_req *dreq, struct cache_head *item)
{
int hash = DFR_HASH(item);
INIT_LIST_HEAD(&dreq->recent);
hlist_add_head(&dreq->hash, &cache_defer_hash[hash]);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
J. Bruce Fields | 25 | 54.35% | 1 | 14.29% |
Neil Brown | 19 | 41.30% | 5 | 71.43% |
Andrew Morton | 2 | 4.35% | 1 | 14.29% |
Total | 46 | 100.00% | 7 | 100.00% |
static void setup_deferral(struct cache_deferred_req *dreq,
struct cache_head *item,
int count_me)
{
dreq->item = item;
spin_lock(&cache_defer_lock);
__hash_deferred_req(dreq, item);
if (count_me) {
cache_defer_cnt++;
list_add(&dreq->recent, &cache_defer_list);
}
spin_unlock(&cache_defer_lock);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Neil Brown | 54 | 84.38% | 4 | 50.00% |
J. Bruce Fields | 5 | 7.81% | 2 | 25.00% |
Andrew Morton | 4 | 6.25% | 1 | 12.50% |
Adrian Bunk | 1 | 1.56% | 1 | 12.50% |
Total | 64 | 100.00% | 8 | 100.00% |
struct thread_deferred_req {
struct cache_deferred_req handle;
struct completion completion;
};
static void cache_restart_thread(struct cache_deferred_req *dreq, int too_many)
{
struct thread_deferred_req *dr =
container_of(dreq, struct thread_deferred_req, handle);
complete(&dr->completion);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
J. Bruce Fields | 25 | 67.57% | 1 | 20.00% |
Neil Brown | 12 | 32.43% | 4 | 80.00% |
Total | 37 | 100.00% | 5 | 100.00% |
static void cache_wait_req(struct cache_req *req, struct cache_head *item)
{
struct thread_deferred_req sleeper;
struct cache_deferred_req *dreq = &sleeper.handle;
sleeper.completion = COMPLETION_INITIALIZER_ONSTACK(sleeper.completion);
dreq->revisit = cache_restart_thread;
setup_deferral(dreq, item, 0);
if (!test_bit(CACHE_PENDING, &item->flags) ||
wait_for_completion_interruptible_timeout(
&sleeper.completion, req->thread_wait) <= 0) {
/* The completion wasn't completed, so we need
* to clean up
*/
spin_lock(&cache_defer_lock);
if (!hlist_unhashed(&sleeper.handle.hash)) {
__unhash_deferred_req(&sleeper.handle);
spin_unlock(&cache_defer_lock);
} else {
/* cache_revisit_request already removed
* this from the hash table, but hasn't
* called ->revisit yet. It will very soon
* and we need to wait for it.
*/
spin_unlock(&cache_defer_lock);
wait_for_completion(&sleeper.completion);
}
}
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Neil Brown | 85 | 61.15% | 5 | 71.43% |
J. Bruce Fields | 54 | 38.85% | 2 | 28.57% |
Total | 139 | 100.00% | 7 | 100.00% |
static void cache_limit_defers(void)
{
/* Make sure we haven't exceed the limit of allowed deferred
* requests.
*/
struct cache_deferred_req *discard = NULL;
if (cache_defer_cnt <= DFR_MAX)
return;
spin_lock(&cache_defer_lock);
/* Consider removing either the first or the last */
if (cache_defer_cnt > DFR_MAX) {
if (prandom_u32() & 1)
discard = list_entry(cache_defer_list.next,
struct cache_deferred_req, recent);
else
discard = list_entry(cache_defer_list.prev,
struct cache_deferred_req, recent);
__unhash_deferred_req(discard);
}
spin_unlock(&cache_defer_lock);
if (discard)
discard->revisit(discard, 1);
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Neil Brown | 74 | 75.51% | 5 | 62.50% |
J. Bruce Fields | 19 | 19.39% | 1 | 12.50% |
Andrew Morton | 4 | 4.08% | 1 | 12.50% |
Aruna-Hewapathirane | 1 | 1.02% | 1 | 12.50% |
Total | 98 | 100.00% | 8 | 100.00% |
/* Return true if and only if a deferred request is queued. */
static bool cache_defer_req(struct cache_req *req, struct cache_head *item)
{
struct cache_deferred_req *dreq;
if (req->thread_wait) {
cache_wait_req(req, item);
if (!test_bit(CACHE_PENDING, &item->flags))
return false;
}
dreq = req->defer(req);
if (dreq == NULL)
return false;
setup_deferral(dreq, item, 1);
if (!test_bit(CACHE_PENDING, &item->flags))
/* Bit could have been cleared before we managed to
* set up the deferral, so need to revisit just in case
*/
cache_revisit_request(item);
cache_limit_defers();
return true;
}
Contributors
Person | Tokens | Prop | Commits | CommitProp |
Neil Brown | 67 | 64.42% | 6 | 75.00% |
J. Bruce Fields | 37 | 35.58% | 2 | 25.00% |
Total | 104 | 100.00% | 8 | 100.00% |
static void cache_revisit_request(struct cache_head *item)
{
struct cache_deferred_req *dreq;
struct list_head pending;
struct hlist_node *tmp;
int hash = DFR_HASH(item);
INIT_LIST_HEAD(&pending);
spin_lock(&cache_defer_lock);
hlist_for_each_entry_safe(dreq, tmp, &cache_defer_hash[hash], hash)
if (dreq->item == item) {
__unhash_deferred_req(dreq);
list_add(&dreq->recent, &pending);
}
spin_unlock(&cache_defer_lock);
while (!list_empty(&pending)) {
dreq = list_entry(pending.next, struct cache_deferred_req, recent);
list_del_init(&dreq->recent