Skip to content

Commit 1c29a3c

Browse files
committed
percpu: use pcpu_free_slot instead of pcpu_nr_slots - 1
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: Dennis Zhou <[email protected]> Acked-by: Roman Gushchin <[email protected]> Signed-off-by: Dennis Zhou <[email protected]>
1 parent 8ea2e1e commit 1c29a3c

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

mm/percpu.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ static int pcpu_unit_size __ro_after_init;
135135
static int pcpu_nr_units __ro_after_init;
136136
static int pcpu_atom_size __ro_after_init;
137137
int pcpu_nr_slots __ro_after_init;
138+
int pcpu_free_slot __ro_after_init;
138139
static size_t pcpu_chunk_struct_size __ro_after_init;
139140

140141
/* cpus with the lowest and highest unit addresses */
@@ -237,7 +238,7 @@ static int __pcpu_size_to_slot(int size)
237238
static int pcpu_size_to_slot(int size)
238239
{
239240
if (size == pcpu_unit_size)
240-
return pcpu_nr_slots - 1;
241+
return pcpu_free_slot;
241242
return __pcpu_size_to_slot(size);
242243
}
243244

@@ -1806,7 +1807,7 @@ static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved,
18061807
goto fail;
18071808
}
18081809

1809-
if (list_empty(&pcpu_slot[pcpu_nr_slots - 1])) {
1810+
if (list_empty(&pcpu_slot[pcpu_free_slot])) {
18101811
chunk = pcpu_create_chunk(type, pcpu_gfp);
18111812
if (!chunk) {
18121813
err = "failed to allocate new chunk";
@@ -1958,7 +1959,7 @@ static void pcpu_balance_free(enum pcpu_chunk_type type)
19581959
{
19591960
LIST_HEAD(to_free);
19601961
struct list_head *pcpu_slot = pcpu_chunk_list(type);
1961-
struct list_head *free_head = &pcpu_slot[pcpu_nr_slots - 1];
1962+
struct list_head *free_head = &pcpu_slot[pcpu_free_slot];
19621963
struct pcpu_chunk *chunk, *next;
19631964

19641965
/*
@@ -2033,7 +2034,7 @@ static void pcpu_balance_populated(enum pcpu_chunk_type type)
20332034
0, PCPU_EMPTY_POP_PAGES_HIGH);
20342035
}
20352036

2036-
for (slot = pcpu_size_to_slot(PAGE_SIZE); slot < pcpu_nr_slots; slot++) {
2037+
for (slot = pcpu_size_to_slot(PAGE_SIZE); slot <= pcpu_free_slot; slot++) {
20372038
unsigned int nr_unpop = 0, rs, re;
20382039

20392040
if (!nr_to_pop)
@@ -2140,7 +2141,7 @@ void free_percpu(void __percpu *ptr)
21402141
if (chunk->free_bytes == pcpu_unit_size) {
21412142
struct pcpu_chunk *pos;
21422143

2143-
list_for_each_entry(pos, &pcpu_slot[pcpu_nr_slots - 1], list)
2144+
list_for_each_entry(pos, &pcpu_slot[pcpu_free_slot], list)
21442145
if (pos != chunk) {
21452146
need_balance = true;
21462147
break;
@@ -2562,7 +2563,8 @@ void __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
25622563
* Allocate chunk slots. The additional last slot is for
25632564
* empty chunks.
25642565
*/
2565-
pcpu_nr_slots = __pcpu_size_to_slot(pcpu_unit_size) + 2;
2566+
pcpu_free_slot = __pcpu_size_to_slot(pcpu_unit_size) + 1;
2567+
pcpu_nr_slots = pcpu_free_slot + 1;
25662568
pcpu_chunk_lists = memblock_alloc(pcpu_nr_slots *
25672569
sizeof(pcpu_chunk_lists[0]) *
25682570
PCPU_NR_CHUNK_TYPES,

0 commit comments

Comments
 (0)