From: Lai Jiangshan <laijs@cn.fujitsu.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@elte.hu>,
Linux Kernel Mailing List <linux-kernel@vger.kernel.org>,
"Paul E. McKenney" <paulmck@linux.vnet.ibm.com>,
Dipankar Sarma <dipankar@in.ibm.com>,
Peter Zijlstra <peterz@infradead.org>,
manfred@colorfullife.com
Subject: Re: [RFC PATCH] rcu: introduce kfree_rcu()
Date: Fri, 19 Sep 2008 10:31:37 +0800 [thread overview]
Message-ID: <48D30F09.1030601@cn.fujitsu.com> (raw)
In-Reply-To: <20080917213748.7571fbdf.akpm@linux-foundation.org>
Andrew Morton wrote:
>> diff --git a/include/linux/rcupdate.h b/include/linux/rcupdate.h
>> index e8b4039..04c654f 100644
>> --- a/include/linux/rcupdate.h
>> +++ b/include/linux/rcupdate.h
>> @@ -253,4 +253,25 @@ extern void rcu_barrier_sched(void);
>> extern void rcu_init(void);
>> extern int rcu_needs_cpu(int cpu);
>>
>> +#define __KFREE_RCU_MAX_OFFSET 4095
>> +#define KFREE_RCU_MAX_OFFSET (sizeof(void *) * __KFREE_RCU_MAX_OFFSET)
>> +
>> +#define __rcu_reclaim(head) \
>> +do { \
>> + unsigned long __offset = (unsigned long)head->func; \
>> + if (__offset <= __KFREE_RCU_MAX_OFFSET) \
>> + kfree((void *)head - sizeof(void *) * __offset); \
>> + else \
>> + head->func(head); \
>> +} while(0)
>
> All the above could do with some comments explaining what it does.
>
> Please use checkpatch.
>
> Surely it cannot be resirable to have a "function" which can call kfree
> either synchronously or asynchronously depending upon the size of the
> object which was passed to it? If the caller wants rcu treatment of
> the freeing then that is what the caller must be given. I mean, if the
> caller can tolerate a synchrnous call to kfree() then the caller should
> have directly called kfree?
>
> I think (and pray) that the above could have been implemented as an
> out-of-line C function?
>
__rcu_reclaim(head) is called when @head 's grace period had completed.
__rcu_reclaim(head) uses "if (__offset <= __KFREE_RCU_MAX_OFFSET)" to
check whether @head is queued by kfree_rcu() or normal call_rcu().
if @head is queued by kfree_rcu(), ((void *)head - sizeof(void *) * __offset)
is the pointer that the memory chunk need to be freed.
otherwise call head->func(head) as original code.
__rcu_reclaim has __prefix, will not be used by user, it is a helper
for rcu-machine. it is always called asynchronously. sorry for not comments
for it.
>> +
>> +/**
>> + * kfree_rcu - free previously allocated memory after a grace period.
>> + * @ptr: pointer returned by kmalloc.
>> + * @head: structure to be used for queueing the RCU updates. This structure
>> + * is a part of previously allocated memory @ptr.
>> + */
>> +extern void kfree_rcu(const void *ptr, struct rcu_head *head);
>
> rcu kerneldoc is implemented in the .c file, not in the .h file.
Good, Thanks.
>
>> #endif /* __LINUX_RCUPDATE_H */
>> diff --git a/kernel/rcuclassic.c b/kernel/rcuclassic.c
>> index aad93cd..5a14190 100644
>> --- a/kernel/rcuclassic.c
>> +++ b/kernel/rcuclassic.c
>> @@ -232,7 +232,7 @@ static void rcu_do_batch(struct rcu_data *rdp)
>> while (list) {
>> next = list->next;
>> prefetch(next);
>> - list->func(list);
>> + __rcu_reclaim(list);
>> list = next;
>> if (++count >= rdp->blimit)
>> break;
>> diff --git a/kernel/rcupdate.c b/kernel/rcupdate.c
>> index 467d594..aa9b56a 100644
>> --- a/kernel/rcupdate.c
>> +++ b/kernel/rcupdate.c
>> @@ -162,6 +162,18 @@ void rcu_barrier_sched(void)
>> }
>> EXPORT_SYMBOL_GPL(rcu_barrier_sched);
>>
>> +void kfree_rcu(const void *ptr, struct rcu_head *head)
>> +{
>> + unsigned long offset;
>> + typedef void (*rcu_callback)(struct rcu_head *);
>> +
>> + offset = (void *)head - (void *)ptr;
>> + BUG_ON(offset > KFREE_RCU_MAX_OFFSET);
>> +
>> + call_rcu(head, (rcu_callback)(offset / sizeof(void *)));
>
> How can this work? We take the difference between two pointers, divide
> that by 4 or 8, then treat the resulting number as the address of an
> RCU callback function.
>
> I think I'm missing something here.
We will use __rcu_reclaim(head) sort it out when it's grace period has
completed.
>
>> +}
>> +EXPORT_SYMBOL_GPL(kfree_rcu);
>> +
>> void __init rcu_init(void)
>> {
>> __rcu_init();
>> diff --git a/kernel/rcupreempt.c b/kernel/rcupreempt.c
>> index 2782793..62a9e54 100644
>> --- a/kernel/rcupreempt.c
>> +++ b/kernel/rcupreempt.c
>> @@ -1108,7 +1108,7 @@ static void rcu_process_callbacks(struct softirq_action *unused)
>> spin_unlock_irqrestore(&rdp->lock, flags);
>> while (list) {
>> next = list->next;
>> - list->func(list);
>> + __rcu_reclaim(list);
>> list = next;
>> RCU_TRACE_ME(rcupreempt_trace_invoke);
>> }
>
>
>
next prev parent reply other threads:[~2008-09-19 2:33 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-18 4:18 Lai Jiangshan
2008-09-18 4:37 ` Andrew Morton
2008-09-18 16:52 ` Manfred Spraul
2008-09-19 2:31 ` Lai Jiangshan [this message]
2008-09-18 6:44 ` Paul E. McKenney
2008-09-18 8:59 ` Lai Jiangshan
2008-09-18 17:15 ` Paul E. McKenney
2008-09-18 16:56 ` Manfred Spraul
2008-09-18 17:46 ` Paul E. McKenney
2008-09-19 16:03 ` Manfred Spraul
2008-09-19 1:04 ` Lai Jiangshan
2008-09-19 3:58 ` Paul E. McKenney
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=48D30F09.1030601@cn.fujitsu.com \
--to=laijs@cn.fujitsu.com \
--cc=akpm@linux-foundation.org \
--cc=dipankar@in.ibm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=manfred@colorfullife.com \
--cc=mingo@elte.hu \
--cc=paulmck@linux.vnet.ibm.com \
--cc=peterz@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Powered by JetHome