@@ -135,6 +135,7 @@ static int pcpu_unit_size __ro_after_init;
135
135
static int pcpu_nr_units __ro_after_init ;
136
136
static int pcpu_atom_size __ro_after_init ;
137
137
int pcpu_nr_slots __ro_after_init ;
138
+ int pcpu_free_slot __ro_after_init ;
138
139
static size_t pcpu_chunk_struct_size __ro_after_init ;
139
140
140
141
/* cpus with the lowest and highest unit addresses */
@@ -237,7 +238,7 @@ static int __pcpu_size_to_slot(int size)
237
238
static int pcpu_size_to_slot (int size )
238
239
{
239
240
if (size == pcpu_unit_size )
240
- return pcpu_nr_slots - 1 ;
241
+ return pcpu_free_slot ;
241
242
return __pcpu_size_to_slot (size );
242
243
}
243
244
@@ -1806,7 +1807,7 @@ static void __percpu *pcpu_alloc(size_t size, size_t align, bool reserved,
1806
1807
goto fail ;
1807
1808
}
1808
1809
1809
- if (list_empty (& pcpu_slot [pcpu_nr_slots - 1 ])) {
1810
+ if (list_empty (& pcpu_slot [pcpu_free_slot ])) {
1810
1811
chunk = pcpu_create_chunk (type , pcpu_gfp );
1811
1812
if (!chunk ) {
1812
1813
err = "failed to allocate new chunk" ;
@@ -1958,7 +1959,7 @@ static void pcpu_balance_free(enum pcpu_chunk_type type)
1958
1959
{
1959
1960
LIST_HEAD (to_free );
1960
1961
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 ];
1962
1963
struct pcpu_chunk * chunk , * next ;
1963
1964
1964
1965
/*
@@ -2033,7 +2034,7 @@ static void pcpu_balance_populated(enum pcpu_chunk_type type)
2033
2034
0 , PCPU_EMPTY_POP_PAGES_HIGH );
2034
2035
}
2035
2036
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 ++ ) {
2037
2038
unsigned int nr_unpop = 0 , rs , re ;
2038
2039
2039
2040
if (!nr_to_pop )
@@ -2140,7 +2141,7 @@ void free_percpu(void __percpu *ptr)
2140
2141
if (chunk -> free_bytes == pcpu_unit_size ) {
2141
2142
struct pcpu_chunk * pos ;
2142
2143
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 )
2144
2145
if (pos != chunk ) {
2145
2146
need_balance = true;
2146
2147
break ;
@@ -2562,7 +2563,8 @@ void __init pcpu_setup_first_chunk(const struct pcpu_alloc_info *ai,
2562
2563
* Allocate chunk slots. The additional last slot is for
2563
2564
* empty chunks.
2564
2565
*/
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 ;
2566
2568
pcpu_chunk_lists = memblock_alloc (pcpu_nr_slots *
2567
2569
sizeof (pcpu_chunk_lists [0 ]) *
2568
2570
PCPU_NR_CHUNK_TYPES ,
0 commit comments