Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1586111 > unrolled thread
| Started by | Michal Hocko <mhocko@kernel.org> |
|---|---|
| First post | 2017-02-22 13:10 +0100 |
| Last post | 2017-02-24 11:20 +0100 |
| Articles | 13 — 4 participants |
Back to article view | Back to linux.kernel
[PATCH] staging, android: remove lowmemory killer from the tree Michal Hocko <mhocko@kernel.org> - 2017-02-22 13:10 +0100
Re: [PATCH] staging, android: remove lowmemory killer from the tree John Stultz <john.stultz@linaro.org> - 2017-02-23 21:30 +0100
Re: [PATCH] staging, android: remove lowmemory killer from the tree Martijn Coenen <maco@google.com> - 2017-02-23 21:40 +0100
Re: [PATCH] staging, android: remove lowmemory killer from the tree Michal Hocko <mhocko@kernel.org> - 2017-02-24 10:40 +0100
Re: [PATCH] staging, android: remove lowmemory killer from the tree peter enderborg <peter.enderborg@sonymobile.com> - 2017-02-24 13:20 +0100
Re: [PATCH] staging, android: remove lowmemory killer from the tree Michal Hocko <mhocko@kernel.org> - 2017-02-24 14:10 +0100
Re: [PATCH] staging, android: remove lowmemory killer from the tree peter enderborg <peter.enderborg@sonymobile.com> - 2017-02-24 14:30 +0100
Re: [PATCH] staging, android: remove lowmemory killer from the tree Michal Hocko <mhocko@kernel.org> - 2017-02-24 15:20 +0100
Re: [PATCH] staging, android: remove lowmemory killer from the tree peter enderborg <peter.enderborg@sonymobile.com> - 2017-02-24 15:50 +0100
Re: [PATCH] staging, android: remove lowmemory killer from the tree Michal Hocko <mhocko@kernel.org> - 2017-02-24 16:10 +0100
Re: [PATCH] staging, android: remove lowmemory killer from the tree peter enderborg <peter.enderborg@sonymobile.com> - 2017-02-24 16:50 +0100
Re: [PATCH] staging, android: remove lowmemory killer from the tree Michal Hocko <mhocko@kernel.org> - 2017-02-24 17:00 +0100
Re: [PATCH] staging, android: remove lowmemory killer from the tree Michal Hocko <mhocko@kernel.org> - 2017-02-24 11:20 +0100
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Date | 2017-02-22 13:10 +0100 |
| Subject | [PATCH] staging, android: remove lowmemory killer from the tree |
| Message-ID | <tdDU6-1tU-23@gated-at.bofh.it> |
From: Michal Hocko <mhocko@suse.com>
Lowmemory killer is sitting in the staging tree since 2008 without any
serious interest for fixing issues brought up by the MM folks. The main
objection is that the implementation is basically broken by design:
- it hooks into slab shrinker API which is not suitable for this
purpose. lowmem_count implementation just shows this nicely.
There is no scaling based on the memory pressure and no
feedback to the generic shrinker infrastructure.
Moreover lowmem_scan is called way too often for the heavy
work it performs.
- it is not reclaim context aware - no NUMA and/or memcg
awareness.
As the code stands right now it just adds a maintenance overhead when
core MM changes have to update lowmemorykiller.c as well. It also seems
that the alternative LMK implementation will be solely in the userspace
so this code has no perspective it seems. The staging tree is supposed
to be for a code which needs to be put in shape before it can be merged
which is not the case here obviously.
Signed-off-by: Michal Hocko <mhocko@suse.com>
---
drivers/staging/android/Kconfig | 10 --
drivers/staging/android/Makefile | 1 -
drivers/staging/android/lowmemorykiller.c | 212 ------------------------------
include/linux/sched.h | 4 -
4 files changed, 227 deletions(-)
delete mode 100644 drivers/staging/android/lowmemorykiller.c
diff --git a/drivers/staging/android/Kconfig b/drivers/staging/android/Kconfig
index 6c00d6f765c6..71a50b99caff 100644
--- a/drivers/staging/android/Kconfig
+++ b/drivers/staging/android/Kconfig
@@ -14,16 +14,6 @@ config ASHMEM
It is, in theory, a good memory allocator for low-memory devices,
because it can discard shared memory units when under memory pressure.
-config ANDROID_LOW_MEMORY_KILLER
- bool "Android Low Memory Killer"
- ---help---
- Registers processes to be killed when low memory conditions, this is useful
- as there is no particular swap space on android.
-
- The registered process will kill according to the priorities in android init
- scripts (/init.rc), and it defines priority values with minimum free memory size
- for each priority.
-
source "drivers/staging/android/ion/Kconfig"
endif # if ANDROID
diff --git a/drivers/staging/android/Makefile b/drivers/staging/android/Makefile
index 7ed1be798909..7cf1564a49a5 100644
--- a/drivers/staging/android/Makefile
+++ b/drivers/staging/android/Makefile
@@ -3,4 +3,3 @@ ccflags-y += -I$(src) # needed for trace events
obj-y += ion/
obj-$(CONFIG_ASHMEM) += ashmem.o
-obj-$(CONFIG_ANDROID_LOW_MEMORY_KILLER) += lowmemorykiller.o
diff --git a/drivers/staging/android/lowmemorykiller.c b/drivers/staging/android/lowmemorykiller.c
deleted file mode 100644
index ec3b66561412..000000000000
--- a/drivers/staging/android/lowmemorykiller.c
+++ /dev/null
@@ -1,212 +0,0 @@
-/* drivers/misc/lowmemorykiller.c
- *
- * The lowmemorykiller driver lets user-space specify a set of memory thresholds
- * where processes with a range of oom_score_adj values will get killed. Specify
- * the minimum oom_score_adj values in
- * /sys/module/lowmemorykiller/parameters/adj and the number of free pages in
- * /sys/module/lowmemorykiller/parameters/minfree. Both files take a comma
- * separated list of numbers in ascending order.
- *
- * For example, write "0,8" to /sys/module/lowmemorykiller/parameters/adj and
- * "1024,4096" to /sys/module/lowmemorykiller/parameters/minfree to kill
- * processes with a oom_score_adj value of 8 or higher when the free memory
- * drops below 4096 pages and kill processes with a oom_score_adj value of 0 or
- * higher when the free memory drops below 1024 pages.
- *
- * The driver considers memory used for caches to be free, but if a large
- * percentage of the cached memory is locked this can be very inaccurate
- * and processes may not get killed until the normal oom killer is triggered.
- *
- * Copyright (C) 2007-2008 Google, Inc.
- *
- * This software is licensed under the terms of the GNU General Public
- * License version 2, as published by the Free Software Foundation, and
- * may be copied, distributed, and modified under those terms.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- */
-
-#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
-
-#include <linux/init.h>
-#include <linux/moduleparam.h>
-#include <linux/kernel.h>
-#include <linux/mm.h>
-#include <linux/oom.h>
-#include <linux/sched.h>
-#include <linux/swap.h>
-#include <linux/rcupdate.h>
-#include <linux/profile.h>
-#include <linux/notifier.h>
-
-static u32 lowmem_debug_level = 1;
-static short lowmem_adj[6] = {
- 0,
- 1,
- 6,
- 12,
-};
-
-static int lowmem_adj_size = 4;
-static int lowmem_minfree[6] = {
- 3 * 512, /* 6MB */
- 2 * 1024, /* 8MB */
- 4 * 1024, /* 16MB */
- 16 * 1024, /* 64MB */
-};
-
-static int lowmem_minfree_size = 4;
-
-static unsigned long lowmem_deathpending_timeout;
-
-#define lowmem_print(level, x...) \
- do { \
- if (lowmem_debug_level >= (level)) \
- pr_info(x); \
- } while (0)
-
-static unsigned long lowmem_count(struct shrinker *s,
- struct shrink_control *sc)
-{
- return global_node_page_state(NR_ACTIVE_ANON) +
- global_node_page_state(NR_ACTIVE_FILE) +
- global_node_page_state(NR_INACTIVE_ANON) +
- global_node_page_state(NR_INACTIVE_FILE);
-}
-
-static unsigned long lowmem_scan(struct shrinker *s, struct shrink_control *sc)
-{
- struct task_struct *tsk;
- struct task_struct *selected = NULL;
- unsigned long rem = 0;
- int tasksize;
- int i;
- short min_score_adj = OOM_SCORE_ADJ_MAX + 1;
- int minfree = 0;
- int selected_tasksize = 0;
- short selected_oom_score_adj;
- int array_size = ARRAY_SIZE(lowmem_adj);
- int other_free = global_page_state(NR_FREE_PAGES) - totalreserve_pages;
- int other_file = global_node_page_state(NR_FILE_PAGES) -
- global_node_page_state(NR_SHMEM) -
- total_swapcache_pages();
-
- if (lowmem_adj_size < array_size)
- array_size = lowmem_adj_size;
- if (lowmem_minfree_size < array_size)
- array_size = lowmem_minfree_size;
- for (i = 0; i < array_size; i++) {
- minfree = lowmem_minfree[i];
- if (other_free < minfree && other_file < minfree) {
- min_score_adj = lowmem_adj[i];
- break;
- }
- }
-
- lowmem_print(3, "lowmem_scan %lu, %x, ofree %d %d, ma %hd\n",
- sc->nr_to_scan, sc->gfp_mask, other_free,
- other_file, min_score_adj);
-
- if (min_score_adj == OOM_SCORE_ADJ_MAX + 1) {
- lowmem_print(5, "lowmem_scan %lu, %x, return 0\n",
- sc->nr_to_scan, sc->gfp_mask);
- return 0;
- }
-
- selected_oom_score_adj = min_score_adj;
-
- rcu_read_lock();
- for_each_process(tsk) {
- struct task_struct *p;
- short oom_score_adj;
-
- if (tsk->flags & PF_KTHREAD)
- continue;
-
- p = find_lock_task_mm(tsk);
- if (!p)
- continue;
-
- if (task_lmk_waiting(p) &&
- time_before_eq(jiffies, lowmem_deathpending_timeout)) {
- task_unlock(p);
- rcu_read_unlock();
- return 0;
- }
- oom_score_adj = p->signal->oom_score_adj;
- if (oom_score_adj < min_score_adj) {
- task_unlock(p);
- continue;
- }
- tasksize = get_mm_rss(p->mm);
- task_unlock(p);
- if (tasksize <= 0)
- continue;
- if (selected) {
- if (oom_score_adj < selected_oom_score_adj)
- continue;
- if (oom_score_adj == selected_oom_score_adj &&
- tasksize <= selected_tasksize)
- continue;
- }
- selected = p;
- selected_tasksize = tasksize;
- selected_oom_score_adj = oom_score_adj;
- lowmem_print(2, "select '%s' (%d), adj %hd, size %d, to kill\n",
- p->comm, p->pid, oom_score_adj, tasksize);
- }
- if (selected) {
- task_lock(selected);
- send_sig(SIGKILL, selected, 0);
- if (selected->mm)
- task_set_lmk_waiting(selected);
- task_unlock(selected);
- lowmem_print(1, "Killing '%s' (%d), adj %hd,\n"
- " to free %ldkB on behalf of '%s' (%d) because\n"
- " cache %ldkB is below limit %ldkB for oom_score_adj %hd\n"
- " Free memory is %ldkB above reserved\n",
- selected->comm, selected->pid,
- selected_oom_score_adj,
- selected_tasksize * (long)(PAGE_SIZE / 1024),
- current->comm, current->pid,
- other_file * (long)(PAGE_SIZE / 1024),
- minfree * (long)(PAGE_SIZE / 1024),
- min_score_adj,
- other_free * (long)(PAGE_SIZE / 1024));
- lowmem_deathpending_timeout = jiffies + HZ;
- rem += selected_tasksize;
- }
-
- lowmem_print(4, "lowmem_scan %lu, %x, return %lu\n",
- sc->nr_to_scan, sc->gfp_mask, rem);
- rcu_read_unlock();
- return rem;
-}
-
-static struct shrinker lowmem_shrinker = {
- .scan_objects = lowmem_scan,
- .count_objects = lowmem_count,
- .seeks = DEFAULT_SEEKS * 16
-};
-
-static int __init lowmem_init(void)
-{
- register_shrinker(&lowmem_shrinker);
- return 0;
-}
-device_initcall(lowmem_init);
-
-/*
- * not really modular, but the easiest way to keep compat with existing
- * bootargs behaviour is to continue using module_param here.
- */
-module_param_named(cost, lowmem_shrinker.seeks, int, 0644);
-module_param_array_named(adj, lowmem_adj, short, &lowmem_adj_size, 0644);
-module_param_array_named(minfree, lowmem_minfree, uint, &lowmem_minfree_size,
- 0644);
-module_param_named(debug_level, lowmem_debug_level, uint, 0644);
-
diff --git a/include/linux/sched.h b/include/linux/sched.h
index e93594b88130..3cc6c650fa6a 100644
--- a/include/linux/sched.h
+++ b/include/linux/sched.h
@@ -2347,7 +2347,6 @@ static inline void memalloc_noio_restore(unsigned int flags)
#define PFA_NO_NEW_PRIVS 0 /* May not gain new privileges. */
#define PFA_SPREAD_PAGE 1 /* Spread page cache over cpuset */
#define PFA_SPREAD_SLAB 2 /* Spread some slab caches over cpuset */
-#define PFA_LMK_WAITING 3 /* Lowmemorykiller is waiting */
#define TASK_PFA_TEST(name, func) \
@@ -2371,9 +2370,6 @@ TASK_PFA_TEST(SPREAD_SLAB, spread_slab)
TASK_PFA_SET(SPREAD_SLAB, spread_slab)
TASK_PFA_CLEAR(SPREAD_SLAB, spread_slab)
-TASK_PFA_TEST(LMK_WAITING, lmk_waiting)
-TASK_PFA_SET(LMK_WAITING, lmk_waiting)
-
/*
* task->jobctl flags
*/
--
2.11.0
[toc] | [next] | [standalone]
| From | John Stultz <john.stultz@linaro.org> |
|---|---|
| Date | 2017-02-23 21:30 +0100 |
| Message-ID | <te8bw-6hU-13@gated-at.bofh.it> |
| In reply to | #1586111 |
On Wed, Feb 22, 2017 at 4:01 AM, Michal Hocko <mhocko@kernel.org> wrote: > From: Michal Hocko <mhocko@suse.com> > > Lowmemory killer is sitting in the staging tree since 2008 without any > serious interest for fixing issues brought up by the MM folks. The main > objection is that the implementation is basically broken by design: > - it hooks into slab shrinker API which is not suitable for this > purpose. lowmem_count implementation just shows this nicely. > There is no scaling based on the memory pressure and no > feedback to the generic shrinker infrastructure. > Moreover lowmem_scan is called way too often for the heavy > work it performs. > - it is not reclaim context aware - no NUMA and/or memcg > awareness. > > As the code stands right now it just adds a maintenance overhead when > core MM changes have to update lowmemorykiller.c as well. It also seems > that the alternative LMK implementation will be solely in the userspace > so this code has no perspective it seems. The staging tree is supposed > to be for a code which needs to be put in shape before it can be merged > which is not the case here obviously. So, just for context, Android does have a userland LMK daemon (using the mempressure notifiers) as you mentioned, but unfortunately I'm unaware of any devices that ship with that implementation. This is reportedly because while the mempressure notifiers provide a the signal to userspace, the work the deamon then has to do to look up per process memory usage, in order to figure out who is best to kill at that point was too costly and resulted in poor device performance. So for shipping Android devices, the LMK is still needed. However, its not critical for basic android development, as the system will function without it. Additionally I believe most vendors heavily customize the LMK in their vendor tree, so the value of having it in staging might be relatively low. It would be great however to get a discussion going here on what the ulmkd needs from the kernel in order to efficiently determine who best to kill, and how we might best implement that. thanks -john
[toc] | [prev] | [next] | [standalone]
| From | Martijn Coenen <maco@google.com> |
|---|---|
| Date | 2017-02-23 21:40 +0100 |
| Message-ID | <te8lc-6kY-5@gated-at.bofh.it> |
| In reply to | #1587111 |
On Thu, Feb 23, 2017 at 9:24 PM, John Stultz <john.stultz@linaro.org> wrote: > > So, just for context, Android does have a userland LMK daemon (using > the mempressure notifiers) as you mentioned, but unfortunately I'm > unaware of any devices that ship with that implementation. I've previously worked on enabling userspace lmkd for a previous release, but ran into some issues there (see below). > This is reportedly because while the mempressure notifiers provide a > the signal to userspace, the work the deamon then has to do to look up > per process memory usage, in order to figure out who is best to kill > at that point was too costly and resulted in poor device performance. In particular, mempressure requires memory cgroups to function, and we saw performance regressions due to the accounting done in mem cgroups. At the time we didn't have enough time left to solve this before the release, and we reverted back to kernel lmkd. > > So for shipping Android devices, the LMK is still needed. However, its > not critical for basic android development, as the system will > function without it. It will function, but it most likely will perform horribly (as the page cache will be trashed to such a level that the system will be unusable). >Additionally I believe most vendors heavily > customize the LMK in their vendor tree, so the value of having it in > staging might be relatively low. > > It would be great however to get a discussion going here on what the > ulmkd needs from the kernel in order to efficiently determine who best > to kill, and how we might best implement that. The two main issues I think we need to address are: 1) Getting the right granularity of events from the kernel; I once tried to submit a patch upstream to address this: https://lkml.org/lkml/2016/2/24/582 2) Find out where exactly the memory cgroup overhead is coming from, and how to reduce it or work around it to acceptable levels for Android. This was also on 3.10, and maybe this has long been fixed or improved in more recent kernel versions. I don't have cycles to work on this now, but I'm happy to talk to whoever picks this up on the Android side. Thanks, Martijn > > thanks > -john
[toc] | [prev] | [next] | [standalone]
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Date | 2017-02-24 10:40 +0100 |
| Message-ID | <tekw2-6Db-5@gated-at.bofh.it> |
| In reply to | #1587114 |
On Thu 23-02-17 21:36:00, Martijn Coenen wrote:
> On Thu, Feb 23, 2017 at 9:24 PM, John Stultz <john.stultz@linaro.org> wrote:
[...]
> > This is reportedly because while the mempressure notifiers provide a
> > the signal to userspace, the work the deamon then has to do to look up
> > per process memory usage, in order to figure out who is best to kill
> > at that point was too costly and resulted in poor device performance.
>
> In particular, mempressure requires memory cgroups to function, and we
> saw performance regressions due to the accounting done in mem cgroups.
> At the time we didn't have enough time left to solve this before the
> release, and we reverted back to kernel lmkd.
I would be more than interested to hear details. We used to have some
visible charge path performance footprint but this should be gone now.
[...]
> > It would be great however to get a discussion going here on what the
> > ulmkd needs from the kernel in order to efficiently determine who best
> > to kill, and how we might best implement that.
>
> The two main issues I think we need to address are:
> 1) Getting the right granularity of events from the kernel; I once
> tried to submit a patch upstream to address this:
> https://lkml.org/lkml/2016/2/24/582
Not only that, the implementation of tht vmpressure needs some serious
rethinking as well. The current one can hit critical events
unexpectedly. The calculation also doesn't consider slab reclaim
sensibly.
> 2) Find out where exactly the memory cgroup overhead is coming from,
> and how to reduce it or work around it to acceptable levels for
> Android. This was also on 3.10, and maybe this has long been fixed or
> improved in more recent kernel versions.
3e32cb2e0a12 ("mm: memcontrol: lockless page counters") has improved
situation a lot as all the charging is lockless since then (3.19).
--
Michal Hocko
SUSE Labs
[toc] | [prev] | [next] | [standalone]
| From | peter enderborg <peter.enderborg@sonymobile.com> |
|---|---|
| Date | 2017-02-24 13:20 +0100 |
| Message-ID | <ten0S-8s6-29@gated-at.bofh.it> |
| In reply to | #1587114 |
On 02/23/2017 09:36 PM, Martijn Coenen wrote: > On Thu, Feb 23, 2017 at 9:24 PM, John Stultz <john.stultz@linaro.org> wrote: >> So, just for context, Android does have a userland LMK daemon (using >> the mempressure notifiers) as you mentioned, but unfortunately I'm >> unaware of any devices that ship with that implementation. > I've previously worked on enabling userspace lmkd for a previous > release, but ran into some issues there (see below). > >> This is reportedly because while the mempressure notifiers provide a >> the signal to userspace, the work the deamon then has to do to look up >> per process memory usage, in order to figure out who is best to kill >> at that point was too costly and resulted in poor device performance. > In particular, mempressure requires memory cgroups to function, and we > saw performance regressions due to the accounting done in mem cgroups. > At the time we didn't have enough time left to solve this before the > release, and we reverted back to kernel lmkd. > >> So for shipping Android devices, the LMK is still needed. However, its >> not critical for basic android development, as the system will >> function without it. > It will function, but it most likely will perform horribly (as the > page cache will be trashed to such a level that the system will be > unusable). > >> Additionally I believe most vendors heavily >> customize the LMK in their vendor tree, so the value of having it in >> staging might be relatively low. >> >> It would be great however to get a discussion going here on what the >> ulmkd needs from the kernel in order to efficiently determine who best >> to kill, and how we might best implement that. > The two main issues I think we need to address are: > 1) Getting the right granularity of events from the kernel; I once > tried to submit a patch upstream to address this: > https://lkml.org/lkml/2016/2/24/582 > 2) Find out where exactly the memory cgroup overhead is coming from, > and how to reduce it or work around it to acceptable levels for > Android. This was also on 3.10, and maybe this has long been fixed or > improved in more recent kernel versions. > > I don't have cycles to work on this now, but I'm happy to talk to > whoever picks this up on the Android side. I sent some patches that is different approach. It still uses shrinkers but it has a kernel part that do the kill part better than the old one but it does it the android way. The future for this is get it triggered with other path's than slab shrinker. But we will not continue unless we get google-android to be part of it. Hocko objected heavy on the patches but seems not to see that we need something to do the job before we can disconnect from shrinker. > Thanks, > Martijn > >> thanks >> -john
[toc] | [prev] | [next] | [standalone]
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Date | 2017-02-24 14:10 +0100 |
| Message-ID | <tenNh-yV-29@gated-at.bofh.it> |
| In reply to | #1587559 |
On Fri 24-02-17 13:19:46, peter enderborg wrote: > On 02/23/2017 09:36 PM, Martijn Coenen wrote: > > On Thu, Feb 23, 2017 at 9:24 PM, John Stultz <john.stultz@linaro.org> wrote: > >> So, just for context, Android does have a userland LMK daemon (using > >> the mempressure notifiers) as you mentioned, but unfortunately I'm > >> unaware of any devices that ship with that implementation. > > I've previously worked on enabling userspace lmkd for a previous > > release, but ran into some issues there (see below). > > > >> This is reportedly because while the mempressure notifiers provide a > >> the signal to userspace, the work the deamon then has to do to look up > >> per process memory usage, in order to figure out who is best to kill > >> at that point was too costly and resulted in poor device performance. > > In particular, mempressure requires memory cgroups to function, and we > > saw performance regressions due to the accounting done in mem cgroups. > > At the time we didn't have enough time left to solve this before the > > release, and we reverted back to kernel lmkd. > > > >> So for shipping Android devices, the LMK is still needed. However, its > >> not critical for basic android development, as the system will > >> function without it. > > It will function, but it most likely will perform horribly (as the > > page cache will be trashed to such a level that the system will be > > unusable). > > > >> Additionally I believe most vendors heavily > >> customize the LMK in their vendor tree, so the value of having it in > >> staging might be relatively low. > >> > >> It would be great however to get a discussion going here on what the > >> ulmkd needs from the kernel in order to efficiently determine who best > >> to kill, and how we might best implement that. > > The two main issues I think we need to address are: > > 1) Getting the right granularity of events from the kernel; I once > > tried to submit a patch upstream to address this: > > https://lkml.org/lkml/2016/2/24/582 > > 2) Find out where exactly the memory cgroup overhead is coming from, > > and how to reduce it or work around it to acceptable levels for > > Android. This was also on 3.10, and maybe this has long been fixed or > > improved in more recent kernel versions. > > > > I don't have cycles to work on this now, but I'm happy to talk to > > whoever picks this up on the Android side. > I sent some patches that is different approach. It still uses shrinkers > but it has a kernel part that do the kill part better than the old one > but it does it the android way. The future for this is get it triggered > with other path's than slab shrinker. But we will not continue unless > we get google-android to be part of it. Hocko objected heavy on > the patches but seems not to see that we need something to > do the job before we can disconnect from shrinker. Yeah, I strongly believe that the chosen approach is completely wrong. Both in abusing the shrinker interface and abusing oom_score_adj as the only criterion for the oom victim selection. -- Michal Hocko SUSE Labs
[toc] | [prev] | [next] | [standalone]
| From | peter enderborg <peter.enderborg@sonymobile.com> |
|---|---|
| Date | 2017-02-24 14:30 +0100 |
| Message-ID | <teo6C-J9-19@gated-at.bofh.it> |
| In reply to | #1587608 |
On 02/24/2017 01:28 PM, Michal Hocko wrote: > On Fri 24-02-17 13:19:46, peter enderborg wrote: >> On 02/23/2017 09:36 PM, Martijn Coenen wrote: >>> On Thu, Feb 23, 2017 at 9:24 PM, John Stultz <john.stultz@linaro.org> wrote: >>>> So, just for context, Android does have a userland LMK daemon (using >>>> the mempressure notifiers) as you mentioned, but unfortunately I'm >>>> unaware of any devices that ship with that implementation. >>> I've previously worked on enabling userspace lmkd for a previous >>> release, but ran into some issues there (see below). >>> >>>> This is reportedly because while the mempressure notifiers provide a >>>> the signal to userspace, the work the deamon then has to do to look up >>>> per process memory usage, in order to figure out who is best to kill >>>> at that point was too costly and resulted in poor device performance. >>> In particular, mempressure requires memory cgroups to function, and we >>> saw performance regressions due to the accounting done in mem cgroups. >>> At the time we didn't have enough time left to solve this before the >>> release, and we reverted back to kernel lmkd. >>> >>>> So for shipping Android devices, the LMK is still needed. However, its >>>> not critical for basic android development, as the system will >>>> function without it. >>> It will function, but it most likely will perform horribly (as the >>> page cache will be trashed to such a level that the system will be >>> unusable). >>> >>>> Additionally I believe most vendors heavily >>>> customize the LMK in their vendor tree, so the value of having it in >>>> staging might be relatively low. >>>> >>>> It would be great however to get a discussion going here on what the >>>> ulmkd needs from the kernel in order to efficiently determine who best >>>> to kill, and how we might best implement that. >>> The two main issues I think we need to address are: >>> 1) Getting the right granularity of events from the kernel; I once >>> tried to submit a patch upstream to address this: >>> https://lkml.org/lkml/2016/2/24/582 >>> 2) Find out where exactly the memory cgroup overhead is coming from, >>> and how to reduce it or work around it to acceptable levels for >>> Android. This was also on 3.10, and maybe this has long been fixed or >>> improved in more recent kernel versions. >>> >>> I don't have cycles to work on this now, but I'm happy to talk to >>> whoever picks this up on the Android side. >> I sent some patches that is different approach. It still uses shrinkers >> but it has a kernel part that do the kill part better than the old one >> but it does it the android way. The future for this is get it triggered >> with other path's than slab shrinker. But we will not continue unless >> we get google-android to be part of it. Hocko objected heavy on >> the patches but seems not to see that we need something to >> do the job before we can disconnect from shrinker. > Yeah, I strongly believe that the chosen approach is completely wrong. > Both in abusing the shrinker interface and abusing oom_score_adj as the > only criterion for the oom victim selection. No one is arguing that shrinker is not problematic. And would be great if it is removed from lmk. The oom_score_adj is the way user-space tells the kernel what the user-space has as prio. And android is using that very much. It's a core part. I have never seen it be used on other linux system so what is the intended usage of oom_score_adj? Is this really abusing? I think I can help out with removing shrinker from lmk. Not using oom_score_adj is harder and has a bigger impact on android, except the trivial solution by adding replacement oom_user_prio and use that within android and kernel.
[toc] | [prev] | [next] | [standalone]
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Date | 2017-02-24 15:20 +0100 |
| Message-ID | <teoT0-1iX-5@gated-at.bofh.it> |
| In reply to | #1587659 |
On Fri 24-02-17 14:16:34, peter enderborg wrote: > On 02/24/2017 01:28 PM, Michal Hocko wrote: [...] > > Yeah, I strongly believe that the chosen approach is completely wrong. > > Both in abusing the shrinker interface and abusing oom_score_adj as the > > only criterion for the oom victim selection. > > No one is arguing that shrinker is not problematic. And would be great > if it is removed from lmk. The oom_score_adj is the way user-space > tells the kernel what the user-space has as prio. And android is using > that very much. It's a core part. Is there any documentation which describes how this is done? > I have never seen it be used on > other linux system so what is the intended usage of oom_score_adj? Is > this really abusing? oom_score_adj is used to _adjust_ the calculated oom score. It is not a criterion on its own, well, except for the extreme sides of the range which are defined to enforce resp. disallow selecting the task. The global oom killer calculates the oom score as a function of the memory consumption. Your patch simply ignores the memory consumption (and uses pids to sort tasks with the same oom score which is just mind boggling) and that is what I call the abuse. The oom score calculation might change in future, of course, but all consumers of the oom_score_adj really have to agree on the base which is adjusted by this tunable otherwise you can see a lot of unexpected behavior. I would even argue that nobody outside of mm/oom_kill.c should really have any business with this tunable. You can of course tweak the value from the userspace and help to chose a better oom victim this way but that is it. Anyway, I guess we are getting quite off-topic here. -- Michal Hocko SUSE Labs
[toc] | [prev] | [next] | [standalone]
| From | peter enderborg <peter.enderborg@sonymobile.com> |
|---|---|
| Date | 2017-02-24 15:50 +0100 |
| Message-ID | <tepm2-1yw-13@gated-at.bofh.it> |
| In reply to | #1587684 |
On 02/24/2017 03:11 PM, Michal Hocko wrote: > On Fri 24-02-17 14:16:34, peter enderborg wrote: >> On 02/24/2017 01:28 PM, Michal Hocko wrote: > [...] >>> Yeah, I strongly believe that the chosen approach is completely wrong. >>> Both in abusing the shrinker interface and abusing oom_score_adj as the >>> only criterion for the oom victim selection. >> No one is arguing that shrinker is not problematic. And would be great >> if it is removed from lmk. The oom_score_adj is the way user-space >> tells the kernel what the user-space has as prio. And android is using >> that very much. It's a core part. > Is there any documentation which describes how this is done? > >> I have never seen it be used on >> other linux system so what is the intended usage of oom_score_adj? Is >> this really abusing? > oom_score_adj is used to _adjust_ the calculated oom score. It is not a > criterion on its own, well, except for the extreme sides of the range > which are defined to enforce resp. disallow selecting the task. The > global oom killer calculates the oom score as a function of the memory > consumption. Your patch simply ignores the memory consumption (and uses > pids to sort tasks with the same oom score which is just mind boggling) How much it uses is of very little importance for android. The score used are only for apps and their services. System related are not touched by android lmk. The pid is only to have a unique key to be able to have it fast within a rbtree. One idea was to use task_pid to get a strict age of process to get a round robin but since it does not matter i skipped that idea since it does not matter. > and that is what I call the abuse. The oom score calculation might > change in future, of course, but all consumers of the oom_score_adj > really have to agree on the base which is adjusted by this tunable > otherwise you can see a lot of unexpected behavior. Then can we just define a range that is strictly for user-space? > I would even argue that nobody outside of mm/oom_kill.c should really > have any business with this tunable. You can of course tweak the value > from the userspace and help to chose a better oom victim this way but > that is it. Why only help? If userspace can give an exact order to kernel that must be a good thing; other wise kernel have to guess and when can that be better? > Anyway, I guess we are getting quite off-topic here. >
[toc] | [prev] | [next] | [standalone]
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Date | 2017-02-24 16:10 +0100 |
| Message-ID | <tepFo-1V0-25@gated-at.bofh.it> |
| In reply to | #1587698 |
On Fri 24-02-17 15:42:49, peter enderborg wrote:
> On 02/24/2017 03:11 PM, Michal Hocko wrote:
> > On Fri 24-02-17 14:16:34, peter enderborg wrote:
> >> On 02/24/2017 01:28 PM, Michal Hocko wrote:
> > [...]
> >>> Yeah, I strongly believe that the chosen approach is completely wrong.
> >>> Both in abusing the shrinker interface and abusing oom_score_adj as the
> >>> only criterion for the oom victim selection.
> >> No one is arguing that shrinker is not problematic. And would be great
> >> if it is removed from lmk. The oom_score_adj is the way user-space
> >> tells the kernel what the user-space has as prio. And android is using
> >> that very much. It's a core part.
> > Is there any documentation which describes how this is done?
> >
> >> I have never seen it be used on
> >> other linux system so what is the intended usage of oom_score_adj? Is
> >> this really abusing?
> > oom_score_adj is used to _adjust_ the calculated oom score. It is not a
> > criterion on its own, well, except for the extreme sides of the range
> > which are defined to enforce resp. disallow selecting the task. The
> > global oom killer calculates the oom score as a function of the memory
> > consumption. Your patch simply ignores the memory consumption (and uses
> > pids to sort tasks with the same oom score which is just mind boggling)
>
> How much it uses is of very little importance for android.
But it is relevant for the global oom killer which is the main consumer of
the oom_score_adj.
> The score
> used are only for apps and their services. System related are not
> touched by android lmk. The pid is only to have a unique key to be
> able to have it fast within a rbtree. One idea was to use task_pid to
> get a strict age of process to get a round robin but since it does not
> matter i skipped that idea since it does not matter.
Pid will not tell you anything about the age. Pids do wrap around.
> > and that is what I call the abuse. The oom score calculation might
> > change in future, of course, but all consumers of the oom_score_adj
> > really have to agree on the base which is adjusted by this tunable
> > otherwise you can see a lot of unexpected behavior.
>
> Then can we just define a range that is strictly for user-space?
This is already well defined. The whole range OOM_SCORE_ADJ_{MIN,MAX}
is usable.
> > I would even argue that nobody outside of mm/oom_kill.c should really
> > have any business with this tunable. You can of course tweak the value
> > from the userspace and help to chose a better oom victim this way but
> > that is it.
>
> Why only help? If userspace can give an exact order to kernel that
> must be a good thing; other wise kernel have to guess and when
> can that be better?
Because userspace doesn't know who is the best victim in 99% cases.
Android might be different, although, I am a bit skeptical - especially
after hearing quite some complains about random application being
killed... If you do believe that you know better then, by all means,
implement your custom user space LMK and chose the oom victim on a
different basis but try to understand that the global OOM killer is the
last resort measure to make the system usable again. There is a good
reason why the kernel uses the current badness calculation. The previous
implementation which considered the process age ad other things was just
too random to have a understandable behavior.
In any case playing nasty games with the oom killer tunables might and
will lead, well, to unexpected behavior.
--
Michal Hocko
SUSE Labs
[toc] | [prev] | [next] | [standalone]
| From | peter enderborg <peter.enderborg@sonymobile.com> |
|---|---|
| Date | 2017-02-24 16:50 +0100 |
| Message-ID | <teqi7-2bp-41@gated-at.bofh.it> |
| In reply to | #1587704 |
On 02/24/2017 04:03 PM, Michal Hocko wrote:
> On Fri 24-02-17 15:42:49, peter enderborg wrote:
>> On 02/24/2017 03:11 PM, Michal Hocko wrote:
>>> On Fri 24-02-17 14:16:34, peter enderborg wrote:
>>>> On 02/24/2017 01:28 PM, Michal Hocko wrote:
>>> [...]
>>>>> Yeah, I strongly believe that the chosen approach is completely wrong.
>>>>> Both in abusing the shrinker interface and abusing oom_score_adj as the
>>>>> only criterion for the oom victim selection.
>>>> No one is arguing that shrinker is not problematic. And would be great
>>>> if it is removed from lmk. The oom_score_adj is the way user-space
>>>> tells the kernel what the user-space has as prio. And android is using
>>>> that very much. It's a core part.
>>> Is there any documentation which describes how this is done?
>>>
>>>> I have never seen it be used on
>>>> other linux system so what is the intended usage of oom_score_adj? Is
>>>> this really abusing?
>>> oom_score_adj is used to _adjust_ the calculated oom score. It is not a
>>> criterion on its own, well, except for the extreme sides of the range
>>> which are defined to enforce resp. disallow selecting the task. The
>>> global oom killer calculates the oom score as a function of the memory
>>> consumption. Your patch simply ignores the memory consumption (and uses
>>> pids to sort tasks with the same oom score which is just mind boggling)
>> How much it uses is of very little importance for android.
> But it is relevant for the global oom killer which is the main consumer of
> the oom_score_adj.
>
>> The score
>> used are only for apps and their services. System related are not
>> touched by android lmk. The pid is only to have a unique key to be
>> able to have it fast within a rbtree. One idea was to use task_pid to
>> get a strict age of process to get a round robin but since it does not
>> matter i skipped that idea since it does not matter.
> Pid will not tell you anything about the age. Pids do wrap around.
>
>>> and that is what I call the abuse. The oom score calculation might
>>> change in future, of course, but all consumers of the oom_score_adj
>>> really have to agree on the base which is adjusted by this tunable
>>> otherwise you can see a lot of unexpected behavior.
>> Then can we just define a range that is strictly for user-space?
> This is already well defined. The whole range OOM_SCORE_ADJ_{MIN,MAX}
> is usable.
So we use them in userspace and kernel space but where is the abuse then?
>>> I would even argue that nobody outside of mm/oom_kill.c should really
>>> have any business with this tunable. You can of course tweak the value
>>> from the userspace and help to chose a better oom victim this way but
>>> that is it.
>> Why only help? If userspace can give an exact order to kernel that
>> must be a good thing; other wise kernel have to guess and when
>> can that be better?
> Because userspace doesn't know who is the best victim in 99% cases.
If user-space does not tell kernel what to it have to guess, android
user-space does, and maybe other should too.
> Android might be different, although, I am a bit skeptical - especially
> after hearing quite some complains about random application being
> killed... If you do believe that you know better then, by all means,
> implement your custom user space LMK and chose the oom victim on a
> different basis but try to understand that the global OOM killer is the
> last resort measure to make the system usable again. There is a good
> reason why the kernel uses the current badness calculation. The previous
> implementation which considered the process age ad other things was just
> too random to have a understandable behavior.
I think it make sense that there is only one way to describe what is
important what is not. And oom_kill is the last resort is one problem
for android. Android lowmemorykiller balance memory usage and
tries to be more proactive and that is why shrinkers work so well.
> In any case playing nasty games with the oom killer tunables might and
> will lead, well, to unexpected behavior.
I don't follow. If we only use values OOM_SCORE_ADJ_{MIN,MAX} can
we then be "safe"?
[toc] | [prev] | [next] | [standalone]
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Date | 2017-02-24 17:00 +0100 |
| Message-ID | <teqrM-2gQ-11@gated-at.bofh.it> |
| In reply to | #1587741 |
On Fri 24-02-17 16:40:13, peter enderborg wrote:
> On 02/24/2017 04:03 PM, Michal Hocko wrote:
> > On Fri 24-02-17 15:42:49, peter enderborg wrote:
> >> On 02/24/2017 03:11 PM, Michal Hocko wrote:
> >>> On Fri 24-02-17 14:16:34, peter enderborg wrote:
> >>>> On 02/24/2017 01:28 PM, Michal Hocko wrote:
> >>> [...]
> >>>>> Yeah, I strongly believe that the chosen approach is completely wrong.
> >>>>> Both in abusing the shrinker interface and abusing oom_score_adj as the
> >>>>> only criterion for the oom victim selection.
> >>>> No one is arguing that shrinker is not problematic. And would be great
> >>>> if it is removed from lmk. The oom_score_adj is the way user-space
> >>>> tells the kernel what the user-space has as prio. And android is using
> >>>> that very much. It's a core part.
> >>> Is there any documentation which describes how this is done?
> >>>
> >>>> I have never seen it be used on
> >>>> other linux system so what is the intended usage of oom_score_adj? Is
> >>>> this really abusing?
> >>> oom_score_adj is used to _adjust_ the calculated oom score. It is not a
> >>> criterion on its own, well, except for the extreme sides of the range
> >>> which are defined to enforce resp. disallow selecting the task. The
> >>> global oom killer calculates the oom score as a function of the memory
> >>> consumption. Your patch simply ignores the memory consumption (and uses
> >>> pids to sort tasks with the same oom score which is just mind boggling)
> >> How much it uses is of very little importance for android.
> > But it is relevant for the global oom killer which is the main consumer of
> > the oom_score_adj.
> >
> >> The score
> >> used are only for apps and their services. System related are not
> >> touched by android lmk. The pid is only to have a unique key to be
> >> able to have it fast within a rbtree. One idea was to use task_pid to
> >> get a strict age of process to get a round robin but since it does not
> >> matter i skipped that idea since it does not matter.
> > Pid will not tell you anything about the age. Pids do wrap around.
> >
> >>> and that is what I call the abuse. The oom score calculation might
> >>> change in future, of course, but all consumers of the oom_score_adj
> >>> really have to agree on the base which is adjusted by this tunable
> >>> otherwise you can see a lot of unexpected behavior.
> >> Then can we just define a range that is strictly for user-space?
> > This is already well defined. The whole range OOM_SCORE_ADJ_{MIN,MAX}
> > is usable.
>
> So we use them in userspace and kernel space but where is the abuse then?
I believe I have already answered that.
> >>> I would even argue that nobody outside of mm/oom_kill.c should really
> >>> have any business with this tunable. You can of course tweak the value
> >>> from the userspace and help to chose a better oom victim this way but
> >>> that is it.
> >> Why only help? If userspace can give an exact order to kernel that
> >> must be a good thing; other wise kernel have to guess and when
> >> can that be better?
> > Because userspace doesn't know who is the best victim in 99% cases.
>
> If user-space does not tell kernel what to it have to guess, android
> user-space does, and maybe other should too.
I believe they would do if this was so simple. This is not as easy to
answer as you might think. If you ask, everybody will consider their
task important enough to be killed.
[...]
> > In any case playing nasty games with the oom killer tunables might and
> > will lead, well, to unexpected behavior.
>
> I don't follow. If we only use values OOM_SCORE_ADJ_{MIN,MAX} can
> we then be "safe"?
I didn't say that. I was just trying to say that you cannot give a
single knob two different semantics depending on who is using them. That
simply won't work. So if you believe that your LMK knows better then try
to use something else for your heuristics.
Anyway, this is still offtopic I believe.
--
Michal Hocko
SUSE Labs
[toc] | [prev] | [next] | [standalone]
| From | Michal Hocko <mhocko@kernel.org> |
|---|---|
| Date | 2017-02-24 11:20 +0100 |
| Message-ID | <tel8J-79A-3@gated-at.bofh.it> |
| In reply to | #1587111 |
On Thu 23-02-17 12:24:57, John Stultz wrote: > On Wed, Feb 22, 2017 at 4:01 AM, Michal Hocko <mhocko@kernel.org> wrote: > > From: Michal Hocko <mhocko@suse.com> > > > > Lowmemory killer is sitting in the staging tree since 2008 without any > > serious interest for fixing issues brought up by the MM folks. The main > > objection is that the implementation is basically broken by design: > > - it hooks into slab shrinker API which is not suitable for this > > purpose. lowmem_count implementation just shows this nicely. > > There is no scaling based on the memory pressure and no > > feedback to the generic shrinker infrastructure. > > Moreover lowmem_scan is called way too often for the heavy > > work it performs. > > - it is not reclaim context aware - no NUMA and/or memcg > > awareness. > > > > As the code stands right now it just adds a maintenance overhead when > > core MM changes have to update lowmemorykiller.c as well. It also seems > > that the alternative LMK implementation will be solely in the userspace > > so this code has no perspective it seems. The staging tree is supposed > > to be for a code which needs to be put in shape before it can be merged > > which is not the case here obviously. > > So, just for context, Android does have a userland LMK daemon (using > the mempressure notifiers) as you mentioned, but unfortunately I'm > unaware of any devices that ship with that implementation. > > This is reportedly because while the mempressure notifiers provide a > the signal to userspace, the work the deamon then has to do to look up > per process memory usage, in order to figure out who is best to kill > at that point was too costly and resulted in poor device performance. What was the expensive part? > So for shipping Android devices, the LMK is still needed. However, its > not critical for basic android development, as the system will > function without it. Additionally I believe most vendors heavily > customize the LMK in their vendor tree, so the value of having it in > staging might be relatively low. This is even a stronger reason to drop it from the tree. We do not want to maintain the code which is not used in fact. > It would be great however to get a discussion going here on what the > ulmkd needs from the kernel in order to efficiently determine who best > to kill, and how we might best implement that. I would really like to see this happen and, to be honest, it should have happened quite some time ago (around the time when the lmk was merged to the staging tree). -- Michal Hocko SUSE Labs
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web