diff --git a/mm/swap.c b/mm/swap.c index cd8f0150ba3a..a375af65f471 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -912,6 +912,7 @@ void lru_add_drain_all(void) #endif /* CONFIG_SMP */ atomic_t lru_disable_count = ATOMIC_INIT(0); +EXPORT_SYMBOL_GPL(lru_disable_count); /* * lru_cache_disable() needs to be called before we start compiling @@ -923,7 +924,12 @@ atomic_t lru_disable_count = ATOMIC_INIT(0); */ void lru_cache_disable(void) { - atomic_inc(&lru_disable_count); + /* + * If someone is already disabled lru_cache, just return with + * increasing the lru_disable_count. + */ + if (atomic_inc_not_zero(&lru_disable_count)) + return; /* * Readers of lru_disable_count are protected by either disabling * preemption or rcu_read_lock: @@ -943,7 +949,9 @@ void lru_cache_disable(void) #else lru_add_and_bh_lrus_drain(); #endif + atomic_inc(&lru_disable_count); } +EXPORT_SYMBOL_GPL(lru_cache_disable); /** * release_pages - batched put_page()