Skip to content

Commit

Permalink
ftrace: Free hash with call_rcu_sched()
Browse files Browse the repository at this point in the history
When a hash is modified and might be in use, we need to perform
a schedule RCU operation on it, as the hashes will soon be used
directly in the function tracer callback.

Cc: Paul E. McKenney <paulmck@linux.vnet.ibm.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
  • Loading branch information
Steven Rostedt authored and Steven Rostedt committed May 18, 2011
1 parent 2b49938 commit 07fd551
Showing 1 changed file with 28 additions and 27 deletions.
55 changes: 28 additions & 27 deletions kernel/trace/ftrace.c
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,7 @@ struct ftrace_hash {
unsigned long size_bits;
struct hlist_head *buckets;
unsigned long count;
struct rcu_head rcu;
};

/*
Expand Down Expand Up @@ -1058,6 +1059,21 @@ static void free_ftrace_hash(struct ftrace_hash *hash)
kfree(hash);
}

static void __free_ftrace_hash_rcu(struct rcu_head *rcu)
{
struct ftrace_hash *hash;

hash = container_of(rcu, struct ftrace_hash, rcu);
free_ftrace_hash(hash);
}

static void free_ftrace_hash_rcu(struct ftrace_hash *hash)
{
if (!hash || hash == EMPTY_HASH)
return;
call_rcu_sched(&hash->rcu, __free_ftrace_hash_rcu);
}

static struct ftrace_hash *alloc_ftrace_hash(int size_bits)
{
struct ftrace_hash *hash;
Expand Down Expand Up @@ -1122,7 +1138,8 @@ ftrace_hash_move(struct ftrace_hash **dst, struct ftrace_hash *src)
struct ftrace_func_entry *entry;
struct hlist_node *tp, *tn;
struct hlist_head *hhd;
struct ftrace_hash *hash = *dst;
struct ftrace_hash *old_hash;
struct ftrace_hash *new_hash;
unsigned long key;
int size = src->count;
int bits = 0;
Expand All @@ -1133,13 +1150,11 @@ ftrace_hash_move(struct ftrace_hash **dst, struct ftrace_hash *src)
* the empty_hash.
*/
if (!src->count) {
free_ftrace_hash(*dst);
*dst = EMPTY_HASH;
free_ftrace_hash_rcu(*dst);
rcu_assign_pointer(*dst, EMPTY_HASH);
return 0;
}

ftrace_hash_clear(hash);

/*
* Make the hash size about 1/2 the # found
*/
Expand All @@ -1150,27 +1165,9 @@ ftrace_hash_move(struct ftrace_hash **dst, struct ftrace_hash *src)
if (bits > FTRACE_HASH_MAX_BITS)
bits = FTRACE_HASH_MAX_BITS;

/* We can't modify the empty_hash */
if (hash == EMPTY_HASH) {
/* Create a new hash */
*dst = alloc_ftrace_hash(bits);
if (!*dst) {
*dst = EMPTY_HASH;
return -ENOMEM;
}
hash = *dst;
} else {
size = 1 << bits;

/* Use the old hash, but create new buckets */
hhd = kzalloc(sizeof(*hhd) * size, GFP_KERNEL);
if (!hhd)
return -ENOMEM;

kfree(hash->buckets);
hash->buckets = hhd;
hash->size_bits = bits;
}
new_hash = alloc_ftrace_hash(bits);
if (!new_hash)
return -ENOMEM;

size = 1 << src->size_bits;
for (i = 0; i < size; i++) {
Expand All @@ -1181,10 +1178,14 @@ ftrace_hash_move(struct ftrace_hash **dst, struct ftrace_hash *src)
else
key = 0;
remove_hash_entry(src, entry);
__add_hash_entry(hash, entry);
__add_hash_entry(new_hash, entry);
}
}

old_hash = *dst;
rcu_assign_pointer(*dst, new_hash);
free_ftrace_hash_rcu(old_hash);

return 0;
}

Expand Down

0 comments on commit 07fd551

Please sign in to comment.