From: wuchi <wuchi.zero@gmail.com>
To: akpm@linux-foundation.org, alexs@kernel.org, sjhuang@iluvatar.ai,
sfr@canb.auug.org.au
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH] lib/genalloc: Set chunk size to real size which gen_pool managed.
Date: Sun, 12 Jun 2022 18:59:37 +0800 [thread overview]
Message-ID: <20220612105937.30862-1-wuchi.zero@gmail.com> (raw)
The demand size (chunk->avail > size > round_down(chunk->avail)) will
lead to meaningless algo calls in gen_pool_alloc_algo_owner without the
patch, alse move the follow code:
size = nbits << order
out of read-side critical section.
Signed-off-by: wuchi <wuchi.zero@gmail.com>
---
lib/genalloc.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/lib/genalloc.c b/lib/genalloc.c
index 00fc50d0a640..1b1843613fb8 100644
--- a/lib/genalloc.c
+++ b/lib/genalloc.c
@@ -193,6 +193,7 @@ int gen_pool_add_owner(struct gen_pool *pool, unsigned long virt, phys_addr_t ph
if (unlikely(chunk == NULL))
return -ENOMEM;
+ size = nbits << pool->min_alloc_order;
chunk->phys_addr = phys;
chunk->start_addr = virt;
chunk->end_addr = virt + size - 1;
@@ -293,6 +294,7 @@ unsigned long gen_pool_alloc_algo_owner(struct gen_pool *pool, size_t size,
return 0;
nbits = (size + (1UL << order) - 1) >> order;
+ size = nbits << order;
rcu_read_lock();
list_for_each_entry_rcu(chunk, &pool->chunks, next_chunk) {
if (size > atomic_long_read(&chunk->avail))
@@ -314,7 +316,6 @@ unsigned long gen_pool_alloc_algo_owner(struct gen_pool *pool, size_t size,
}
addr = chunk->start_addr + ((unsigned long)start_bit << order);
- size = nbits << order;
atomic_long_sub(size, &chunk->avail);
if (owner)
*owner = chunk->owner;
@@ -499,6 +500,7 @@ void gen_pool_free_owner(struct gen_pool *pool, unsigned long addr, size_t size,
*owner = NULL;
nbits = (size + (1UL << order) - 1) >> order;
+ size = nbits << order;
rcu_read_lock();
list_for_each_entry_rcu(chunk, &pool->chunks, next_chunk) {
if (addr >= chunk->start_addr && addr <= chunk->end_addr) {
@@ -506,7 +508,6 @@ void gen_pool_free_owner(struct gen_pool *pool, unsigned long addr, size_t size,
start_bit = (addr - chunk->start_addr) >> order;
remain = bitmap_clear_ll(chunk->bits, start_bit, nbits);
BUG_ON(remain);
- size = nbits << order;
atomic_long_add(size, &chunk->avail);
if (owner)
*owner = chunk->owner;
--
2.20.1
next reply other threads:[~2022-06-12 11:00 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-06-12 10:59 wuchi [this message]
2022-06-13 18:14 ` [PATCH] lib/genalloc: Set chunk size to real size which gen_pool managed Andrew Morton
2022-06-14 5:20 ` chi wu
2022-06-14 17:53 ` Andrew Morton
2022-06-15 12:41 ` chi wu
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=20220612105937.30862-1-wuchi.zero@gmail.com \
--to=wuchi.zero@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=alexs@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=sfr@canb.auug.org.au \
--cc=sjhuang@iluvatar.ai \
/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