From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753183AbbGTJQV (ORCPT ); Mon, 20 Jul 2015 05:16:21 -0400 Received: from mailout4.samsung.com ([203.254.224.34]:59310 "EHLO mailout4.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752417AbbGTJQT (ORCPT ); Mon, 20 Jul 2015 05:16:19 -0400 X-AuditID: cbfee68e-f79c56d000006efb-da-55acbc61944e From: Vishnu Pratap Singh To: akpm@linux-foundation.org, linux@rasmusvillemoes.dk, riel@redhat.com, isimatu.yasuaki@jp.fujitsu.com, aquini@redhat.com, linux-kernel@vger.kernel.org Cc: cpgs@samsung.com, vishu13285@gmail.com, pintu.k@samsung.com, rohit.kr@samsung.com, Vishnu Pratap Singh Subject: [PATCH] lib/show_mem.c: correct reserved memory calculation Date: Mon, 20 Jul 2015 14:44:25 +0530 Message-id: <1437383665-29874-1-git-send-email-vishnu.ps@samsung.com> X-Mailer: git-send-email 1.7.9.5 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrHLMWRmVeSWpSXmKPExsWyRsSkVjdxz5pQg+vnlC3mrF/DZjHj4S8W i5eHNC2mT9C1uLxrDpvF41nz2Cz6vh9mt/h7ZT2LxfPmVhaLKX13GS22rHjI6sDtsXPWXXaP E08usXmcmPGbxeNCV7bH+31X2Tz6tqxi9Pi8SS6APYrLJiU1J7MstUjfLoEr40vXWZaCxcIV FzY8YW5g/MzfxcjJISFgIvH8wjkWCFtM4sK99WxdjFwcQgJLGSU+zpoAlOAAK9r62wQivohR 4s2fY6wQThMTUFETI0g3m4ChxIbZR9hBEiICsxklTn++wwjiMAu0MEpMPb2OCaRKWMBF4sqZ v2wgY1kEVCUOXi4FCfMKuErc6P8EtU1BYs4kG5BWCYF17BJrJ/4Ga2UREJD4NvkQVI2sxKYD zBBXS0ocXHGDZQKj4AJGhlWMoqkFyQXFSelFRnrFibnFpXnpesn5u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lYe3yzINM5svarYMz4nty g6dHV01oe87Zq6uVWrnsvf70qwE9PZ8K4n0PhEWrcGv0WHUxB1lONlzzWGRizrG9rIpzVklY n7/xanXHm2cZ130EpBI+OQWv6H+hzZvCejjUdr/t+VaeiKv6FfVy5peeNL0+bfFKiaU4I9FQ i7moOBEAikysB7sCAAA= DLP-Filter: Pass X-MTR: 20000000000000000@CPGS X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org CMA reserved memory is not part of total reserved memory. Currently when we print the total reserve memory it considers cma as part of reserve memory and do minus of totalcma_pages from reserved, which is wrong. In cases where total reserved is less than cma reserved we will get negative values & while printing we print as unsigned and we will get a very large value. Below is the show mem output on X86 ubuntu based system where CMA reserved is 100MB (25600 pages) & total reserved is ~40MB(10316 pages). And reserve memory shows a large value because of this bug. Before: [ 127.066430] 898908 pages RAM [ 127.066432] 671682 pages HighMem/MovableOnly [ 127.066434] 4294952012 pages reserved [ 127.066436] 25600 pages cma reserved After: [ 44.663129] 898908 pages RAM [ 44.663130] 671682 pages HighMem/MovableOnly [ 44.663130] 10316 pages reserved [ 44.663131] 25600 pages cma reserved Also this patch change printk to pr_info. Signed-off-by: Vishnu Pratap Singh --- lib/show_mem.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/lib/show_mem.c b/lib/show_mem.c index adc98e18..0af5ede 100644 --- a/lib/show_mem.c +++ b/lib/show_mem.c @@ -14,7 +14,7 @@ void show_mem(unsigned int filter) pg_data_t *pgdat; unsigned long total = 0, reserved = 0, highmem = 0; - printk("Mem-Info:\n"); + pr_info("Mem-Info:\n"); show_free_areas(filter); for_each_online_pgdat(pgdat) { @@ -36,19 +36,18 @@ void show_mem(unsigned int filter) pgdat_resize_unlock(pgdat, &flags); } - printk("%lu pages RAM\n", total); - printk("%lu pages HighMem/MovableOnly\n", highmem); + pr_info("%lu pages RAM\n", total); + pr_info("%lu pages HighMem/MovableOnly\n", highmem); + pr_info("%lu pages reserved\n", reserved); #ifdef CONFIG_CMA - printk("%lu pages reserved\n", (reserved - totalcma_pages)); - printk("%lu pages cma reserved\n", totalcma_pages); -#else - printk("%lu pages reserved\n", reserved); + pr_info("%lu pages cma reserved\n", totalcma_pages); #endif #ifdef CONFIG_QUICKLIST - printk("%lu pages in pagetable cache\n", + pr_info("%lu pages in pagetable cache\n", quicklist_total_size()); #endif #ifdef CONFIG_MEMORY_FAILURE - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages)); + pr_info("%lu pages hwpoisoned\n", + atomic_long_read(&num_poisoned_pages)); #endif } -- 1.7.9.5