From 7c2729a05135dcdb3984ca5d92613080d056d69c Mon Sep 17 00:00:00 2001 From: Tang Yizhou Date: Sat, 30 Oct 2021 11:09:26 +0800 Subject: [PATCH] share_pool: Turn the negative statistics into zeros MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ascend inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I4EUVI CVE: NA ------------------------------------------------- For the implementation of Linux, statistics of RSS has a maximum 64 pages deviation (256KB) but the track of share pool are all precise. So the calculation results may be negative and confuse people. We decide to show zeros when the results are negative. It is still imprecise, but maybe better. Signed-off-by: Tang Yizhou Reviewed-by: Ding Tianhong Reviewed-by: KefengĀ  Wang Signed-off-by: Yang Yingliang Reviewed-by: Weilong Chen Signed-off-by: Yang Yingliang --- mm/share_pool.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mm/share_pool.c b/mm/share_pool.c index 37a5b94726f6..99e63bb7762a 100644 --- a/mm/share_pool.c +++ b/mm/share_pool.c @@ -2788,9 +2788,14 @@ static int idr_proc_stat_cb(int id, void *p, void *data) file = get_mm_counter(mm, MM_FILEPAGES); shmem = get_mm_counter(mm, MM_SHMEMPAGES); total_rss = anon + file + shmem; + /* + * Statistics of RSS has a maximum 64 pages deviation (256KB). + * Please check_sync_rss_stat(). + */ non_sp_res = page2kb(total_rss) - sp_alloc_nsize; + non_sp_res = non_sp_res < 0 ? 0 : non_sp_res; non_sp_shm = page2kb(shmem) - sp_alloc_nsize; - non_sp_shm = non_sp_shm < 0 ? 0 : non_sp_shm; /* to be investigated */ + non_sp_shm = non_sp_shm < 0 ? 0 : non_sp_shm; seq_printf(seq, "%-8d ", id); if (spg_id == 0) -- GitLab