提交 8e7c786a 编写于 作者: D Dennis Zhou 提交者: Zheng Zengkai

percpu: use pcpu_free_slot instead of pcpu_nr_slots - 1

mainline inclusion
from mainline-v5.14-rc1
commit 1c29a3ce
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I4BE79
CVE: NA

-------------------------------------------------
This prepares for adding a to_depopulate list and sidelined list after
the free slot in the set of lists in pcpu_slot.
Signed-off-by: NDennis Zhou <dennis@kernel.org>
Acked-by: NRoman Gushchin <guro@fb.com>
Signed-off-by: NDennis Zhou <dennis@kernel.org>
(cherry picked from commit 1c29a3ce)
Signed-off-by: NYuanzheng Song <songyuanzheng@huawei.com>
Reviewed-by: NKefeng Wang <wangkefeng.wang@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 797a1ad6
...@@ -134,6 +134,7 @@ static int pcpu_unit_size __ro_after_init; ...@@ -134,6 +134,7 @@ static int pcpu_unit_size __ro_after_init;
static int pcpu_nr_units __ro_after_init; static int pcpu_nr_units __ro_after_init;
static int pcpu_atom_size __ro_after_init; static int pcpu_atom_size __ro_after_init;
int pcpu_nr_slots __ro_after_init; int pcpu_nr_slots __ro_after_init;
int pcpu_free_slot __ro_after_init;
static size_t pcpu_chunk_struct_size __ro_after_init; static size_t pcpu_chunk_struct_size __ro_after_init;
/* cpus with the lowest and highest unit addresses */ /* cpus with the lowest and highest unit addresses */
...@@ -236,7 +237,7 @@ static int __pcpu_size_to_slot(int size) ...@@ -236,7 +237,7 @@ static int __pcpu_size_to_slot(int size)
static int pcpu_size_to_slot(int size) static int pcpu_size_to_slot(int size)
{ {
if (size == pcpu_unit_size) if (size == pcpu_unit_size)
return pcpu_nr_slots - 1; return pcpu_free_slot;
return __pcpu_size_to_slot(size); return __pcpu_size_to_slot(size);
} }
...@@ -1805,7 +1806,7 @@ static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved, ...@@ -1805,7 +1806,7 @@ static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved,
goto fail; goto fail;
} }
if (list_empty(&pcpu_slot[pcpu_nr_slots - 1])) { if (list_empty(&pcpu_slot[pcpu_free_slot])) {
chunk = pcpu_create_chunk(type, pcpu_gfp); chunk = pcpu_create_chunk(type, pcpu_gfp);
if (!chunk) { if (!chunk) {
err = "failed to allocate new chunk"; err = "failed to allocate new chunk";
...@@ -1957,7 +1958,7 @@ static void pcpu_balance_free(enum pcpu_chunk_type type) ...@@ -1957,7 +1958,7 @@ static void pcpu_balance_free(enum pcpu_chunk_type type)
{ {
LIST_HEAD(to_free); LIST_HEAD(to_free);
struct list_head *pcpu_slot = pcpu_chunk_list(type); struct list_head *pcpu_slot = pcpu_chunk_list(type);
struct list_head *free_head = &pcpu_slot[pcpu_nr_slots - 1]; struct list_head *free_head = &pcpu_slot[pcpu_free_slot];
struct pcpu_chunk *chunk, *next; struct pcpu_chunk *chunk, *next;
/* /*
...@@ -2032,7 +2033,7 @@ static void pcpu_balance_populated(enum pcpu_chunk_type type) ...@@ -2032,7 +2033,7 @@ static void pcpu_balance_populated(enum pcpu_chunk_type type)
0, PCPU_EMPTY_POP_PAGES_HIGH); 0, PCPU_EMPTY_POP_PAGES_HIGH);
} }
for (slot = pcpu_size_to_slot(PAGE_SIZE); slot < pcpu_nr_slots; slot++) { for (slot = pcpu_size_to_slot(PAGE_SIZE); slot <= pcpu_free_slot; slot++) {
unsigned int nr_unpop = 0, rs, re; unsigned int nr_unpop = 0, rs, re;
if (!nr_to_pop) if (!nr_to_pop)
...@@ -2139,7 +2140,7 @@ void free_percpu(void __percpu *ptr) ...@@ -2139,7 +2140,7 @@ void free_percpu(void __percpu *ptr)
if (chunk->free_bytes == pcpu_unit_size) { if (chunk->free_bytes == pcpu_unit_size) {
struct pcpu_chunk *pos; struct pcpu_chunk *pos;
list_for_each_entry(pos, &pcpu_slot[pcpu_nr_slots - 1], list) list_for_each_entry(pos, &pcpu_slot[pcpu_free_slot], list)
if (pos != chunk) { if (pos != chunk) {
need_balance = true; need_balance = true;
break; break;
...@@ -2561,7 +2562,8 @@ void __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai, ...@@ -2561,7 +2562,8 @@ void __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
* Allocate chunk slots. The additional last slot is for * Allocate chunk slots. The additional last slot is for
* empty chunks. * empty chunks.
*/ */
pcpu_nr_slots = __pcpu_size_to_slot(pcpu_unit_size) + 2; pcpu_free_slot = __pcpu_size_to_slot(pcpu_unit_size) + 1;
pcpu_nr_slots = pcpu_free_slot + 1;
pcpu_chunk_lists = memblock_alloc(pcpu_nr_slots * pcpu_chunk_lists = memblock_alloc(pcpu_nr_slots *
sizeof(pcpu_chunk_lists[0]) * sizeof(pcpu_chunk_lists[0]) *
PCPU_NR_CHUNK_TYPES, PCPU_NR_CHUNK_TYPES,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册