From: Dean Nelson <dcn@sgi.com>
To: torvalds@osdl.org
Cc: linux-kernel@vger.kernel.org, holt@sgi.com,
swise@opengridcomputing.com, rdunlap@xenotime.net,
jes@trained-monkey.org, avolkov@varma-el.com, dcn@sgi.com
Subject: Re: [PATCH] add gen_pool_destroy()
Date: Thu, 28 Sep 2006 10:48:49 -0500 [thread overview]
Message-ID: <20060928154849.GA10434@sgi.com> (raw)
In-Reply-To: <20060928145142.GA6715@lnx-holt.americas.sgi.com>
Modules using the genpool allocator need to be able to kfree() the memory
used for the genpool data structures when unloading.
Signed-off-by: Steve Wise <swise@opengridcomputing.com>
Signed-off-by: Dean Nelson <dcn@sgi.com>
---
On Thu, Sep 28, 2006 at 09:51:42AM -0500, Robin Holt wrote:
> Nack this.
>
> Dean, you changed the list_for_each to list_for_each_safe where it was
> not needed. I think you only needed to change that in the remove path.
> IIRC, list_for_each_safe is intended for walking a list where you unlink
> the entry as part of your operation. Keep it for the gen_pool_destroy
> function since you are using kfree on those objects and somebody else
> could reuse them (sort of a list delete), but do not change them for
> the other case. The list_for_each does an explicit prefetch which will
> improve performance in many cases.
Thanks Robin.
Linus, here's a new version of the patch which corrects the
issue that Robin Holt pointed out.
Again, there is an issue with the block comments not being up to
kernel-doc standards that plagues the entire file, which I will
remedy in a followup patch.
Thanks,
Dean
include/linux/genalloc.h | 1 +
lib/genalloc.c | 30 ++++++++++++++++++++++++++++++
2 files changed, 31 insertions(+)
Index: linux-2.6/lib/genalloc.c
===================================================================
--- linux-2.6.orig/lib/genalloc.c 2006-09-28 09:53:53.372104302 -0500
+++ linux-2.6/lib/genalloc.c 2006-09-28 10:42:47.627258805 -0500
@@ -71,6 +71,36 @@
/*
+ * Destroy a memory pool. Verifies that there are no outstanding allocations.
+ *
+ * @pool: pool to destroy
+ */
+void gen_pool_destroy(struct gen_pool *pool)
+{
+ struct list_head *_chunk, *_next_chunk;
+ struct gen_pool_chunk *chunk;
+ int order = pool->min_alloc_order;
+ int bit, end_bit;
+
+
+ write_lock(&pool->lock);
+ list_for_each_safe(_chunk, _next_chunk, &pool->chunks) {
+ chunk = list_entry(_chunk, struct gen_pool_chunk, next_chunk);
+ list_del(&chunk->next_chunk);
+
+ end_bit = (chunk->end_addr - chunk->start_addr) >> order;
+ bit = find_next_bit(chunk->bits, end_bit, 0);
+ BUG_ON(bit < end_bit);
+
+ kfree(chunk);
+ }
+ kfree(pool);
+ return;
+}
+EXPORT_SYMBOL(gen_pool_destroy);
+
+
+/*
* Allocate the requested number of bytes from the specified pool.
* Uses a first-fit algorithm.
*
Index: linux-2.6/include/linux/genalloc.h
===================================================================
--- linux-2.6.orig/include/linux/genalloc.h 2006-09-28 09:53:53.372104302 -0500
+++ linux-2.6/include/linux/genalloc.h 2006-09-28 09:53:55.200331504 -0500
@@ -31,5 +31,6 @@
extern struct gen_pool *gen_pool_create(int, int);
extern int gen_pool_add(struct gen_pool *, unsigned long, size_t, int);
+extern void gen_pool_destroy(struct gen_pool *);
extern unsigned long gen_pool_alloc(struct gen_pool *, size_t);
extern void gen_pool_free(struct gen_pool *, unsigned long, size_t);
prev parent reply other threads:[~2006-09-28 15:48 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-09-27 15:35 [PATCH 2.6.18 ] LIB Add gen_pool_destroy() Steve Wise
2006-09-27 15:51 ` Randy Dunlap
2006-09-27 15:53 ` Steve Wise
2006-09-27 15:56 ` Randy Dunlap
2006-09-27 19:59 ` Dean Nelson
2006-09-27 20:27 ` Randy Dunlap
2006-09-28 17:24 ` [PATCH] make genpool allocator adhere to kernel-doc standards Dean Nelson
2006-09-28 17:48 ` Randy Dunlap
2006-09-28 18:17 ` Dean Nelson
2006-09-27 19:51 ` [PATCH 2.6.18 ] LIB Add gen_pool_destroy() Dean Nelson
2006-09-27 21:09 ` Steve Wise
2006-09-28 13:16 ` [PATCH] add gen_pool_destroy() Dean Nelson
2006-09-28 14:51 ` Robin Holt
2006-09-28 15:48 ` Dean Nelson [this message]
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=20060928154849.GA10434@sgi.com \
--to=dcn@sgi.com \
--cc=avolkov@varma-el.com \
--cc=holt@sgi.com \
--cc=jes@trained-monkey.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rdunlap@xenotime.net \
--cc=swise@opengridcomputing.com \
--cc=torvalds@osdl.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.