android: Collect statistics from lowmemorykiller
Subsystems (6)
PATCH 1/3 android: Collect statistics from lowmemorykiller
From: Peter Enderborg <[email protected]>
This collects stats for shrinker calls and how much waste work we do within the lowmemorykiller.
--- drivers/staging/android/Kconfig | 11 ++++ drivers/staging/android/Makefile | 1 + drivers/staging/android/lowmemorykiller.c | 9 ++- drivers/staging/android/lowmemorykiller_stats.c | 85 +++++++++++++++++++++++++ drivers/staging/android/lowmemorykiller_stats.h | 29 +++++++++ 5 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 drivers/staging/android/lowmemorykiller_stats.c create mode 100644 drivers/staging/android/lowmemorykiller_stats.h
drivers/staging/android/Kconfig +11 -0
@@ -24,6 +24,17 @@ config ANDROID_LOW_MEMORY_KILLER scripts (/init.rc), and it defines priority values with minimum free memory size for each priority. +config ANDROID_LOW_MEMORY_KILLER_STATS + bool "Android Low Memory Killer: collect statistics" + depends on ANDROID_LOW_MEMORY_KILLER + default n + help + Create a file in /proc/lmkstats that includes + collected statistics about kills, scans and counts + and interaction with the shrinker. Its content + will be different depeding on lmk implementation used. + + source "drivers/staging/android/ion/Kconfig" endif # if ANDROID
drivers/staging/android/Makefile +1 -0
@@ -4,3 +4,4 @@ obj-y += ion/ obj-$(CONFIG_ASHMEM) += ashmem.o obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER) += lowmemorykiller.o +obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER_STATS) += lowmemorykiller_stats.o
drivers/staging/android/lowmemorykiller.c +8 -1
@@ -42,6 +42,7 @@#include <linux/rcupdate.h> #include <linux/profile.h> #include <linux/notifier.h> +#include "lowmemorykiller_stats.h" static u32 lowmem_debug_level =1 ;static short lowmem_adj[6 ] = {
@@ -72,6 +73,7 @@ static unsigned long lowmem_deathpending_timeout;static unsigned long lowmem_count (struct shrinker *s,struct shrink_control *sc) { +lmk_inc_stats (LMK_COUNT );return global_node_page_state (NR_ACTIVE_ANON ) +global_node_page_state (NR_ACTIVE_FILE ) + global_node_page_state(NR_INACTIVE_ANON) +
@@ -95,6 +97,7 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc)global_node_page_state (NR_SHMEM ) -total_swapcache_pages (); +lmk_inc_stats (LMK_SCAN );if (lowmem_adj_size < array_size) array_size = lowmem_adj_size;if (lowmem_minfree_size < array_size)
@@ -134,6 +137,7 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc)if (task_lmk_waiting (p) &&time_before_eq (jiffies, lowmem_deathpending_timeout)) {task_unlock (p); +lmk_inc_stats (LMK_TIMEOUT );rcu_read_unlock ();return 0 ; }
@@ -179,7 +183,9 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc) other_free * (long)(PAGE_SIZE / 1024)); lowmem_deathpending_timeout = jiffies +HZ ; rem += selected_tasksize; - } +lmk_inc_stats (LMK_KILL ); + }else +lmk_inc_stats (LMK_WASTE );lowmem_print (4 ,"lowmem_scan %lu, %x, return %lu\n" , sc->nr_to_scan, sc->gfp_mask, rem);
@@ -196,6 +202,7 @@ static struct shrinker lowmem_shrinker = {static int __init lowmem_init (void ) {register_shrinker (&lowmem_shrinker); +init_procfs_lmk ();return 0 ; }device_initcall (lowmem_init);
drivers/staging/android/lowmemorykiller_stats.c new file +85 -0
85 lines not on this page · raw message
drivers/staging/android/lowmemorykiller_stats.h new file +29 -0
@@ -0,0 +1,29 @@ +/* +* lowmemorykiller_stats interface +* +* Copyright (C) 2017 Sony Mobile Communications Inc. +* +* Author: Peter Enderborg <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +enum lmk_kill_stats { +LMK_SCAN =1 , +LMK_KILL =2 , +LMK_WASTE =3 , +LMK_TIMEOUT =4 , +LMK_COUNT =5 +}; + +#define LMK_PROCFS_NAME "lmkstats" + +#ifdef CONFIG_ANDROID_LOW_MEMORY_KILLER_STATS +void lmk_inc_stats (int key); +int __init init_procfs_lmk (void ); +#else +static inline void lmk_inc_stats (int key) {return ; }; +static inline int __init init_procfs_lmk (void ) {return 0 ; }; +#endif
Signature · 7 lines
2.4.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 2/3 oom: Add notification for oom_score_adj
From: Peter Enderborg <[email protected]>
This adds subscribtion for changes in oom_score_adj, this value is important to android systems. For task that uses oom_score_adj they read the task list. This can be long and need rcu locks and has a impact on the system. Let the user track the changes based on oom_score_adj changes and keep them in their own context so they do their actions with minimal system impact.
--- fs/proc/base.c | 13 +++++++ include/linux/oom_score_notifier.h | 47 ++++++++++++++++++++++++ kernel/Makefile | 1 + kernel/fork.c | 6 +++ kernel/oom_score_notifier.c | 75 ++++++++++++++++++++++++++++++++++++++ mm/Kconfig | 9 +++++ 6 files changed, 151 insertions(+) create mode 100644 include/linux/oom_score_notifier.h create mode 100644 kernel/oom_score_notifier.c
fs/proc/base.c +13 -0
@@ -87,6 +87,7 @@#include <linux/slab.h> #include <linux/flex_array.h> #include <linux/posix-timers.h> +#include <linux/oom_score_notifier.h> #ifdef CONFIG_HARDWALL #include <asm/hardwall.h> #endif
@@ -1057,6 +1058,7 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy)static DEFINE_MUTEX (oom_adj_mutex);struct mm_struct *mm =NULL ;struct task_struct *task; +int old_oom_score_adj;int err =0 ; task =get_proc_task (file_inode (file));
@@ -1102,9 +1104,20 @@ static int __set_oom_adj(struct file *file, int oom_adj, bool legacy) } } + old_oom_score_adj = task->signal->oom_score_adj; task->signal->oom_score_adj = oom_adj;if (!legacy &&has_capability_noaudit (current,CAP_SYS_RESOURCE )) task->signal->oom_score_adj_min = (short )oom_adj; + +#ifdef CONFIG_OOM_SCORE_NOTIFIER + err =oom_score_notify_update (task, old_oom_score_adj); +if (err) { +/* rollback and error handle. */ + task->signal->oom_score_adj = old_oom_score_adj; + goto err_unlock; + } +#endif +trace_oom_score_adj_update (task);if (mm) {
include/linux/oom_score_notifier.h new file +47 -0
47 lines not on this page · raw message
kernel/Makefile +1 -0
@@ -91,6 +91,7 @@ obj-$(CONFIG_SYSCTL) += utsname_sysctl.o obj-$(CONFIG_TASK_DELAY_ACCT) += delayacct.o obj-$(CONFIG_TASKSTATS) += taskstats.o tsacct.o obj-$(CONFIG_TRACEPOINTS) += tracepoint.o +obj-$(CONFIG_OOM_SCORE_NOTIFIER) += oom_score_notifier.o obj-$(CONFIG_LATENCYTOP) += latencytop.o obj-$(CONFIG_ELFCORE) += elfcore.o obj-$(CONFIG_FUNCTION_TRACER) += trace/
kernel/fork.c +6 -0
@@ -73,6 +73,7 @@#include <linux/signalfd.h> #include <linux/uprobes.h> #include <linux/aio.h> +#include <linux/oom_score_notifier.h> #include <linux/compiler.h> #include <linux/sysctl.h> #include <linux/kcov.h>
@@ -391,6 +392,7 @@ void __put_task_struct(struct task_struct *tsk)exit_creds (tsk);delayacct_tsk_free (tsk);put_signal_struct (tsk->signal); +oom_score_notify_free (tsk);if (!profile_handoff_task (tsk))free_task (tsk);
@@ -1790,6 +1792,10 @@ static __latent_entropy struct task_struct *copy_process(init_task_pid (p,PIDTYPE_PID , pid);if (thread_group_leader (p)) { + retval =oom_score_notify_new (p); +if (retval) + goto bad_fork_cancel_cgroup; +init_task_pid (p,PIDTYPE_PGID ,task_pgrp (current));init_task_pid (p,PIDTYPE_SID ,task_session (current));
kernel/oom_score_notifier.c new file +75 -0
75 lines not on this page · raw message
mm/Kconfig +9 -0
@@ -327,6 +327,15 @@ config MMU_NOTIFIER bool select SRCU +config OOM_SCORE_NOTIFIER + bool "OOM score notifier" + default n + help + This create a notifier for process oom_score_adj status. + It create events for new, updated or freed tasks and + are used to build a mirrored task list in + lowmemmorykiller. + config KSM bool "Enable KSM for page merging" depends on MMU
Signature · 7 lines
2.4.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
PATCH 3/3 mm: Remove RCU and tasklocks from lmk
In reply to [email protected]From: Peter Enderborg <[email protected]>
Fundamental changes:
1 Does NOT take any RCU lock in shrinker functions.
2 It returns same result for scan and counts, so we dont need to do
shinker will know when it is pointless to call scan.
3 It does not lock any other process than the one that is
going to be killed.
Background.
The low memory killer scans for process that can be killed to free memory. This can be cpu consuming when there is a high demand for memory. This can be seen by analysing the kswapd0 task work. The stats function added in earler patch adds a counter for waste work.
How it works.
This patch create a structure within the lowmemory killer that caches the user spaces processes that it might kill. It is done with a sorted rbtree so we can very easy find the candidate to be killed, and knows its properies as memory usage and sorted by oom_score_adj to look up the task with highest oom_score_adj. To be able to achive this it uses oom_score_notify events.
This patch also as a other effect, we are now free to do other lowmemorykiller configurations. Without the patch there is a need for a tradeoff between freed memory and task and rcu locks. This is no longer a concern for tuning lmk. This patch is not intended to do any calculation changes other than we do use the cache for calculate the count values and that makes kswapd0 to shrink other areas.
--- drivers/staging/android/Kconfig | 1 + drivers/staging/android/Makefile | 1 + drivers/staging/android/lowmemorykiller.c | 294 +++++++++++++++--------- drivers/staging/android/lowmemorykiller.h | 15 ++ drivers/staging/android/lowmemorykiller_stats.c | 24 ++ drivers/staging/android/lowmemorykiller_stats.h | 14 +- drivers/staging/android/lowmemorykiller_tasks.c | 220 ++++++++++++++++++ drivers/staging/android/lowmemorykiller_tasks.h | 35 +++ 8 files changed, 498 insertions(+), 106 deletions(-) create mode 100644 drivers/staging/android/lowmemorykiller.h create mode 100644 drivers/staging/android/lowmemorykiller_tasks.c create mode 100644 drivers/staging/android/lowmemorykiller_tasks.h
drivers/staging/android/Kconfig +1 -0
@@ -16,6 +16,7 @@ config ASHMEM config ANDROID_LOW_MEMORY_KILLER bool "Android Low Memory Killer" + select OOM_SCORE_NOTIFIER ---help--- Registers processes to be killed when low memory conditions, this is useful as there is no particular swap space on android.
drivers/staging/android/Makefile +1 -0
@@ -4,4 +4,5 @@ obj-y += ion/ obj-$(CONFIG_ASHMEM) += ashmem.o obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER) += lowmemorykiller.o +obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER) += lowmemorykiller_tasks.o obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER_STATS) += lowmemorykiller_stats.o
drivers/staging/android/lowmemorykiller.c +189 -105
340 lines not on this page · raw message
drivers/staging/android/lowmemorykiller.h new file +15 -0
@@ -0,0 +1,15 @@ +#ifndef __LOWMEMORYKILLER_H +#define __LOWMEMORYKILLER_H + +/* The lowest score LMK is using */ +#define LMK_SCORE_THRESHOLD 0 + +extern u32 lowmem_debug_level; + +#define lowmem_print(level, x...) \ + do { \ + if (lowmem_debug_level >= (level)) \ + pr_info(x); \ + } while (0) + +#endif
drivers/staging/android/lowmemorykiller_stats.c +24 -0
@@ -15,7 +15,9 @@#include <linux/proc_fs.h> #include <linux/seq_file.h> +#include "lowmemorykiller.h" #include "lowmemorykiller_stats.h" +#include "lowmemorykiller_tasks.h" struct lmk_stats {atomic_long_t scans;/* counter as in shrinker scans */
@@ -27,6 +29,10 @@ struct lmk_stats {* to be cancelled due to pending kills */ atomic_long_t count;/* number of shrinker count calls */ +atomic_long_t scan_busy;/* mutex held */ +atomic_long_t no_kill;/* mutex held */ +atomic_long_t busy; +atomic_long_t error;atomic_long_t unknown;/* internal */ } st;
@@ -48,6 +54,15 @@ void lmk_inc_stats(int key)case LMK_COUNT :atomic_long_inc (&st.count);break ; +case LMK_BUSY : +atomic_long_inc (&st.busy); +break ; +case LMK_ERROR : +atomic_long_inc (&st.error); +break ; +case LMK_NO_KILL : +atomic_long_inc (&st.no_kill); +break ;default :atomic_long_inc (&st.unknown);break ;
@@ -61,6 +76,10 @@ static int lmk_proc_show(struct seq_file *m, void *v)seq_printf (m,"waste: %ld\n" ,atomic_long_read (&st.waste));seq_printf (m,"timeout: %ld\n" ,atomic_long_read (&st.timeout));seq_printf (m,"count: %ld\n" ,atomic_long_read (&st.count)); +seq_printf (m,"busy: %ld\n" ,atomic_long_read (&st.busy)); +seq_printf (m,"error: %ld\n" ,atomic_long_read (&st.error)); +seq_printf (m,"no kill: %ld\n" ,atomic_long_read (&st.no_kill)); +seq_printf (m,"queue: %d\n" , death_pending_len);seq_printf (m,"unknown: %ld (internal)\n" ,atomic_long_read (&st.unknown));
@@ -83,3 +102,8 @@ int __init init_procfs_lmk(void)proc_create_data (LMK_PROCFS_NAME ,0444 ,NULL , &lmk_proc_fops,NULL );return 0 ; } + +void exit_procfs_lmk (void ) +{ +remove_proc_entry (LMK_PROCFS_NAME ,NULL ); +}
drivers/staging/android/lowmemorykiller_stats.h +13 -1
@@ -10,12 +10,20 @@* published by the Free Software Foundation. */ +#ifndef __LOWMEMORYKILLER_STATS_H +#define __LOWMEMORYKILLER_STATS_H +enum lmk_kill_stats {LMK_SCAN =1 ,LMK_KILL =2 ,LMK_WASTE =3 ,LMK_TIMEOUT =4 , -LMK_COUNT =5 +LMK_COUNT =5 , +LMK_SCAN_BUSY =6 , +LMK_NO_KILL =7 , +LMK_BUSY =8 , +LMK_ERROR =9 , + };#define LMK_PROCFS_NAME "lmkstats"
@@ -23,7 +31,11 @@ enum lmk_kill_stats {#ifdef CONFIG_ANDROID_LOW_MEMORY_KILLER_STATS void lmk_inc_stats (int key);int __init init_procfs_lmk (void ); +void exit_procfs_lmk (void );#else static inline void lmk_inc_stats (int key) {return ; };static inline int __init init_procfs_lmk (void ) {return 0 ; }; +static inline void exit_procfs_lmk (void ) {return ; }; +#endif +#endif
drivers/staging/android/lowmemorykiller_tasks.c new file +220 -0
220 lines not on this page · raw message
drivers/staging/android/lowmemorykiller_tasks.h new file +35 -0
@@ -0,0 +1,35 @@ +/* +* lowmemorykiller_tasks interface +* +* Copyright (C) 2017 Sony Mobile Communications Inc. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +#ifndef __LOWMEMORYKILLER_TASKS_H +#define __LOWMEMORYKILLER_TASKS_H + +struct lmk_death_pending_entry { +struct list_head lmk_dp_list; +struct task_struct *tsk; +}; + +struct lmk_rb_watch { +struct rb_node rb_node; +struct task_struct *tsk; +int key; +}; + +extern int death_pending_len; +extern struct kmem_cache *lmk_dp_cache; +extern struct kmem_cache *lmk_task_cache; +extern spinlock_t lmk_task_lock; +extern struct notifier_block lmk_oom_score_nb; + +int __lmk_task_remove (struct task_struct *tsk,int score); +int __lmk_death_pending_add (struct lmk_death_pending_entry *lwp); +struct lmk_rb_watch *__lmk_first (void ); + +#endif
Signature · 7 lines
2.4.2 -- To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM, see: http://www.linux-mm.org/ . Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Greg KH
maintainerQuoted 23 lines · On Tue, Feb 14, 2017 at 05:09:30PM +0100, [email protected] wrote:
From: Peter Enderborg <[email protected]>
This collects stats for shrinker calls and how much waste work we do within the lowmemorykiller.
Signed-off-by Peter Enderborg <[email protected]>--- drivers/staging/android/Kconfig | 11 ++++ drivers/staging/android/Makefile | 1 + drivers/staging/android/lowmemorykiller.c | 9 ++- drivers/staging/android/lowmemorykiller_stats.c | 85 +++++++++++++++++++++++++ drivers/staging/android/lowmemorykiller_stats.h | 29 +++++++++ 5 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 drivers/staging/android/lowmemorykiller_stats.c create mode 100644 drivers/staging/android/lowmemorykiller_stats.hdrivers/staging/android/Kconfig +0
-0@@ -24,6 +24,17 @@ config ANDROID_LOW_MEMORY_KILLER scripts (/init.rc), and it defines priority values with minimum free memory size for each priority.
drivers/staging/android/Kconfig config ANDROID_LOW_MEMORY_KILLER · line 35
Quoted 10 lines
drivers/staging/android/Kconfig +9
-0+config ANDROID_LOW_MEMORY_KILLER_STATS + bool "Android Low Memory Killer: collect statistics" + depends on ANDROID_LOW_MEMORY_KILLER + default n + help + Create a file in /proc/lmkstats that includes + collected statistics about kills, scans and counts + and interaction with the shrinker. Its content + will be different depeding on lmk implementation used.
Ick, no new /proc files please, this isn't a "process" value. What's wrong with debugfs?
Also note the minor ' ' usage in your first sentence of the help text.
Quoted 93 lines
drivers/staging/android/Kconfig +0
-0source "drivers/staging/android/ion/Kconfig" endif # if ANDROIDdrivers/staging/android/Makefile +1
-0@@ -4,3 +4,4 @@ obj-y += ion/ obj-$(CONFIG_ASHMEM) += ashmem.o obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER) += lowmemorykiller.o +obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER_STATS) += lowmemorykiller_stats.odrivers/staging/android/lowmemorykiller.c +8
-1@@ -42,6 +42,7 @@#include <linux/rcupdate.h> #include <linux/profile.h> #include <linux/notifier.h> +#include "lowmemorykiller_stats.h" static u32 lowmem_debug_level =1 ;static short lowmem_adj[6 ] = {@@ -72,6 +73,7 @@ static unsigned long lowmem_deathpending_timeout;static unsigned long lowmem_count (struct shrinker *s,struct shrink_control *sc) { +lmk_inc_stats (LMK_COUNT );return global_node_page_state (NR_ACTIVE_ANON ) +global_node_page_state (NR_ACTIVE_FILE ) + global_node_page_state(NR_INACTIVE_ANON) +@@ -95,6 +97,7 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc)global_node_page_state (NR_SHMEM ) -total_swapcache_pages (); +lmk_inc_stats (LMK_SCAN );if (lowmem_adj_size < array_size) array_size = lowmem_adj_size;if (lowmem_minfree_size < array_size)@@ -134,6 +137,7 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc)if (task_lmk_waiting (p) &&time_before_eq (jiffies, lowmem_deathpending_timeout)) {task_unlock (p); +lmk_inc_stats (LMK_TIMEOUT );rcu_read_unlock ();return 0 ; }@@ -179,7 +183,9 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc) other_free * (long)(PAGE_SIZE / 1024)); lowmem_deathpending_timeout = jiffies +HZ ; rem += selected_tasksize; - } +lmk_inc_stats (LMK_KILL ); + }else +lmk_inc_stats (LMK_WASTE );lowmem_print (4 ,"lowmem_scan %lu, %x, return %lu\n" , sc->nr_to_scan, sc->gfp_mask, rem);@@ -196,6 +202,7 @@ static struct shrinker lowmem_shrinker = {static int __init lowmem_init (void ) {register_shrinker (&lowmem_shrinker); +init_procfs_lmk ();return 0 ; }device_initcall (lowmem_init);drivers/staging/android/lowmemorykiller_stats.c new file +20
-0@@ -0,0 +1,85 @@ +/* +* lowmemorykiller_stats +* +* Copyright (C) 2017 Sony Mobile Communications Inc. +* +* Author: Peter Enderborg <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ +/* This code is bookkeeping of statistical information +* from lowmemorykiller and provide a node in proc "/proc/lmkstats". +*/ + +#include <linux/proc_fs.h> +#include <linux/seq_file.h> +#include "lowmemorykiller_stats.h" + +struct lmk_stats {
drivers/staging/android/lowmemorykiller_stats.c line 30
Quoted 10 lines
drivers/staging/android/lowmemorykiller_stats.c new file +10
-0+atomic_long_t scans;/* counter as in shrinker scans */ +atomic_long_t kills;/* the number of sigkills sent */ +atomic_long_t waste;/* the numer of extensive calls that did +* not lead to anything +*/ +atomic_long_t timeout;/* counter for shrinker calls that needed +* to be cancelled due to pending kills +*/ +atomic_long_t count;/* number of shrinker count calls */ +atomic_long_t unknown;/* internal */
Why not document the structure in the proper kernel-doc format?
Also, do you really need atomic variables here?
Quoted 64 lines
drivers/staging/android/lowmemorykiller_stats.c new file +55
-0+} st; + +void lmk_inc_stats (int key) +{ +switch (key) { +case LMK_SCAN : +atomic_long_inc (&st.scans); +break ; +case LMK_KILL : +atomic_long_inc (&st.kills); +break ; +case LMK_WASTE : +atomic_long_inc (&st.waste); +break ; +case LMK_TIMEOUT : +atomic_long_inc (&st.timeout); +break ; +case LMK_COUNT : +atomic_long_inc (&st.count); +break ; +default : +atomic_long_inc (&st.unknown); +break ; + } +} + +static int lmk_proc_show (struct seq_file *m,void *v) +{ +seq_printf (m,"kill: %ld\n" ,atomic_long_read (&st.kills)); +seq_printf (m,"scan: %ld\n" ,atomic_long_read (&st.scans)); +seq_printf (m,"waste: %ld\n" ,atomic_long_read (&st.waste)); +seq_printf (m,"timeout: %ld\n" ,atomic_long_read (&st.timeout)); +seq_printf (m,"count: %ld\n" ,atomic_long_read (&st.count)); +seq_printf (m,"unknown: %ld (internal)\n" , +atomic_long_read (&st.unknown)); + +return 0 ; +} + +static int lmk_proc_open (struct inode *inode,struct file *file) +{ +return single_open (file, lmk_proc_show,PDE_DATA (inode)); +} + +static const struct file_operations lmk_proc_fops = { + .open = lmk_proc_open, + .read = seq_read, + .release = single_release +}; + +int __init init_procfs_lmk (void ) +{ +proc_create_data (LMK_PROCFS_NAME ,0444 ,NULL , &lmk_proc_fops,NULL ); +return 0 ; +}drivers/staging/android/lowmemorykiller_stats.h new file +3
-0@@ -0,0 +1,29 @@ +/* +* lowmemorykiller_stats interface +*
drivers/staging/android/lowmemorykiller_stats.h line 13
Quoted 10 lines
drivers/staging/android/lowmemorykiller_stats.h new file +10
-0+* Copyright (C) 2017 Sony Mobile Communications Inc. +* +* Author: Peter Enderborg <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +enum lmk_kill_stats {
nit, two spaces?
drivers/staging/android/lowmemorykiller_stats.h line 21
Quoted 8 lines
drivers/staging/android/lowmemorykiller_stats.h new file +8
-0+LMK_SCAN =1 , +LMK_KILL =2 , +LMK_WASTE =3 , +LMK_TIMEOUT =4 , + LMK_COUNT = 5 +}; + +#define LMK_PROCFS_NAME "lmkstats"
You only use it once, why create a #define? Anyway, debugfs is better for debugging stuff like this, that is what it was created for.
thanks,
greg k-h
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 25 lines · Greg KH
Quoted 24 lines · On Tue, Feb 14, 2017 at 05:09:30PM +0100, [email protected] wrote:
From: Peter Enderborg <[email protected]>
This collects stats for shrinker calls and how much waste work we do within the lowmemorykiller.
Signed-off-by Peter Enderborg <[email protected]>--- drivers/staging/android/Kconfig | 11 ++++ drivers/staging/android/Makefile | 1 + drivers/staging/android/lowmemorykiller.c | 9 ++- drivers/staging/android/lowmemorykiller_stats.c | 85 +++++++++++++++++++++++++ drivers/staging/android/lowmemorykiller_stats.h | 29 +++++++++ 5 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 drivers/staging/android/lowmemorykiller_stats.c create mode 100644 drivers/staging/android/lowmemorykiller_stats.hdrivers/staging/android/Kconfig +0
-0@@ -24,6 +24,17 @@ config ANDROID_LOW_MEMORY_KILLER scripts (/init.rc), and it defines priority values with minimum free memory size for each priority.
Quoted 11 lines
drivers/staging/android/Kconfig config ANDROID_LOW_MEMORY_KILLER · line 35
Quoted 9 lines
drivers/staging/android/Kconfig +9
-0+config ANDROID_LOW_MEMORY_KILLER_STATS + bool "Android Low Memory Killer: collect statistics" + depends on ANDROID_LOW_MEMORY_KILLER + default n + help + Create a file in /proc/lmkstats that includes + collected statistics about kills, scans and counts + and interaction with the shrinker. Its content + will be different depeding on lmk implementation used.Ick, no new /proc files please, this isn't a "process" value. What's wrong with debugfs?
This is intended for android. Android users are very limited in their access
to linux part of the system on commercial models and lmk activity has a bad impact on the performance of the device. Even the application developers has not much access so it seems to be fair to give the users the information about why there is a problem.
Quoted 107 lines
Also note the minor ' ' usage in your first sentence of the help text.
Quoted 93 lines
drivers/staging/android/Kconfig +0
-0source "drivers/staging/android/ion/Kconfig" endif # if ANDROIDdrivers/staging/android/Makefile +1
-0@@ -4,3 +4,4 @@ obj-y += ion/ obj-$(CONFIG_ASHMEM) += ashmem.o obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER) += lowmemorykiller.o +obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER_STATS) += lowmemorykiller_stats.odrivers/staging/android/lowmemorykiller.c +8
-1@@ -42,6 +42,7 @@#include <linux/rcupdate.h> #include <linux/profile.h> #include <linux/notifier.h> +#include "lowmemorykiller_stats.h" static u32 lowmem_debug_level =1 ;static short lowmem_adj[6 ] = {@@ -72,6 +73,7 @@ static unsigned long lowmem_deathpending_timeout;static unsigned long lowmem_count (struct shrinker *s,struct shrink_control *sc) { +lmk_inc_stats (LMK_COUNT );return global_node_page_state (NR_ACTIVE_ANON ) +global_node_page_state (NR_ACTIVE_FILE ) + global_node_page_state(NR_INACTIVE_ANON) +@@ -95,6 +97,7 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc)global_node_page_state (NR_SHMEM ) -total_swapcache_pages (); +lmk_inc_stats (LMK_SCAN );if (lowmem_adj_size < array_size) array_size = lowmem_adj_size;if (lowmem_minfree_size < array_size)@@ -134,6 +137,7 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc)if (task_lmk_waiting (p) &&time_before_eq (jiffies, lowmem_deathpending_timeout)) {task_unlock (p); +lmk_inc_stats (LMK_TIMEOUT );rcu_read_unlock ();return 0 ; }@@ -179,7 +183,9 @@ static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc) other_free * (long)(PAGE_SIZE / 1024)); lowmem_deathpending_timeout = jiffies +HZ ; rem += selected_tasksize; - } +lmk_inc_stats (LMK_KILL ); + }else +lmk_inc_stats (LMK_WASTE );lowmem_print (4 ,"lowmem_scan %lu, %x, return %lu\n" , sc->nr_to_scan, sc->gfp_mask, rem);@@ -196,6 +202,7 @@ static struct shrinker lowmem_shrinker = {static int __init lowmem_init (void ) {register_shrinker (&lowmem_shrinker); +init_procfs_lmk ();return 0 ; }device_initcall (lowmem_init);drivers/staging/android/lowmemorykiller_stats.c new file +20
-0@@ -0,0 +1,85 @@ +/* +* lowmemorykiller_stats +* +* Copyright (C) 2017 Sony Mobile Communications Inc. +* +* Author: Peter Enderborg <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ +/* This code is bookkeeping of statistical information +* from lowmemorykiller and provide a node in proc "/proc/lmkstats". +*/ + +#include <linux/proc_fs.h> +#include <linux/seq_file.h> +#include "lowmemorykiller_stats.h" + +struct lmk_stats {drivers/staging/android/lowmemorykiller_stats.c line 30
Quoted 10 lines
drivers/staging/android/lowmemorykiller_stats.c new file +10
-0+atomic_long_t scans;/* counter as in shrinker scans */ +atomic_long_t kills;/* the number of sigkills sent */ +atomic_long_t waste;/* the numer of extensive calls that did +* not lead to anything +*/ +atomic_long_t timeout;/* counter for shrinker calls that needed +* to be cancelled due to pending kills +*/ +atomic_long_t count;/* number of shrinker count calls */ +atomic_long_t unknown;/* internal */ Why not document the structure in the proper kernel-doc format?
Quoted 1 line
Also, do you really need atomic variables here?
I think so. The lmk are usually called from kswapd0, but can also be called from other parts. At least for arm the cost is low so better safe than sorry and it is better to focus on have the spin_lock held as short time as possible.
Quoted 77 lines
Quoted 65 lines
drivers/staging/android/lowmemorykiller_stats.c new file +55
-0+} st; + +void lmk_inc_stats (int key) +{ +switch (key) { +case LMK_SCAN : +atomic_long_inc (&st.scans); +break ; +case LMK_KILL : +atomic_long_inc (&st.kills); +break ; +case LMK_WASTE : +atomic_long_inc (&st.waste); +break ; +case LMK_TIMEOUT : +atomic_long_inc (&st.timeout); +break ; +case LMK_COUNT : +atomic_long_inc (&st.count); +break ; +default : +atomic_long_inc (&st.unknown); +break ; + } +} + +static int lmk_proc_show (struct seq_file *m,void *v) +{ +seq_printf (m,"kill: %ld\n" ,atomic_long_read (&st.kills)); +seq_printf (m,"scan: %ld\n" ,atomic_long_read (&st.scans)); +seq_printf (m,"waste: %ld\n" ,atomic_long_read (&st.waste)); +seq_printf (m,"timeout: %ld\n" ,atomic_long_read (&st.timeout)); +seq_printf (m,"count: %ld\n" ,atomic_long_read (&st.count)); +seq_printf (m,"unknown: %ld (internal)\n" , +atomic_long_read (&st.unknown)); + +return 0 ; +} + +static int lmk_proc_open (struct inode *inode,struct file *file) +{ +return single_open (file, lmk_proc_show,PDE_DATA (inode)); +} + +static const struct file_operations lmk_proc_fops = { + .open = lmk_proc_open, + .read = seq_read, + .release = single_release +}; + +int __init init_procfs_lmk (void ) +{ +proc_create_data (LMK_PROCFS_NAME ,0444 ,NULL , &lmk_proc_fops,NULL ); +return 0 ; +}drivers/staging/android/lowmemorykiller_stats.h new file +3
-0@@ -0,0 +1,29 @@ +/* +* lowmemorykiller_stats interface +* drivers/staging/android/lowmemorykiller_stats.h line 13
Quoted 10 lines
drivers/staging/android/lowmemorykiller_stats.h new file +10
-0+* Copyright (C) 2017 Sony Mobile Communications Inc. +* +* Author: Peter Enderborg <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 as +* published by the Free Software Foundation. +*/ + +enum lmk_kill_stats {nit, two spaces?
Quoted 11 lines
drivers/staging/android/lowmemorykiller_stats.h line 21
Quoted 8 lines
drivers/staging/android/lowmemorykiller_stats.h new file +8
-0+LMK_SCAN =1 , +LMK_KILL =2 , +LMK_WASTE =3 , +LMK_TIMEOUT =4 , + LMK_COUNT = 5 +}; + +#define LMK_PROCFS_NAME "lmkstats"You only use it once, why create a #define? Anyway, debugfs is better for debugging stuff like this, that is what it was created for. From android selinux:
neverallow untrusted_app debugfs_type:file read;
And the define was created upon requests from internal reviews that prefer to see this in headers.
I have debugfs patch ongoing, but it's more about the internal structure for debugging than statistical data from the lmk.
Quoted 3 lines
thanks,
greg k-h
thanks
/Peter
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Greg KH
maintainerQuoted 37 lines · peter enderborg
Quoted 25 lines · Greg KH
Quoted 24 lines · On Tue, Feb 14, 2017 at 05:09:30PM +0100, [email protected] wrote:
From: Peter Enderborg <[email protected]>
This collects stats for shrinker calls and how much waste work we do within the lowmemorykiller.
Signed-off-by Peter Enderborg <[email protected]>--- drivers/staging/android/Kconfig | 11 ++++ drivers/staging/android/Makefile | 1 + drivers/staging/android/lowmemorykiller.c | 9 ++- drivers/staging/android/lowmemorykiller_stats.c | 85 +++++++++++++++++++++++++ drivers/staging/android/lowmemorykiller_stats.h | 29 +++++++++ 5 files changed, 134 insertions(+), 1 deletion(-) create mode 100644 drivers/staging/android/lowmemorykiller_stats.c create mode 100644 drivers/staging/android/lowmemorykiller_stats.hdrivers/staging/android/Kconfig +0
-0@@ -24,6 +24,17 @@ config ANDROID_LOW_MEMORY_KILLER scripts (/init.rc), and it defines priority values with minimum free memory size for each priority.Quoted 11 lines
drivers/staging/android/Kconfig config ANDROID_LOW_MEMORY_KILLER · line 35
Quoted 9 lines
drivers/staging/android/Kconfig +9
-0+config ANDROID_LOW_MEMORY_KILLER_STATS + bool "Android Low Memory Killer: collect statistics" + depends on ANDROID_LOW_MEMORY_KILLER + default n + help + Create a file in /proc/lmkstats that includes + collected statistics about kills, scans and counts + and interaction with the shrinker. Its content + will be different depeding on lmk implementation used.Ick, no new /proc files please, this isn't a "process" value. What's wrong with debugfs?
Quoted 4 lines
This is intended for android. Android users are very limited in their access
to linux part of the system on commercial models and lmk activity has a bad impact on the performance of the device. Even the application developers has not much access so it seems to be fair to give the users the information about why there is a problem.
Why would you want to give "all users" this information at all? This is a debugging tool, your debugging userspace framework can use whatever interface you create to access it (i.e. debugfs).
Again, do not add debugging stuff to /proc/ that's not ok, sorry.
thanks,
greg k-h
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Greg KH
maintainerQuoted 6 lines · On Tue, Feb 14, 2017 at 05:09:30PM +0100, [email protected] wrote:
From: Peter Enderborg <[email protected]>
This collects stats for shrinker calls and how much waste work we do within the lowmemorykiller.
Signed-off-by Peter Enderborg <[email protected]>
Wait, what changed from the previous versions of this patch? Did you take the review comments into consideration, or is this just a resend of the original patches in a format that isn't corrupted?
thanks,
greg k-h
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Quoted 6 lines · Greg KH
Quoted 5 lines · On Tue, Feb 14, 2017 at 05:09:30PM +0100, [email protected] wrote:
From: Peter Enderborg <[email protected]>
This collects stats for shrinker calls and how much waste work we do within the lowmemorykiller.
Quoted 8 lines
Quoted 1 line
Signed-off-by Peter Enderborg <[email protected]>Wait, what changed from the previous versions of this patch? Did you take the review comments into consideration, or is this just a resend of the original patches in a format that isn't corrupted?
thanks,
greg k-h
This is just a send with git-send-email that seems to work better. Nothing else than tab-spaces should be different. I would like to have some positive feedback from google/android before I start to send updated patches to the list. If google are ready for the userspace solution this patch set is pointless for upstream kernel.
Michal Hocko is very negative to hole thing, but we have addressed at least some issues he pointed out on the list in 2015. Is there any idea to continue?
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Greg KH
maintainerQuoted 16 lines · peter enderborg
Quoted 6 lines · Greg KH
Quoted 5 lines · On Tue, Feb 14, 2017 at 05:09:30PM +0100, [email protected] wrote:
From: Peter Enderborg <[email protected]>
This collects stats for shrinker calls and how much waste work we do within the lowmemorykiller.
Quoted 8 lines
Quoted 1 line
Signed-off-by Peter Enderborg <[email protected]>Wait, what changed from the previous versions of this patch? Did you take the review comments into consideration, or is this just a resend of the original patches in a format that isn't corrupted?
thanks,
greg k-h
Quoted 8 lines
This is just a send with git-send-email that seems to work better. Nothing else than tab-spaces should be different. I would like to have some positive feedback from google/android before I start to send updated patches to the list. If google are ready for the userspace solution this patch set is pointless for upstream kernel.
Michal Hocko is very negative to hole thing, but we have addressed at least some issues he pointed out on the list in 2015. Is there any idea to continue?
If Michal rejected this solution, then I wouldn't be spending much time on it at all. Instead, I strongly suggest you try to do what he pointed out should be done instead. If that requires userspace help, great, try that and see what happens.
thanks,
greg k-h
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>