mm: zswap: function ordering: zswap_pools
Move the operations against the global zswap_pools list (current pool, last, find) to the pool section. Link: https://lkml.kernel.org/r/20240130014208.565554-13-hannes@cmpxchg.org Signed-off-by: Johannes Weiner <hannes@cmpxchg.org> Reviewed-by: Nhat Pham <nphamcs@gmail.com> Cc: Chengming Zhou <zhouchengming@bytedance.com> Cc: Yosry Ahmed <yosryahmed@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
This commit is contained in:
parent
39f3ec8eaa
commit
c1a0ecb82b
150
mm/zswap.c
150
mm/zswap.c
@ -517,6 +517,79 @@ static void zswap_pool_put(struct zswap_pool *pool)
|
||||
kref_put(&pool->kref, __zswap_pool_empty);
|
||||
}
|
||||
|
||||
static struct zswap_pool *__zswap_pool_current(void)
|
||||
{
|
||||
struct zswap_pool *pool;
|
||||
|
||||
pool = list_first_or_null_rcu(&zswap_pools, typeof(*pool), list);
|
||||
WARN_ONCE(!pool && zswap_has_pool,
|
||||
"%s: no page storage pool!\n", __func__);
|
||||
|
||||
return pool;
|
||||
}
|
||||
|
||||
static struct zswap_pool *zswap_pool_current(void)
|
||||
{
|
||||
assert_spin_locked(&zswap_pools_lock);
|
||||
|
||||
return __zswap_pool_current();
|
||||
}
|
||||
|
||||
static struct zswap_pool *zswap_pool_current_get(void)
|
||||
{
|
||||
struct zswap_pool *pool;
|
||||
|
||||
rcu_read_lock();
|
||||
|
||||
pool = __zswap_pool_current();
|
||||
if (!zswap_pool_get(pool))
|
||||
pool = NULL;
|
||||
|
||||
rcu_read_unlock();
|
||||
|
||||
return pool;
|
||||
}
|
||||
|
||||
static struct zswap_pool *zswap_pool_last_get(void)
|
||||
{
|
||||
struct zswap_pool *pool, *last = NULL;
|
||||
|
||||
rcu_read_lock();
|
||||
|
||||
list_for_each_entry_rcu(pool, &zswap_pools, list)
|
||||
last = pool;
|
||||
WARN_ONCE(!last && zswap_has_pool,
|
||||
"%s: no page storage pool!\n", __func__);
|
||||
if (!zswap_pool_get(last))
|
||||
last = NULL;
|
||||
|
||||
rcu_read_unlock();
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
/* type and compressor must be null-terminated */
|
||||
static struct zswap_pool *zswap_pool_find_get(char *type, char *compressor)
|
||||
{
|
||||
struct zswap_pool *pool;
|
||||
|
||||
assert_spin_locked(&zswap_pools_lock);
|
||||
|
||||
list_for_each_entry_rcu(pool, &zswap_pools, list) {
|
||||
if (strcmp(pool->tfm_name, compressor))
|
||||
continue;
|
||||
/* all zpools share the same type */
|
||||
if (strcmp(zpool_get_type(pool->zpools[0]), type))
|
||||
continue;
|
||||
/* if we can't get it, it's about to be destroyed */
|
||||
if (!zswap_pool_get(pool))
|
||||
continue;
|
||||
return pool;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* should be called under RCU */
|
||||
#ifdef CONFIG_MEMCG
|
||||
static inline struct mem_cgroup *mem_cgroup_from_entry(struct zswap_entry *entry)
|
||||
@ -937,83 +1010,6 @@ static int zswap_cpu_comp_dead(unsigned int cpu, struct hlist_node *node)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*********************************
|
||||
* pool functions
|
||||
**********************************/
|
||||
|
||||
static struct zswap_pool *__zswap_pool_current(void)
|
||||
{
|
||||
struct zswap_pool *pool;
|
||||
|
||||
pool = list_first_or_null_rcu(&zswap_pools, typeof(*pool), list);
|
||||
WARN_ONCE(!pool && zswap_has_pool,
|
||||
"%s: no page storage pool!\n", __func__);
|
||||
|
||||
return pool;
|
||||
}
|
||||
|
||||
static struct zswap_pool *zswap_pool_current(void)
|
||||
{
|
||||
assert_spin_locked(&zswap_pools_lock);
|
||||
|
||||
return __zswap_pool_current();
|
||||
}
|
||||
|
||||
static struct zswap_pool *zswap_pool_current_get(void)
|
||||
{
|
||||
struct zswap_pool *pool;
|
||||
|
||||
rcu_read_lock();
|
||||
|
||||
pool = __zswap_pool_current();
|
||||
if (!zswap_pool_get(pool))
|
||||
pool = NULL;
|
||||
|
||||
rcu_read_unlock();
|
||||
|
||||
return pool;
|
||||
}
|
||||
|
||||
static struct zswap_pool *zswap_pool_last_get(void)
|
||||
{
|
||||
struct zswap_pool *pool, *last = NULL;
|
||||
|
||||
rcu_read_lock();
|
||||
|
||||
list_for_each_entry_rcu(pool, &zswap_pools, list)
|
||||
last = pool;
|
||||
WARN_ONCE(!last && zswap_has_pool,
|
||||
"%s: no page storage pool!\n", __func__);
|
||||
if (!zswap_pool_get(last))
|
||||
last = NULL;
|
||||
|
||||
rcu_read_unlock();
|
||||
|
||||
return last;
|
||||
}
|
||||
|
||||
/* type and compressor must be null-terminated */
|
||||
static struct zswap_pool *zswap_pool_find_get(char *type, char *compressor)
|
||||
{
|
||||
struct zswap_pool *pool;
|
||||
|
||||
assert_spin_locked(&zswap_pools_lock);
|
||||
|
||||
list_for_each_entry_rcu(pool, &zswap_pools, list) {
|
||||
if (strcmp(pool->tfm_name, compressor))
|
||||
continue;
|
||||
/* all zpools share the same type */
|
||||
if (strcmp(zpool_get_type(pool->zpools[0]), type))
|
||||
continue;
|
||||
/* if we can't get it, it's about to be destroyed */
|
||||
if (!zswap_pool_get(pool))
|
||||
continue;
|
||||
return pool;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static enum lru_status shrink_memcg_cb(struct list_head *item, struct list_lru_one *l,
|
||||
spinlock_t *lock, void *arg)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user