From: Baoquan He <bhe@redhat.com>
To: linux-kernel@vger.kernel.org
Cc: linux-mm@kvack.org, akpm@linux-foundation.org, dennis@kernel.org,
tj@kernel.org, cl@linux.com, mawupeng1@huawei.com,
Baoquan He <bhe@redhat.com>
Subject: [PATCH 2/3] mm/percpu.c: optimize the code in pcpu_setup_first_chunk() a little bit
Date: Fri, 21 Jul 2023 21:17:59 +0800 [thread overview]
Message-ID: <20230721131800.20003-3-bhe@redhat.com> (raw)
In-Reply-To: <20230721131800.20003-1-bhe@redhat.com>
This removes the need of local varibale 'chunk', and optimize the code
calling pcpu_alloc_first_chunk() to initialize reserved chunk and
dynamic chunk to make it simpler.
Signed-off-by: Baoquan He <bhe@redhat.com>
---
mm/percpu.c | 32 +++++++++++++-------------------
1 file changed, 13 insertions(+), 19 deletions(-)
diff --git a/mm/percpu.c b/mm/percpu.c
index 1480bf283d11..c25b058a46ad 100644
--- a/mm/percpu.c
+++ b/mm/percpu.c
@@ -2581,7 +2581,6 @@ void __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
{
size_t size_sum = ai->static_size + ai->reserved_size + ai->dyn_size;
size_t static_size, dyn_size;
- struct pcpu_chunk *chunk;
unsigned long *group_offsets;
size_t *group_sizes;
unsigned long *unit_off;
@@ -2697,7 +2696,7 @@ void __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
pcpu_unit_pages = ai->unit_size >> PAGE_SHIFT;
pcpu_unit_size = pcpu_unit_pages << PAGE_SHIFT;
pcpu_atom_size = ai->atom_size;
- pcpu_chunk_struct_size = struct_size(chunk, populated,
+ pcpu_chunk_struct_size = struct_size((struct pcpu_chunk *)0, populated,
BITS_TO_LONGS(pcpu_unit_pages));
pcpu_stats_save_ai(ai);
@@ -2735,28 +2734,23 @@ void __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
/*
* Initialize first chunk.
- * If the reserved_size is non-zero, this initializes the reserved
- * chunk. If the reserved_size is zero, the reserved chunk is NULL
- * and the dynamic region is initialized here. The first chunk,
- * pcpu_first_chunk, will always point to the chunk that serves
- * the dynamic region.
+ * If the reserved_size is non-zero, initializes the reserved chunk
+ * firstly. If the reserved_size is zero, the reserved chunk is NULL
+ * and the dynamic region is initialized directly. The first chunk,
+ * pcpu_first_chunk, will always point to the chunk that serves the
+ * dynamic region.
*/
tmp_addr = (unsigned long)base_addr + static_size;
- map_size = ai->reserved_size ?: dyn_size;
- chunk = pcpu_alloc_first_chunk(tmp_addr, map_size);
-
- /* init dynamic chunk if necessary */
if (ai->reserved_size) {
- pcpu_reserved_chunk = chunk;
-
- tmp_addr = (unsigned long)base_addr + static_size +
- ai->reserved_size;
- map_size = dyn_size;
- chunk = pcpu_alloc_first_chunk(tmp_addr, map_size);
+ map_size = ai->reserved_size;
+ pcpu_reserved_chunk = pcpu_alloc_first_chunk(tmp_addr, map_size);
}
- /* link the first chunk in */
- pcpu_first_chunk = chunk;
+ /* init dynamic chunk if necessary */
+ tmp_addr += (unsigned long)ai->reserved_size;
+ map_size = dyn_size;
+ pcpu_first_chunk = pcpu_alloc_first_chunk(tmp_addr, map_size);
+
pcpu_nr_empty_pop_pages = pcpu_first_chunk->nr_empty_pop_pages;
pcpu_chunk_relocate(pcpu_first_chunk, -1);
--
2.34.1
next prev parent reply other threads:[~2023-07-21 13:18 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-21 13:17 [PATCH 0/3] percpu: some trivial cleanup patches Baoquan He
2023-07-21 13:17 ` [PATCH 1/3] mm/percpu.c: remove redundant check Baoquan He
2023-07-21 20:55 ` Dennis Zhou
2023-07-21 13:17 ` Baoquan He [this message]
2023-07-21 21:01 ` [PATCH 2/3] mm/percpu.c: optimize the code in pcpu_setup_first_chunk() a little bit Dennis Zhou
2023-07-22 1:14 ` Baoquan He
2023-07-21 13:18 ` [PATCH 3/3] mm/percpu.c: print error message too if atomic alloc failed Baoquan He
2023-07-21 21:03 ` Dennis Zhou
2023-07-22 1:56 ` Baoquan He
2023-07-21 21:04 ` [PATCH 0/3] percpu: some trivial cleanup patches Dennis Zhou
2023-07-22 3:30 ` Baoquan He
2023-07-27 22:50 ` Dennis Zhou
2023-07-28 3:04 ` Baoquan He
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=20230721131800.20003-3-bhe@redhat.com \
--to=bhe@redhat.com \
--cc=akpm@linux-foundation.org \
--cc=cl@linux.com \
--cc=dennis@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=mawupeng1@huawei.com \
--cc=tj@kernel.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;
as well as URLs for NNTP newsgroup(s).