linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] mm: cma: split cma-reserved in dmesg log
@ 2014-10-20  7:33 Pintu Kumar
  2014-10-20  9:35 ` Michal Nazarewicz
                   ` (3 more replies)
  0 siblings, 4 replies; 20+ messages in thread
From: Pintu Kumar @ 2014-10-20  7:33 UTC (permalink / raw)
  To: akpm, hannes, riel, mgorman, vdavydov, nasa4836, ddstreet,
	m.szyprowski, pintu.k, mina86, iamjoonsoo.kim, aneesh.kumar,
	lauraa, gioh.kim, rientjes, vbabka, sasha.levin, linux-kernel,
	linux-mm
  Cc: cpgs, pintu_agarwal, vishnu.ps, rohit.kr, ed.savinay

When the system boots up, in the dmesg logs we can see
the memory statistics along with total reserved as below.
Memory: 458840k/458840k available, 65448k reserved, 0K highmem

When CMA is enabled, still the total reserved memory remains the same.
However, the CMA memory is not considered as reserved.
But, when we see /proc/meminfo, the CMA memory is part of free memory.
This creates confusion.
This patch corrects the problem by properly substracting the CMA reserved
memory from the total reserved memory in dmesg logs.

Below is the dmesg snaphot from an arm based device with 512MB RAM and
12MB single CMA region.

Before this change:
Memory: 458840k/458840k available, 65448k reserved, 0K highmem

After this change:
Memory: 458840k/458840k available, 53160k reserved, 12288k cma-reserved, 0K highmem

Signed-off-by: Pintu Kumar <pintu.k@samsung.com>
Signed-off-by: Vishnu Pratap Singh <vishnu.ps@samsung.com>
---
 include/linux/swap.h | 3 +++
 mm/cma.c             | 2 ++
 mm/page_alloc.c      | 8 ++++++++
 3 files changed, 13 insertions(+)

diff --git a/include/linux/swap.h b/include/linux/swap.h
index 37a585b..beb84be 100644
--- a/include/linux/swap.h
+++ b/include/linux/swap.h
@@ -295,6 +295,9 @@ static inline void workingset_node_shadows_dec(struct radix_tree_node *node)
 /* linux/mm/page_alloc.c */
 extern unsigned long totalram_pages;
 extern unsigned long totalreserve_pages;
+#ifdef CONFIG_CMA
+extern unsigned long totalcma_pages;
+#endif
 extern unsigned long dirty_balance_reserve;
 extern unsigned long nr_free_buffer_pages(void);
 extern unsigned long nr_free_pagecache_pages(void);
diff --git a/mm/cma.c b/mm/cma.c
index 963bc4a..73fe7be 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -45,6 +45,7 @@ struct cma {
 static struct cma cma_areas[MAX_CMA_AREAS];
 static unsigned cma_area_count;
 static DEFINE_MUTEX(cma_mutex);
+unsigned long totalcma_pages __read_mostly;
 
 phys_addr_t cma_get_base(struct cma *cma)
 {
@@ -288,6 +289,7 @@ int __init cma_declare_contiguous(phys_addr_t base,
 	if (ret)
 		goto err;
 
+	totalcma_pages += (size / PAGE_SIZE);
 	pr_info("Reserved %ld MiB at %08lx\n", (unsigned long)size / SZ_1M,
 		(unsigned long)base);
 	return 0;
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index dd73f9a..c6165ac 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -5521,6 +5521,9 @@ void __init mem_init_print_info(const char *str)
 	pr_info("Memory: %luK/%luK available "
 	       "(%luK kernel code, %luK rwdata, %luK rodata, "
 	       "%luK init, %luK bss, %luK reserved"
+#ifdef CONFIG_CMA
+		", %luK cma-reserved"
+#endif
 #ifdef	CONFIG_HIGHMEM
 	       ", %luK highmem"
 #endif
@@ -5528,7 +5531,12 @@ void __init mem_init_print_info(const char *str)
 	       nr_free_pages() << (PAGE_SHIFT-10), physpages << (PAGE_SHIFT-10),
 	       codesize >> 10, datasize >> 10, rosize >> 10,
 	       (init_data_size + init_code_size) >> 10, bss_size >> 10,
+#ifdef CONFIG_CMA
+	       (physpages - totalram_pages - totalcma_pages) << (PAGE_SHIFT-10),
+	       totalcma_pages << (PAGE_SHIFT-10),
+#else
 	       (physpages - totalram_pages) << (PAGE_SHIFT-10),
+#endif
 #ifdef	CONFIG_HIGHMEM
 	       totalhigh_pages << (PAGE_SHIFT-10),
 #endif
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH] mm: cma: split cma-reserved in dmesg log
  2014-10-20  7:33 [PATCH] mm: cma: split cma-reserved in dmesg log Pintu Kumar
@ 2014-10-20  9:35 ` Michal Nazarewicz
  2014-10-20 22:48 ` Andrew Morton
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 20+ messages in thread
From: Michal Nazarewicz @ 2014-10-20  9:35 UTC (permalink / raw)
  To: Pintu Kumar, akpm, hannes, riel, mgorman, vdavydov, nasa4836,
	ddstreet, m.szyprowski, pintu.k, iamjoonsoo.kim, aneesh.kumar,
	lauraa, gioh.kim, rientjes, vbabka, sasha.levin, linux-kernel,
	linux-mm
  Cc: cpgs, pintu_agarwal, vishnu.ps, rohit.kr, ed.savinay

On Mon, Oct 20 2014, Pintu Kumar <pintu.k@samsung.com> wrote:
> When the system boots up, in the dmesg logs we can see
> the memory statistics along with total reserved as below.
> Memory: 458840k/458840k available, 65448k reserved, 0K highmem
>
> When CMA is enabled, still the total reserved memory remains the same.
> However, the CMA memory is not considered as reserved.
> But, when we see /proc/meminfo, the CMA memory is part of free memory.
> This creates confusion.
> This patch corrects the problem by properly substracting the CMA reserved
> memory from the total reserved memory in dmesg logs.
>
> Below is the dmesg snaphot from an arm based device with 512MB RAM and
> 12MB single CMA region.
>
> Before this change:
> Memory: 458840k/458840k available, 65448k reserved, 0K highmem
>
> After this change:
> Memory: 458840k/458840k available, 53160k reserved, 12288k cma-reserved, 0K highmem
>
> Signed-off-by: Pintu Kumar <pintu.k@samsung.com>
> Signed-off-by: Vishnu Pratap Singh <vishnu.ps@samsung.com>

Acked-by: Michal Nazarewicz <mina86@mina86.com>

> ---
>  include/linux/swap.h | 3 +++
>  mm/cma.c             | 2 ++
>  mm/page_alloc.c      | 8 ++++++++
>  3 files changed, 13 insertions(+)
>
> diff --git a/include/linux/swap.h b/include/linux/swap.h
> index 37a585b..beb84be 100644
> --- a/include/linux/swap.h
> +++ b/include/linux/swap.h
> @@ -295,6 +295,9 @@ static inline void workingset_node_shadows_dec(struct radix_tree_node *node)
>  /* linux/mm/page_alloc.c */
>  extern unsigned long totalram_pages;
>  extern unsigned long totalreserve_pages;
> +#ifdef CONFIG_CMA
> +extern unsigned long totalcma_pages;
> +#endif
>  extern unsigned long dirty_balance_reserve;
>  extern unsigned long nr_free_buffer_pages(void);
>  extern unsigned long nr_free_pagecache_pages(void);
> diff --git a/mm/cma.c b/mm/cma.c
> index 963bc4a..73fe7be 100644
> --- a/mm/cma.c
> +++ b/mm/cma.c
> @@ -45,6 +45,7 @@ struct cma {
>  static struct cma cma_areas[MAX_CMA_AREAS];
>  static unsigned cma_area_count;
>  static DEFINE_MUTEX(cma_mutex);
> +unsigned long totalcma_pages __read_mostly;

It's not __read_mostly.

>  
>  phys_addr_t cma_get_base(struct cma *cma)
>  {
> @@ -288,6 +289,7 @@ int __init cma_declare_contiguous(phys_addr_t base,
>  	if (ret)
>  		goto err;
>  
> +	totalcma_pages += (size / PAGE_SIZE);
>  	pr_info("Reserved %ld MiB at %08lx\n", (unsigned long)size / SZ_1M,
>  		(unsigned long)base);
>  	return 0;
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index dd73f9a..c6165ac 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -5521,6 +5521,9 @@ void __init mem_init_print_info(const char *str)
>  	pr_info("Memory: %luK/%luK available "
>  	       "(%luK kernel code, %luK rwdata, %luK rodata, "
>  	       "%luK init, %luK bss, %luK reserved"
> +#ifdef CONFIG_CMA
> +		", %luK cma-reserved"
> +#endif
>  #ifdef	CONFIG_HIGHMEM
>  	       ", %luK highmem"
>  #endif
> @@ -5528,7 +5531,12 @@ void __init mem_init_print_info(const char *str)
>  	       nr_free_pages() << (PAGE_SHIFT-10), physpages << (PAGE_SHIFT-10),
>  	       codesize >> 10, datasize >> 10, rosize >> 10,
>  	       (init_data_size + init_code_size) >> 10, bss_size >> 10,
> +#ifdef CONFIG_CMA
> +	       (physpages - totalram_pages - totalcma_pages) << (PAGE_SHIFT-10),
> +	       totalcma_pages << (PAGE_SHIFT-10),
> +#else
>  	       (physpages - totalram_pages) << (PAGE_SHIFT-10),
> +#endif
>  #ifdef	CONFIG_HIGHMEM
>  	       totalhigh_pages << (PAGE_SHIFT-10),
>  #endif
> -- 
> 1.8.3.2
>

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] mm: cma: split cma-reserved in dmesg log
  2014-10-20  7:33 [PATCH] mm: cma: split cma-reserved in dmesg log Pintu Kumar
  2014-10-20  9:35 ` Michal Nazarewicz
@ 2014-10-20 22:48 ` Andrew Morton
  2014-10-21  0:47 ` Gioh Kim
  2014-10-22 14:06 ` [PATCH v2 1/2] " Pintu Kumar
  3 siblings, 0 replies; 20+ messages in thread
From: Andrew Morton @ 2014-10-20 22:48 UTC (permalink / raw)
  To: Pintu Kumar
  Cc: hannes, riel, mgorman, vdavydov, nasa4836, ddstreet,
	m.szyprowski, mina86, iamjoonsoo.kim, aneesh.kumar, lauraa,
	gioh.kim, rientjes, vbabka, sasha.levin, linux-kernel, linux-mm,
	cpgs, pintu_agarwal, vishnu.ps, rohit.kr, ed.savinay

On Mon, 20 Oct 2014 13:03:10 +0530 Pintu Kumar <pintu.k@samsung.com> wrote:

> When the system boots up, in the dmesg logs we can see
> the memory statistics along with total reserved as below.
> Memory: 458840k/458840k available, 65448k reserved, 0K highmem
> 
> When CMA is enabled, still the total reserved memory remains the same.
> However, the CMA memory is not considered as reserved.
> But, when we see /proc/meminfo, the CMA memory is part of free memory.
> This creates confusion.
> This patch corrects the problem by properly substracting the CMA reserved
> memory from the total reserved memory in dmesg logs.
> 
> Below is the dmesg snaphot from an arm based device with 512MB RAM and
> 12MB single CMA region.
> 
> Before this change:
> Memory: 458840k/458840k available, 65448k reserved, 0K highmem
> 
> After this change:
> Memory: 458840k/458840k available, 53160k reserved, 12288k cma-reserved, 0K highmem
> 
> ...
>
> --- a/include/linux/swap.h
> +++ b/include/linux/swap.h
> @@ -295,6 +295,9 @@ static inline void workingset_node_shadows_dec(struct radix_tree_node *node)
>  /* linux/mm/page_alloc.c */
>  extern unsigned long totalram_pages;
>  extern unsigned long totalreserve_pages;
> +#ifdef CONFIG_CMA
> +extern unsigned long totalcma_pages;
> +#endif

We don't actually need the ifdefs here - the kernel will compile OK
without them.  This means that a programming error will result in a
link-time error rather than a compile-time error but that's a pretty
small cost to pay for keeping the header files neater.

>  extern unsigned long dirty_balance_reserve;
>  extern unsigned long nr_free_buffer_pages(void);
>  extern unsigned long nr_free_pagecache_pages(void);
> diff --git a/mm/cma.c b/mm/cma.c
> index 963bc4a..73fe7be 100644
> --- a/mm/cma.c
> +++ b/mm/cma.c
> @@ -45,6 +45,7 @@ struct cma {
>  static struct cma cma_areas[MAX_CMA_AREAS];
>  static unsigned cma_area_count;
>  static DEFINE_MUTEX(cma_mutex);
> +unsigned long totalcma_pages __read_mostly;

This could+should be __initdata.

>  phys_addr_t cma_get_base(struct cma *cma)
>  {
> @@ -288,6 +289,7 @@ int __init cma_declare_contiguous(phys_addr_t base,
>  	if (ret)
>  		goto err;
>  
> +	totalcma_pages += (size / PAGE_SIZE);
>  	pr_info("Reserved %ld MiB at %08lx\n", (unsigned long)size / SZ_1M,
>  		(unsigned long)base);
>  	return 0;
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index dd73f9a..c6165ac 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -5521,6 +5521,9 @@ void __init mem_init_print_info(const char *str)
>  	pr_info("Memory: %luK/%luK available "
>  	       "(%luK kernel code, %luK rwdata, %luK rodata, "
>  	       "%luK init, %luK bss, %luK reserved"
> +#ifdef CONFIG_CMA
> +		", %luK cma-reserved"
> +#endif
>  #ifdef	CONFIG_HIGHMEM
>  	       ", %luK highmem"
>  #endif
> @@ -5528,7 +5531,12 @@ void __init mem_init_print_info(const char *str)
>  	       nr_free_pages() << (PAGE_SHIFT-10), physpages << (PAGE_SHIFT-10),
>  	       codesize >> 10, datasize >> 10, rosize >> 10,
>  	       (init_data_size + init_code_size) >> 10, bss_size >> 10,
> +#ifdef CONFIG_CMA
> +	       (physpages - totalram_pages - totalcma_pages) << (PAGE_SHIFT-10),
> +	       totalcma_pages << (PAGE_SHIFT-10),
> +#else
>  	       (physpages - totalram_pages) << (PAGE_SHIFT-10),
> +#endif
>  #ifdef	CONFIG_HIGHMEM
>  	       totalhigh_pages << (PAGE_SHIFT-10),
>  #endif

Do we really need any of the ifdefs?  A non-CMA kernel will print "0K
cma-reserved" but is that harmful?

This is all __init code so the additional code bloat isn't a
significant issue.


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] mm: cma: split cma-reserved in dmesg log
  2014-10-20  7:33 [PATCH] mm: cma: split cma-reserved in dmesg log Pintu Kumar
  2014-10-20  9:35 ` Michal Nazarewicz
  2014-10-20 22:48 ` Andrew Morton
@ 2014-10-21  0:47 ` Gioh Kim
  2014-10-21 13:21   ` PINTU KUMAR
  2014-10-22 14:06 ` [PATCH v2 1/2] " Pintu Kumar
  3 siblings, 1 reply; 20+ messages in thread
From: Gioh Kim @ 2014-10-21  0:47 UTC (permalink / raw)
  To: Pintu Kumar, akpm, hannes, riel, mgorman, vdavydov, nasa4836,
	ddstreet, m.szyprowski, mina86, iamjoonsoo.kim, aneesh.kumar,
	lauraa, rientjes, vbabka, sasha.levin, linux-kernel, linux-mm
  Cc: cpgs, pintu_agarwal, vishnu.ps, rohit.kr, ed.savinay,
	이건호



2014-10-20 오후 4:33, Pintu Kumar 쓴 글:
> When the system boots up, in the dmesg logs we can see
> the memory statistics along with total reserved as below.
> Memory: 458840k/458840k available, 65448k reserved, 0K highmem
> 
> When CMA is enabled, still the total reserved memory remains the same.
> However, the CMA memory is not considered as reserved.
> But, when we see /proc/meminfo, the CMA memory is part of free memory.
> This creates confusion.
> This patch corrects the problem by properly substracting the CMA reserved
> memory from the total reserved memory in dmesg logs.
> 
> Below is the dmesg snaphot from an arm based device with 512MB RAM and
> 12MB single CMA region.
> 
> Before this change:
> Memory: 458840k/458840k available, 65448k reserved, 0K highmem
> 
> After this change:
> Memory: 458840k/458840k available, 53160k reserved, 12288k cma-reserved, 0K highmem
> 
> Signed-off-by: Pintu Kumar <pintu.k@samsung.com>
> Signed-off-by: Vishnu Pratap Singh <vishnu.ps@samsung.com>
> ---
>   include/linux/swap.h | 3 +++
>   mm/cma.c             | 2 ++
>   mm/page_alloc.c      | 8 ++++++++
>   3 files changed, 13 insertions(+)
> 
> diff --git a/include/linux/swap.h b/include/linux/swap.h
> index 37a585b..beb84be 100644
> --- a/include/linux/swap.h
> +++ b/include/linux/swap.h
> @@ -295,6 +295,9 @@ static inline void workingset_node_shadows_dec(struct radix_tree_node *node)
>   /* linux/mm/page_alloc.c */
>   extern unsigned long totalram_pages;
>   extern unsigned long totalreserve_pages;
> +#ifdef CONFIG_CMA
> +extern unsigned long totalcma_pages;
> +#endif
>   extern unsigned long dirty_balance_reserve;
>   extern unsigned long nr_free_buffer_pages(void);
>   extern unsigned long nr_free_pagecache_pages(void);
> diff --git a/mm/cma.c b/mm/cma.c
> index 963bc4a..73fe7be 100644
> --- a/mm/cma.c
> +++ b/mm/cma.c
> @@ -45,6 +45,7 @@ struct cma {
>   static struct cma cma_areas[MAX_CMA_AREAS];
>   static unsigned cma_area_count;
>   static DEFINE_MUTEX(cma_mutex);
> +unsigned long totalcma_pages __read_mostly;

I think __read_mostly is not good here.
Cma areas often are rare
but we cannot expect how many cma areas exists.

>   
>   phys_addr_t cma_get_base(struct cma *cma)
>   {
> @@ -288,6 +289,7 @@ int __init cma_declare_contiguous(phys_addr_t base,
>   	if (ret)
>   		goto err;
>   
> +	totalcma_pages += (size / PAGE_SIZE);
>   	pr_info("Reserved %ld MiB at %08lx\n", (unsigned long)size / SZ_1M,
>   		(unsigned long)base);
>   	return 0;
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index dd73f9a..c6165ac 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -5521,6 +5521,9 @@ void __init mem_init_print_info(const char *str)
>   	pr_info("Memory: %luK/%luK available "
>   	       "(%luK kernel code, %luK rwdata, %luK rodata, "
>   	       "%luK init, %luK bss, %luK reserved"
> +#ifdef CONFIG_CMA
> +		", %luK cma-reserved"
> +#endif
>   #ifdef	CONFIG_HIGHMEM
>   	       ", %luK highmem"
>   #endif
> @@ -5528,7 +5531,12 @@ void __init mem_init_print_info(const char *str)
>   	       nr_free_pages() << (PAGE_SHIFT-10), physpages << (PAGE_SHIFT-10),
>   	       codesize >> 10, datasize >> 10, rosize >> 10,
>   	       (init_data_size + init_code_size) >> 10, bss_size >> 10,
> +#ifdef CONFIG_CMA
> +	       (physpages - totalram_pages - totalcma_pages) << (PAGE_SHIFT-10),
> +	       totalcma_pages << (PAGE_SHIFT-10),
> +#else
>   	       (physpages - totalram_pages) << (PAGE_SHIFT-10),
> +#endif
>   #ifdef	CONFIG_HIGHMEM
>   	       totalhigh_pages << (PAGE_SHIFT-10),
>   #endif
> 

I basically agree with your point.
But CMA feature is not popular yet, so memory develoers probably doesn't like this.

I'm not sure but I think there is a debugfs file for cma.
Can you use it?

Or what do you think about making another proc file to show cma area size and address?
For instance,

# cat /proc/cmainfo
CMATotal:    400kB
0x10000000   300kB
0x20000000   100kB


^ permalink raw reply	[flat|nested] 20+ messages in thread

* RE: [PATCH] mm: cma: split cma-reserved in dmesg log
  2014-10-21  0:47 ` Gioh Kim
@ 2014-10-21 13:21   ` PINTU KUMAR
  2014-10-21 23:55     ` Gioh Kim
  0 siblings, 1 reply; 20+ messages in thread
From: PINTU KUMAR @ 2014-10-21 13:21 UTC (permalink / raw)
  To: 'Gioh Kim',
	akpm, hannes, riel, mgorman, vdavydov, nasa4836, ddstreet,
	m.szyprowski, mina86, iamjoonsoo.kim, aneesh.kumar, lauraa,
	rientjes, vbabka, sasha.levin, linux-kernel, linux-mm, pintu.k
  Cc: cpgs, pintu_agarwal, vishnu.ps, rohit.kr, ed.savinay,
	'이건호'


Hi,

----- Original Message -----
> From: Gioh Kim <gioh.kim@lge.com>
> To: Pintu Kumar <pintu.k@samsung.com>; akpm@linux-foundation.org;
hannes@cmpxchg.org; riel@redhat.com; mgorman@suse.de;
vdavydov@parallels.com; nasa4836@gmail.com; ddstreet@ieee.org;
m.szyprowski@samsung.com; mina86@mina86.com; iamjoonsoo.kim@lge.com; aneesh.
kumar@linux.vnet.ibm.com; lauraa@codeaurora.org; rientjes@google.com;
vbabka@suse.cz; sasha.levin@oracle.com; linux-kernel@vger.kernel.org; linux-
mm@kvack.org
> Cc: cpgs@samsung.com; pintu_agarwal@yahoo.com; vishnu.ps@samsung.com;
rohit.kr@samsung.com; ed.savinay@samsung.com; 이건호 <gunho.lee@lge.com>
> Sent: Tuesday, 21 October 2014 6:17 AM
> Subject: Re: [PATCH] mm: cma: split cma-reserved in dmesg log
> 
> 
> 
> 2014-10-20 오후 4:33, Pintu Kumar 쓴 글:
>> When the system boots up, in the dmesg logs we can see
>> the memory statistics along with total reserved as below.
>> Memory: 458840k/458840k available, 65448k reserved, 0K highmem
>> 
>> When CMA is enabled, still the total reserved memory remains the same.
>> However, the CMA memory is not considered as reserved.
>> But, when we see /proc/meminfo, the CMA memory is part of free memory.
>> This creates confusion.
>> This patch corrects the problem by properly substracting the CMA reserved
>> memory from the total reserved memory in dmesg logs.
>> 
>> Below is the dmesg snaphot from an arm based device with 512MB RAM and
>> 12MB single CMA region.
>> 
>> Before this change:
>> Memory: 458840k/458840k available, 65448k reserved, 0K highmem
>> 
>> After this change:
>> Memory: 458840k/458840k available, 53160k reserved, 12288k cma-reserved,
0K 
> highmem
>> 
>> Signed-off-by: Pintu Kumar <pintu.k@samsung.com>
>> Signed-off-by: Vishnu Pratap Singh <vishnu.ps@samsung.com>
>> ---
>>   include/linux/swap.h | 3 +++
>>   mm/cma.c            | 2 ++
>>   mm/page_alloc.c      | 8 ++++++++
>>   3 files changed, 13 insertions(+)
>> 
>> diff --git a/include/linux/swap.h b/include/linux/swap.h
>> index 37a585b..beb84be 100644
>> --- a/include/linux/swap.h
>> +++ b/include/linux/swap.h
>> @@ -295,6 +295,9 @@ static inline void
workingset_node_shadows_dec(struct 
> radix_tree_node *node)
>>   /* linux/mm/page_alloc.c */
>>   extern unsigned long totalram_pages;
>>   extern unsigned long totalreserve_pages;
>> +#ifdef CONFIG_CMA
>> +extern unsigned long totalcma_pages;
>> +#endif

Ok, as per Andrew Morton comment, will remove CONFIG_CMA, 
But then I need to put it under: include/linux/mm.h
In that case, it will solve the problem for CMA and non-CMA case.
Because, mm.h is already included in cma.c

>>   extern unsigned long dirty_balance_reserve;
>>   extern unsigned long nr_free_buffer_pages(void);
>>   extern unsigned long nr_free_pagecache_pages(void);
>> diff --git a/mm/cma.c b/mm/cma.c
>> index 963bc4a..73fe7be 100644
>> --- a/mm/cma.c
>> +++ b/mm/cma.c
>> @@ -45,6 +45,7 @@ struct cma {
>>   static struct cma cma_areas[MAX_CMA_AREAS];
>>   static unsigned cma_area_count;
>>   static DEFINE_MUTEX(cma_mutex);
>> +unsigned long totalcma_pages __read_mostly;
> 
> I think __read_mostly is not good here.
> Cma areas often are rare
> but we cannot expect how many cma areas exists.
> 

Firstly, I want to move this to mm/page_alloc.c, so that it can be visible
for non-CMA cases.
Next, the purpose this variable is not only during init time.
Just like totalram_pages, I wanted to retain this variable to use it to
populate the CMA info, during /proc/meminfo.
Like:
CMATotal: (using totalcma_pages)
CMAFree:  (using NR_FREE_CMA_PAGES)
I will post these changes in the next patch series.
Please let me know your comments.

>>   
>>   phys_addr_t cma_get_base(struct cma *cma)
>>   {
>> @@ -288,6 +289,7 @@ int __init cma_declare_contiguous(phys_addr_t base,
>>       if (ret)
>>           goto err;
>>   
>> +    totalcma_pages += (size / PAGE_SIZE);
>>       pr_info("Reserved %ld MiB at %08lx\n", (unsigned 
> long)size / SZ_1M,
>>           (unsigned long)base);
>>       return 0;
>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>> index dd73f9a..c6165ac 100644
>> --- a/mm/page_alloc.c
>> +++ b/mm/page_alloc.c
>> @@ -5521,6 +5521,9 @@ void __init mem_init_print_info(const char *str)
>>       pr_info("Memory: %luK/%luK available "
>>             "(%luK kernel code, %luK rwdata, %luK rodata, "
>>             "%luK init, %luK bss, %luK reserved"
>> +#ifdef CONFIG_CMA
>> +        ", %luK cma-reserved"
>> +#endif
>>   #ifdef    CONFIG_HIGHMEM
>>             ", %luK highmem"
>>   #endif
>> @@ -5528,7 +5531,12 @@ void __init mem_init_print_info(const char *str)
>>             nr_free_pages() << (PAGE_SHIFT-10), physpages << 
> (PAGE_SHIFT-10),
>>             codesize >> 10, datasize >> 10, rosize >> 
> 10,
>>             (init_data_size + init_code_size) >> 10, bss_size 
>>> 10,
>> +#ifdef CONFIG_CMA
>> +          (physpages - totalram_pages - totalcma_pages) << 
> (PAGE_SHIFT-10),
>> +          totalcma_pages << (PAGE_SHIFT-10),
>> +#else
>>             (physpages - totalram_pages) << (PAGE_SHIFT-10),
>> +#endif
>>   #ifdef    CONFIG_HIGHMEM
>>             totalhigh_pages << (PAGE_SHIFT-10),
>>   #endif
>> 
> 
> I basically agree with your point.
> But CMA feature is not popular yet, so memory develoers probably doesn't 
> like this.
> 

Ok agree. If we move totalcma_pages declaration to page_alloc.c and mm.h,
then we can get rid of CONFIG_CMA, to make it neat.


> I'm not sure but I think there is a debugfs file for cma.
> Can you use it?
> 

As of now, I think there is no debugfs for cma.
However, we can make one if required.

> Or what do you think about making another proc file to show cma area size
and 
> address?
> For instance,
> 
> # cat /proc/cmainfo
> CMATotal:    400kB
> 0x10000000  300kB
> 0x20000000  100kB
> 

I think this is not required.
For multiple CMA regions, this can be found under:
/sys/kernel/debug/memblock/reserved
However, as I said, we can populate this information under: /proc/meminfo
I think capturing it at one place will be better. For non-CMA cases, it
will be hidden.
Thus summary of CMA info can be seen in meminfo, and detailed information
can be seen in memblock/reserved.
Do, let me know if you have any other idea?

> 
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@kvack.org.  For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"dont@kvack.org"> 
> email@kvack.org </a>
>


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH] mm: cma: split cma-reserved in dmesg log
  2014-10-21 13:21   ` PINTU KUMAR
@ 2014-10-21 23:55     ` Gioh Kim
  0 siblings, 0 replies; 20+ messages in thread
From: Gioh Kim @ 2014-10-21 23:55 UTC (permalink / raw)
  To: PINTU KUMAR, akpm, hannes, riel, mgorman, vdavydov, nasa4836,
	ddstreet, m.szyprowski, mina86, iamjoonsoo.kim, aneesh.kumar,
	lauraa, rientjes, vbabka, sasha.levin, linux-kernel, linux-mm
  Cc: cpgs, pintu_agarwal, vishnu.ps, rohit.kr, ed.savinay,
	'이건호'



2014-10-21 오후 10:21, PINTU KUMAR 쓴 글:
> 
> Hi,
> 
> ----- Original Message -----
>> From: Gioh Kim <gioh.kim@lge.com>
>> To: Pintu Kumar <pintu.k@samsung.com>; akpm@linux-foundation.org;
> hannes@cmpxchg.org; riel@redhat.com; mgorman@suse.de;
> vdavydov@parallels.com; nasa4836@gmail.com; ddstreet@ieee.org;
> m.szyprowski@samsung.com; mina86@mina86.com; iamjoonsoo.kim@lge.com; aneesh.
> kumar@linux.vnet.ibm.com; lauraa@codeaurora.org; rientjes@google.com;
> vbabka@suse.cz; sasha.levin@oracle.com; linux-kernel@vger.kernel.org; linux-
> mm@kvack.org
>> Cc: cpgs@samsung.com; pintu_agarwal@yahoo.com; vishnu.ps@samsung.com;
> rohit.kr@samsung.com; ed.savinay@samsung.com; 이건호 <gunho.lee@lge.com>
>> Sent: Tuesday, 21 October 2014 6:17 AM
>> Subject: Re: [PATCH] mm: cma: split cma-reserved in dmesg log
>>
>>
>>
>> 2014-10-20 오후 4:33, Pintu Kumar 쓴 글:
>>> When the system boots up, in the dmesg logs we can see
>>> the memory statistics along with total reserved as below.
>>> Memory: 458840k/458840k available, 65448k reserved, 0K highmem
>>>
>>> When CMA is enabled, still the total reserved memory remains the same.
>>> However, the CMA memory is not considered as reserved.
>>> But, when we see /proc/meminfo, the CMA memory is part of free memory.
>>> This creates confusion.
>>> This patch corrects the problem by properly substracting the CMA reserved
>>> memory from the total reserved memory in dmesg logs.
>>>
>>> Below is the dmesg snaphot from an arm based device with 512MB RAM and
>>> 12MB single CMA region.
>>>
>>> Before this change:
>>> Memory: 458840k/458840k available, 65448k reserved, 0K highmem
>>>
>>> After this change:
>>> Memory: 458840k/458840k available, 53160k reserved, 12288k cma-reserved,
> 0K
>> highmem
>>>
>>> Signed-off-by: Pintu Kumar <pintu.k@samsung.com>
>>> Signed-off-by: Vishnu Pratap Singh <vishnu.ps@samsung.com>
>>> ---
>>>    include/linux/swap.h | 3 +++
>>>    mm/cma.c            | 2 ++
>>>    mm/page_alloc.c      | 8 ++++++++
>>>    3 files changed, 13 insertions(+)
>>>
>>> diff --git a/include/linux/swap.h b/include/linux/swap.h
>>> index 37a585b..beb84be 100644
>>> --- a/include/linux/swap.h
>>> +++ b/include/linux/swap.h
>>> @@ -295,6 +295,9 @@ static inline void
> workingset_node_shadows_dec(struct
>> radix_tree_node *node)
>>>    /* linux/mm/page_alloc.c */
>>>    extern unsigned long totalram_pages;
>>>    extern unsigned long totalreserve_pages;
>>> +#ifdef CONFIG_CMA
>>> +extern unsigned long totalcma_pages;
>>> +#endif
> 
> Ok, as per Andrew Morton comment, will remove CONFIG_CMA,
> But then I need to put it under: include/linux/mm.h
> In that case, it will solve the problem for CMA and non-CMA case.
> Because, mm.h is already included in cma.c
> 
>>>    extern unsigned long dirty_balance_reserve;
>>>    extern unsigned long nr_free_buffer_pages(void);
>>>    extern unsigned long nr_free_pagecache_pages(void);
>>> diff --git a/mm/cma.c b/mm/cma.c
>>> index 963bc4a..73fe7be 100644
>>> --- a/mm/cma.c
>>> +++ b/mm/cma.c
>>> @@ -45,6 +45,7 @@ struct cma {
>>>    static struct cma cma_areas[MAX_CMA_AREAS];
>>>    static unsigned cma_area_count;
>>>    static DEFINE_MUTEX(cma_mutex);
>>> +unsigned long totalcma_pages __read_mostly;
>>
>> I think __read_mostly is not good here.
>> Cma areas often are rare
>> but we cannot expect how many cma areas exists.
>>
> 
> Firstly, I want to move this to mm/page_alloc.c, so that it can be visible
> for non-CMA cases.
> Next, the purpose this variable is not only during init time.
> Just like totalram_pages, I wanted to retain this variable to use it to
> populate the CMA info, during /proc/meminfo.
> Like:
> CMATotal: (using totalcma_pages)
> CMAFree:  (using NR_FREE_CMA_PAGES)
> I will post these changes in the next patch series.
> Please let me know your comments.
> 
>>>    
>>>    phys_addr_t cma_get_base(struct cma *cma)
>>>    {
>>> @@ -288,6 +289,7 @@ int __init cma_declare_contiguous(phys_addr_t base,
>>>        if (ret)
>>>            goto err;
>>>    
>>> +    totalcma_pages += (size / PAGE_SIZE);
>>>        pr_info("Reserved %ld MiB at %08lx\n", (unsigned
>> long)size / SZ_1M,
>>>            (unsigned long)base);
>>>        return 0;
>>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>>> index dd73f9a..c6165ac 100644
>>> --- a/mm/page_alloc.c
>>> +++ b/mm/page_alloc.c
>>> @@ -5521,6 +5521,9 @@ void __init mem_init_print_info(const char *str)
>>>        pr_info("Memory: %luK/%luK available "
>>>              "(%luK kernel code, %luK rwdata, %luK rodata, "
>>>              "%luK init, %luK bss, %luK reserved"
>>> +#ifdef CONFIG_CMA
>>> +        ", %luK cma-reserved"
>>> +#endif
>>>    #ifdef    CONFIG_HIGHMEM
>>>              ", %luK highmem"
>>>    #endif
>>> @@ -5528,7 +5531,12 @@ void __init mem_init_print_info(const char *str)
>>>              nr_free_pages() << (PAGE_SHIFT-10), physpages <<
>> (PAGE_SHIFT-10),
>>>              codesize >> 10, datasize >> 10, rosize >>
>> 10,
>>>              (init_data_size + init_code_size) >> 10, bss_size
>>>> 10,
>>> +#ifdef CONFIG_CMA
>>> +          (physpages - totalram_pages - totalcma_pages) <<
>> (PAGE_SHIFT-10),
>>> +          totalcma_pages << (PAGE_SHIFT-10),
>>> +#else
>>>              (physpages - totalram_pages) << (PAGE_SHIFT-10),
>>> +#endif
>>>    #ifdef    CONFIG_HIGHMEM
>>>              totalhigh_pages << (PAGE_SHIFT-10),
>>>    #endif
>>>
>>
>> I basically agree with your point.
>> But CMA feature is not popular yet, so memory develoers probably doesn't
>> like this.
>>
> 
> Ok agree. If we move totalcma_pages declaration to page_alloc.c and mm.h,
> then we can get rid of CONFIG_CMA, to make it neat.
> 
> 
>> I'm not sure but I think there is a debugfs file for cma.
>> Can you use it?
>>
> 
> As of now, I think there is no debugfs for cma.
> However, we can make one if required.
> 
>> Or what do you think about making another proc file to show cma area size
> and
>> address?
>> For instance,
>>
>> # cat /proc/cmainfo
>> CMATotal:    400kB
>> 0x10000000  300kB
>> 0x20000000  100kB
>>
> 
> I think this is not required.
> For multiple CMA regions, this can be found under:
> /sys/kernel/debug/memblock/reserved

I'm sorry. I didn't know it.

> However, as I said, we can populate this information under: /proc/meminfo
> I think capturing it at one place will be better. For non-CMA cases, it
> will be hidden.
> Thus summary of CMA info can be seen in meminfo, and detailed information
> can be seen in memblock/reserved.

I agree with you.
I'm looking forward to your next patch.

> Do, let me know if you have any other idea?
> 
>>
>> --
>> To unsubscribe, send a message with 'unsubscribe linux-mm' in
>> the body to majordomo@kvack.org.  For more info on Linux MM,
>> see: http://www.linux-mm.org/ .
>> Don't email: <a href=mailto:"dont@kvack.org">
>> email@kvack.org </a>
>>
> 
> 

^ permalink raw reply	[flat|nested] 20+ messages in thread

* [PATCH v2 1/2] mm: cma: split cma-reserved in dmesg log
  2014-10-20  7:33 [PATCH] mm: cma: split cma-reserved in dmesg log Pintu Kumar
                   ` (2 preceding siblings ...)
  2014-10-21  0:47 ` Gioh Kim
@ 2014-10-22 14:06 ` Pintu Kumar
  2014-10-22 14:06   ` [PATCH v2 2/2] fs: proc: Include cma info in proc/meminfo Pintu Kumar
                     ` (2 more replies)
  3 siblings, 3 replies; 20+ messages in thread
From: Pintu Kumar @ 2014-10-22 14:06 UTC (permalink / raw)
  To: akpm, riel, pintu.k, aquini, paul.gortmaker, jmarchan,
	lcapitulino, kirill.shutemov, m.szyprowski, aneesh.kumar,
	iamjoonsoo.kim, mina86, lauraa, gioh.kim, mgorman, rientjes,
	hannes, vbabka, sasha.levin, linux-kernel, linux-mm
  Cc: pintu_agarwal, cpgs, vishnu.ps, rohit.kr, ed.savinay

When the system boots up, in the dmesg logs we can see
the memory statistics along with total reserved as below.
Memory: 458840k/458840k available, 65448k reserved, 0K highmem

When CMA is enabled, still the total reserved memory remains the same.
However, the CMA memory is not considered as reserved.
But, when we see /proc/meminfo, the CMA memory is part of free memory.
This creates confusion.
This patch corrects the problem by properly subtracting the CMA reserved
memory from the total reserved memory in dmesg logs.

Below is the dmesg snapshot from an arm based device with 512MB RAM and
12MB single CMA region.

Before this change:
Memory: 458840k/458840k available, 65448k reserved, 0K highmem

After this change:
Memory: 458840k/458840k available, 53160k reserved, 12288k cma-reserved, 0K highmem

Signed-off-by: Pintu Kumar <pintu.k@samsung.com>
Signed-off-by: Vishnu Pratap Singh <vishnu.ps@samsung.com>
---
v2: Moved totalcma_pages extern declaration to linux/cma.h
    Removed CONFIG_CMA while show cma-reserved, from page_alloc.c
    Moved totalcma_pages declaration to page_alloc.c, so that if will be visible 
    in non-CMA cases.
 include/linux/cma.h |    1 +
 mm/cma.c            |    1 +
 mm/page_alloc.c     |    6 ++++--
 3 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/include/linux/cma.h b/include/linux/cma.h
index 0430ed0..0b75896 100644
--- a/include/linux/cma.h
+++ b/include/linux/cma.h
@@ -15,6 +15,7 @@
 
 struct cma;
 
+extern unsigned long totalcma_pages;
 extern phys_addr_t cma_get_base(struct cma *cma);
 extern unsigned long cma_get_size(struct cma *cma);
 
diff --git a/mm/cma.c b/mm/cma.c
index 963bc4a..8435762 100644
--- a/mm/cma.c
+++ b/mm/cma.c
@@ -288,6 +288,7 @@ int __init cma_declare_contiguous(phys_addr_t base,
 	if (ret)
 		goto err;
 
+	totalcma_pages += (size / PAGE_SIZE);
 	pr_info("Reserved %ld MiB at %08lx\n", (unsigned long)size / SZ_1M,
 		(unsigned long)base);
 	return 0;
diff --git a/mm/page_alloc.c b/mm/page_alloc.c
index dd73f9a..ababbd8 100644
--- a/mm/page_alloc.c
+++ b/mm/page_alloc.c
@@ -110,6 +110,7 @@ static DEFINE_SPINLOCK(managed_page_count_lock);
 
 unsigned long totalram_pages __read_mostly;
 unsigned long totalreserve_pages __read_mostly;
+unsigned long totalcma_pages __read_mostly;
 /*
  * When calculating the number of globally allowed dirty pages, there
  * is a certain number of per-zone reserves that should not be
@@ -5520,7 +5521,7 @@ void __init mem_init_print_info(const char *str)
 
 	pr_info("Memory: %luK/%luK available "
 	       "(%luK kernel code, %luK rwdata, %luK rodata, "
-	       "%luK init, %luK bss, %luK reserved"
+	       "%luK init, %luK bss, %luK reserved, %luK cma-reserved"
 #ifdef	CONFIG_HIGHMEM
 	       ", %luK highmem"
 #endif
@@ -5528,7 +5529,8 @@ void __init mem_init_print_info(const char *str)
 	       nr_free_pages() << (PAGE_SHIFT-10), physpages << (PAGE_SHIFT-10),
 	       codesize >> 10, datasize >> 10, rosize >> 10,
 	       (init_data_size + init_code_size) >> 10, bss_size >> 10,
-	       (physpages - totalram_pages) << (PAGE_SHIFT-10),
+	       (physpages - totalram_pages - totalcma_pages) << (PAGE_SHIFT-10),
+	       totalcma_pages << (PAGE_SHIFT-10),
 #ifdef	CONFIG_HIGHMEM
 	       totalhigh_pages << (PAGE_SHIFT-10),
 #endif
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* [PATCH v2 2/2] fs: proc: Include cma info in proc/meminfo
  2014-10-22 14:06 ` [PATCH v2 1/2] " Pintu Kumar
@ 2014-10-22 14:06   ` Pintu Kumar
  2014-10-22 20:00     ` Andrew Morton
                       ` (2 more replies)
  2014-10-23 17:01   ` [PATCH v2 1/2] mm: cma: split cma-reserved in dmesg log Michal Nazarewicz
  2014-11-03 23:57   ` David Rientjes
  2 siblings, 3 replies; 20+ messages in thread
From: Pintu Kumar @ 2014-10-22 14:06 UTC (permalink / raw)
  To: akpm, riel, pintu.k, aquini, paul.gortmaker, jmarchan,
	lcapitulino, kirill.shutemov, m.szyprowski, aneesh.kumar,
	iamjoonsoo.kim, mina86, lauraa, gioh.kim, mgorman, rientjes,
	hannes, vbabka, sasha.levin, linux-kernel, linux-mm
  Cc: pintu_agarwal, cpgs, vishnu.ps, rohit.kr, ed.savinay

This patch include CMA info (CMATotal, CMAFree) in /proc/meminfo.
Currently, in a CMA enabled system, if somebody wants to know the
total CMA size declared, there is no way to tell, other than the dmesg
or /var/log/messages logs.
With this patch we are showing the CMA info as part of meminfo, so that
it can be determined at any point of time.
This will be populated only when CMA is enabled.

Below is the sample output from a ARM based device with RAM:512MB and CMA:16MB.

MemTotal:         471172 kB
MemFree:          111712 kB
MemAvailable:     271172 kB
.
.
.
CmaTotal:          16384 kB
CmaFree:            6144 kB

This patch also fix below checkpatch errors that were found during these changes.

ERROR: space required after that ',' (ctx:ExV)
199: FILE: fs/proc/meminfo.c:199:
+       ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
        ^

ERROR: space required after that ',' (ctx:ExV)
202: FILE: fs/proc/meminfo.c:202:
+       ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
        ^

ERROR: space required after that ',' (ctx:ExV)
206: FILE: fs/proc/meminfo.c:206:
+       ,K(totalcma_pages)
        ^

total: 3 errors, 0 warnings, 2 checks, 236 lines checked

Signed-off-by: Pintu Kumar <pintu.k@samsung.com>
Signed-off-by: Vishnu Pratap Singh <vishnu.ps@samsung.com>
---
 fs/proc/meminfo.c |   15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
index aa1eee0..d3ebf2e 100644
--- a/fs/proc/meminfo.c
+++ b/fs/proc/meminfo.c
@@ -12,6 +12,9 @@
 #include <linux/vmstat.h>
 #include <linux/atomic.h>
 #include <linux/vmalloc.h>
+#ifdef CONFIG_CMA
+#include <linux/cma.h>
+#endif
 #include <asm/page.h>
 #include <asm/pgtable.h>
 #include "internal.h"
@@ -138,6 +141,10 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 		"AnonHugePages:  %8lu kB\n"
 #endif
+#ifdef CONFIG_CMA
+		"CmaTotal:       %8lu kB\n"
+		"CmaFree:        %8lu kB\n"
+#endif
 		,
 		K(i.totalram),
 		K(i.freeram),
@@ -187,12 +194,16 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
 		vmi.used >> 10,
 		vmi.largest_chunk >> 10
 #ifdef CONFIG_MEMORY_FAILURE
-		,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
+		, atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
 #endif
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
-		,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
+		, K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
 		   HPAGE_PMD_NR)
 #endif
+#ifdef CONFIG_CMA
+		, K(totalcma_pages)
+		, K(global_page_state(NR_FREE_CMA_PAGES))
+#endif
 		);
 
 	hugetlb_report_meminfo(m);
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 20+ messages in thread

* Re: [PATCH v2 2/2] fs: proc: Include cma info in proc/meminfo
  2014-10-22 14:06   ` [PATCH v2 2/2] fs: proc: Include cma info in proc/meminfo Pintu Kumar
@ 2014-10-22 20:00     ` Andrew Morton
  2014-10-23  0:19     ` Gioh Kim
  2014-10-24 16:31     ` Michal Nazarewicz
  2 siblings, 0 replies; 20+ messages in thread
From: Andrew Morton @ 2014-10-22 20:00 UTC (permalink / raw)
  To: Pintu Kumar
  Cc: riel, aquini, paul.gortmaker, jmarchan, lcapitulino,
	kirill.shutemov, m.szyprowski, aneesh.kumar, iamjoonsoo.kim,
	mina86, lauraa, gioh.kim, mgorman, rientjes, hannes, vbabka,
	sasha.levin, linux-kernel, linux-mm, pintu_agarwal, cpgs,
	vishnu.ps, rohit.kr, ed.savinay

On Wed, 22 Oct 2014 19:36:35 +0530 Pintu Kumar <pintu.k@samsung.com> wrote:

> This patch include CMA info (CMATotal, CMAFree) in /proc/meminfo.
> Currently, in a CMA enabled system, if somebody wants to know the
> total CMA size declared, there is no way to tell, other than the dmesg
> or /var/log/messages logs.
> With this patch we are showing the CMA info as part of meminfo, so that
> it can be determined at any point of time.
> This will be populated only when CMA is enabled.

Fair enough.

We should be pretty careful about what we put in meminfo - it's the
top-level, most-important procfs file and I expect that quite a lot of
userspace reads it with some frequency.  We don't want to clutter it
up.  /proc/vmstat is a suitable place for the less important info which
is more kernel developer oriented.

But CMATotal and CMAFree do pass the "should be in meminfo" test, IMO.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v2 2/2] fs: proc: Include cma info in proc/meminfo
  2014-10-22 14:06   ` [PATCH v2 2/2] fs: proc: Include cma info in proc/meminfo Pintu Kumar
  2014-10-22 20:00     ` Andrew Morton
@ 2014-10-23  0:19     ` Gioh Kim
  2014-10-24  8:57       ` PINTU KUMAR
  2014-10-24 16:31     ` Michal Nazarewicz
  2 siblings, 1 reply; 20+ messages in thread
From: Gioh Kim @ 2014-10-23  0:19 UTC (permalink / raw)
  To: Pintu Kumar, akpm, riel, aquini, paul.gortmaker, jmarchan,
	lcapitulino, kirill.shutemov, m.szyprowski, aneesh.kumar,
	iamjoonsoo.kim, mina86, lauraa, mgorman, rientjes, hannes,
	vbabka, sasha.levin, linux-kernel, linux-mm
  Cc: pintu_agarwal, cpgs, vishnu.ps, rohit.kr, ed.savinay



2014-10-22 오후 11:06, Pintu Kumar 쓴 글:
> This patch include CMA info (CMATotal, CMAFree) in /proc/meminfo.
> Currently, in a CMA enabled system, if somebody wants to know the
> total CMA size declared, there is no way to tell, other than the dmesg
> or /var/log/messages logs.
> With this patch we are showing the CMA info as part of meminfo, so that
> it can be determined at any point of time.
> This will be populated only when CMA is enabled.
> 
> Below is the sample output from a ARM based device with RAM:512MB and CMA:16MB.
> 
> MemTotal:         471172 kB
> MemFree:          111712 kB
> MemAvailable:     271172 kB
> .
> .
> .
> CmaTotal:          16384 kB
> CmaFree:            6144 kB
> 
> This patch also fix below checkpatch errors that were found during these changes.

Why don't you split patch for it?
I think there's a rule not to mix separate patchs.

> 
> ERROR: space required after that ',' (ctx:ExV)
> 199: FILE: fs/proc/meminfo.c:199:
> +       ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
>          ^
> 
> ERROR: space required after that ',' (ctx:ExV)
> 202: FILE: fs/proc/meminfo.c:202:
> +       ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
>          ^
> 
> ERROR: space required after that ',' (ctx:ExV)
> 206: FILE: fs/proc/meminfo.c:206:
> +       ,K(totalcma_pages)
>          ^
> 
> total: 3 errors, 0 warnings, 2 checks, 236 lines checked
> 
> Signed-off-by: Pintu Kumar <pintu.k@samsung.com>
> Signed-off-by: Vishnu Pratap Singh <vishnu.ps@samsung.com>
> ---
>   fs/proc/meminfo.c |   15 +++++++++++++--
>   1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
> index aa1eee0..d3ebf2e 100644
> --- a/fs/proc/meminfo.c
> +++ b/fs/proc/meminfo.c
> @@ -12,6 +12,9 @@
>   #include <linux/vmstat.h>
>   #include <linux/atomic.h>
>   #include <linux/vmalloc.h>
> +#ifdef CONFIG_CMA
> +#include <linux/cma.h>
> +#endif
>   #include <asm/page.h>
>   #include <asm/pgtable.h>
>   #include "internal.h"
> @@ -138,6 +141,10 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
>   #ifdef CONFIG_TRANSPARENT_HUGEPAGE
>   		"AnonHugePages:  %8lu kB\n"
>   #endif
> +#ifdef CONFIG_CMA
> +		"CmaTotal:       %8lu kB\n"
> +		"CmaFree:        %8lu kB\n"
> +#endif
>   		,
>   		K(i.totalram),
>   		K(i.freeram),
> @@ -187,12 +194,16 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
>   		vmi.used >> 10,
>   		vmi.largest_chunk >> 10
>   #ifdef CONFIG_MEMORY_FAILURE
> -		,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
> +		, atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
>   #endif
>   #ifdef CONFIG_TRANSPARENT_HUGEPAGE
> -		,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
> +		, K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
>   		   HPAGE_PMD_NR)
>   #endif
> +#ifdef CONFIG_CMA
> +		, K(totalcma_pages)
> +		, K(global_page_state(NR_FREE_CMA_PAGES))
> +#endif
>   		);

Just for sure, are zoneinfo and pagetypeinfo not suitable?

I don't know HOTPLUG feature so I'm just asking for sure.
Does HOTPLUG not need printing message like this?

Thanks a lot.

>   
>   	hugetlb_report_meminfo(m);
> 

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v2 1/2] mm: cma: split cma-reserved in dmesg log
  2014-10-22 14:06 ` [PATCH v2 1/2] " Pintu Kumar
  2014-10-22 14:06   ` [PATCH v2 2/2] fs: proc: Include cma info in proc/meminfo Pintu Kumar
@ 2014-10-23 17:01   ` Michal Nazarewicz
  2014-10-24 10:30     ` PINTU KUMAR
  2014-11-03 23:57   ` David Rientjes
  2 siblings, 1 reply; 20+ messages in thread
From: Michal Nazarewicz @ 2014-10-23 17:01 UTC (permalink / raw)
  To: Pintu Kumar, akpm, riel, pintu.k, aquini, paul.gortmaker,
	jmarchan, lcapitulino, kirill.shutemov, m.szyprowski,
	aneesh.kumar, iamjoonsoo.kim, lauraa, gioh.kim, mgorman,
	rientjes, hannes, vbabka, sasha.levin, linux-kernel, linux-mm
  Cc: pintu_agarwal, cpgs, vishnu.ps, rohit.kr, ed.savinay

On Wed, Oct 22 2014, Pintu Kumar wrote:
> When the system boots up, in the dmesg logs we can see
> the memory statistics along with total reserved as below.
> Memory: 458840k/458840k available, 65448k reserved, 0K highmem
>
> When CMA is enabled, still the total reserved memory remains the same.
> However, the CMA memory is not considered as reserved.
> But, when we see /proc/meminfo, the CMA memory is part of free memory.
> This creates confusion.
> This patch corrects the problem by properly subtracting the CMA reserved
> memory from the total reserved memory in dmesg logs.
>
> Below is the dmesg snapshot from an arm based device with 512MB RAM and
> 12MB single CMA region.
>
> Before this change:
> Memory: 458840k/458840k available, 65448k reserved, 0K highmem
>
> After this change:
> Memory: 458840k/458840k available, 53160k reserved, 12288k cma-reserved, 0K highmem
>
> Signed-off-by: Pintu Kumar <pintu.k@samsung.com>
> Signed-off-by: Vishnu Pratap Singh <vishnu.ps@samsung.com>

Acked-by: Michal Nazarewicz <mina86@mina86.com>


I'm not sure how Andrew would think about it, and I don't have strong
feelings, but I would consider a few changes:

> ---
> v2: Moved totalcma_pages extern declaration to linux/cma.h
>     Removed CONFIG_CMA while show cma-reserved, from page_alloc.c
>     Moved totalcma_pages declaration to page_alloc.c, so that if will be visible 
>     in non-CMA cases.
>  include/linux/cma.h |    1 +
>  mm/cma.c            |    1 +
>  mm/page_alloc.c     |    6 ++++--
>  3 files changed, 6 insertions(+), 2 deletions(-)
>
> diff --git a/include/linux/cma.h b/include/linux/cma.h
> index 0430ed0..0b75896 100644
> --- a/include/linux/cma.h
> +++ b/include/linux/cma.h
> @@ -15,6 +15,7 @@
>  
>  struct cma;
>  
> +extern unsigned long totalcma_pages;

+#ifdef CONFIG_CMA
+extern unsigned long totalcma_pages;
+#else
+#  define totalcma_pages 0UL
+#endif

>  extern phys_addr_t cma_get_base(struct cma *cma);
>  extern unsigned long cma_get_size(struct cma *cma);
>  
> diff --git a/mm/cma.c b/mm/cma.c
> index 963bc4a..8435762 100644
> --- a/mm/cma.c
> +++ b/mm/cma.c
> @@ -288,6 +288,7 @@ int __init cma_declare_contiguous(phys_addr_t base,
>  	if (ret)
>  		goto err;
>  
> +	totalcma_pages += (size / PAGE_SIZE);
>  	pr_info("Reserved %ld MiB at %08lx\n", (unsigned long)size / SZ_1M,
>  		(unsigned long)base);
>  	return 0;
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index dd73f9a..ababbd8 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -110,6 +110,7 @@ static DEFINE_SPINLOCK(managed_page_count_lock);
>  
>  unsigned long totalram_pages __read_mostly;
>  unsigned long totalreserve_pages __read_mostly;
> +unsigned long totalcma_pages __read_mostly;

Move this to cma.c.

>  /*
>   * When calculating the number of globally allowed dirty pages, there
>   * is a certain number of per-zone reserves that should not be
> @@ -5520,7 +5521,7 @@ void __init mem_init_print_info(const char *str)
>  
>  	pr_info("Memory: %luK/%luK available "
>  	       "(%luK kernel code, %luK rwdata, %luK rodata, "
> -	       "%luK init, %luK bss, %luK reserved"
> +	       "%luK init, %luK bss, %luK reserved, %luK cma-reserved"
>  #ifdef	CONFIG_HIGHMEM
>  	       ", %luK highmem"
>  #endif
> @@ -5528,7 +5529,8 @@ void __init mem_init_print_info(const char *str)
>  	       nr_free_pages() << (PAGE_SHIFT-10), physpages << (PAGE_SHIFT-10),
>  	       codesize >> 10, datasize >> 10, rosize >> 10,
>  	       (init_data_size + init_code_size) >> 10, bss_size >> 10,
> -	       (physpages - totalram_pages) << (PAGE_SHIFT-10),
> +	       (physpages - totalram_pages - totalcma_pages) << (PAGE_SHIFT-10),
> +	       totalcma_pages << (PAGE_SHIFT-10),
>  #ifdef	CONFIG_HIGHMEM
>  	       totalhigh_pages << (PAGE_SHIFT-10),
>  #endif
> -- 
> 1.7.9.5
>

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--

^ permalink raw reply	[flat|nested] 20+ messages in thread

* RE: [PATCH v2 2/2] fs: proc: Include cma info in proc/meminfo
  2014-10-23  0:19     ` Gioh Kim
@ 2014-10-24  8:57       ` PINTU KUMAR
  2014-10-24 10:10         ` Gioh Kim
  0 siblings, 1 reply; 20+ messages in thread
From: PINTU KUMAR @ 2014-10-24  8:57 UTC (permalink / raw)
  To: 'Gioh Kim',
	akpm, riel, aquini, paul.gortmaker, jmarchan, lcapitulino,
	kirill.shutemov, m.szyprowski, aneesh.kumar, iamjoonsoo.kim,
	mina86, lauraa, mgorman, rientjes, hannes, vbabka, sasha.levin,
	linux-kernel, linux-mm
  Cc: pintu_agarwal, cpgs, vishnu.ps, rohit.kr, ed.savinay

Hi,

----- Original Message -----
> From: Gioh Kim <gioh.kim@lge.com>
> To: Pintu Kumar <pintu.k@samsung.com>; akpm@linux-foundation.org;
riel@redhat.com; aquini@redhat.com; paul.gortmaker@windriver.com;
jmarchan@redhat.com; lcapitulino@redhat.com;
kirill.shutemov@linux.intel.com; m.szyprowski@samsung.com;
aneesh.kumar@linux.vnet.ibm.com; iamjoonsoo.kim@lge.com; mina86@mina86.com;
lauraa@codeaurora.org; mgorman@suse.de; rientjes@google.com; hannes@cmpxchg.
org; vbabka@suse.cz; sasha.levin@oracle.com; linux-kernel@vger.kernel.org;
linux-mm@kvack.org
> Cc: pintu_agarwal@yahoo.com; cpgs@samsung.com; vishnu.ps@samsung.com;
rohit.kr@samsung.com; ed.savinay@samsung.com
> Sent: Thursday, 23 October 2014 5:49 AM
> Subject: Re: [PATCH v2 2/2] fs: proc: Include cma info in proc/meminfo
> 
> 
> 
> 2014-10-22 오후 11:06, Pintu Kumar 쓴 글:
>> This patch include CMA info (CMATotal, CMAFree) in /proc/meminfo.
>> Currently, in a CMA enabled system, if somebody wants to know the
>> total CMA size declared, there is no way to tell, other than the dmesg
>> or /var/log/messages logs.
>> With this patch we are showing the CMA info as part of meminfo, so that
>> it can be determined at any point of time.
>> This will be populated only when CMA is enabled.
>> 
>> Below is the sample output from a ARM based device with RAM:512MB and 
> CMA:16MB.
>> 
>> MemTotal:        471172 kB
>> MemFree:          111712 kB
>> MemAvailable:    271172 kB
>> .
>> .
>> .
>> CmaTotal:          16384 kB
>> CmaFree:            6144 kB
>> 
>> This patch also fix below checkpatch errors that were found during these 
> changes.
> 
> Why don't you split patch for it?
> I think there's a rule not to mix separate patchs.
> 

Last time when we submitted separate patches for checkpatch errors, it was
suggested to 
Include these kinds of fixes along with some meaningful patches together.
So, we included it in same patch.

>> 
>> ERROR: space required after that ',' (ctx:ExV)
>> 199: FILE: fs/proc/meminfo.c:199:
>> +      ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 
> 10)
>>           ^
>> 
>> ERROR: space required after that ',' (ctx:ExV)
>> 202: FILE: fs/proc/meminfo.c:202:
>> +      ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
>>           ^
>> 
>> ERROR: space required after that ',' (ctx:ExV)
>> 206: FILE: fs/proc/meminfo.c:206:
>> +      ,K(totalcma_pages)
>>           ^
>> 
>> total: 3 errors, 0 warnings, 2 checks, 236 lines checked
>> 
>> Signed-off-by: Pintu Kumar <pintu.k@samsung.com>
>> Signed-off-by: Vishnu Pratap Singh <vishnu.ps@samsung.com>
>> ---
>>   fs/proc/meminfo.c |  15 +++++++++++++--
>>   1 file changed, 13 insertions(+), 2 deletions(-)
>> 
>> diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
>> index aa1eee0..d3ebf2e 100644
>> --- a/fs/proc/meminfo.c
>> +++ b/fs/proc/meminfo.c
>> @@ -12,6 +12,9 @@
>>   #include <linux/vmstat.h>
>>   #include <linux/atomic.h>
>>   #include <linux/vmalloc.h>
>> +#ifdef CONFIG_CMA
>> +#include <linux/cma.h>
>> +#endif
>>   #include <asm/page.h>
>>   #include <asm/pgtable.h>
>>   #include "internal.h"
>> @@ -138,6 +141,10 @@ static int meminfo_proc_show(struct seq_file *m,
void 
> *v)
>>   #ifdef CONFIG_TRANSPARENT_HUGEPAGE
>>           "AnonHugePages:  %8lu kB\n"
>>   #endif
>> +#ifdef CONFIG_CMA
>> +        "CmaTotal:      %8lu kB\n"
>> +        "CmaFree:        %8lu kB\n"
>> +#endif
>>           ,
>>           K(i.totalram),
>>           K(i.freeram),
>> @@ -187,12 +194,16 @@ static int meminfo_proc_show(struct seq_file *m,
void 
> *v)
>>           vmi.used >> 10,
>>           vmi.largest_chunk >> 10
>>   #ifdef CONFIG_MEMORY_FAILURE
>> -        ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 
> 10)
>> +        , atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 
> 10)
>>   #endif
>>   #ifdef CONFIG_TRANSPARENT_HUGEPAGE
>> -        ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
>> +        , K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
>>             HPAGE_PMD_NR)
>>   #endif
>> +#ifdef CONFIG_CMA
>> +        , K(totalcma_pages)
>> +        , K(global_page_state(NR_FREE_CMA_PAGES))
>> +#endif
>>           );
> 
> Just for sure, are zoneinfo and pagetypeinfo not suitable?
> 

I think zoneinfo shows only current free cma pages.
Same is the case with vmstat.
# cat /proc/zoneinfo | grep cma
    nr_free_cma  2560
# cat /proc/vmstat | grep cma
nr_free_cma 2560

> I don't know HOTPLUG feature so I'm just asking for sure.
> Does HOTPLUG not need printing message like this?
> 

Sorry, I am also not sure what hotplug feature you are referring to.

> Thanks a lot.
> 
> 
>>   
>>       hugetlb_report_meminfo(m);
>> 
> 
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@kvack.org.  For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"dont@kvack.org"> 
> email@kvack.org </a>
>


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v2 2/2] fs: proc: Include cma info in proc/meminfo
  2014-10-24  8:57       ` PINTU KUMAR
@ 2014-10-24 10:10         ` Gioh Kim
  2014-10-24 10:43           ` PINTU KUMAR
  0 siblings, 1 reply; 20+ messages in thread
From: Gioh Kim @ 2014-10-24 10:10 UTC (permalink / raw)
  To: PINTU KUMAR, akpm, riel, aquini, paul.gortmaker, jmarchan,
	lcapitulino, kirill.shutemov, m.szyprowski, aneesh.kumar,
	iamjoonsoo.kim, mina86, lauraa, mgorman, rientjes, hannes,
	vbabka, sasha.levin, linux-kernel, linux-mm
  Cc: pintu_agarwal, cpgs, vishnu.ps, rohit.kr, ed.savinay



2014-10-24 오후 5:57, PINTU KUMAR 쓴 글:
> Hi,
> 
> ----- Original Message -----
>> From: Gioh Kim <gioh.kim@lge.com>
>> To: Pintu Kumar <pintu.k@samsung.com>; akpm@linux-foundation.org;
> riel@redhat.com; aquini@redhat.com; paul.gortmaker@windriver.com;
> jmarchan@redhat.com; lcapitulino@redhat.com;
> kirill.shutemov@linux.intel.com; m.szyprowski@samsung.com;
> aneesh.kumar@linux.vnet.ibm.com; iamjoonsoo.kim@lge.com; mina86@mina86.com;
> lauraa@codeaurora.org; mgorman@suse.de; rientjes@google.com; hannes@cmpxchg.
> org; vbabka@suse.cz; sasha.levin@oracle.com; linux-kernel@vger.kernel.org;
> linux-mm@kvack.org
>> Cc: pintu_agarwal@yahoo.com; cpgs@samsung.com; vishnu.ps@samsung.com;
> rohit.kr@samsung.com; ed.savinay@samsung.com
>> Sent: Thursday, 23 October 2014 5:49 AM
>> Subject: Re: [PATCH v2 2/2] fs: proc: Include cma info in proc/meminfo
>>
>>
>>
>> 2014-10-22 오후 11:06, Pintu Kumar 쓴 글:
>>> This patch include CMA info (CMATotal, CMAFree) in /proc/meminfo.
>>> Currently, in a CMA enabled system, if somebody wants to know the
>>> total CMA size declared, there is no way to tell, other than the dmesg
>>> or /var/log/messages logs.
>>> With this patch we are showing the CMA info as part of meminfo, so that
>>> it can be determined at any point of time.
>>> This will be populated only when CMA is enabled.
>>>
>>> Below is the sample output from a ARM based device with RAM:512MB and
>> CMA:16MB.
>>>
>>> MemTotal:        471172 kB
>>> MemFree:          111712 kB
>>> MemAvailable:    271172 kB
>>> .
>>> .
>>> .
>>> CmaTotal:          16384 kB
>>> CmaFree:            6144 kB
>>>
>>> This patch also fix below checkpatch errors that were found during these
>> changes.
>>
>> Why don't you split patch for it?
>> I think there's a rule not to mix separate patchs.
>>
> 
> Last time when we submitted separate patches for checkpatch errors, it was
> suggested to
> Include these kinds of fixes along with some meaningful patches together.
> So, we included it in same patch.
> 
>>>
>>> ERROR: space required after that ',' (ctx:ExV)
>>> 199: FILE: fs/proc/meminfo.c:199:
>>> +      ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT -
>> 10)
>>>            ^
>>>
>>> ERROR: space required after that ',' (ctx:ExV)
>>> 202: FILE: fs/proc/meminfo.c:202:
>>> +      ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
>>>            ^
>>>
>>> ERROR: space required after that ',' (ctx:ExV)
>>> 206: FILE: fs/proc/meminfo.c:206:
>>> +      ,K(totalcma_pages)
>>>            ^
>>>
>>> total: 3 errors, 0 warnings, 2 checks, 236 lines checked
>>>
>>> Signed-off-by: Pintu Kumar <pintu.k@samsung.com>
>>> Signed-off-by: Vishnu Pratap Singh <vishnu.ps@samsung.com>
>>> ---
>>>    fs/proc/meminfo.c |  15 +++++++++++++--
>>>    1 file changed, 13 insertions(+), 2 deletions(-)
>>>
>>> diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
>>> index aa1eee0..d3ebf2e 100644
>>> --- a/fs/proc/meminfo.c
>>> +++ b/fs/proc/meminfo.c
>>> @@ -12,6 +12,9 @@
>>>    #include <linux/vmstat.h>
>>>    #include <linux/atomic.h>
>>>    #include <linux/vmalloc.h>
>>> +#ifdef CONFIG_CMA
>>> +#include <linux/cma.h>
>>> +#endif
>>>    #include <asm/page.h>
>>>    #include <asm/pgtable.h>
>>>    #include "internal.h"
>>> @@ -138,6 +141,10 @@ static int meminfo_proc_show(struct seq_file *m,
> void
>> *v)
>>>    #ifdef CONFIG_TRANSPARENT_HUGEPAGE
>>>            "AnonHugePages:  %8lu kB\n"
>>>    #endif
>>> +#ifdef CONFIG_CMA
>>> +        "CmaTotal:      %8lu kB\n"
>>> +        "CmaFree:        %8lu kB\n"
>>> +#endif
>>>            ,
>>>            K(i.totalram),
>>>            K(i.freeram),
>>> @@ -187,12 +194,16 @@ static int meminfo_proc_show(struct seq_file *m,
> void
>> *v)
>>>            vmi.used >> 10,
>>>            vmi.largest_chunk >> 10
>>>    #ifdef CONFIG_MEMORY_FAILURE
>>> -        ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT -
>> 10)
>>> +        , atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT -
>> 10)
>>>    #endif
>>>    #ifdef CONFIG_TRANSPARENT_HUGEPAGE
>>> -        ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
>>> +        , K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
>>>              HPAGE_PMD_NR)
>>>    #endif
>>> +#ifdef CONFIG_CMA
>>> +        , K(totalcma_pages)
>>> +        , K(global_page_state(NR_FREE_CMA_PAGES))
>>> +#endif
>>>            );
>>
>> Just for sure, are zoneinfo and pagetypeinfo not suitable?
>>
> 
> I think zoneinfo shows only current free cma pages.
> Same is the case with vmstat.
> # cat /proc/zoneinfo | grep cma
>      nr_free_cma  2560
> # cat /proc/vmstat | grep cma
> nr_free_cma 2560

We could add a line to show total cma pages like following and add it all.
# cat /proc/zoneinfo | grep cma
      nr_total_cma XXXX
      nr_free_cma  2560

Yes. each zone can have cma area and it is annoying to add it all.
But IMO it is rare and not difficult.
And I think it'd better that zoneinfo has nr_total_cma line.

I think you already considered my thoughts and choosed /proc/meminfo for a certain reason.
Why is /proc/meminfo better?

Andrew already accepted it. I'm not against your idea. Just curious.

> 
>> I don't know HOTPLUG feature so I'm just asking for sure.
>> Does HOTPLUG not need printing message like this?
>>
> 
> Sorry, I am also not sure what hotplug feature you are referring to.

I mean "memory hotplug" feature.
Forget it ;-)

> 
>> Thanks a lot.
>>
>>
>>>    
>>>        hugetlb_report_meminfo(m);
>>>
>>
>> --
>> To unsubscribe, send a message with 'unsubscribe linux-mm' in
>> the body to majordomo@kvack.org.  For more info on Linux MM,
>> see: http://www.linux-mm.org/ .
>> Don't email: <a href=mailto:"dont@kvack.org">
>> email@kvack.org </a>
>>
> 
> 

^ permalink raw reply	[flat|nested] 20+ messages in thread

* RE: [PATCH v2 1/2] mm: cma: split cma-reserved in dmesg log
  2014-10-23 17:01   ` [PATCH v2 1/2] mm: cma: split cma-reserved in dmesg log Michal Nazarewicz
@ 2014-10-24 10:30     ` PINTU KUMAR
  2014-10-24 16:32       ` Michal Nazarewicz
  0 siblings, 1 reply; 20+ messages in thread
From: PINTU KUMAR @ 2014-10-24 10:30 UTC (permalink / raw)
  To: 'Michal Nazarewicz',
	akpm, riel, aquini, paul.gortmaker, jmarchan, lcapitulino,
	kirill.shutemov, m.szyprowski, aneesh.kumar, iamjoonsoo.kim,
	lauraa, gioh.kim, mgorman, rientjes, hannes, vbabka, sasha.levin,
	linux-kernel, linux-mm
  Cc: pintu_agarwal, cpgs, vishnu.ps, rohit.kr, ed.savinay



----- Original Message -----
> From: Michal Nazarewicz <mina86@mina86.com>
> To: Pintu Kumar <pintu.k@samsung.com>; akpm@linux-foundation.org; riel@redhat.com; pintu.k@samsung.com; aquini@redhat.com; paul.gortmaker@windriver.com; jmarchan@redhat.com; lcapitulino@redhat.com; kirill.shutemov@linux.intel.com; m.szyprowski@samsung.com; aneesh.kumar@linux.vnet.ibm.com; iamjoonsoo.kim@lge.com; lauraa@codeaurora.org; gioh.kim@lge.com; mgorman@suse.de; rientjes@google.com; hannes@cmpxchg.org; vbabka@suse.cz; sasha.levin@oracle.com; linux-kernel@vger.kernel.org; linux-mm@kvack.org
> Cc: pintu_agarwal@yahoo.com; cpgs@samsung.com; vishnu.ps@samsung.com; rohit.kr@samsung.com; ed.savinay@samsung.com
> Sent: Thursday, 23 October 2014 10:31 PM
> Subject: Re: [PATCH v2 1/2] mm: cma: split cma-reserved in dmesg log
> 
> On Wed, Oct 22 2014, Pintu Kumar wrote:
>> When the system boots up, in the dmesg logs we can see
>> the memory statistics along with total reserved as below.
>> Memory: 458840k/458840k available, 65448k reserved, 0K highmem
>> 
>> When CMA is enabled, still the total reserved memory remains the same.
>> However, the CMA memory is not considered as reserved.
>> But, when we see /proc/meminfo, the CMA memory is part of free memory.
>> This creates confusion.
>> This patch corrects the problem by properly subtracting the CMA reserved
>> memory from the total reserved memory in dmesg logs.
>> 
>> Below is the dmesg snapshot from an arm based device with 512MB RAM and
>> 12MB single CMA region.
>> 
>> Before this change:
>> Memory: 458840k/458840k available, 65448k reserved, 0K highmem
>> 
>> After this change:
>> Memory: 458840k/458840k available, 53160k reserved, 12288k cma-reserved, 0K 
> highmem
>> 
>> Signed-off-by: Pintu Kumar <pintu.k@samsung.com>
>> Signed-off-by: Vishnu Pratap Singh <vishnu.ps@samsung.com>
> 
> Acked-by: Michal Nazarewicz <mina86@mina86.com>
> 
> 
> I'm not sure how Andrew would think about it, and I don't have strong
> feelings, but I would consider a few changes:
> 
>> ---
>> v2: Moved totalcma_pages extern declaration to linux/cma.h
>>     Removed CONFIG_CMA while show cma-reserved, from page_alloc.c
>>     Moved totalcma_pages declaration to page_alloc.c, so that if will be 
> visible 
>>     in non-CMA cases.
>>   include/linux/cma.h |    1 +
>>   mm/cma.c            |    1 +
>>   mm/page_alloc.c    |    6 ++++--
>>   3 files changed, 6 insertions(+), 2 deletions(-)
>> 
>> diff --git a/include/linux/cma.h b/include/linux/cma.h
>> index 0430ed0..0b75896 100644
>> --- a/include/linux/cma.h
>> +++ b/include/linux/cma.h
>> @@ -15,6 +15,7 @@
>>   
>>   struct cma;
>>   
>> +extern unsigned long totalcma_pages;
> 
> +#ifdef CONFIG_CMA
> +extern unsigned long totalcma_pages;
> +#else
> +#  define totalcma_pages 0UL
> +#endif
> 
>>   extern phys_addr_t cma_get_base(struct cma *cma);
>>   extern unsigned long cma_get_size(struct cma *cma);
>>   
>> diff --git a/mm/cma.c b/mm/cma.c
>> index 963bc4a..8435762 100644
>> --- a/mm/cma.c
>> +++ b/mm/cma.c
>> @@ -288,6 +288,7 @@ int __init cma_declare_contiguous(phys_addr_t base,
>>       if (ret)
>>           goto err;
>>   
>> +    totalcma_pages += (size / PAGE_SIZE);
>>       pr_info("Reserved %ld MiB at %08lx\n", (unsigned 
> long)size / SZ_1M,
>>           (unsigned long)base);
>>       return 0;
>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>> index dd73f9a..ababbd8 100644
>> --- a/mm/page_alloc.c
>> +++ b/mm/page_alloc.c
>> @@ -110,6 +110,7 @@ static DEFINE_SPINLOCK(managed_page_count_lock);
>>   
>>   unsigned long totalram_pages __read_mostly;
>>   unsigned long totalreserve_pages __read_mostly;
>> +unsigned long totalcma_pages __read_mostly;
> 
> Move this to cma.c.
> 

In our earlier patch (first version), we added it in cmc.c itself.
But, Andrew wanted this variable to be visible in non-CMA case as well to avoid build error, when we use 
this variable in mem_init_print_info, without CONFIG_CMA.
So, we moved it to page_alloc.c

>>   /*
>>   * When calculating the number of globally allowed dirty pages, there
>>   * is a certain number of per-zone reserves that should not be
>> @@ -5520,7 +5521,7 @@ void __init mem_init_print_info(const char *str)
>>   
>>       pr_info("Memory: %luK/%luK available "
>>             "(%luK kernel code, %luK rwdata, %luK rodata, "
>> -          "%luK init, %luK bss, %luK reserved"
>> +          "%luK init, %luK bss, %luK reserved, %luK 
> cma-reserved"
>>   #ifdef    CONFIG_HIGHMEM
>>             ", %luK highmem"
>>   #endif
>> @@ -5528,7 +5529,8 @@ void __init mem_init_print_info(const char *str)
>>             nr_free_pages() << (PAGE_SHIFT-10), physpages << 
> (PAGE_SHIFT-10),
>>             codesize >> 10, datasize >> 10, rosize >> 10,
>>             (init_data_size + init_code_size) >> 10, bss_size 
>>> 10,
>> -          (physpages - totalram_pages) << (PAGE_SHIFT-10),
>> +          (physpages - totalram_pages - totalcma_pages) << 
> (PAGE_SHIFT-10),
>> +          totalcma_pages << (PAGE_SHIFT-10),
>>   #ifdef    CONFIG_HIGHMEM
>>             totalhigh_pages << (PAGE_SHIFT-10),
>>   #endif
>> -- 
>> 1.7.9.5
>> 
> 
> -- 
> Best regards,                                        _    _
> .o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
> ..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
> ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--
> 
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@kvack.org.  For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"dont@kvack.org"> 
> email@kvack.org </a>
>


^ permalink raw reply	[flat|nested] 20+ messages in thread

* RE: [PATCH v2 2/2] fs: proc: Include cma info in proc/meminfo
  2014-10-24 10:10         ` Gioh Kim
@ 2014-10-24 10:43           ` PINTU KUMAR
  0 siblings, 0 replies; 20+ messages in thread
From: PINTU KUMAR @ 2014-10-24 10:43 UTC (permalink / raw)
  To: 'Gioh Kim',
	akpm, riel, aquini, paul.gortmaker, jmarchan, lcapitulino,
	kirill.shutemov, m.szyprowski, aneesh.kumar, iamjoonsoo.kim,
	mina86, lauraa, mgorman, rientjes, hannes, vbabka, sasha.levin,
	linux-kernel, linux-mm
  Cc: pintu_agarwal, cpgs, vishnu.ps, rohit.kr, ed.savinay



----- Original Message -----
> From: Gioh Kim <gioh.kim@lge.com>
> To: PINTU KUMAR <pintu.k@samsung.com>; akpm@linux-foundation.org;
riel@redhat.com; aquini@redhat.com; paul.gortmaker@windriver.com;
jmarchan@redhat.com; lcapitulino@redhat.com;
kirill.shutemov@linux.intel.com; m.szyprowski@samsung.com;
aneesh.kumar@linux.vnet.ibm.com; iamjoonsoo.kim@lge.com; mina86@mina86.com;
lauraa@codeaurora.org; mgorman@suse.de; rientjes@google.com; hannes@cmpxchg.
org; vbabka@suse.cz; sasha.levin@oracle.com; linux-kernel@vger.kernel.org;
linux-mm@kvack.org
> Cc: pintu_agarwal@yahoo.com; cpgs@samsung.com; vishnu.ps@samsung.com;
rohit.kr@samsung.com; ed.savinay@samsung.com
> Sent: Friday, 24 October 2014 3:40 PM
> Subject: Re: [PATCH v2 2/2] fs: proc: Include cma info in proc/meminfo
> 
> 
> 
> 2014-10-24 오후 5:57, PINTU KUMAR 쓴 글:
>> Hi,
>> 
>> ----- Original Message -----
>>> From: Gioh Kim <gioh.kim@lge.com>
>>> To: Pintu Kumar <pintu.k@samsung.com>; akpm@linux-foundation.org;
>> riel@redhat.com; aquini@redhat.com; paul.gortmaker@windriver.com;
>> jmarchan@redhat.com; lcapitulino@redhat.com;
>> kirill.shutemov@linux.intel.com; m.szyprowski@samsung.com;
>> aneesh.kumar@linux.vnet.ibm.com; iamjoonsoo.kim@lge.com;
mina86@mina86.com;
>> lauraa@codeaurora.org; mgorman@suse.de; rientjes@google.com; 
> hannes@cmpxchg.
>> org; vbabka@suse.cz; sasha.levin@oracle.com; linux-
kernel@vger.kernel.org;
>> linux-mm@kvack.org
>>> Cc: pintu_agarwal@yahoo.com; cpgs@samsung.com; vishnu.ps@samsung.com;
>> rohit.kr@samsung.com; ed.savinay@samsung.com
>>> Sent: Thursday, 23 October 2014 5:49 AM
>>> Subject: Re: [PATCH v2 2/2] fs: proc: Include cma info in proc/meminfo
>>> 
>>> 
>>> 
>>> 2014-10-22 오후 11:06, Pintu Kumar 쓴 글:
>>>> This patch include CMA info (CMATotal, CMAFree) in /proc/meminfo.
>>>> Currently, in a CMA enabled system, if somebody wants to know the
>>>> total CMA size declared, there is no way to tell, other than the 
> dmesg
>>>> or /var/log/messages logs.
>>>> With this patch we are showing the CMA info as part of meminfo, so 
> that
>>>> it can be determined at any point of time.
>>>> This will be populated only when CMA is enabled.
>>>> 
>>>> Below is the sample output from a ARM based device with RAM:512MB 
> and
>>> CMA:16MB.
>>>> 
>>>> MemTotal:        471172 kB
>>>> MemFree:          111712 kB
>>>> MemAvailable:    271172 kB
>>>> .
>>>> .
>>>> .
>>>> CmaTotal:          16384 kB
>>>> CmaFree:            6144 kB
>>>> 
>>>> This patch also fix below checkpatch errors that were found during 
> these
>>> changes.
>>> 
>>> Why don't you split patch for it?
>>> I think there's a rule not to mix separate patchs.
>>> 
>> 
>> Last time when we submitted separate patches for checkpatch errors, it
was
>> suggested to
>> Include these kinds of fixes along with some meaningful patches together.
>> So, we included it in same patch.
>> 
>>>> 
>>>> ERROR: space required after that ',' (ctx:ExV)
>>>> 199: FILE: fs/proc/meminfo.c:199:
>>>> +      ,atomic_long_read(&num_poisoned_pages) << 
> (PAGE_SHIFT -
>>> 10)
>>>>             ^
>>>> 
>>>> ERROR: space required after that ',' (ctx:ExV)
>>>> 202: FILE: fs/proc/meminfo.c:202:
>>>> +      ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
>>>>             ^
>>>> 
>>>> ERROR: space required after that ',' (ctx:ExV)
>>>> 206: FILE: fs/proc/meminfo.c:206:
>>>> +      ,K(totalcma_pages)
>>>>             ^
>>>> 
>>>> total: 3 errors, 0 warnings, 2 checks, 236 lines checked
>>>> 
>>>> Signed-off-by: Pintu Kumar <pintu.k@samsung.com>
>>>> Signed-off-by: Vishnu Pratap Singh <vishnu.ps@samsung.com>
>>>> ---
>>>>     fs/proc/meminfo.c |  15 +++++++++++++--
>>>>     1 file changed, 13 insertions(+), 2 deletions(-)
>>>> 
>>>> diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
>>>> index aa1eee0..d3ebf2e 100644
>>>> --- a/fs/proc/meminfo.c
>>>> +++ b/fs/proc/meminfo.c
>>>> @@ -12,6 +12,9 @@
>>>>     #include <linux/vmstat.h>
>>>>     #include <linux/atomic.h>
>>>>     #include <linux/vmalloc.h>
>>>> +#ifdef CONFIG_CMA
>>>> +#include <linux/cma.h>
>>>> +#endif
>>>>     #include <asm/page.h>
>>>>     #include <asm/pgtable.h>
>>>>     #include "internal.h"
>>>> @@ -138,6 +141,10 @@ static int meminfo_proc_show(struct seq_file 
> *m,
>> void
>>> *v)
>>>>     #ifdef CONFIG_TRANSPARENT_HUGEPAGE
>>>>             "AnonHugePages:  %8lu kB\n"
>>>>     #endif
>>>> +#ifdef CONFIG_CMA
>>>> +        "CmaTotal:      %8lu kB\n"
>>>> +        "CmaFree:        %8lu kB\n"
>>>> +#endif
>>>>             ,
>>>>             K(i.totalram),
>>>>             K(i.freeram),
>>>> @@ -187,12 +194,16 @@ static int meminfo_proc_show(struct seq_file 
> *m,
>> void
>>> *v)
>>>>             vmi.used >> 10,
>>>>             vmi.largest_chunk >> 10
>>>>     #ifdef CONFIG_MEMORY_FAILURE
>>>> -        ,atomic_long_read(&num_poisoned_pages) << 
> (PAGE_SHIFT -
>>> 10)
>>>> +        , atomic_long_read(&num_poisoned_pages) << 
> (PAGE_SHIFT -
>>> 10)
>>>>     #endif
>>>>     #ifdef CONFIG_TRANSPARENT_HUGEPAGE
>>>> -        ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
>>>> +        , K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
>>>>               HPAGE_PMD_NR)
>>>>     #endif
>>>> +#ifdef CONFIG_CMA
>>>> +        , K(totalcma_pages)
>>>> +        , K(global_page_state(NR_FREE_CMA_PAGES))
>>>> +#endif
>>>>             );
>>> 
>>> Just for sure, are zoneinfo and pagetypeinfo not suitable?
>>> 
>> 
>> I think zoneinfo shows only current free cma pages.
>> Same is the case with vmstat.
>> # cat /proc/zoneinfo | grep cma
>>       nr_free_cma  2560
>> # cat /proc/vmstat | grep cma
>> nr_free_cma 2560
> 
> We could add a line to show total cma pages like following and add it all.
> # cat /proc/zoneinfo | grep cma
>       nr_total_cma XXXX
>       nr_free_cma  2560
> 
> Yes. each zone can have cma area and it is annoying to add it all.
> But IMO it is rare and not difficult.
> And I think it'd better that zoneinfo has nr_total_cma line.
> 
> I think you already considered my thoughts and choosed /proc/meminfo for
a 
> certain reason.
> Why is /proc/meminfo better?
> 
We already had a plan to include CMA info in meminfo, but first we wanted
to have totalcma_pages available.
So, we developed it as second patch, if first is accepted.
We have chosen meminfo, because, we thought it's better to capture all
information at one place.
We have a tool where we capture free/cached/swap memory info, along with
CMA info.
So, reading from single proc entry it is better.
And I am sure there will be many other user space tool like that, and it
will be easy to integrate CMA info to them.
For example; we can integrate CMA info in "free" command, if required.

Also, when we saw /proc/meminfo, we saw that other similar fields are also
present here.
Such as;
SwapTotal:             0 kB
SwapFree:              0 kB
VmallocTotal:     499712 kB
VmallocUsed:       31576 kB

> Andrew already accepted it. I'm not against your idea. Just curious.
> 
>> 
>>> I don't know HOTPLUG feature so I'm just asking for sure.
>>> Does HOTPLUG not need printing message like this?
>>> 
>> 
>> Sorry, I am also not sure what hotplug feature you are referring to.
> 
> I mean "memory hotplug" feature.
> Forget it ;-)
> 
>> 
>>> Thanks a lot.
>>> 
>>> 
>>>>     
>>>>         hugetlb_report_meminfo(m);
>>>> 
>>> 
>>> --
>>> To unsubscribe, send a message with 'unsubscribe linux-mm' in
>>> the body to majordomo@kvack.org.  For more info on Linux MM,
>>> see: http://www.linux-mm.org/ .
>>> Don't email: <a href=mailto:"dont@kvack.org">
>>> email@kvack.org </a>
> 
>>> 
>> 
>> 
> 
> --
> To unsubscribe, send a message with 'unsubscribe linux-mm' in
> the body to majordomo@kvack.org.  For more info on Linux MM,
> see: http://www.linux-mm.org/ .
> Don't email: <a href=mailto:"dont@kvack.org"> 
> email@kvack.org </a>
>


^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v2 2/2] fs: proc: Include cma info in proc/meminfo
  2014-10-22 14:06   ` [PATCH v2 2/2] fs: proc: Include cma info in proc/meminfo Pintu Kumar
  2014-10-22 20:00     ` Andrew Morton
  2014-10-23  0:19     ` Gioh Kim
@ 2014-10-24 16:31     ` Michal Nazarewicz
  2014-10-27 23:15       ` Andrew Morton
  2 siblings, 1 reply; 20+ messages in thread
From: Michal Nazarewicz @ 2014-10-24 16:31 UTC (permalink / raw)
  To: Pintu Kumar, akpm, riel, pintu.k, aquini, paul.gortmaker,
	jmarchan, lcapitulino, kirill.shutemov, m.szyprowski,
	aneesh.kumar, iamjoonsoo.kim, lauraa, gioh.kim, mgorman,
	rientjes, hannes, vbabka, sasha.levin, linux-kernel, linux-mm
  Cc: pintu_agarwal, cpgs, vishnu.ps, rohit.kr, ed.savinay

On Wed, Oct 22 2014, Pintu Kumar <pintu.k@samsung.com> wrote:
> This patch include CMA info (CMATotal, CMAFree) in /proc/meminfo.
> Currently, in a CMA enabled system, if somebody wants to know the
> total CMA size declared, there is no way to tell, other than the dmesg
> or /var/log/messages logs.
> With this patch we are showing the CMA info as part of meminfo, so that
> it can be determined at any point of time.
> This will be populated only when CMA is enabled.
>
> Below is the sample output from a ARM based device with RAM:512MB and CMA:16MB.
>
> MemTotal:         471172 kB
> MemFree:          111712 kB
> MemAvailable:     271172 kB
> .
> .
> .
> CmaTotal:          16384 kB
> CmaFree:            6144 kB
>
> This patch also fix below checkpatch errors that were found during these changes.

As already mentioned, this should be in separate patch.

>
> ERROR: space required after that ',' (ctx:ExV)
> 199: FILE: fs/proc/meminfo.c:199:
> +       ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
>         ^
>
> ERROR: space required after that ',' (ctx:ExV)
> 202: FILE: fs/proc/meminfo.c:202:
> +       ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
>         ^
>
> ERROR: space required after that ',' (ctx:ExV)
> 206: FILE: fs/proc/meminfo.c:206:
> +       ,K(totalcma_pages)
>         ^
>
> total: 3 errors, 0 warnings, 2 checks, 236 lines checked
>
> Signed-off-by: Pintu Kumar <pintu.k@samsung.com>
> Signed-off-by: Vishnu Pratap Singh <vishnu.ps@samsung.com>

Acked-by: Michal Nazarewicz <mina86@mina86.com>

> ---
>  fs/proc/meminfo.c |   15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
>
> diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
> index aa1eee0..d3ebf2e 100644
> --- a/fs/proc/meminfo.c
> +++ b/fs/proc/meminfo.c
> @@ -12,6 +12,9 @@
>  #include <linux/vmstat.h>
>  #include <linux/atomic.h>
>  #include <linux/vmalloc.h>
> +#ifdef CONFIG_CMA
> +#include <linux/cma.h>
> +#endif
>  #include <asm/page.h>
>  #include <asm/pgtable.h>
>  #include "internal.h"
> @@ -138,6 +141,10 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
>  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
>  		"AnonHugePages:  %8lu kB\n"
>  #endif
> +#ifdef CONFIG_CMA
> +		"CmaTotal:       %8lu kB\n"
> +		"CmaFree:        %8lu kB\n"
> +#endif
>  		,
>  		K(i.totalram),
>  		K(i.freeram),
> @@ -187,12 +194,16 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
>  		vmi.used >> 10,
>  		vmi.largest_chunk >> 10
>  #ifdef CONFIG_MEMORY_FAILURE
> -		,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
> +		, atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
>  #endif
>  #ifdef CONFIG_TRANSPARENT_HUGEPAGE
> -		,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
> +		, K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
>  		   HPAGE_PMD_NR)
>  #endif
> +#ifdef CONFIG_CMA
> +		, K(totalcma_pages)
> +		, K(global_page_state(NR_FREE_CMA_PAGES))
> +#endif
>  		);
>  
>  	hugetlb_report_meminfo(m);
> -- 
> 1.7.9.5
>

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v2 1/2] mm: cma: split cma-reserved in dmesg log
  2014-10-24 10:30     ` PINTU KUMAR
@ 2014-10-24 16:32       ` Michal Nazarewicz
  0 siblings, 0 replies; 20+ messages in thread
From: Michal Nazarewicz @ 2014-10-24 16:32 UTC (permalink / raw)
  To: PINTU KUMAR, akpm, riel, aquini, paul.gortmaker, jmarchan,
	lcapitulino, kirill.shutemov, m.szyprowski, aneesh.kumar,
	iamjoonsoo.kim, lauraa, gioh.kim, mgorman, rientjes, hannes,
	vbabka, sasha.levin, linux-kernel, linux-mm
  Cc: pintu_agarwal, cpgs, vishnu.ps, rohit.kr, ed.savinay

>> On Wed, Oct 22 2014, Pintu Kumar wrote:
>>> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
>>> index dd73f9a..ababbd8 100644
>>> --- a/mm/page_alloc.c
>>> +++ b/mm/page_alloc.c
>>> @@ -110,6 +110,7 @@ static DEFINE_SPINLOCK(managed_page_count_lock);
>>>   
>>>   unsigned long totalram_pages __read_mostly;
>>>   unsigned long totalreserve_pages __read_mostly;
>>> +unsigned long totalcma_pages __read_mostly;
>> 
>> Move this to cma.c.

On Fri, Oct 24 2014, PINTU KUMAR <pintu.k@samsung.com> wrote:
> In our earlier patch (first version), we added it in cmc.c itself.
> But, Andrew wanted this variable to be visible in non-CMA case as well to avoid build error, when we use 
> this variable in mem_init_print_info, without CONFIG_CMA.
> So, we moved it to page_alloc.c

If you add 

+#ifdef CONFIG_CMA
+extern unsigned long totalcma_pages;
+#else
+#  define totalcma_pages 0UL
+#endif

to linux/cma.h the variable will get replaced with a constant zero if
!CONFIG_CMA.

-- 
Best regards,                                         _     _
.o. | Liege of Serenely Enlightened Majesty of      o' \,=./ `o
..o | Computer Science,  Michał “mina86” Nazarewicz    (o o)
ooo +--<mpn@google.com>--<xmpp:mina86@jabber.org>--ooO--(_)--Ooo--

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v2 2/2] fs: proc: Include cma info in proc/meminfo
  2014-10-24 16:31     ` Michal Nazarewicz
@ 2014-10-27 23:15       ` Andrew Morton
  0 siblings, 0 replies; 20+ messages in thread
From: Andrew Morton @ 2014-10-27 23:15 UTC (permalink / raw)
  To: Michal Nazarewicz
  Cc: Pintu Kumar, riel, aquini, paul.gortmaker, jmarchan, lcapitulino,
	kirill.shutemov, m.szyprowski, aneesh.kumar, iamjoonsoo.kim,
	lauraa, gioh.kim, mgorman, rientjes, hannes, vbabka, sasha.levin,
	linux-kernel, linux-mm, pintu_agarwal, cpgs, vishnu.ps, rohit.kr,
	ed.savinay

On Fri, 24 Oct 2014 18:31:21 +0200 Michal Nazarewicz <mina86@mina86.com> wrote:

> On Wed, Oct 22 2014, Pintu Kumar <pintu.k@samsung.com> wrote:
> > This patch include CMA info (CMATotal, CMAFree) in /proc/meminfo.
> > Currently, in a CMA enabled system, if somebody wants to know the
> > total CMA size declared, there is no way to tell, other than the dmesg
> > or /var/log/messages logs.
> > With this patch we are showing the CMA info as part of meminfo, so that
> > it can be determined at any point of time.
> > This will be populated only when CMA is enabled.
> >
> > Below is the sample output from a ARM based device with RAM:512MB and CMA:16MB.
> >
> > MemTotal:         471172 kB
> > MemFree:          111712 kB
> > MemAvailable:     271172 kB
> > .
> > .
> > .
> > CmaTotal:          16384 kB
> > CmaFree:            6144 kB
> >
> > This patch also fix below checkpatch errors that were found during these changes.
> 
> As already mentioned, this should be in separate patch.

Yes, in theory.  But a couple of little whitespace fixes aren't really
worth a resend.  As long as they don't make the patch harder to read
and to backport I usually just let them through.

^ permalink raw reply	[flat|nested] 20+ messages in thread

* Re: [PATCH v2 1/2] mm: cma: split cma-reserved in dmesg log
  2014-10-22 14:06 ` [PATCH v2 1/2] " Pintu Kumar
  2014-10-22 14:06   ` [PATCH v2 2/2] fs: proc: Include cma info in proc/meminfo Pintu Kumar
  2014-10-23 17:01   ` [PATCH v2 1/2] mm: cma: split cma-reserved in dmesg log Michal Nazarewicz
@ 2014-11-03 23:57   ` David Rientjes
  2014-11-04 17:15     ` PINTU KUMAR
  2 siblings, 1 reply; 20+ messages in thread
From: David Rientjes @ 2014-11-03 23:57 UTC (permalink / raw)
  To: Pintu Kumar
  Cc: akpm, riel, aquini, paul.gortmaker, jmarchan, lcapitulino,
	kirill.shutemov, m.szyprowski, aneesh.kumar, iamjoonsoo.kim,
	mina86, lauraa, gioh.kim, mgorman, hannes, vbabka, sasha.levin,
	linux-kernel, linux-mm, pintu_agarwal, cpgs, vishnu.ps, rohit.kr,
	ed.savinay

On Wed, 22 Oct 2014, Pintu Kumar wrote:

> diff --git a/include/linux/cma.h b/include/linux/cma.h
> index 0430ed0..0b75896 100644
> --- a/include/linux/cma.h
> +++ b/include/linux/cma.h
> @@ -15,6 +15,7 @@
>  
>  struct cma;
>  
> +extern unsigned long totalcma_pages;
>  extern phys_addr_t cma_get_base(struct cma *cma);
>  extern unsigned long cma_get_size(struct cma *cma);
>  
> diff --git a/mm/cma.c b/mm/cma.c
> index 963bc4a..8435762 100644
> --- a/mm/cma.c
> +++ b/mm/cma.c
> @@ -288,6 +288,7 @@ int __init cma_declare_contiguous(phys_addr_t base,
>  	if (ret)
>  		goto err;
>  
> +	totalcma_pages += (size / PAGE_SIZE);
>  	pr_info("Reserved %ld MiB at %08lx\n", (unsigned long)size / SZ_1M,
>  		(unsigned long)base);
>  	return 0;
> diff --git a/mm/page_alloc.c b/mm/page_alloc.c
> index dd73f9a..ababbd8 100644
> --- a/mm/page_alloc.c
> +++ b/mm/page_alloc.c
> @@ -110,6 +110,7 @@ static DEFINE_SPINLOCK(managed_page_count_lock);
>  
>  unsigned long totalram_pages __read_mostly;
>  unsigned long totalreserve_pages __read_mostly;
> +unsigned long totalcma_pages __read_mostly;

Shouldn't this be __initdata instead?

>  /*
>   * When calculating the number of globally allowed dirty pages, there
>   * is a certain number of per-zone reserves that should not be
> @@ -5520,7 +5521,7 @@ void __init mem_init_print_info(const char *str)
>  
>  	pr_info("Memory: %luK/%luK available "
>  	       "(%luK kernel code, %luK rwdata, %luK rodata, "
> -	       "%luK init, %luK bss, %luK reserved"
> +	       "%luK init, %luK bss, %luK reserved, %luK cma-reserved"
>  #ifdef	CONFIG_HIGHMEM
>  	       ", %luK highmem"
>  #endif
> @@ -5528,7 +5529,8 @@ void __init mem_init_print_info(const char *str)
>  	       nr_free_pages() << (PAGE_SHIFT-10), physpages << (PAGE_SHIFT-10),
>  	       codesize >> 10, datasize >> 10, rosize >> 10,
>  	       (init_data_size + init_code_size) >> 10, bss_size >> 10,
> -	       (physpages - totalram_pages) << (PAGE_SHIFT-10),
> +	       (physpages - totalram_pages - totalcma_pages) << (PAGE_SHIFT-10),
> +	       totalcma_pages << (PAGE_SHIFT-10),
>  #ifdef	CONFIG_HIGHMEM
>  	       totalhigh_pages << (PAGE_SHIFT-10),
>  #endif

^ permalink raw reply	[flat|nested] 20+ messages in thread

* RE: [PATCH v2 1/2] mm: cma: split cma-reserved in dmesg log
  2014-11-03 23:57   ` David Rientjes
@ 2014-11-04 17:15     ` PINTU KUMAR
  0 siblings, 0 replies; 20+ messages in thread
From: PINTU KUMAR @ 2014-11-04 17:15 UTC (permalink / raw)
  To: 'David Rientjes'
  Cc: akpm, riel, aquini, paul.gortmaker, jmarchan, lcapitulino,
	kirill.shutemov, m.szyprowski, aneesh.kumar, iamjoonsoo.kim,
	mina86, lauraa, gioh.kim, mgorman, hannes, vbabka, sasha.levin,
	linux-kernel, linux-mm, pintu_agarwal, cpgs, vishnu.ps, rohit.kr,
	ed.savinay



> -----Original Message-----
> From: David Rientjes [mailto:rientjes@google.com]
> Sent: Tuesday, November 04, 2014 5:27 AM
> To: Pintu Kumar
> Cc: akpm@linux-foundation.org; riel@redhat.com; aquini@redhat.com;
> paul.gortmaker@windriver.com; jmarchan@redhat.com;
> lcapitulino@redhat.com; kirill.shutemov@linux.intel.com;
> m.szyprowski@samsung.com; aneesh.kumar@linux.vnet.ibm.com;
> iamjoonsoo.kim@lge.com; mina86@mina86.com; lauraa@codeaurora.org;
> gioh.kim@lge.com; mgorman@suse.de; hannes@cmpxchg.org; vbabka@suse.cz;
> sasha.levin@oracle.com; linux-kernel@vger.kernel.org; linux-mm@kvack.org;
> pintu_agarwal@yahoo.com; cpgs@samsung.com; vishnu.ps@samsung.com;
> rohit.kr@samsung.com; ed.savinay@samsung.com
> Subject: Re: [PATCH v2 1/2] mm: cma: split cma-reserved in dmesg log
> 
> On Wed, 22 Oct 2014, Pintu Kumar wrote:
> 
> > diff --git a/include/linux/cma.h b/include/linux/cma.h index
> > 0430ed0..0b75896 100644
> > --- a/include/linux/cma.h
> > +++ b/include/linux/cma.h
> > @@ -15,6 +15,7 @@
> >
> >  struct cma;
> >
> > +extern unsigned long totalcma_pages;
> >  extern phys_addr_t cma_get_base(struct cma *cma);  extern unsigned
> > long cma_get_size(struct cma *cma);
> >
> > diff --git a/mm/cma.c b/mm/cma.c
> > index 963bc4a..8435762 100644
> > --- a/mm/cma.c
> > +++ b/mm/cma.c
> > @@ -288,6 +288,7 @@ int __init cma_declare_contiguous(phys_addr_t base,
> >  	if (ret)
> >  		goto err;
> >
> > +	totalcma_pages += (size / PAGE_SIZE);
> >  	pr_info("Reserved %ld MiB at %08lx\n", (unsigned long)size / SZ_1M,
> >  		(unsigned long)base);
> >  	return 0;
> > diff --git a/mm/page_alloc.c b/mm/page_alloc.c index dd73f9a..ababbd8
> > 100644
> > --- a/mm/page_alloc.c
> > +++ b/mm/page_alloc.c
> > @@ -110,6 +110,7 @@ static DEFINE_SPINLOCK(managed_page_count_lock);
> >
> >  unsigned long totalram_pages __read_mostly;  unsigned long
> > totalreserve_pages __read_mostly;
> > +unsigned long totalcma_pages __read_mostly;
> 
> Shouldn't this be __initdata instead?
> 

No, we wanted to retain this variable for later use. 
We wanted to use this to print CMA info in /proc/meminfo.
Please see the next patch for this set.
[PATCH v2 2/2] fs: proc: Include cma info in proc/meminfo


> >  /*
> >   * When calculating the number of globally allowed dirty pages, there
> >   * is a certain number of per-zone reserves that should not be @@
> > -5520,7 +5521,7 @@ void __init mem_init_print_info(const char *str)
> >
> >  	pr_info("Memory: %luK/%luK available "
> >  	       "(%luK kernel code, %luK rwdata, %luK rodata, "
> > -	       "%luK init, %luK bss, %luK reserved"
> > +	       "%luK init, %luK bss, %luK reserved, %luK cma-reserved"
> >  #ifdef	CONFIG_HIGHMEM
> >  	       ", %luK highmem"
> >  #endif
> > @@ -5528,7 +5529,8 @@ void __init mem_init_print_info(const char *str)
> >  	       nr_free_pages() << (PAGE_SHIFT-10), physpages << (PAGE_SHIFT-10),
> >  	       codesize >> 10, datasize >> 10, rosize >> 10,
> >  	       (init_data_size + init_code_size) >> 10, bss_size >> 10,
> > -	       (physpages - totalram_pages) << (PAGE_SHIFT-10),
> > +	       (physpages - totalram_pages - totalcma_pages) << (PAGE_SHIFT-10),
> > +	       totalcma_pages << (PAGE_SHIFT-10),
> >  #ifdef	CONFIG_HIGHMEM
> >  	       totalhigh_pages << (PAGE_SHIFT-10),  #endif


^ permalink raw reply	[flat|nested] 20+ messages in thread

end of thread, other threads:[~2014-11-04 17:15 UTC | newest]

Thread overview: 20+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-10-20  7:33 [PATCH] mm: cma: split cma-reserved in dmesg log Pintu Kumar
2014-10-20  9:35 ` Michal Nazarewicz
2014-10-20 22:48 ` Andrew Morton
2014-10-21  0:47 ` Gioh Kim
2014-10-21 13:21   ` PINTU KUMAR
2014-10-21 23:55     ` Gioh Kim
2014-10-22 14:06 ` [PATCH v2 1/2] " Pintu Kumar
2014-10-22 14:06   ` [PATCH v2 2/2] fs: proc: Include cma info in proc/meminfo Pintu Kumar
2014-10-22 20:00     ` Andrew Morton
2014-10-23  0:19     ` Gioh Kim
2014-10-24  8:57       ` PINTU KUMAR
2014-10-24 10:10         ` Gioh Kim
2014-10-24 10:43           ` PINTU KUMAR
2014-10-24 16:31     ` Michal Nazarewicz
2014-10-27 23:15       ` Andrew Morton
2014-10-23 17:01   ` [PATCH v2 1/2] mm: cma: split cma-reserved in dmesg log Michal Nazarewicz
2014-10-24 10:30     ` PINTU KUMAR
2014-10-24 16:32       ` Michal Nazarewicz
2014-11-03 23:57   ` David Rientjes
2014-11-04 17:15     ` PINTU KUMAR

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).