Skip to content

Commit c9f8f12

Browse files
committed
slab: don't batch kvfree_rcu() with SLUB_TINY
kvfree_rcu() is batched for better performance except on TINY_RCU, which is a simple implementation for small UP systems. Similarly SLUB_TINY is an option intended for small systems, whether or not used together with TINY_RCU. In case SLUB_TINY is used with !TINY_RCU, it makes arguably sense to not do the batching and limit the memory footprint. It's also suboptimal to have RCU-specific #ifdefs in slab code. With that, add CONFIG_KVFREE_RCU_BATCHED to determine whether batching kvfree_rcu() implementation is used. It is not set by a user prompt, but enabled by default and disabled in case TINY_RCU or SLUB_TINY are enabled. Use the new config for #ifdef's in slab code and extend their scope to cover all code used by the batched kvfree_rcu(). For example there's no need to perform kvfree_rcu_init() if the batching is disabled. Reviewed-by: Uladzislau Rezki (Sony) <[email protected]> Reviewed-by: Joel Fernandes (Google) <[email protected]> Reviewed-by: Hyeonggon Yoo <[email protected]> Tested-by: Paul E. McKenney <[email protected]> Signed-off-by: Vlastimil Babka <[email protected]>
1 parent 49d5377 commit c9f8f12

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

include/linux/slab.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1083,7 +1083,7 @@ extern void kvfree_sensitive(const void *addr, size_t len);
10831083

10841084
unsigned int kmem_cache_size(struct kmem_cache *s);
10851085

1086-
#ifdef CONFIG_TINY_RCU
1086+
#ifndef CONFIG_KVFREE_RCU_BATCHED
10871087
static inline void kvfree_rcu_barrier(void)
10881088
{
10891089
rcu_barrier();

mm/Kconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ menu "Slab allocator options"
242242
config SLUB
243243
def_bool y
244244

245+
config KVFREE_RCU_BATCHED
246+
def_bool y
247+
depends on !SLUB_TINY && !TINY_RCU
248+
245249
config SLUB_TINY
246250
bool "Configure for minimal memory footprint"
247251
depends on EXPERT

mm/slab_common.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,7 +1284,7 @@ EXPORT_TRACEPOINT_SYMBOL(kmem_cache_alloc);
12841284
EXPORT_TRACEPOINT_SYMBOL(kfree);
12851285
EXPORT_TRACEPOINT_SYMBOL(kmem_cache_free);
12861286

1287-
#ifdef CONFIG_TINY_RCU
1287+
#ifndef CONFIG_KVFREE_RCU_BATCHED
12881288

12891289
void kvfree_call_rcu(struct rcu_head *head, void *ptr)
12901290
{
@@ -1301,7 +1301,11 @@ void kvfree_call_rcu(struct rcu_head *head, void *ptr)
13011301
}
13021302
EXPORT_SYMBOL_GPL(kvfree_call_rcu);
13031303

1304-
#endif
1304+
void __init kvfree_rcu_init(void)
1305+
{
1306+
}
1307+
1308+
#else /* CONFIG_KVFREE_RCU_BATCHED */
13051309

13061310
/*
13071311
* This rcu parameter is runtime-read-only. It reflects
@@ -1879,8 +1883,6 @@ add_ptr_to_bulk_krc_lock(struct kfree_rcu_cpu **krcp,
18791883
return true;
18801884
}
18811885

1882-
#if !defined(CONFIG_TINY_RCU)
1883-
18841886
static enum hrtimer_restart
18851887
schedule_page_work_fn(struct hrtimer *t)
18861888
{
@@ -2089,8 +2091,6 @@ void kvfree_rcu_barrier(void)
20892091
}
20902092
EXPORT_SYMBOL_GPL(kvfree_rcu_barrier);
20912093

2092-
#endif /* #if !defined(CONFIG_TINY_RCU) */
2093-
20942094
static unsigned long
20952095
kfree_rcu_shrink_count(struct shrinker *shrink, struct shrink_control *sc)
20962096
{
@@ -2180,3 +2180,6 @@ void __init kvfree_rcu_init(void)
21802180

21812181
shrinker_register(kfree_rcu_shrinker);
21822182
}
2183+
2184+
#endif /* CONFIG_KVFREE_RCU_BATCHED */
2185+

0 commit comments

Comments
 (0)