@@ -504,10 +504,18 @@ static inline struct kmem_cache_node *get_node(struct kmem_cache *s, int node)
504504 return s -> node [node ];
505505}
506506
507- /* Get the barn of the current cpu's memory node */
507+ /*
508+ * Get the barn of the current cpu's closest memory node. It may not exist on
509+ * systems with memoryless nodes but without CONFIG_HAVE_MEMORYLESS_NODES
510+ */
508511static inline struct node_barn * get_barn (struct kmem_cache * s )
509512{
510- return get_node (s , numa_mem_id ())-> barn ;
513+ struct kmem_cache_node * n = get_node (s , numa_mem_id ());
514+
515+ if (!n )
516+ return NULL ;
517+
518+ return n -> barn ;
511519}
512520
513521/*
@@ -4982,6 +4990,10 @@ __pcs_replace_empty_main(struct kmem_cache *s, struct slub_percpu_sheaves *pcs,
49824990 }
49834991
49844992 barn = get_barn (s );
4993+ if (!barn ) {
4994+ local_unlock (& s -> cpu_sheaves -> lock );
4995+ return NULL ;
4996+ }
49854997
49864998 full = barn_replace_empty_sheaf (barn , pcs -> main );
49874999
@@ -5153,13 +5165,20 @@ unsigned int alloc_from_pcs_bulk(struct kmem_cache *s, size_t size, void **p)
51535165 if (unlikely (pcs -> main -> size == 0 )) {
51545166
51555167 struct slab_sheaf * full ;
5168+ struct node_barn * barn ;
51565169
51575170 if (pcs -> spare && pcs -> spare -> size > 0 ) {
51585171 swap (pcs -> main , pcs -> spare );
51595172 goto do_alloc ;
51605173 }
51615174
5162- full = barn_replace_empty_sheaf (get_barn (s ), pcs -> main );
5175+ barn = get_barn (s );
5176+ if (!barn ) {
5177+ local_unlock (& s -> cpu_sheaves -> lock );
5178+ return allocated ;
5179+ }
5180+
5181+ full = barn_replace_empty_sheaf (barn , pcs -> main );
51635182
51645183 if (full ) {
51655184 stat (s , BARN_GET );
@@ -5314,6 +5333,7 @@ kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t gfp, unsigned int size)
53145333{
53155334 struct slub_percpu_sheaves * pcs ;
53165335 struct slab_sheaf * sheaf = NULL ;
5336+ struct node_barn * barn ;
53175337
53185338 if (unlikely (size > s -> sheaf_capacity )) {
53195339
@@ -5355,8 +5375,11 @@ kmem_cache_prefill_sheaf(struct kmem_cache *s, gfp_t gfp, unsigned int size)
53555375 pcs -> spare = NULL ;
53565376 stat (s , SHEAF_PREFILL_FAST );
53575377 } else {
5378+ barn = get_barn (s );
5379+
53585380 stat (s , SHEAF_PREFILL_SLOW );
5359- sheaf = barn_get_full_or_empty_sheaf (get_barn (s ));
5381+ if (barn )
5382+ sheaf = barn_get_full_or_empty_sheaf (barn );
53605383 if (sheaf && sheaf -> size )
53615384 stat (s , BARN_GET );
53625385 else
@@ -5426,7 +5449,7 @@ void kmem_cache_return_sheaf(struct kmem_cache *s, gfp_t gfp,
54265449 * If the barn has too many full sheaves or we fail to refill the sheaf,
54275450 * simply flush and free it.
54285451 */
5429- if (data_race (barn -> nr_full ) >= MAX_FULL_SHEAVES ||
5452+ if (! barn || data_race (barn -> nr_full ) >= MAX_FULL_SHEAVES ||
54305453 refill_sheaf (s , sheaf , gfp )) {
54315454 sheaf_flush_unused (s , sheaf );
54325455 free_empty_sheaf (s , sheaf );
@@ -5943,10 +5966,9 @@ static void __slab_free(struct kmem_cache *s, struct slab *slab,
59435966 * put the full sheaf there.
59445967 */
59455968static void __pcs_install_empty_sheaf (struct kmem_cache * s ,
5946- struct slub_percpu_sheaves * pcs , struct slab_sheaf * empty )
5969+ struct slub_percpu_sheaves * pcs , struct slab_sheaf * empty ,
5970+ struct node_barn * barn )
59475971{
5948- struct node_barn * barn ;
5949-
59505972 lockdep_assert_held (this_cpu_ptr (& s -> cpu_sheaves -> lock ));
59515973
59525974 /* This is what we expect to find if nobody interrupted us. */
@@ -5956,8 +5978,6 @@ static void __pcs_install_empty_sheaf(struct kmem_cache *s,
59565978 return ;
59575979 }
59585980
5959- barn = get_barn (s );
5960-
59615981 /*
59625982 * Unlikely because if the main sheaf had space, we would have just
59635983 * freed to it. Get rid of our empty sheaf.
@@ -6002,6 +6022,11 @@ __pcs_replace_full_main(struct kmem_cache *s, struct slub_percpu_sheaves *pcs)
60026022 lockdep_assert_held (this_cpu_ptr (& s -> cpu_sheaves -> lock ));
60036023
60046024 barn = get_barn (s );
6025+ if (!barn ) {
6026+ local_unlock (& s -> cpu_sheaves -> lock );
6027+ return NULL ;
6028+ }
6029+
60056030 put_fail = false;
60066031
60076032 if (!pcs -> spare ) {
@@ -6084,7 +6109,7 @@ __pcs_replace_full_main(struct kmem_cache *s, struct slub_percpu_sheaves *pcs)
60846109 }
60856110
60866111 pcs = this_cpu_ptr (s -> cpu_sheaves );
6087- __pcs_install_empty_sheaf (s , pcs , empty );
6112+ __pcs_install_empty_sheaf (s , pcs , empty , barn );
60886113
60896114 return pcs ;
60906115}
@@ -6121,8 +6146,9 @@ bool free_to_pcs(struct kmem_cache *s, void *object)
61216146
61226147static void rcu_free_sheaf (struct rcu_head * head )
61236148{
6149+ struct kmem_cache_node * n ;
61246150 struct slab_sheaf * sheaf ;
6125- struct node_barn * barn ;
6151+ struct node_barn * barn = NULL ;
61266152 struct kmem_cache * s ;
61276153
61286154 sheaf = container_of (head , struct slab_sheaf , rcu_head );
@@ -6139,7 +6165,11 @@ static void rcu_free_sheaf(struct rcu_head *head)
61396165 */
61406166 __rcu_free_sheaf_prepare (s , sheaf );
61416167
6142- barn = get_node (s , sheaf -> node )-> barn ;
6168+ n = get_node (s , sheaf -> node );
6169+ if (!n )
6170+ goto flush ;
6171+
6172+ barn = n -> barn ;
61436173
61446174 /* due to slab_free_hook() */
61456175 if (unlikely (sheaf -> size == 0 ))
@@ -6157,11 +6187,12 @@ static void rcu_free_sheaf(struct rcu_head *head)
61576187 return ;
61586188 }
61596189
6190+ flush :
61606191 stat (s , BARN_PUT_FAIL );
61616192 sheaf_flush_unused (s , sheaf );
61626193
61636194empty :
6164- if (data_race (barn -> nr_empty ) < MAX_EMPTY_SHEAVES ) {
6195+ if (barn && data_race (barn -> nr_empty ) < MAX_EMPTY_SHEAVES ) {
61656196 barn_put_empty_sheaf (barn , sheaf );
61666197 return ;
61676198 }
@@ -6191,6 +6222,10 @@ bool __kfree_rcu_sheaf(struct kmem_cache *s, void *obj)
61916222 }
61926223
61936224 barn = get_barn (s );
6225+ if (!barn ) {
6226+ local_unlock (& s -> cpu_sheaves -> lock );
6227+ goto fail ;
6228+ }
61946229
61956230 empty = barn_get_empty_sheaf (barn );
61966231
@@ -6304,6 +6339,8 @@ static void free_to_pcs_bulk(struct kmem_cache *s, size_t size, void **p)
63046339 goto do_free ;
63056340
63066341 barn = get_barn (s );
6342+ if (!barn )
6343+ goto no_empty ;
63076344
63086345 if (!pcs -> spare ) {
63096346 empty = barn_get_empty_sheaf (barn );
0 commit comments