@@ -131,6 +131,9 @@ static inline int kmem_cache_debug(struct kmem_cache *s)
131131/* Enable to test recovery from slab corruption on boot */
132132#undef SLUB_RESILIENCY_TEST
133133
134+ /* Enable to log cmpxchg failures */
135+ #undef SLUB_DEBUG_CMPXCHG
136+
134137/*
135138 * Mininum number of partial slabs. These will be left on the partial
136139 * lists even if they are empty. kmem_cache_shrink may reclaim them.
@@ -170,6 +173,7 @@ static inline int kmem_cache_debug(struct kmem_cache *s)
170173
171174/* Internal SLUB flags */
172175#define __OBJECT_POISON 0x80000000UL /* Poison object */
176+ #define __CMPXCHG_DOUBLE 0x40000000UL /* Use cmpxchg_double */
173177
174178static int kmem_size = sizeof (struct kmem_cache );
175179
@@ -338,6 +342,37 @@ static inline int oo_objects(struct kmem_cache_order_objects x)
338342 return x .x & OO_MASK ;
339343}
340344
345+ static inline bool cmpxchg_double_slab (struct kmem_cache * s , struct page * page ,
346+ void * freelist_old , unsigned long counters_old ,
347+ void * freelist_new , unsigned long counters_new ,
348+ const char * n )
349+ {
350+ #ifdef CONFIG_CMPXCHG_DOUBLE
351+ if (s -> flags & __CMPXCHG_DOUBLE ) {
352+ if (cmpxchg_double (& page -> freelist ,
353+ freelist_old , counters_old ,
354+ freelist_new , counters_new ))
355+ return 1 ;
356+ } else
357+ #endif
358+ {
359+ if (page -> freelist == freelist_old && page -> counters == counters_old ) {
360+ page -> freelist = freelist_new ;
361+ page -> counters = counters_new ;
362+ return 1 ;
363+ }
364+ }
365+
366+ cpu_relax ();
367+ stat (s , CMPXCHG_DOUBLE_FAIL );
368+
369+ #ifdef SLUB_DEBUG_CMPXCHG
370+ printk (KERN_INFO "%s %s: cmpxchg double redo " , n , s -> name );
371+ #endif
372+
373+ return 0 ;
374+ }
375+
341376#ifdef CONFIG_SLUB_DEBUG
342377/*
343378 * Determine a map of object in use on a page.
@@ -2596,6 +2631,12 @@ static int kmem_cache_open(struct kmem_cache *s,
25962631 }
25972632 }
25982633
2634+ #ifdef CONFIG_CMPXCHG_DOUBLE
2635+ if (system_has_cmpxchg_double () && (s -> flags & SLAB_DEBUG_FLAGS ) == 0 )
2636+ /* Enable fast mode */
2637+ s -> flags |= __CMPXCHG_DOUBLE ;
2638+ #endif
2639+
25992640 /*
26002641 * The larger the object size is, the more pages we want on the partial
26012642 * list to avoid pounding the page allocator excessively.
@@ -4248,8 +4289,10 @@ static ssize_t sanity_checks_store(struct kmem_cache *s,
42484289 const char * buf , size_t length )
42494290{
42504291 s -> flags &= ~SLAB_DEBUG_FREE ;
4251- if (buf [0 ] == '1' )
4292+ if (buf [0 ] == '1' ) {
4293+ s -> flags &= ~__CMPXCHG_DOUBLE ;
42524294 s -> flags |= SLAB_DEBUG_FREE ;
4295+ }
42534296 return length ;
42544297}
42554298SLAB_ATTR (sanity_checks );
@@ -4263,8 +4306,10 @@ static ssize_t trace_store(struct kmem_cache *s, const char *buf,
42634306 size_t length )
42644307{
42654308 s -> flags &= ~SLAB_TRACE ;
4266- if (buf [0 ] == '1' )
4309+ if (buf [0 ] == '1' ) {
4310+ s -> flags &= ~__CMPXCHG_DOUBLE ;
42674311 s -> flags |= SLAB_TRACE ;
4312+ }
42684313 return length ;
42694314}
42704315SLAB_ATTR (trace );
@@ -4281,8 +4326,10 @@ static ssize_t red_zone_store(struct kmem_cache *s,
42814326 return - EBUSY ;
42824327
42834328 s -> flags &= ~SLAB_RED_ZONE ;
4284- if (buf [0 ] == '1' )
4329+ if (buf [0 ] == '1' ) {
4330+ s -> flags &= ~__CMPXCHG_DOUBLE ;
42854331 s -> flags |= SLAB_RED_ZONE ;
4332+ }
42864333 calculate_sizes (s , -1 );
42874334 return length ;
42884335}
@@ -4300,8 +4347,10 @@ static ssize_t poison_store(struct kmem_cache *s,
43004347 return - EBUSY ;
43014348
43024349 s -> flags &= ~SLAB_POISON ;
4303- if (buf [0 ] == '1' )
4350+ if (buf [0 ] == '1' ) {
4351+ s -> flags &= ~__CMPXCHG_DOUBLE ;
43044352 s -> flags |= SLAB_POISON ;
4353+ }
43054354 calculate_sizes (s , -1 );
43064355 return length ;
43074356}
@@ -4319,8 +4368,10 @@ static ssize_t store_user_store(struct kmem_cache *s,
43194368 return - EBUSY ;
43204369
43214370 s -> flags &= ~SLAB_STORE_USER ;
4322- if (buf [0 ] == '1' )
4371+ if (buf [0 ] == '1' ) {
4372+ s -> flags &= ~__CMPXCHG_DOUBLE ;
43234373 s -> flags |= SLAB_STORE_USER ;
4374+ }
43244375 calculate_sizes (s , -1 );
43254376 return length ;
43264377}
@@ -4493,6 +4544,8 @@ STAT_ATTR(DEACTIVATE_TO_HEAD, deactivate_to_head);
44934544STAT_ATTR (DEACTIVATE_TO_TAIL , deactivate_to_tail );
44944545STAT_ATTR (DEACTIVATE_REMOTE_FREES , deactivate_remote_frees );
44954546STAT_ATTR (ORDER_FALLBACK , order_fallback );
4547+ STAT_ATTR (CMPXCHG_DOUBLE_CPU_FAIL , cmpxchg_double_cpu_fail );
4548+ STAT_ATTR (CMPXCHG_DOUBLE_FAIL , cmpxchg_double_fail );
44964549#endif
44974550
44984551static struct attribute * slab_attrs [] = {
@@ -4550,6 +4603,8 @@ static struct attribute *slab_attrs[] = {
45504603 & deactivate_to_tail_attr .attr ,
45514604 & deactivate_remote_frees_attr .attr ,
45524605 & order_fallback_attr .attr ,
4606+ & cmpxchg_double_fail_attr .attr ,
4607+ & cmpxchg_double_cpu_fail_attr .attr ,
45534608#endif
45544609#ifdef CONFIG_FAILSLAB
45554610 & failslab_attr .attr ,
0 commit comments