From: Matthew Wilcox <willy@infradead.org>
To: rao.shoaib@oracle.com
Cc: linux-kernel@vger.kernel.org, paulmck@linux.vnet.ibm.com,
brouer@redhat.com, linux-mm@kvack.org
Subject: Re: [PATCH] kfree_rcu() should use the new kfree_bulk() interface for freeing rcu structures
Date: Tue, 19 Dec 2017 11:30:39 -0800 [thread overview]
Message-ID: <20171219193039.GB6515@bombadil.infradead.org> (raw)
In-Reply-To: <1513705948-31072-1-git-send-email-rao.shoaib@oracle.com>
On Tue, Dec 19, 2017 at 09:52:27AM -0800, rao.shoaib@oracle.com wrote:
> @@ -129,6 +130,7 @@ int __kmem_cache_alloc_bulk(struct kmem_cache *s, gfp_t flags, size_t nr,
>
> for (i = 0; i < nr; i++) {
> void *x = p[i] = kmem_cache_alloc(s, flags);
> +
> if (!x) {
> __kmem_cache_free_bulk(s, i, p);
> return 0;
Don't mix whitespace changes with significant patches.
> +/* Main RCU function that is called to free RCU structures */
> +static void
> +__rcu_bulk_free(struct rcu_head *head, rcu_callback_t func, int cpu, bool lazy)
> +{
> + unsigned long offset;
> + void *ptr;
> + struct rcu_bulk_free *rbf;
> + struct rcu_bulk_free_container *rbfc = NULL;
> +
> + rbf = this_cpu_ptr(&cpu_rbf);
> +
> + if (unlikely(!rbf->rbf_init)) {
> + spin_lock_init(&rbf->rbf_lock);
> + rbf->rbf_cpu = smp_processor_id();
> + rbf->rbf_init = true;
> + }
> +
> + /* hold lock to protect against other cpu's */
> + spin_lock_bh(&rbf->rbf_lock);
Are you sure we can't call kfree_rcu() from interrupt context?
> + rbfc = rbf->rbf_container;
> + rbfc->rbfc_entries = 0;
> +
> + if (rbf->rbf_list_head != NULL)
> + __rcu_bulk_schedule_list(rbf);
You've broken RCU. Consider this scenario:
Thread 1 Thread 2 Thread 3
kfree_rcu(a)
schedule()
schedule()
gets pointer to b
kfree_rcu(b)
processes rcu callbacks
uses b
Thread 3 will free a and also free b, so thread 2 is going to use freed
memory and go splat. You can't batch up memory to be freed without
taking into account the grace periods.
It might make sense for RCU to batch up all the memory it's going to free
in a single grace period, and hand it all off to slub at once, but that's
not what you've done here.
I've been doing a lot of thinking about this because I really want a
way to kfree_rcu() an object without embedding a struct rcu_head in it.
But I see no way to do that today; even if we have an external memory
allocation to point to the object to be freed, we have to keep track of
the grace periods.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>
next prev parent reply other threads:[~2017-12-19 19:30 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-12-19 17:52 [PATCH] kfree_rcu() should use the new kfree_bulk() interface for freeing rcu structures rao.shoaib
2017-12-19 19:12 ` Matthew Wilcox
2017-12-19 19:42 ` Rao Shoaib
2017-12-19 19:30 ` Matthew Wilcox [this message]
2017-12-19 19:56 ` Rao Shoaib
2017-12-19 20:22 ` Paul E. McKenney
2017-12-19 19:33 ` Jesper Dangaard Brouer
2017-12-19 19:33 ` Christopher Lameter
2017-12-19 20:02 ` Rao Shoaib
2017-12-20 0:56 ` Christopher Lameter
2017-12-20 18:14 ` Jesper Dangaard Brouer
2017-12-20 14:17 ` Michal Hocko
2017-12-19 20:41 ` Jesper Dangaard Brouer
2017-12-19 20:56 ` Paul E. McKenney
2017-12-19 21:20 ` Rao Shoaib
2017-12-20 7:31 ` Jesper Dangaard Brouer
2017-12-19 22:12 ` Matthew Wilcox
2017-12-19 23:25 ` Rao Shoaib
2017-12-20 0:20 ` Paul E. McKenney
2017-12-20 1:53 ` Matthew Wilcox
2017-12-20 5:19 ` Paul E. McKenney
2017-12-20 7:06 ` Jesper Dangaard Brouer
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=20171219193039.GB6515@bombadil.infradead.org \
--to=willy@infradead.org \
--cc=brouer@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=paulmck@linux.vnet.ibm.com \
--cc=rao.shoaib@oracle.com \
/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;
as well as URLs for NNTP newsgroup(s).