All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] lib/show_mem.c: extend show_mem() to support showing drivers' memory consumption
@ 2020-01-17  8:24 Jing Xia
  2020-02-11  3:19 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Jing Xia @ 2020-01-17  8:24 UTC (permalink / raw)
  To: akpm
  Cc: npiggin, rppt, allison, tglx, linux-mm, linux-kernel, yuming.han,
	chunyang.zhang, Jing Xia

From: Jing Xia <jing.xia@unisoc.com>

In low memory situations, sometimes we need to check how much memory
a driver using.This patch add a notifer chain to show_mem.So a driver
can show their memory usage when show_mem_extend() is called.

Co-developed-by: Yuming Han <yuming.han@unisoc.com>
Signed-off-by: Yuming Han <yuming.han@unisoc.com>
Signed-off-by: Jing Xia <jing.xia@unisoc.com>
---
 include/linux/mm.h |  9 +++++++++
 lib/show_mem.c     | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+)

diff --git a/include/linux/mm.h b/include/linux/mm.h
index cfaa8fe..a37274a 100644
--- a/include/linux/mm.h
+++ b/include/linux/mm.h
@@ -2201,6 +2201,15 @@ extern void memmap_init_zone(unsigned long, int, unsigned long, unsigned long,
 #ifdef __HAVE_ARCH_RESERVED_KERNEL_PAGES
 extern unsigned long arch_reserved_kernel_pages(void);
 #endif
+enum show_mem_extend_type {
+	SHOW_MEM_EXTEND_BASIC,
+	SHOW_MEM_EXTEND_CLASSIC,
+	SHOW_MEM_EXTEND_ALL
+};
+extern int register_show_mem_notifier(struct notifier_block *nb);
+extern int unregister_show_mem_notifier(struct notifier_block *nb);
+extern void show_mem_extend(unsigned int flags, nodemask_t *nodemask,
+			    enum show_mem_extend_type type);
 
 extern __printf(3, 4)
 void warn_alloc(gfp_t gfp_mask, nodemask_t *nodemask, const char *fmt, ...);
diff --git a/lib/show_mem.c b/lib/show_mem.c
index 1c26c14..6b013cb 100644
--- a/lib/show_mem.c
+++ b/lib/show_mem.c
@@ -7,6 +7,8 @@
 
 #include <linux/mm.h>
 #include <linux/cma.h>
+#include <linux/notifier.h>
+#include <linux/swap.h>
 
 void show_mem(unsigned int filter, nodemask_t *nodemask)
 {
@@ -42,3 +44,37 @@ void show_mem(unsigned int filter, nodemask_t *nodemask)
 	printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
 #endif
 }
+
+static BLOCKING_NOTIFIER_HEAD(show_mem_notify_list);
+
+int register_show_mem_notifier(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_register(&show_mem_notify_list, nb);
+}
+EXPORT_SYMBOL_GPL(register_show_mem_notifier);
+
+int unregister_show_mem_notifier(struct notifier_block *nb)
+{
+	return blocking_notifier_chain_unregister(&show_mem_notify_list, nb);
+}
+EXPORT_SYMBOL_GPL(unregister_show_mem_notifier);
+
+void show_mem_extend(unsigned int filter, nodemask_t *nodemask,
+		     enum show_mem_extend_type type)
+{
+	unsigned long used = 0;
+	struct sysinfo si;
+
+	pr_info("Mem-Info-Extend:\n");
+	show_mem(filter, NULL);
+	si_meminfo(&si);
+	pr_info("MemTotal:	%8lu KB\n"
+		"Buffers:	%8lu KB\n"
+		"SwapCached:	%8lu KB\n",
+		(si.totalram) << (PAGE_SHIFT - 10),
+		(si.bufferram) << (PAGE_SHIFT - 10),
+		total_swapcache_pages() << (PAGE_SHIFT - 10));
+
+	blocking_notifier_call_chain(&show_mem_notify_list,
+				     (unsigned long)type, &used);
+}
-- 
1.9.1


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

* Re: [RFC] lib/show_mem.c: extend show_mem() to support showing drivers' memory consumption
  2020-01-17  8:24 [RFC] lib/show_mem.c: extend show_mem() to support showing drivers' memory consumption Jing Xia
@ 2020-02-11  3:19 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2020-02-11  3:19 UTC (permalink / raw)
  To: Jing Xia
  Cc: akpm, npiggin, rppt, allison, tglx, linux-mm, linux-kernel,
	yuming.han, chunyang.zhang, Jing Xia

On Fri, Jan 17, 2020 at 04:24:05PM +0800, Jing Xia wrote:
> From: Jing Xia <jing.xia@unisoc.com>
> 
> In low memory situations, sometimes we need to check how much memory
> a driver using.This patch add a notifer chain to show_mem.So a driver
> can show their memory usage when show_mem_extend() is called.
> 
> Co-developed-by: Yuming Han <yuming.han@unisoc.com>
> Signed-off-by: Yuming Han <yuming.han@unisoc.com>
> Signed-off-by: Jing Xia <jing.xia@unisoc.com>
> ---
>  include/linux/mm.h |  9 +++++++++
>  lib/show_mem.c     | 36 ++++++++++++++++++++++++++++++++++++
>  2 files changed, 45 insertions(+)
> 
> diff --git a/include/linux/mm.h b/include/linux/mm.h
> index cfaa8fe..a37274a 100644
> --- a/include/linux/mm.h
> +++ b/include/linux/mm.h
> @@ -2201,6 +2201,15 @@ extern void memmap_init_zone(unsigned long, int, unsigned long, unsigned long,
>  #ifdef __HAVE_ARCH_RESERVED_KERNEL_PAGES
>  extern unsigned long arch_reserved_kernel_pages(void);
>  #endif
> +enum show_mem_extend_type {
> +	SHOW_MEM_EXTEND_BASIC,
> +	SHOW_MEM_EXTEND_CLASSIC,
> +	SHOW_MEM_EXTEND_ALL
> +};
> +extern int register_show_mem_notifier(struct notifier_block *nb);
> +extern int unregister_show_mem_notifier(struct notifier_block *nb);
> +extern void show_mem_extend(unsigned int flags, nodemask_t *nodemask,
> +			    enum show_mem_extend_type type);
>  
>  extern __printf(3, 4)
>  void warn_alloc(gfp_t gfp_mask, nodemask_t *nodemask, const char *fmt, ...);
> diff --git a/lib/show_mem.c b/lib/show_mem.c
> index 1c26c14..6b013cb 100644
> --- a/lib/show_mem.c
> +++ b/lib/show_mem.c
> @@ -7,6 +7,8 @@
>  
>  #include <linux/mm.h>
>  #include <linux/cma.h>
> +#include <linux/notifier.h>
> +#include <linux/swap.h>
>  
>  void show_mem(unsigned int filter, nodemask_t *nodemask)
>  {
> @@ -42,3 +44,37 @@ void show_mem(unsigned int filter, nodemask_t *nodemask)
>  	printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
>  #endif
>  }
> +
> +static BLOCKING_NOTIFIER_HEAD(show_mem_notify_list);
> +
> +int register_show_mem_notifier(struct notifier_block *nb)
> +{
> +	return blocking_notifier_chain_register(&show_mem_notify_list, nb);
> +}
> +EXPORT_SYMBOL_GPL(register_show_mem_notifier);
> +
> +int unregister_show_mem_notifier(struct notifier_block *nb)
> +{
> +	return blocking_notifier_chain_unregister(&show_mem_notify_list, nb);
> +}
> +EXPORT_SYMBOL_GPL(unregister_show_mem_notifier);

You are exporting functions that are never used at all.  We can't do
that.


> +
> +void show_mem_extend(unsigned int filter, nodemask_t *nodemask,
> +		     enum show_mem_extend_type type)
> +{
> +	unsigned long used = 0;
> +	struct sysinfo si;
> +
> +	pr_info("Mem-Info-Extend:\n");
> +	show_mem(filter, NULL);
> +	si_meminfo(&si);
> +	pr_info("MemTotal:	%8lu KB\n"
> +		"Buffers:	%8lu KB\n"
> +		"SwapCached:	%8lu KB\n",
> +		(si.totalram) << (PAGE_SHIFT - 10),
> +		(si.bufferram) << (PAGE_SHIFT - 10),
> +		total_swapcache_pages() << (PAGE_SHIFT - 10));
> +
> +	blocking_notifier_call_chain(&show_mem_notify_list,
> +				     (unsigned long)type, &used);
> +}

Who calls this function?

As a stand-alone patch, this makes no sense as it doesn't seem to do
anything, so there's no way it can be accepted.

Please submit this as a patch series, with actual users of these
functions, if you wish to have it properly considered.

thanks,

greg k-h

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

end of thread, other threads:[~2020-02-11  3:19 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-01-17  8:24 [RFC] lib/show_mem.c: extend show_mem() to support showing drivers' memory consumption Jing Xia
2020-02-11  3:19 ` Greg KH

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.