moto_swap:fix kernel panic on memcg conf

the app_score in default oemdata(hybridswap) is initialized as 300
however, the userspace only configures 100, 200, 400, 600 groups,
there is no room fit for initial value, while go through all the
memcgroups, it is not possible to find a slot to fit in the default
value, the outbond index causes the panic

Change-Id: I45e59a2629c17ae9eaa326c749d6ed4b51e3b2e7
Signed-off-by: wangwang <wangwang@motorola.com>
Reviewed-on: https://gerrit.mot.com/2782610
SLTApproved: Slta Waiver
SME-Granted: SME Approvals Granted
Reviewed-by: Xiangpo Zhao <zhaoxp3@motorola.com>
Tested-by: Jira Key
Submit-Approved: Jira Key
This commit is contained in:
wangwang 2023-11-01 15:23:19 +08:00 • committed by Wang Wang
commit 16c65f5da8

View file

@ -397,21 +397,26 @@ static void swapd_mcgs_setup_parse(int level_num)
{
struct mem_cgroup *memcg = NULL;
memcg_hybs_t *hybs = NULL;
int i;
int i, k;
while ((memcg = fetch_next_memcg(memcg))) {
hybs = MEMCGRP_ITEM_DATA(memcg);
if (!hybs) continue;
for (i = 0; i < level_num; ++i) {
for (i = level_num - 1, k = 0; i >= 0; i--) {
if (atomic64_read(&hybs->app_grade) >= zswap_param[i].min_grade &&
atomic64_read(&hybs->app_grade) <= zswap_param[i].max_grade)
atomic64_read(&hybs->app_grade) <= zswap_param[i].max_grade) {
k = i;
break;
}
else if (atomic64_read(&hybs->app_grade) <= zswap_param[i].max_grade) {
k = i;
}
}
atomic_set(&hybs->mem2zram_scale, zswap_param[i].mem2zram_scale);
atomic_set(&hybs->zram2ufs_scale, zswap_param[i].zram2ufs_scale);
atomic_set(&hybs->pagefault_level, zswap_param[i].pagefault_level);
atomic_set(&hybs->mem2zram_scale, zswap_param[k].mem2zram_scale);
atomic_set(&hybs->zram2ufs_scale, zswap_param[k].zram2ufs_scale);
atomic_set(&hybs->pagefault_level, zswap_param[k].pagefault_level);
}
}