From: Tang Yizhou tangyizhou@huawei.com
ascend inclusion category: feature bugzilla: https://gitee.com/openeuler/kernel/issues/I4EUVI CVE: NA
------------------------------------------------- spg_overview() will show how many normal page memory and hugepage memory are allocated for a sp_group.
Signed-off-by: Tang Yizhou tangyizhou@huawei.com Reviewed-by: Ding Tianhong dingtianhong@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com Reviewed-by: Weilong Chen chenweilong@huawei.com Signed-off-by: Yang Yingliang yangyingliang@huawei.com --- include/linux/share_pool.h | 12 ++++++++---- mm/share_pool.c | 28 ++++++++++++++++++++++------ 2 files changed, 30 insertions(+), 10 deletions(-)
diff --git a/include/linux/share_pool.h b/include/linux/share_pool.h index 3c5a41ae5bd14..eb0358bb6633b 100644 --- a/include/linux/share_pool.h +++ b/include/linux/share_pool.h @@ -66,6 +66,8 @@ extern bool vmap_allow_huge; */ struct sp_group { int id; + /* record the number of hugepage allocation failures */ + int hugepage_failures; struct file *file; struct file *file_hugetlb; /* list head of processes */ @@ -76,12 +78,14 @@ struct sp_group { atomic_t spa_num; /* total size of all sp_area from sp_alloc and k2u(spg) */ atomic64_t size; - /* record the number of hugepage allocation failures */ - int hugepage_failures; - /* is_alive == false means it's being destroyed */ - bool is_alive; + /* total size of all sp_area from sp_alloc normal page */ + atomic64_t alloc_nsize; + /* total size of all sp_area from sp_alloc hugepage */ + atomic64_t alloc_hsize; /* we define the creator process of a sp_group as owner */ struct task_struct *owner; + /* is_alive == false means it's being destroyed */ + bool is_alive; /* dvpp_multi_spaces == true means multiple dvpp 16G spaces are set */ bool dvpp_multi_spaces; unsigned long dvpp_va_start; diff --git a/mm/share_pool.c b/mm/share_pool.c index eb5fe5a6d616e..fb0a8f1b54405 100644 --- a/mm/share_pool.c +++ b/mm/share_pool.c @@ -52,8 +52,8 @@ #define spg_valid(spg) ((spg) && ((spg)->is_alive == true)) #define ESPGMMEXIT 4000
-#define byte2kb(size) ((size) / 1024) -#define byte2mb(size) ((size) / 1024 / 1024) +#define byte2kb(size) ((size) >> 10) +#define byte2mb(size) ((size) >> 20)
/* mdc scene hack */ int enable_mdc_default_group; @@ -366,6 +366,8 @@ static struct sp_group *find_or_alloc_sp_group(int spg_id) spg->id = spg_id; atomic_set(&spg->spa_num, 0); atomic64_set(&spg->size, 0); + atomic64_set(&spg->alloc_nsize, 0); + atomic64_set(&spg->alloc_hsize, 0); spg->is_alive = true; spg->hugepage_failures = 0; spg->dvpp_multi_spaces = false; @@ -925,6 +927,12 @@ static struct sp_area *sp_alloc_area(unsigned long size, unsigned long flags, if (spa->spg) { atomic_inc(&spg->spa_num); atomic64_add(size, &spg->size); + if (type == SPA_TYPE_ALLOC) { + if (spa->is_hugepage) + atomic64_add(size, &spg->alloc_hsize); + else + atomic64_add(size, &spg->alloc_nsize); + } atomic_inc(&spg_stat.spa_total_num); atomic64_add(size, &spg_stat.spa_total_size); list_add_tail(&spa->link, &spg->spa_list); @@ -1003,6 +1011,12 @@ static void sp_free_area(struct sp_area *spa) if (spa->spg) { atomic_dec(&spa->spg->spa_num); atomic64_sub(spa->real_size, &spa->spg->size); + if (spa->type == SPA_TYPE_ALLOC) { + if (spa->is_hugepage) + atomic64_sub(spa->real_size, &spa->spg->alloc_hsize); + else + atomic64_sub(spa->real_size, &spa->spg->alloc_nsize); + } atomic_dec(&spg_stat.spa_total_num); atomic64_sub(spa->real_size, &spg_stat.spa_total_size); list_del(&spa->link); @@ -2509,16 +2523,18 @@ static int idr_spg_stat_cb(int id, void *p, void *data) struct sp_group *spg = p; struct seq_file *seq = data;
- seq_printf(seq, "Group %-10d size: %13ld KB, spa num: %d.\n", - id, byte2kb(atomic64_read(&spg->size)), - atomic_read(&spg->spa_num)); + seq_printf(seq, "Group %6d size: %ld KB, spa num: %d, normal alloc: %ld KB, " + "huge alloc: %ld KB\n", + id, byte2kb(atomic64_read(&spg->size)), atomic_read(&spg->spa_num), + byte2kb(atomic64_read(&spg->alloc_nsize)), + byte2kb(atomic64_read(&spg->alloc_hsize)));
return 0; }
static void spg_overview_show(struct seq_file *seq) { - seq_printf(seq, "Share pool total size: %13ld KB, spa total num: %d.\n", + seq_printf(seq, "Share pool total size: %ld KB, spa total num: %d.\n", byte2kb(atomic64_read(&spg_stat.spa_total_size)), atomic_read(&spg_stat.spa_total_num)); mutex_lock(&sp_mutex);