Skip to contentSkip to conversation

Used Memory Meter pseudo-device and related changes in MM

PATCH Superseded Leonid Moiseichuk 8 participants 38 messages Jan 4, 2012 – Jan 13, 2012

Subsystems (5)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Used Memory Meter pseudo-device and related changes in MM

The main idea of Used Memory Meter (UMM) is to provide low-cost interface for user-space to notify about memory consumption using similar approach /proc/meminfo does but focusing only on "modified" pages which cannot be fogotten.

The calculation formula in terms of meminfo looks the following:
UsedMemory = (MemTotal - MemFree - Buffers - Cached - SwapCached) +
(SwapTotal - SwapFree)
It reflects well amount of system memory used in applications in heaps and shared pages.

Previously (n770..n900) we had lowmem.c [1] which used LSM and did a lot other things, n9 implementation based on memcg [2] which has own problems, so the proposed variant I hope is the best one for n9:
- Keeps connections from user space
- When amount of modified pages reaches crossed pointed value for particular connection makes POLLIN and allow user-space app to read it and react
- Economic as much as possible, so currently its operates if allocation higher than 487 pages or last check happened 250 ms before
Of course if no allocation happened then no activities performed, use-time must be not affected.

Testing results:
- Checkpatch produced 0 warning
- Sparse does not produce warnings
- One check costs ~20 us or less (could be checked with probe=1 insmod)
- One connection costs 20 bytes in kernel-space (see observer structure) for 32-bit variant
- For 10K connections poll update in requested in ~10ms, but for practically device expected to will have about 10 connections (like n9 has now).

Known weak points which I do not know how to fix but will if you have a brillian idea:
- Having hook in MM is nasty but MM/shrinker cannot be used there and LSM even worse idea
- If I made
$cat /dev/used_memory
it is produced lines in non-stop mode. Adding position check in umm_read seems doesn not help, so "head -1 /dev/used_memory" should be used if you need to quick check
- Format of output is USED_PAGES:AVAILABLE_PAGES, primitive but enough for tasks module does

Tested on ARM, x86-32 and x86-64 with and without CONFIG_SWAP. Seems works in all combinations. Sorry for wide distributions but list of names were produced by scripts/get_maintainer.pl

References
[1] http://elinux.org/Accurate_Memory_Measurement
[2] http://maemo.gitorious.org/maemo-tools/libmemnotify

Leonid Moiseichuk (3):
Making si_swapinfo exportable
MM hook for page allocation and release
Used Memory Meter pseudo-device module

 drivers/misc/Kconfig  |   12 ++
 drivers/misc/Makefile |    1 +
 drivers/misc/umm.c    |  452 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/mm.h    |   15 ++
 include/linux/umm.h   |   42 +++++
 mm/Kconfig            |    8 +
 mm/page_alloc.c       |   31 ++++
 mm/swapfile.c         |    3 +
 8 files changed, 564 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/umm.c
 create mode 100644 include/linux/umm.h
Signature · 8 lines
1.7.7.3

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#1 lore raw

PATCH 1/3 Making si_swapinfo exportable

If we will make si_swapinfo() exportable it could be called from modules. Otherwise modules have no interface to obtain information about swap usage. Change made in the same way as si_meminfo() declared.

---
 mm/swapfile.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
mm/swapfile.c +3 -0
index b1cd120..192cc25 100644
@@ -5,10 +5,12 @@
  *  Swap reorganised 29.12.95, Stephen Tweedie
  */
 
+#include <linux/export.h>
 #include <linux/mm.h>
 #include <linux/hugetlb.h>
 #include <linux/mman.h>
 #include <linux/slab.h>
+#include <linux/kernel.h>
 #include <linux/kernel_stat.h>
 #include <linux/swap.h>
 #include <linux/vmalloc.h>
@@ -2177,6 +2179,7 @@ void si_swapinfo(struct sysinfo *val)
 	val->totalswap = total_swap_pages + nr_to_be_unused;
 	spin_unlock(&swap_lock);
 }
+EXPORT_SYMBOL(si_swapinfo);
 
 /*
  * Verify that a swap entry is valid and increment its swap map count.
Signature · 8 lines
1.7.7.3

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#2 lore raw

PATCH 2/3 MM hook for page allocation and release

In reply to Leonid Moiseichuk

That is required by Used Memory Meter (UMM) pseudo-device to track memory utilization in system. It is expected that hook MUST be very light to prevent performance impact on the hot allocation path. Accuracy of number managed pages does not expected to be absolute but fact of allocation or deallocation must be registered.

---
 include/linux/mm.h |   15 +++++++++++++++
 mm/Kconfig         |    8 ++++++++
 mm/page_alloc.c    |   31 +++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 0 deletions(-)
include/linux/mm.h +15 -0
index 3dc3a8c..d133f73 100644
@@ -1618,6 +1618,21 @@ extern int soft_offline_page(struct page *page, int flags);
 
 extern void dump_page(struct page *page);
 
+#ifdef CONFIG_MM_ALLOC_FREE_HOOK
+/*
+ * Hook function type which called when some pages allocated or released.
+ * Value of nr_pages is positive for post-allocation calls and negative
+ * after free.
+ */
+typedef void (*mm_alloc_free_hook_t)(int nr_pages);
+
+/*
+ * Setups specified hook function for tracking pages allocation.
+ * Returns value of old hook to organize chains of calls if necessary.
+ */
+mm_alloc_free_hook_t set_mm_alloc_free_hook(mm_alloc_free_hook_t hook);
+#endif
+
 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
 extern void clear_huge_page(struct page *page,
 			    unsigned long addr,
mm/Kconfig +8 -0
index 011b110..2aaa1e9 100644
@@ -373,3 +373,11 @@ config CLEANCACHE
 	  in a negligible performance hit.
 
 	  If unsure, say Y to enable cleancache
+
+config MM_ALLOC_FREE_HOOK
+	bool "Enable callback support for pages allocation and releasing"
+	default n
+	help
+	  Required for some features like used memory meter.
+	  If unsure, say N to disable alloc/free hook.
+
mm/page_alloc.c +31 -0
index 9dd443d..9307800 100644
@@ -236,6 +236,30 @@ static void set_pageblock_migratetype(struct page *page, int migratetype)
 
 bool oom_killer_disabled __read_mostly;
 
+#ifdef CONFIG_MM_ALLOC_FREE_HOOK
+static atomic_long_t alloc_free_hook __read_mostly = ATOMIC_LONG_INIT(0);
+
+mm_alloc_free_hook_t set_mm_alloc_free_hook(mm_alloc_free_hook_t hook)
+{
+	const mm_alloc_free_hook_t old_hook =
+		(mm_alloc_free_hook_t)atomic_long_read(&alloc_free_hook);
+
+	atomic_long_set(&alloc_free_hook, (long)hook);
+	pr_info("MM alloc/free hook set to 0x%p (was 0x%p)\n", hook, old_hook);
+
+	return old_hook;
+}
+EXPORT_SYMBOL(set_mm_alloc_free_hook);
+
+static inline void call_alloc_free_hook(int pages)
+{
+	const mm_alloc_free_hook_t hook =
+		(mm_alloc_free_hook_t)atomic_long_read(&alloc_free_hook);
+	if (hook)
+		hook(pages);
+}
+#endif
+
 #ifdef CONFIG_DEBUG_VM
 static int page_outside_zone_boundaries(struct zone *zone, struct page *page)
 {
@@ -2298,6 +2322,10 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
 	put_mems_allowed();
 
 	trace_mm_page_alloc(page, order, gfp_mask, migratetype);
+#ifdef CONFIG_MM_ALLOC_FREE_HOOK
+	call_alloc_free_hook(1 << order);
+#endif
+
 	return page;
 }
 EXPORT_SYMBOL(__alloc_pages_nodemask);
@@ -2345,6 +2373,9 @@ void __free_pages(struct page *page, unsigned int order)
 			free_hot_cold_page(page, 0);
 		else
 			__free_pages_ok(page, order);
+#ifdef CONFIG_MM_ALLOC_FREE_HOOK
+		call_alloc_free_hook(-(1 << order));
+#endif
 	}
 }
 
Signature · 8 lines
1.7.7.3

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Nacked-by on v1 2/3 NAK
#3 lore raw

Re: [PATCH 3.2.0-rc1 2/3] MM hook for page allocation and release

Quoted 109 lines · Leonid Moiseichuk

That is required by Used Memory Meter (UMM) pseudo-device to track memory utilization in system. It is expected that hook MUST be very light to prevent performance impact on the hot allocation path. Accuracy of number managed pages does not expected to be absolute but fact of allocation or deallocation must be registered.

---
 include/linux/mm.h |   15 +++++++++++++++ mm/Kconfig         |    8 ++++++++ mm/page_alloc.c    |   31 +++++++++++++++++++++++++++++++

 3 files changed, 54 insertions(+), 0 deletions(-)
include/linux/mm.h +15 -0
index 3dc3a8c..d133f73 100644
@@ -1618,6 +1618,21 @@ extern int soft_offline_page(struct page *page, int flags);
 
  extern void dump_page(struct page *page);
 
+#ifdef CONFIG_MM_ALLOC_FREE_HOOK
+/*
+ * Hook function type which called when some pages allocated or released.
+ * Value of nr_pages is positive for post-allocation calls and negative
+ * after free.
+ */
+typedef void (*mm_alloc_free_hook_t)(int nr_pages);
+
+/*
+ * Setups specified hook function for tracking pages allocation.
+ * Returns value of old hook to organize chains of calls if necessary.
+ */
+mm_alloc_free_hook_t set_mm_alloc_free_hook(mm_alloc_free_hook_t hook);
+#endif
+
  #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
  extern void clear_huge_page(struct page *page,
                            unsigned long addr,
mm/Kconfig +0 -0
index 011b110..2aaa1e9 100644
@@ -373,3 +373,11 @@ config CLEANCACHE

         in a negligible performance hit.

         If unsure, say Y to enable cleancache

mm/Kconfig +8 -0
+
+config MM_ALLOC_FREE_HOOK
+       bool "Enable callback support for pages allocation and releasing"
+       default n
+       help
+         Required for some features like used memory meter.
+         If unsure, say N to disable alloc/free hook.
+
mm/page_alloc.c +28 -0
index 9dd443d..9307800 100644
@@ -236,6 +236,30 @@ static void set_pageblock_migratetype(struct page *page, int migratetype)
 
  bool oom_killer_disabled __read_mostly;
 
+#ifdef CONFIG_MM_ALLOC_FREE_HOOK
+static atomic_long_t alloc_free_hook __read_mostly = ATOMIC_LONG_INIT(0);
+
+mm_alloc_free_hook_t set_mm_alloc_free_hook(mm_alloc_free_hook_t hook)
+{
+       const mm_alloc_free_hook_t old_hook =
+               (mm_alloc_free_hook_t)atomic_long_read(&alloc_free_hook);
+
+       atomic_long_set(&alloc_free_hook, (long)hook);
+       pr_info("MM alloc/free hook set to 0x%p (was 0x%p)\n", hook, old_hook);
+
+       return old_hook;
+}
+EXPORT_SYMBOL(set_mm_alloc_free_hook);
+
+static inline void call_alloc_free_hook(int pages)
+{
+       const mm_alloc_free_hook_t hook =
+               (mm_alloc_free_hook_t)atomic_long_read(&alloc_free_hook);
+       if (hook)
+               hook(pages);
+}
+#endif
+
  #ifdef CONFIG_DEBUG_VM
  static int page_outside_zone_boundaries(struct zone *zone, struct page *page)
  {
@@ -2298,6 +2322,10 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
        put_mems_allowed();
 
        trace_mm_page_alloc(page, order, gfp_mask, migratetype);
+#ifdef CONFIG_MM_ALLOC_FREE_HOOK
+       call_alloc_free_hook(1 << order);
+#endif
+
        return page;
  }
  EXPORT_SYMBOL(__alloc_pages_nodemask);
@@ -2345,6 +2373,9 @@ void __free_pages(struct page *page, unsigned int order)
                        free_hot_cold_page(page, 0);

               else
                       __free_pages_ok(page, order);

mm/page_alloc.c +3 -0
+#ifdef CONFIG_MM_ALLOC_FREE_HOOK
+               call_alloc_free_hook(-(1 << order));
+#endif
Quoted 2 lines

       }
 }

No, we definitely don't want to allow random modules to insert hooks to the page allocator:

Can't we introduce some super-lightweight lowmem_{alloc|free}_hook() hooks that live in mm/lowmem.c and call those directly? If you need to support different ABIs for lowmem notifier, N9, and Android, you could make that observer code more generic, no? The swaphook people might be interested in that as well.

Pekka

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#4 lore raw

Re: [PATCH 3.2.0-rc1 2/3] MM hook for page allocation and release

In reply to Leonid Moiseichuk
Quoted 8 lines · On Wed, 4 Jan 2012 19:21:55 +0200 Leonid Moiseichuk…

That is required by Used Memory Meter (UMM) pseudo-device to track memory utilization in system. It is expected that hook MUST be very light to prevent performance impact on the hot allocation path. Accuracy of number managed pages does not expected to be absolute but fact of allocation or deallocation must be registered.

I never like arbitrary hooks to alloc_pages().
Could you find another way ?

Hmm. memcg uses per-cpu counters for counting event of alloc/free and trigger threashold check per 128 event on a cpu.

Thanks,
-Kame

Quoted 108 lines
---
 include/linux/mm.h |   15 +++++++++++++++
 mm/Kconfig         |    8 ++++++++
 mm/page_alloc.c    |   31 +++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 0 deletions(-)
include/linux/mm.h +15 -0
index 3dc3a8c..d133f73 100644
@@ -1618,6 +1618,21 @@ extern int soft_offline_page(struct page *page, int flags);
 
 extern void dump_page(struct page *page);
 
+#ifdef CONFIG_MM_ALLOC_FREE_HOOK
+/*
+ * Hook function type which called when some pages allocated or released.
+ * Value of nr_pages is positive for post-allocation calls and negative
+ * after free.
+ */
+typedef void (*mm_alloc_free_hook_t)(int nr_pages);
+
+/*
+ * Setups specified hook function for tracking pages allocation.
+ * Returns value of old hook to organize chains of calls if necessary.
+ */
+mm_alloc_free_hook_t set_mm_alloc_free_hook(mm_alloc_free_hook_t hook);
+#endif
+
 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
 extern void clear_huge_page(struct page *page,
 			    unsigned long addr,
mm/Kconfig +8 -0
index 011b110..2aaa1e9 100644
@@ -373,3 +373,11 @@ config CLEANCACHE
 	  in a negligible performance hit.
 
 	  If unsure, say Y to enable cleancache
+
+config MM_ALLOC_FREE_HOOK
+	bool "Enable callback support for pages allocation and releasing"
+	default n
+	help
+	  Required for some features like used memory meter.
+	  If unsure, say N to disable alloc/free hook.
+
mm/page_alloc.c +31 -0
index 9dd443d..9307800 100644
@@ -236,6 +236,30 @@ static void set_pageblock_migratetype(struct page *page, int migratetype)
 
 bool oom_killer_disabled __read_mostly;
 
+#ifdef CONFIG_MM_ALLOC_FREE_HOOK
+static atomic_long_t alloc_free_hook __read_mostly = ATOMIC_LONG_INIT(0);
+
+mm_alloc_free_hook_t set_mm_alloc_free_hook(mm_alloc_free_hook_t hook)
+{
+	const mm_alloc_free_hook_t old_hook =
+		(mm_alloc_free_hook_t)atomic_long_read(&alloc_free_hook);
+
+	atomic_long_set(&alloc_free_hook, (long)hook);
+	pr_info("MM alloc/free hook set to 0x%p (was 0x%p)\n", hook, old_hook);
+
+	return old_hook;
+}
+EXPORT_SYMBOL(set_mm_alloc_free_hook);
+
+static inline void call_alloc_free_hook(int pages)
+{
+	const mm_alloc_free_hook_t hook =
+		(mm_alloc_free_hook_t)atomic_long_read(&alloc_free_hook);
+	if (hook)
+		hook(pages);
+}
+#endif
+
 #ifdef CONFIG_DEBUG_VM
 static int page_outside_zone_boundaries(struct zone *zone, struct page *page)
 {
@@ -2298,6 +2322,10 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
 	put_mems_allowed();
 
 	trace_mm_page_alloc(page, order, gfp_mask, migratetype);
+#ifdef CONFIG_MM_ALLOC_FREE_HOOK
+	call_alloc_free_hook(1 << order);
+#endif
+
 	return page;
 }
 EXPORT_SYMBOL(__alloc_pages_nodemask);
@@ -2345,6 +2373,9 @@ void __free_pages(struct page *page, unsigned int order)
 			free_hot_cold_page(page, 0);
 		else
 			__free_pages_ok(page, order);
+#ifdef CONFIG_MM_ALLOC_FREE_HOOK
+		call_alloc_free_hook(-(1 << order));
+#endif
 	}
 }
 
Signature · 1 line
1.7.7.3

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#5 lore raw

RE: [PATCH 3.2.0-rc1 2/3] MM hook for page allocation and release

Hi,

I agree that hooking alloc_pages is ugly way. So alternatives I see:

- shrinkers (as e.g. Android OOM used) but shrink_slab called only from try_to_free_pages only if we are on slow reclaim path on memory allocation, so it cannot be used for e.g. 75% memory tracking or when pages released to notify user space that we are OK. But according to easy to use it will be the best approach.

- memcg-kind of changes like mem_cgroup_newpage_charge/uncharge_page but without blocking decision making logic. Seems to me more changes. Threshold currently in memcg set 128 pages per CPU, that is quite often for level tracking needs.

- tracking situation using timer? Maybe not due to will impact battery.

With Best Wishes,
Leonid

-----Original Message-----
From: ext KAMEZAWA Hiroyuki [mailto:[email protected]]
Sent: 05 January, 2012 09:00
To: Moiseichuk Leonid (Nokia-MP/Helsinki)
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jaaskelainen Vesa (Nokia-MP/Helsinki)
Subject: Re: [PATCH 3.2.0-rc1 2/3] MM hook for page allocation and release

Quoted 7 lines · On Wed, 4 Jan 2012 19:21:55 +0200 Leonid Moiseichuk…

That is required by Used Memory Meter (UMM) pseudo-device to track memory utilization in system. It is expected that hook MUST be very light to prevent performance impact on the hot allocation path. Accuracy of number managed pages does not expected to be absolute but fact of allocation or deallocation must be registered.

I never like arbitrary hooks to alloc_pages().
Could you find another way ?

Hmm. memcg uses per-cpu counters for counting event of alloc/free and trigger threashold check per 128 event on a cpu.

Thanks,
-Kame

Quoted 108 lines
---
 include/linux/mm.h |   15 +++++++++++++++
 mm/Kconfig         |    8 ++++++++
 mm/page_alloc.c    |   31 +++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 0 deletions(-)
include/linux/mm.h index renamed from include/linux/mm.h +0 -0

3dc3a8c..d133f73 100644

include/linux/mm.h +16 -0
@@ -1618,6 +1618,21 @@ extern int soft_offline_page(struct page *page, 
 int flags);
 
 extern void dump_page(struct page *page);
 
+#ifdef CONFIG_MM_ALLOC_FREE_HOOK
+/*
+ * Hook function type which called when some pages allocated or released.
+ * Value of nr_pages is positive for post-allocation calls and 
+negative
+ * after free.
+ */
+typedef void (*mm_alloc_free_hook_t)(int nr_pages);
+
+/*
+ * Setups specified hook function for tracking pages allocation.
+ * Returns value of old hook to organize chains of calls if necessary.
+ */
+mm_alloc_free_hook_t set_mm_alloc_free_hook(mm_alloc_free_hook_t 
+hook); #endif
+
 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)  

extern void clear_huge_page(struct page *page,

include/linux/mm.h +0 -0
 			    unsigned long addr,
mm/Kconfig +8 -0
index 011b110..2aaa1e9 100644
@@ -373,3 +373,11 @@ config CLEANCACHE
 	  in a negligible performance hit.
 
 	  If unsure, say Y to enable cleancache
+
+config MM_ALLOC_FREE_HOOK
+	bool "Enable callback support for pages allocation and releasing"
+	default n
+	help
+	  Required for some features like used memory meter.
+	  If unsure, say N to disable alloc/free hook.
+
mm/page_alloc.c index 9dd443d..9307800 renamed from mm/page_alloc.c +0 -0

100644

mm/page_alloc.c +25 -0
@@ -236,6 +236,30 @@ static void set_pageblock_migratetype(struct page 
 *page, int migratetype)
 
 bool oom_killer_disabled __read_mostly;
 
+#ifdef CONFIG_MM_ALLOC_FREE_HOOK
+static atomic_long_t alloc_free_hook __read_mostly = 
+ATOMIC_LONG_INIT(0);
+
+mm_alloc_free_hook_t set_mm_alloc_free_hook(mm_alloc_free_hook_t 
+hook) {
+	const mm_alloc_free_hook_t old_hook =
+		(mm_alloc_free_hook_t)atomic_long_read(&alloc_free_hook);
+
+	atomic_long_set(&alloc_free_hook, (long)hook);
+	pr_info("MM alloc/free hook set to 0x%p (was 0x%p)\n", hook, 
+old_hook);
+
+	return old_hook;
+}
+EXPORT_SYMBOL(set_mm_alloc_free_hook);
+
+static inline void call_alloc_free_hook(int pages) {
+	const mm_alloc_free_hook_t hook =
+		(mm_alloc_free_hook_t)atomic_long_read(&alloc_free_hook);
+	if (hook)
+		hook(pages);
+}
+#endif
+
 #ifdef CONFIG_DEBUG_VM
 static int page_outside_zone_boundaries(struct zone *zone, struct 

page *page) { @@ -2298,6 +2322,10 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,

mm/page_alloc.c +6 -1
 	put_mems_allowed();
 
 	trace_mm_page_alloc(page, order, gfp_mask, migratetype);
+#ifdef CONFIG_MM_ALLOC_FREE_HOOK
+	call_alloc_free_hook(1 << order);
+#endif
+
 	return page;
 }
 EXPORT_SYMBOL(__alloc_pages_nodemask);
@@ -2345,6 +2373,9 @@ void __free_pages(struct page *page, unsigned int order)
 			free_hot_cold_page(page, 0);
 		else
 			__free_pages_ok(page, order);
+#ifdef CONFIG_MM_ALLOC_FREE_HOOK
+		call_alloc_free_hook(-(1 << order)); #endif
 	}
 }
 
--
Quoted 3 lines

1.7.7.3

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#6 lore raw

Re: [PATCH 3.2.0-rc1 2/3] MM hook for page allocation and release

Quoted 8 lines · On Thu, Jan 5, 2012 at 1:26 PM, <[email protected]> wrote:

I agree that hooking alloc_pages is ugly way. So alternatives I see:

- shrinkers (as e.g. Android OOM used) but shrink_slab called only from try_to_free_pages only if we are on slow reclaim path on memory allocation, so it cannot be used for e.g. 75% memory tracking or when pages released to notify user space that we are OK. But according to easy to use it will be the best approach.

Quoted 6 lines

- memcg-kind of changes like mem_cgroup_newpage_charge/uncharge_page but without blocking decision making logic. Seems to me more changes. Threshold currently in memcg set 128 pages per CPU, that is quite often for level tracking needs.

- tracking situation using timer? Maybe not due to will impact battery.

Can we hook into mm/vmscan.c and mm/page-writeback.c for this?

Pekka

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#7 lore raw

Re: [PATCH 3.2.0-rc1 2/3] MM hook for page allocation and release

Quoted 8 lines · Pekka Enberg
Quoted 7 lines · On Thu, Jan 5, 2012 at 1:26 PM,<[email protected]> wrote:

I agree that hooking alloc_pages is ugly way. So alternatives I see:

- shrinkers (as e.g. Android OOM used) but shrink_slab called only from try_to_free_pages only if we are on slow reclaim path on memory allocation, so it cannot be used for e.g. 75% memory tracking or when pages released to notify user space that we are OK. But according to easy to use it will be the best approach.

Well, there is always the page cache.

If, at reclaim time, the amount of page cache + free memory is below the free threshold, we should still have space left to handle userspace things.

It may be possible to hijack memcg accounting to get lower usage thresholds for earlier notification. That way the code can stay out of the true fast paths like alloc_pages.

Signature · 8 lines
All rights reversed

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#8 lore raw

RE: [PATCH 3.2.0-rc1 2/3] MM hook for page allocation and release

SHVoLA0KRWFybHkgbm90aWZpY2F0aW9uIG5vdCBtdWNoIGJldHRlciB0aGVuIGxhdGUuIENhY2hl IHNpemUgaW1wYWN0cyBtb3N0bHkgdXNlci1zcGFjZSByZXNwb25zaXZlbmVzcywgc28gY2FjaGUg aXMgYWNjb3VudGVkIGFzIGZyZWUgbWVtb3J5IGJ1dCBkZXZpY2UgbmVlZCBiZSB0dW5lZCBkZXZl bG9wbWVudCB0aW1lIGFjY29yZGluZyBob3cgZmFzdCBpdCBzaG91bGQgYmUgaW4gZGlmZmVyZW50 IGRldmljZS1zcGVjaWZpYyB1c2UtY2FzZXMgKGl0IGRlcGVuZHMgZnJvbSB6aWxsaW9ucyB0ZWNo bmljYWwgYW5kIG5vbi10ZWNobmljYWwgZmFjdG9ycyBlLmcuICBwcm9kdWNlciBuZWVkcykuDQpJ IGZpeGVkIGFsbCBrbm93biBmaW5kaW5ncyBhbmQgdHJ5aW5nIHRvIGZpbmQgcGxhY2VzIHRvIGlu dGVncmF0ZSBpbnRvIHZtc2Nhbi9wYWdlLXdyaXRlYmFjayBhcyBQZWtrYSBoYXMgYWR2aXNlZC4g DQoNCldpdGggQmVzdCBXaXNoZXMsDQpMZW9uaWQNCg0KDQotLS0tLU9yaWdpbmFsIE1lc3NhZ2Ut LS0tLQ0KRnJvbTogZXh0IFJpayB2YW4gUmllbCBbbWFpbHRvOnJpZWxAcmVkaGF0LmNvbV0gDQpT ZW50OiAwNSBKYW51YXJ5LCAyMDEyIDE3OjA1DQpUbzogUGVra2EgRW5iZXJnDQpDYzogTW9pc2Vp Y2h1ayBMZW9uaWQgKE5va2lhLU1QL0hlbHNpbmtpKTsga2FtZXphd2EuaGlyb3l1QGpwLmZ1aml0 c3UuY29tOyBsaW51eC1tbUBrdmFjay5vcmc7IGxpbnV4LWtlcm5lbEB2Z2VyLmtlcm5lbC5vcmc7 IGNlc2FyYkBjZXNhcmIubmV0OyBlbXVuc29uQG1nZWJtLm5ldDsgYWFyY2FuZ2VAcmVkaGF0LmNv bTsgbWVsQGNzbi51bC5pZTsgcmllbnRqZXNAZ29vZ2xlLmNvbTsgZGltYUBhbmRyb2lkLmNvbTsg Z3JlZ2toQHN1c2UuZGU7IHJlYmVjY2FAYW5kcm9pZC5jb207IHNhbkBnb29nbGUuY29tOyBha3Bt QGxpbnV4LWZvdW5kYXRpb24ub3JnOyBKYWFza2VsYWluZW4gVmVzYSAoTm9raWEtTVAvSGVsc2lu a2kpDQpTdWJqZWN0OiBSZTogW1BBVENIIDMuMi4wLXJjMSAyLzNdIE1NIGhvb2sgZm9yIHBhZ2Ug YWxsb2NhdGlvbiBhbmQgcmVsZWFzZQ0KDQpPbiAwMS8wNS8yMDEyIDA3OjQ5IEFNLCBQZWtrYSBF bmJlcmcgd3JvdGU6DQo+IE9uIFRodSwgSmFuIDUsIDIwMTIgYXQgMToyNiBQTSw8bGVvbmlkLm1v aXNlaWNodWtAbm9raWEuY29tPiAgd3JvdGU6DQo+PiBJIGFncmVlIHRoYXQgaG9va2luZyBhbGxv Y19wYWdlcyBpcyB1Z2x5IHdheS4gU28gYWx0ZXJuYXRpdmVzIEkgc2VlOg0KPj4NCj4+IC0gc2hy aW5rZXJzIChhcyBlLmcuIEFuZHJvaWQgT09NIHVzZWQpIGJ1dCBzaHJpbmtfc2xhYiBjYWxsZWQg b25seSANCj4+IGZyb20gdHJ5X3RvX2ZyZWVfcGFnZXMgb25seSBpZiB3ZSBhcmUgb24gc2xvdyBy ZWNsYWltIHBhdGggb24gbWVtb3J5IA0KPj4gYWxsb2NhdGlvbiwgc28gaXQgY2Fubm90IGJlIHVz ZWQgZm9yIGUuZy4gNzUlIG1lbW9yeSB0cmFja2luZyBvciB3aGVuIA0KPj4gcGFnZXMgcmVsZWFz ZWQgdG8gbm90aWZ5IHVzZXIgc3BhY2UgdGhhdCB3ZSBhcmUgT0suIEJ1dCBhY2NvcmRpbmcgdG8g DQo+PiBlYXN5IHRvIHVzZSBpdCB3aWxsIGJlIHRoZSBiZXN0IGFwcHJvYWNoLg0KDQpXZWxsLCB0 aGVyZSBpcyBhbHdheXMgdGhlIHBhZ2UgY2FjaGUuDQoNCklmLCBhdCByZWNsYWltIHRpbWUsIHRo ZSBhbW91bnQgb2YgcGFnZSBjYWNoZSArIGZyZWUgbWVtb3J5IGlzIGJlbG93IHRoZSBmcmVlIHRo cmVzaG9sZCwgd2Ugc2hvdWxkIHN0aWxsIGhhdmUgc3BhY2UgbGVmdCB0byBoYW5kbGUgdXNlcnNw YWNlIHRoaW5ncy4NCg0KSXQgbWF5IGJlIHBvc3NpYmxlIHRvIGhpamFjayBtZW1jZyBhY2NvdW50 aW5nIHRvIGdldCBsb3dlciB1c2FnZSB0aHJlc2hvbGRzIGZvciBlYXJsaWVyIG5vdGlmaWNhdGlv bi4gIFRoYXQgd2F5IHRoZSBjb2RlIGNhbiBzdGF5IG91dCBvZiB0aGUgdHJ1ZSBmYXN0IHBhdGhz IGxpa2UgYWxsb2NfcGFnZXMuDQoNCi0tDQpBbGwgcmlnaHRzIHJldmVyc2VkDQo=

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#9 lore raw

Re: [PATCH 3.2.0-rc1 2/3] MM hook for page allocation and release

In reply to Leonid Moiseichuk
Quoted 21 lines · Leonid Moiseichuk

That is required by Used Memory Meter (UMM) pseudo-device to track memory utilization in system. It is expected that hook MUST be very light to prevent performance impact on the hot allocation path. Accuracy of number managed pages does not expected to be absolute but fact of allocation or deallocation must be registered.

---
 include/linux/mm.h |   15 +++++++++++++++
 mm/Kconfig         |    8 ++++++++
 mm/page_alloc.c    |   31 +++++++++++++++++++++++++++++++
 3 files changed, 54 insertions(+), 0 deletions(-)
include/linux/mm.h +0 -0
index 3dc3a8c..d133f73 100644
@@ -1618,6 +1618,21 @@ extern int soft_offline_page(struct page *page, int flags);
 
 extern void dump_page(struct page *page);

include/linux/mm.h extern int soft_offline_page(struct page *page, int flags); · line 1629

Quoted 10 lines
include/linux/mm.h +9 -0
 
+#ifdef CONFIG_MM_ALLOC_FREE_HOOK
+/*
+ * Hook function type which called when some pages allocated or released.
+ * Value of nr_pages is positive for post-allocation calls and negative
+ * after free.
+ */
+typedef void (*mm_alloc_free_hook_t)(int nr_pages);
+
+/*

I'm going to chime in and say that hooks like this into the page allocator are a no-go unless there really is absolutely no other option. There is too much scope for abuse.

Even if they were not, this takes no account of the zone or node we are allocating from making it useful only in the case where the system had a single node and zone. This applies to mobile devices but not a lot of other systems.

It also would have very poor information about memory pressure which is likely to be far more interesting and for that, awareness of what is happening in page reclaim is required.

I haven't looked at the alternatives but there has been some vague discussion recently on reviving the concept of a low memory notifier, somehow making the existing memcg oom notifier global or maybe the andro lowmem killer can be adapted to your needs.

include/linux/mm.h __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order, · line 2330

Quoted 10 lines
include/linux/mm.h +4 -0
@@ -2298,6 +2322,10 @@ __alloc_pages_nodemask(gfp_t gfp_mask, unsigned int order,
 	put_mems_allowed();
 
 	trace_mm_page_alloc(page, order, gfp_mask, migratetype);
+#ifdef CONFIG_MM_ALLOC_FREE_HOOK
+	call_alloc_free_hook(1 << order);
+#endif
+
 	return page;
 }

you are calling a free hook there in the alloc path. Seems odd.

This is just a side-note but as this information is meant to be consumed by userspace you have the option of hooking into the mm_page_alloc tracepoint. You get the same information about how many pages are allocated or freed. I accept that it will probably be a bit slower but on the plus side it'll be backwards compatible and you don't need a kernel patch for it.

Signature · 9 lines
Mel Gorman
SUSE Labs

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#10 lore raw

PATCH 3/3 Used Memory Meter pseudo-device module

In reply to Leonid Moiseichuk

The Used Memory Meter (UMM) device tracks level of memory utilization and notifies subscribed processes when consumption crossed specified threshold up or down. It could be used on embedded devices to implementation of performance-cheap memory reacting by using e.g. libmemnotify or similar user-space component.

---
 drivers/misc/Kconfig  |   12 ++
 drivers/misc/Makefile |    1 +
 drivers/misc/umm.c    |  452 +++++++++++++++++++++++++++++++++++++++++++++++++
 include/linux/umm.h   |   42 +++++
 4 files changed, 507 insertions(+), 0 deletions(-)
 create mode 100644 drivers/misc/umm.c
 create mode 100644 include/linux/umm.h
drivers/misc/Kconfig +12 -0
index d593878..5d71960 100644
@@ -499,6 +499,18 @@ config USB_SWITCH_FSA9480
 	  stereo and mono audio, video, microphone and UART data to use
 	  a common connector port.
 
+config USED_MEMORY_METER
+	tristate "Enables used memory meter pseudo-device"
+	default n
+	select MM_ALLOC_FREE_HOOK
+	help
+	  This option enables pseudo-device /dev/used_memory for tracking
+	  system memory utilization and updating state to subscribed clients
+	  when specified threshold reached.
+
+	  Say Y here if you want to support used memory monitor.
+	  If unsure, say N.
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
drivers/misc/Makefile +1 -0
index b26495a..eaec343 100644
@@ -48,3 +48,4 @@ obj-y				+= lis3lv02d/
 obj-y				+= carma/
 obj-$(CONFIG_USB_SWITCH_FSA9480) += fsa9480.o
 obj-$(CONFIG_ALTERA_STAPL)	+=altera-stapl/
+obj-$(CONFIG_USED_MEMORY_METER)	+= umm.o
drivers/misc/umm.c new file +452 -0

452 lines not on this page · raw message

include/linux/umm.h new file +42 -0

42 lines not on this page · raw message

Signature · 8 lines
1.7.7.3

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#11 lore raw

Re: [PATCH 3.2.0-rc1 3/3] Used Memory Meter pseudo-device module

Quoted 7 lines · Leonid Moiseichuk

The Used Memory Meter (UMM) device tracks level of memory utilization and notifies subscribed processes when consumption crossed specified threshold up or down. It could be used on embedded devices to implementation of performance-cheap memory reacting by using e.g. libmemnotify or similar user-space component.

Note, I don't agree that this code is the correct thing to be doing here, you'll have to get the buy-in from the mm developers on that, but I do have some comments on the implementation:

Quoted 26 lines
drivers/misc/umm.c new file +23 -0
@@ -0,0 +1,452 @@
+/*
+ * umm.c - system-wide Used Memory Meter pseudo-device implementation
+ *
+ * Copyright (C) 2011 Nokia Corporation.
+ *      Leonid Moiseichuk
+ *
+ * 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 program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#include <linux/types.h>
+#include <linux/module.h>
+#include <linux/device.h>
+#include <linux/kernel.h>
+#include <linux/atomic.h>
+#include <linux/jiffies.h>
+#include <linux/mm.h>

drivers/misc/umm.c line 33

Quoted 10 lines
drivers/misc/umm.c new file +10 -0
+#include <linux/slab.h>
+#include <linux/poll.h>
+#include <linux/highmem.h>
+#include <linux/swap.h>
+#include <linux/list.h>
+#include <linux/wait.h>
+#include <linux/spinlock.h>
+#include <linux/spinlock_types.h>
+
+#include <linux/umm.h>

Why do you need a header file at all?

Quoted 22 lines
drivers/misc/umm.c new file +22 -0
+/* subscriber information to be notified when level changed */
+struct observer {
+	/* list data to check from notify_memory_usage and wakeup user-space */
+	struct list_head list;
+	/* related file structure for open/close/read/write and poll */
+	struct file	*file;
+	/* threshold [pages] when we should trigger notification */
+	unsigned long	threshold;
+	/* did we crossed theshold on last validation? */
+	bool		active;
+	/* flag about new notification is required */
+	bool		updated;
+};
+
+
+
+MODULE_AUTHOR("Leonid Moiseichuk ([email protected])");
+MODULE_DESCRIPTION("System used memory meter pseudo-device");
+MODULE_LICENSE("GPL v2");
+MODULE_VERSION("0.0.2");
+
+static int debug __read_mostly;

drivers/misc/umm.c line 68

Quoted 10 lines
drivers/misc/umm.c new file +10 -0
+module_param(debug, bool, 0);
+MODULE_PARM_DESC(debug, "More info about module parameters and operations");
+
+static int probe __read_mostly;
+module_param(probe, bool, 0);
+MODULE_PARM_DESC(probe, "Probe measurement overhead during loading");
+
+static char device_name[64] __read_mostly = UMM_DEVICE_NAME;
+module_param_string(device_name, device_name, sizeof(device_name), 0);
+MODULE_PARM_DESC(device_name, "Device name in /dev if need different");

This is pointless, right?

drivers/misc/umm.c line 314

Quoted 1 line
drivers/misc/umm.c new file +1 -0
+static struct device *umm_device __read_mostly;

Enough with the __read_mostly markings, they really aren't needed for every single variable, right? Especially for trivial stuff like this one, and all of the module parameters.

drivers/misc/umm.c line 315

Quoted 1 line
drivers/misc/umm.c new file +1 -0
+static struct class  *umm_class  __read_mostly;

Just use a misc device, as you are only creating/needing one character device, right? That will make your init and destroy code a lot cleaner and smaller.

drivers/misc/umm.c line 69

Quoted 2 lines
drivers/misc/umm.c new file +2 -0
+	pr_info("UMM: Used Memory Meter loading to support /dev/%s\n",
+							device_name);

Not needed.

Quoted 63 lines
drivers/misc/umm.c new file +63 -0
+
+	umm_major = register_chrdev(0, device_name, &umm_fops);
+	if (umm_major < 0) {
+		pr_err("UMM: unable to get major number for device %s\n",
+							device_name);
+		error = -EBUSY;
+		goto register_failed;
+	}
+
+	umm_class = class_create(THIS_MODULE, device_name);
+	if (IS_ERR(umm_class)) {
+		error = PTR_ERR(umm_class);
+		pr_err("UMM: unable to create class for device %s - %d\n",
+						device_name, error);
+		goto class_failed;
+	}
+
+	umm_device = device_create(
+			umm_class, NULL,
+			MKDEV(umm_major, 0),
+			NULL, device_name);
+	if (IS_ERR(umm_device)) {
+		error = PTR_ERR(umm_device);
+		pr_err("UMM: unable to create device %s - %d\n",
+						device_name, error);
+		goto device_failed;
+	}
+
+	update_period_jiffies = msecs_to_jiffies(update_period);
+	if (!update_period_jiffies)
+		update_period_jiffies = msecs_to_jiffies(UMM_UPDATE_PERIOD);
+
+	/* query amount of available ram and swap, mem_unit is PAGE_SIZE */
+	si_meminfo(&si);
+#ifdef CONFIG_SWAP
+	si_swapinfo(&si);
+	available_pages = si.totalram + si.totalswap;
+	available_swap_pages = si.totalswap;
+#else
+	available_pages = si.totalram;
+#endif
+	/* if autodetect then set granularity to ~1.4% from available memory */
+	if (update_space)
+		update_space_pages = update_space >> (PAGE_SHIFT - 10);
+	else
+		update_space_pages = available_pages >> 6;
+	if (!update_space_pages)
+		update_space_pages = UMM_UPDATE_SPACE >> (PAGE_SHIFT - 10);
+
+	update_memory_usage();
+	old_mm_hook = set_mm_alloc_free_hook(mm_alloc_free_hook);
+
+	if (debug) {
+		pr_info("UMM: /dev/%s got major %d\n", device_name, umm_major);
+		pr_info("UMM: update period set to %u ms or %lu jiffies\n",
+					update_period, update_period_jiffies);
+		pr_info("UMM: update space set to %u kb or %u pages\n",
+					update_space, update_space_pages);
+		pr_info("UMM: old mm alloc/free hook is 0x%p\n", old_mm_hook);
+		pr_info("UMM: now hook set to 0x%p\n", mm_alloc_free_hook);
+#ifdef CONFIG_SWAP
+		pr_info("UMM: %lu available pages found (only ram)\n",
+							available_pages);

drivers/misc/umm.c line 398

Quoted 10 lines
drivers/misc/umm.c new file +10 -0
+#else
+		pr_info("UMM: %lu available pages found (%lu ram + %lu swap)\n",
+				available_pages, si.totalram, si.totalswap);
+#endif
+		pr_info("UMM: %lu used pages, utilization %lu percents\n",
+					atomic_long_read(&last_used_pages),
+			(100 * atomic_long_read(&last_used_pages)) /
+							available_pages);
+		pr_info("UMM: overhead per client connection is %lu bytes\n",
+						sizeof(struct observer));

Please use the dev_dbg() macro instead, that removes the debug flag here, and properly identifies your code/device in the kernel log. Same goes for other pr_* usages in the file, just use the appropriate dev_* call instead.

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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#12 lore raw

RE: [PATCH 3.2.0-rc1 3/3] Used Memory Meter pseudo-device module

Quoted 3 lines

-----Original Message-----
From: ext Greg KH [mailto:[email protected]]
Sent: 04 January, 2012 21:55

...

Quoted 3 lines

Note, I don't agree that this code is the correct thing to be doing here, you'll have to get the buy-in from the mm developers on that, but I do have some comments on the implementation:

Hello everyone and thanks for comments.

If I not wrong in addition to Greg's remarks about polishing I got 14 findings (see details below):
1. Alternative solutions: why not Android OOM or memcg
2. How to connect to MM - the current variant is no-go and that is a critical part
3. What should be tracked (e.g. memory pressure 3.1)

For sure I used wrong approach to solve notification problem. The user-space reaction should fit under 1s, so to react 250-500 ms on kernel side absolutely not necessary hook page_alloc due to this component should be used only for notification and not denying allocations. It also inadequate idea due to I need only data from global_page_state/vm_stat which is cpu-independent and has a lot of traces in MM where it could be updated.

So major changes in coming version will be:
1. timer-based access to global_page_state() data. If I understand documentation right the deferred timer will not wake up if cpu frozen. Otherwise timer must be set using register_cpu_notifier
2. to track high memory pressure cases the shrinker should be added without filtering by last call time
3. used memory calculation will be changed and active page set added
4. file renamed to memnotify.c and interface to /dev/memnotify due to it will report not only used memory + low probability it will be accepted as mm/notify.c as advised below (but maybe someone will use it).

With Best Wishes,
Leonid

Remarks collected from emails
=======================

1. Alternative solutions
------------------------

1.1. Pekka Enberg

Quoted 2 lines

However, from VM point of view, both have the exact same functionality: detect when we reach low memory condition (for some configurable threshold) and notify userspace or kernel subsystem about it.

Well, I cannot say that SIGKILL is a notification. From kernel side maybe. But Android OOM uses different memory tracking rules. From my opinion OOM killer should be as reliable as default is but functionality Android OOM killer does should be done in user space by some "smart killer" which closes application correct way (save data, notify user etc.). It heavily depends from product design.

1.2. Pekka Enberg

Quoted 2 lines

That's the part I'd like to see implemented in mm/notify.c or similar.
I really don't care what Android or any other folks use it for exactly as long as the generic code is light-weight, > clean, and we can reasonably assume that distros can actually enable it.

I will try to do memnotify.c but due to I am not sure it will be well enough done to be accepted it will be in drivers.

1.3. Rik van Riel

Quoted 1 line

Also, the low memory notification that Kosaki-san has worked on, and which Minchan is looking at now.

Finally I found only patches from 2009 which are not look for me good from user space point of view. For example I do not understand how to specify application limit(s).

1.4. Mel Gorman

Quoted 3 lines

I haven't looked at the alternatives but there has been some vague discussion recently on reviving the concept of a low memory notifier, somehow making the existing memcg oom notifier global or maybe the andro lowmem killer can be adapted to your needs.

Most likely not. The memcg OOM handling can but idea is to not have memcg/partitions.

1.5. David Rientjes

Quoted 5 lines

If you can accept the overhead of the memory controller (increase in kernel text size and amount of metadata for page_cgroup), then you can already do this with a combination of memory thresholds with cgroup.event_control and disabling of the oom killer entirely with memory.oom_control.

already done in libmemnotifyqt used in n9

1.6. David Rientjes

Quoted 1 line

Agreed. This came up recently when another lowmem killer was proposed and the suggestion was to enable the memory > controller to be able to have the memory threshold notifications with eventfd(2) and cgroup.event_control.

already done in libmemnotifyqt used in n9

1.7. David Rientjes

Quoted 4 lines

This is just a side-note but as this information is meant to be consumed by userspace you have the option of hooking into the mm_page_alloc tracepoint. You get the same information about how many pages are allocated or freed. I accept that it will probably be a bit slower but on the plus side it'll be backwards compatible and you don't need a kernel patch for it.

That is odd for sure, I have to use another kind of access to vm_stat.

2. How to hook MM
-----------------

2.1. Pekka Enberg

Quoted 1 line

Can we hook into mm/vmscan.c and mm/page-writeback.c for this?

Thanks for pointing. For vmscan I plan to use shrinker. But changes in page-writeback seems to be the same bad as page-alloc hooking.

2.2. Rik van Riel

Quoted 2 lines

It may be possible to hijack memcg accounting to get lower usage thresholds for earlier notification. That way the code can stay out of the true fast paths like alloc_pages

That is a case but memcg is not well suitable when processes migrating in-between cgroups e.g. forced to be swapped out and device becomes slaggy or if process is big enough it cannot be injected into cgroup and stays in root group without any restrictions

2.3. Mel Gorman

Quoted 2 lines

I'm going to chime in and say that hooks like this into the page allocator are a no-go unless there really s absolutely no other option. There is too much scope for abuse.

Agree. The idea is based on vm_stat which is global, and to track it absolutely do not necessary to hook in page_alloc

2.4. David Rientjes

Quoted 3 lines

It would be very nice to have a generic lowmem notifier (like /dev/mem_notify that has been reworked several times in the past) rather than tying it to a particular cgroup, especially when that cgroup incurs a substantial overhead for embedded users.

Ok, will try to do more generic and re-use memnotify name. But due to high risk to be not accepted in mainline I will keep it as drivers/misc/memnotify.c

3. What to track
----------------

3.1. Mel Gorman

Quoted 2 lines

It also would have very poor information about memory pressure which is likely to be far more interesting and for that, awareness of what is happening in page reclaim is required.

Could to be added later, now I try to focus on vm_stat due to it is simpler.

3.2. KOSAKI Motohiro

Quoted 4 lines

If you spent a few time to read past discuttion, you should have understand your fomula
is broken and unacceptable. Think, mlocked (or pinning by other way) cache can't be discarded.

NR_MLOCK will be added

3.3. KOSAKI Motohiro

Quoted 1 line

And, When system is under swap thrashing, userland notification is useless.

Well, cgroups CPU shares and ionice seems to me better but as a quick solution extension with LRU_ACTIVE_ANON + LRU_ACTIVE_FILE could be done easily.

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#13 lore raw

RE: [PATCH 3.2.0-rc1 3/3] Used Memory Meter pseudo-device module

Quoted 6 lines · On Mon, 9 Jan 2012, [email protected] wrote:

1.1. Pekka Enberg

Quoted 4 lines

However, from VM point of view, both have the exact same
functionality: detect when we reach low memory condition (for some configurable threshold) and notify userspace or kernel subsystem about it.

Quoted 7 lines

Well, I cannot say that SIGKILL is a notification. From kernel side maybe. But Android OOM uses different memory tracking rules. From my opinion OOM killer should be as reliable as default is but functionality Android OOM killer does should be done in user space by some "smart killer" which closes application correct way (save data, notify user etc.). It heavily depends from product design.

I'm not sure why you need to detect low memory thresholds if you're not interested in using the memory controller, why not just use the oom killer delay that I suggested earlier and allow userspace to respond to conditions when you are known to failed reclaim and require that something be killed? Userspace should be able to make sane decisions or trigger external knobs to be able to free memory much better than having the kernel handling signals or notification to individual applications.

Quoted 6 lines

1.7. David Rientjes

Quoted 4 lines

This is just a side-note but as this information is meant to be consumed by userspace you have the option of hooking into the mm_page_alloc tracepoint. You get the same information about how many pages are allocated or freed. I accept that it will probably be a bit slower but on the plus side it'll be backwards compatible and you don't need a kernel patch for it.

I didn't write that.

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#14 lore raw

RE: [PATCH 3.2.0-rc1 3/3] Used Memory Meter pseudo-device module

Quoted 3 lines

-----Original Message-----
From: ext David Rientjes [mailto:[email protected]]
Sent: 09 January, 2012 12:09

...

Quoted 5 lines

I'm not sure why you need to detect low memory thresholds if you're not interested in using the memory controller, why not just use the oom killer delay that I suggested earlier and allow userspace to respond to conditions when you are known to failed reclaim and require that something be killed?

As I understand that is required to turn on memcg and memcg is a thing I try to avoid.

Quoted 10 lines
Quoted 5 lines

1.7. David Rientjes

Quoted 4 lines

This is just a side-note but as this information is meant to be consumed by userspace you have the option of hooking into the mm_page_alloc tracepoint. You get the same information about how many pages are allocated or freed. I accept that it will probably be a bit

slower but on the plus side it'll be backwards compatible and you don't need a kernel patch for it.

Quoted 1 line

I didn't write that.

Sorry, it was Mel Gorman. Copy-paste problem.

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#15 lore raw

RE: [PATCH 3.2.0-rc1 3/3] Used Memory Meter pseudo-device module

Quoted 8 lines · On Mon, 9 Jan 2012, [email protected] wrote:
Quoted 4 lines

I'm not sure why you need to detect low memory thresholds if you're not interested in using the memory controller, why not just use the oom killer delay that I suggested earlier and allow userspace to respond to conditions when you are known to failed reclaim and require that something be killed?

As I understand that is required to turn on memcg and memcg is a thing I try to avoid.

Maybe there's some confusion: the proposed oom killer delay that I'm referring to here is not upstream and has never been written for global oom conditions. My reference to it earlier was as an internal patch that we carry on top of memory controller, but what I'm proposing here is for it to be implemented globally.

So if the page allocator can make no progress in freeing memory, we would introduce a delay in out_of_memory() if it were configured via a sysctl from userspace. When this delay is started, applications waiting on this event can be notified with eventfd(2) that the delay has started and they have however many milliseconds to address the situation. When they rewrite the sysctl, the delay is cleared. If they don't rewrite the sysctl and the delay expires, the oom killer proceeds with killing.

What's missing for your usecase with this proposal?

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#16 lore raw

RE: [PATCH 3.2.0-rc1 3/3] Used Memory Meter pseudo-device module

Quoted 3 lines

-----Original Message-----
From: ext David Rientjes [mailto:[email protected]]
Sent: 09 January, 2012 21:55

...

Quoted 6 lines

Maybe there's some confusion: the proposed oom killer delay that I'm referring to here is not upstream and has never been written for global oom conditions. My reference to it earlier was as an internal patch that we carry on top of memory controller, but what I'm proposing here is for it to be implemented globally.

That is explains situation - I know how memcg can handle OOM in cgroup but not about internal patch.

Quoted 9 lines

So if the page allocator can make no progress in freeing memory, we would introduce a delay in out_of_memory() if it were configured via a sysctl from userspace. When this delay is started, applications waiting on this event can be notified with eventfd(2) that the delay has started and they have however many milliseconds to address the situation. When they rewrite the sysctl, the delay is cleared. If they don't rewrite the sysctl and the delay expires, the oom killer proceeds with killing.

What's missing for your use case with this proposal?

Timed delays in multi-process handling in case OOM looks for me fragile construction due to delays are not predicable. Memcg supports [1] better approach to freeze whole group and kick pointed user-space application to handle it. We planned to use it as:
- enlarge cgroup
- send SIGTERM to selected "bad" application e.g. based on oom_score
- wait a bit
- send SIGKILL to "bad" application
- reduce group size

But finally default OOM killer starts to work fine.

[1] http://lwn.net/Articles/377708/

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#17 lore raw

RE: [PATCH 3.2.0-rc1 3/3] Used Memory Meter pseudo-device module

Quoted 8 lines · On Wed, 11 Jan 2012, [email protected] wrote:
Quoted 8 lines

So if the page allocator can make no progress in freeing memory, we would introduce a delay in out_of_memory() if it were configured via a sysctl from userspace. When this delay is started, applications waiting on this event can be notified with eventfd(2) that the delay has started and they have however many milliseconds to address the situation. When they rewrite the sysctl, the delay is cleared. If they don't rewrite the sysctl and the delay expires, the oom killer proceeds with killing.

Quoted 4 lines
Quoted 1 line

What's missing for your use case with this proposal?

Timed delays in multi-process handling in case OOM looks for me fragile construction due to delays are not predicable.

Not sure what you mean by predictable; the oom conditions themselves certainly aren't predictable, otherwise you wouldn't need notification at all. The delays are predictable since you configure it to be a number of millisecs via a global sysctl. Userspace can either handle the oom itself and rewrite that sysctl to reset the delay or write 0 to make the kernel immediately oom. If the delay expires, then it is assumed that userspace is dead and the kernel will proceed to avoid livelock.

Quoted 11 lines

Memcg supports [1] better approach to freeze whole group and kick pointed user-space application to handle it. We planned to use it as:
- enlarge cgroup
- send SIGTERM to selected "bad" application e.g. based on oom_score
- wait a bit
- send SIGKILL to "bad" application
- reduce group size

But finally default OOM killer starts to work fine.

I think you're misunderstanding the proposal; in the case of a global oom (that means without memcg) then, by definition, all threads that are allocating memory would be frozen and incur the delay at the point they would currently call into the oom killer. If your userspace is alive, i.e. the application responsible for managing oom killing, then it can wait on eventfd(2), wake up, and then send SIGTERM and SIGKILL to the appropriate threads based on priority.

So, again, why wouldn't this work for you?

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#18 lore raw

RE: [PATCH 3.2.0-rc1 3/3] Used Memory Meter pseudo-device module

Quoted 12 lines

-----Original Message-----
From: ext David Rientjes [mailto:[email protected]]
Sent: 11 January, 2012 22:45

I think you're misunderstanding the proposal; in the case of a global oom (that means without memcg) then, by definition, all threads that are allocating memory would be frozen and incur the delay at the point they would currently call into the oom killer. If your userspace is alive, i.e. the application responsible for managing oom killing, then it can wait on eventfd(2), wake up, and then send SIGTERM and SIGKILL to the appropriate threads based on priority.

Quoted 1 line

So, again, why wouldn't this work for you?

As I wrote the proposed change is not safety belt but looking ahead radar.
If it detects that we are close to wall it starts to alarm and alarm volume is proportional to distance.

In close-to-OOM situations device becomes very slow, which is not good for user. The performance difference depends on code size and storage performance to trash code pages but even 20% is noticeable. Practically 2x-5x times slowdown was observed.

We can do some actions ahead of time and try to prevent OOM at all like shrink caches in applications, close unused apps etc. If OOM still happened due to 3rd party components or misbehaving software even default OOM killer works good enough if oom_score_adj values are properly set.

Thus, controlling device on wider set of memory situations looks for me more beneficial than trying to recover when situation is bad. And increasing complexity of recovery mechanism (OOM, Android OOM, OOM with delay), involving user-space into decision-making, makes recovery _potentially_ less predictable.

Best Wishes,
Leonid

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#19 lore raw

RE: [PATCH 3.2.0-rc1 3/3] Used Memory Meter pseudo-device module

Quoted 5 lines · On Thu, 12 Jan 2012, [email protected] wrote:

As I wrote the proposed change is not safety belt but looking ahead radar.
If it detects that we are close to wall it starts to alarm and alarm volume is proportional to distance.

Then it's fundamentally flawed since there's no guarantee that coming with 100MB of the min watermark, for example, means that an oom is imminent and will just result in unnecessary notification to userspace that will cause some action to be taken that may not be necessary. If the setting of these thresholds depends on some pattern that is guaranteed to be along the path to oom for a certain workload, then that will also change depending on VM implementation changes, kernel versions, other applications, etc., and simply is unmaintainable.

Quoted 5 lines

In close-to-OOM situations device becomes very slow, which is not good for user. The performance difference depends on code size and storage performance to trash code pages but even 20% is noticeable. Practically 2x-5x times slowdown was observed.

It would be much better to address the slowdown when running out of memory rather than requiring userspace to react and unnecessarily send signals to threads that may or may not have the ability to respond because they may already be oom themselves. You can do crazy things to reduce latency in lowmem memory allocations like changing gfp_allowed_mask to be GFP_ATOMIC so that direct reclaim is never called, for example, and then use the proposed oom killer delay to handle the situation at the time of oom.

Regardless, you should be addressing the slowness in lowmem situations rather than implementing notifiers to userspace to handle the events itself, so nack on this proposal.

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#20 lore raw

RE: [PATCH 3.2.0-rc1 3/3] Used Memory Meter pseudo-device module

Quoted 4 lines

-----Original Message-----
From: ext David Rientjes [mailto:[email protected]]
Sent: 12 January, 2012 21:55
To: Moiseichuk Leonid (Nokia-MP/Helsinki)

....

Quoted 9 lines

Then it's fundamentally flawed since there's no guarantee that coming with 100MB of the min watermark, for example, means that an oom is imminent and will just result in unnecessary notification to userspace that will cause some action to be taken that may not be necessary. If the setting of these thresholds depends on some pattern that is guaranteed to be along the path to oom for a certain workload, then that will also change depending on VM implementation changes, kernel versions, other applications, etc., and simply is unmaintainable.

Why? That is expected that product tested and tuned properly, applications fixed, and at least no apps installed which might consume 100 MB in second or two. If you have another product with big difference in memory size, applications etc. you might need to re-calibrate reactions.
Let's focus on realistic cases.

Quoted 4 lines

It would be much better to address the slowdown when running out of memory rather than requiring userspace to react and unnecessarily send signals to threads that may or may not have the ability to respond because they may already be oom themselves.

That is not possible - signals usually set at level you have 20-50 MB to react. Slowdown is natural thing if you have lack of space for code paging, I do not see any ways to fix it.

Quoted 4 lines

You can do crazy things to reduce
latency in lowmem memory allocations like changing gfp_allowed_mask to be GFP_ATOMIC so that direct reclaim is never called, for example, and then use the proposed oom killer delay to handle the situation at the time of oom.

It is not necessary.

Quoted 3 lines

Regardless, you should be addressing the slowness in lowmem situations rather than implementing notifiers to userspace to handle the events itself, so nack on this proposal.

Define "lowmem situation" first. For proposed approach it is from 50-90% of memory usage until user-space can do something.

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#21 lore raw

RE: [PATCH 3.2.0-rc1 3/3] Used Memory Meter pseudo-device module

Quoted 9 lines · On Fri, 13 Jan 2012, [email protected] wrote:
Quoted 8 lines

Then it's fundamentally flawed since there's no guarantee that coming with 100MB of the min watermark, for example, means that an oom is imminent and will just result in unnecessary notification to userspace that will cause some action to be taken that may not be necessary. If the setting of these thresholds depends on some pattern that is guaranteed to be along the path to oom for a certain workload, then that will also change depending on VM implementation changes, kernel versions, other applications, etc., and simply is unmaintainable.

Quoted 3 lines

Why? That is expected that product tested and tuned properly, applications fixed, and at least no apps installed which might consume 100 MB in second or two.

I'm trying to make this easy for you, if you haven't noticed. Your memory threshold, as proposed, will have values that are tied directly to the implementation of the VM in the kernel when its under memory pressure and that implementation evolves at a constant rate.

What I'm proposing is limiting the amount of latency that the VM incurs when under memory pressure, notify userspace, and allow it to react to the situation until the delay expires. This doesn't require recalibration for other products or upgraded kernels, it just works all the time.

Quoted 3 lines

Slowdown is natural thing if you have lack of space for code paging, I do not see any ways to fix it.

mlock() the memory that your userspace monitoring needs to send signals to applications, whether those signals are handled to free memory internally or its SIGTERM or SIGKILL.

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#22 lore raw

RE: [PATCH 3.2.0-rc1 3/3] Used Memory Meter pseudo-device module

Quoted 4 lines

-----Original Message-----
From: ext David Rientjes [mailto:[email protected]]
Sent: 13 January, 2012 12:06
To: Moiseichuk Leonid (Nokia-MP/Helsinki)

...

Quoted 5 lines
Quoted 3 lines

Why? That is expected that product tested and tuned properly, applications fixed, and at least no apps installed which might consume 100 MB in second or two.

I'm trying to make this easy for you, if you haven't noticed.

Thanks, I did.

Quoted 3 lines

Your memory threshold, as proposed, will have values that are tied directly to the implementation of the VM in the kernel when its under memory pressure and that implementation evolves at a constant rate.

Not sure that I understand this statement. Free/Used/Active page sets are properties of any VM.
I have a new implementation but it is in testing now. I do not see any relation to VM implementation except statistics and it could be extended with "virtual values" which are suitable for user-space e.g. active page set. It could be extended with something else if someone needs it.
The thresholds are set by user-space and individual for applications which likes to be informed.

Quoted 3 lines

mlock() the memory that your userspace monitoring needs to send signals to applications, whether those signals are handled to free memory internally or its SIGTERM or SIGKILL.

Mlocked memory should be avoid as much as possible because efficiency rate is lowest possible and makes situation for non-mlocked pages even worse. You cannot mlock whole UI only most critical parts.
Thus, handling time in case of 3rd party apps will be not controllable, User will observe it as device jam/hang/freeze.

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#23 lore raw

RE: [PATCH 3.2.0-rc1 3/3] Used Memory Meter pseudo-device module

Quoted 6 lines · On Fri, 13 Jan 2012, [email protected] wrote:
Quoted 3 lines

Your memory threshold, as proposed, will have values that are tied directly to the implementation of the VM in the kernel when its under memory pressure and that implementation evolves at a constant rate.

Not sure that I understand this statement. Free/Used/Active page sets are properties of any VM.

The point at which the latency is deemed to be unacceptable in your trail-and-error is tied directly to the implementation of the VM and must be recalibrated with each userspace change or kernel upgrade. I assume here that some reclaim is allowed in the VM for your usecase; if not, then I already gave a solution for how to disable that entirely.

Quoted 3 lines

The thresholds are set by user-space and individual for applications
which likes to be informed.

You haven't given a usecase for the thresholds for anything other than when you're just about oom, and I think it's much simpler if you actually get to the point of oom and your userspace notifier is guaranteed to be able to respond over a preconfigured delay. It works pretty well for us internally, you should consider it.

Quoted 7 lines
Quoted 3 lines

mlock() the memory that your userspace monitoring needs to send signals to applications, whether those signals are handled to free memory internally or its SIGTERM or SIGKILL.

Mlocked memory should be avoid as much as possible because efficiency rate is lowest possible and makes situation for non-mlocked pages even worse.

It's used only to protect the thread that is notified right before the oom killer is triggered so that it can send the appropriate signals. If it can't do that, the oom killer delay will expire on subsequent memory allocation attempts and kill something itself. This thread should have a minimal memory footprint, be mlock()'d into memory, and have an oom_score_adj of OOM_SCORE_ADJ_MIN.

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#24 lore raw
In reply to Leonid Moiseichuk
Quoted 36 lines · Leonid Moiseichuk

The main idea of Used Memory Meter (UMM) is to provide low-cost interface for user-space to notify about memory consumption using similar approach /proc/meminfo does but focusing only on "modified" pages which cannot be fogotten.

The calculation formula in terms of meminfo looks the following:
UsedMemory = (MemTotal - MemFree - Buffers - Cached - SwapCached) +
(SwapTotal - SwapFree)
It reflects well amount of system memory used in applications in heaps and shared pages.

Previously (n770..n900) we had lowmem.c [1] which used LSM and did a lot other things, n9 implementation based on memcg [2] which has own problems, so the proposed variant I hope is the best one for n9:
- Keeps connections from user space
- When amount of modified pages reaches crossed pointed value for particular connection makes POLLIN and allow user-space app to read it and react
- Economic as much as possible, so currently its operates if allocation higher than 487 pages or last check happened 250 ms before
Of course if no allocation happened then no activities performed, use-time must be not affected.

Testing results:
- Checkpatch produced 0 warning
- Sparse does not produce warnings
- One check costs ~20 us or less (could be checked with probe=1 insmod)
- One connection costs 20 bytes in kernel-space (see observer structure) for 32-bit variant
- For 10K connections poll update in requested in ~10ms, but for practically device expected to will have about 10 connections (like n9 has now).

Known weak points which I do not know how to fix but will if you have a brillian idea:
- Having hook in MM is nasty but MM/shrinker cannot be used there and LSM even worse idea
- If I made
$cat /dev/used_memory
it is produced lines in non-stop mode. Adding position check in umm_read seems doesn not help, so "head -1 /dev/used_memory" should be used if you need to quick check
- Format of output is USED_PAGES:AVAILABLE_PAGES, primitive but enough for tasks module does

Quoted 2 lines

Tested on ARM, x86-32 and x86-64 with and without CONFIG_SWAP. Seems works in all combinations. Sorry for wide distributions but list of names were produced by scripts/get_maintainer.pl

How does this compare with the lowmemorykiller.c driver from the android developers that is currently in the linux-next tree?

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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#25 lore raw
Quoted 2 lines · Greg KH

How does this compare with the lowmemorykiller.c driver from the android developers that is currently in the linux-next tree?

Also, the low memory notification that Kosaki-san has worked on, and which Minchan is looking at now.

We seem to have many mechanisms under development, all aimed at similar goals. I believe it would be good to agree on one mechanism that could solve multiple of these goals at once, instead of sticking a handful of different partial solutions in the kernel...

Exactly what is the problem you are trying to solve?

Signature · 8 lines
All rights reversed

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
#26 lore raw
Quoted 7 lines · Rik van Riel

Also, the low memory notification that Kosaki-san has worked on, and which Minchan is looking at now.

We seem to have many mechanisms under development, all aimed at similar goals. I believe it would be good to agree on one mechanism that could solve multiple of these goals at once, instead of sticking a handful of different partial solutions in the kernel...

And even if people want to support multiple ABIs and fight it out to see which one wins, we should factor out the generic parts and put them under mm/*.c and not hide them in random modules.

Pekka

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#27 lore raw
Quoted 4 lines · Pekka Enberg

And even if people want to support multiple ABIs and fight it out to see which one wins, we should factor out the generic parts and put them under mm/*.c and not hide them in random modules.

Agreed. This came up recently when another lowmem killer was proposed and the suggestion was to enable the memory controller to be able to have the memory threshold notifications with eventfd(2) and cgroup.event_control. It would be very nice to have a generic lowmem notifier (like /dev/mem_notify that has been reworked several times in the past) rather than tying it to a particular cgroup, especially when that cgroup incurs a substantial overhead for embedded users.

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#28 lore raw
In reply to Rik van Riel

SGksDQoNCldlIChzbWFsbCBhbmQgZW1iZWRkZWQpIG5lZWRzIHNvbWUgbWVjaGFuaXNtIHRvIG5v dGlmeSB1c2Vyc3BhY2UgdGhhdCBtZW1vcnkgY29uc3VtcHRpb24gaXMgZ29pbmcgdG8gYmUgaGln aCB0byBhbGxvdyByZWFjdCBwcm9wZXJseSBhbmQga2VlcCBkZXZpY2UgZmFzdCBhbmQgc3RhYmxl OiAgY2xvc2UgYmlnIGdyYXBoaWNzLCBzaHV0cyBzb21ldGhpbmcgbm90IHVzZWQsIHN0b3AgcHJv Y2Vzc2luZyBkYXRhIGV0Yy4gIElmIHdlIG5vdCBhYmxlIHRvIGRvIGl0IGluIHRoZSByaWdodCBt b21lbnQgT09NIGtpbGxlciBzdGFydHMgdG8gd29yayBhbmQgYXBwbGljYXRpb25zIGp1c3QgZGlz YXBwZWFycyB3aGljaCBpcyBub3QgbmljZSBmb3IgdXNlciBpbiBhbGwgY2FzZXMuIFNvIHRoZSBw cm9wb3NlZCBjb2RlIGlzIG5vdCByZXBsYWNlbWVudCBvZiBPT00ga2lsbGVyIGF0IGFsbCBidXQs IHllcywgY291bGQgYmUgcmVjb2duaXplZCBhcyBwYXJ0IG9mICJjb29wZXJhdGl2ZS1vb20iLiAN Cg0KU2luY2UgbjkwMCB3ZSB0cmllZCB0byB1c2UgbWVtY2cgYW5kIG5vdGlmaWNhdGlvbnMuIFVu Zm9ydHVuYXRlbHkgbWVtY2cgaXMgbm90IG5pY2Ugc3VpdGFibGUgdG8gaGFuZGxpbmcgcHJvY2Vz c2VzIGR1ZSB0byBob3cgbWVtb3J5IGlzIGFjY291bnRlZDogdGFraW5nIGludG8gYWNjb3VudCBj YWNoZXMgcHJvZHVjZSBmYWxzZS1wb3NpdGl2ZSBub3RpZmljYXRpb25zIHBsdXMgc3RhYmlsaXR5 IGlzc3VlcyB3aGljaCBjb3VsZCBiZSByZXN1bHQgb2Ygb3V0ZGF0ZWQgMi42LjMyIGtlcm5lbCBl LmcuIHVubmVjZXNzYXJ5IHN3YXBwaW5nIG92ZXJoZWFkIHdoZW4gYmlnIHByb2Nlc3MgbW92ZWQg ZnJvbSBvbmUgZ3JvdXAgdG8gYW5vdGhlciBvciBldmVuIGRldmljZSBodW5nLiAgDQoNCldpdGgg QmVzdCBXaXNoZXMsDQpMZW9uaWQNCg0KDQotLS0tLU9yaWdpbmFsIE1lc3NhZ2UtLS0tLQ0KRnJv bTogZXh0IFJpayB2YW4gUmllbCBbbWFpbHRvOnJpZWxAcmVkaGF0LmNvbV0gDQpTZW50OiAwNCBK YW51YXJ5LCAyMDEyIDIyOjE4DQpUbzogR3JlZyBLSA0KQ2M6IE1vaXNlaWNodWsgTGVvbmlkIChO b2tpYS1NUC9IZWxzaW5raSk7IGxpbnV4LW1tQGt2YWNrLm9yZzsgbGludXgta2VybmVsQHZnZXIu a2VybmVsLm9yZzsgY2VzYXJiQGNlc2FyYi5uZXQ7IGthbWV6YXdhLmhpcm95dUBqcC5mdWppdHN1 LmNvbTsgZW11bnNvbkBtZ2VibS5uZXQ7IHBlbmJlcmdAa2VybmVsLm9yZzsgYWFyY2FuZ2VAcmVk aGF0LmNvbTsgbWVsQGNzbi51bC5pZTsgcmllbnRqZXNAZ29vZ2xlLmNvbTsgZGltYUBhbmRyb2lk LmNvbTsgcmViZWNjYUBhbmRyb2lkLmNvbTsgc2FuQGdvb2dsZS5jb207IGFrcG1AbGludXgtZm91 bmRhdGlvbi5vcmc7IEphYXNrZWxhaW5lbiBWZXNhIChOb2tpYS1NUC9IZWxzaW5raSk7IE1pbmNo YW4gS2ltOyBLT1NBS0kgTW90b2hpcm8NClN1YmplY3Q6IFJlOiBbUEFUQ0ggMy4yLjAtcmMxIDAv M10gVXNlZCBNZW1vcnkgTWV0ZXIgcHNldWRvLWRldmljZSBhbmQgcmVsYXRlZCBjaGFuZ2VzIGlu IE1NDQoNCk9uIDAxLzA0LzIwMTIgMDI6NTYgUE0sIEdyZWcgS0ggd3JvdGU6DQoNCj4gSG93IGRv ZXMgdGhpcyBjb21wYXJlIHdpdGggdGhlIGxvd21lbW9yeWtpbGxlci5jIGRyaXZlciBmcm9tIHRo ZSANCj4gYW5kcm9pZCBkZXZlbG9wZXJzIHRoYXQgaXMgY3VycmVudGx5IGluIHRoZSBsaW51eC1u ZXh0IHRyZWU/DQoNCkFsc28sIHRoZSBsb3cgbWVtb3J5IG5vdGlmaWNhdGlvbiB0aGF0IEtvc2Fr aS1zYW4gaGFzIHdvcmtlZCBvbiwgYW5kIHdoaWNoIE1pbmNoYW4gaXMgbG9va2luZyBhdCBub3cu DQoNCldlIHNlZW0gdG8gaGF2ZSBtYW55IG1lY2hhbmlzbXMgdW5kZXIgZGV2ZWxvcG1lbnQsIGFs bCBhaW1lZCBhdCBzaW1pbGFyIGdvYWxzLiBJIGJlbGlldmUgaXQgd291bGQgYmUgZ29vZCB0byBh Z3JlZSBvbiBvbmUgbWVjaGFuaXNtIHRoYXQgY291bGQgc29sdmUgbXVsdGlwbGUgb2YgdGhlc2Ug Z29hbHMgYXQgb25jZSwgaW5zdGVhZCBvZiBzdGlja2luZyBhIGhhbmRmdWwgb2YgZGlmZmVyZW50 IHBhcnRpYWwgc29sdXRpb25zIGluIHRoZSBrZXJuZWwuLi4NCg0KRXhhY3RseSB3aGF0IGlzIHRo ZSBwcm9ibGVtIHlvdSBhcmUgdHJ5aW5nIHRvIHNvbHZlPw0KDQotLQ0KQWxsIHJpZ2h0cyByZXZl cnNlZA0K

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#29 lore raw
In reply to Greg KH

Hi,

Android OOM (AOOM) is a different thing. Briefly Android OOM is a safety belt, but I try to introduce look-ahead radar to stop before hitting wall.

As I understand AOOM it wait until situation is reached bad conditions which required memory reclaiming, selects application according to free memory and oom_adj level and kills it. So no intermediate levels could be checked (e.g. 75% usage), nothing could be done in user-space to prevent killing, no notification for case when memory becomes OK.

What I try to do is to get notification in any application that memory becomes low, and do something about it like stop processing data, close unused pages or correctly shuts applications, daemons. Application(s) might have necessity to install several notification levels, so reaction could be adjusted based on current utilization level per each application, not globally.

Rik van Riel have pointed Kosaki-san's low memory notification. I know about mem_notify but according to Anton Vorontsov's statement [1] it is died since 2008 and for me it is really good news that is still not. I need to re-investigate it.

With Best Wishes,
Leonid

[1] http://permalink.gmane.org/gmane.linux.kernel.mm/71626

-----Original Message-----
From: ext Greg KH [mailto:[email protected]]
Sent: 04 January, 2012 21:56
To: Moiseichuk Leonid (Nokia-MP/Helsinki)
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jaaskelainen Vesa (Nokia-MP/Helsinki)
Subject: Re: [PATCH 3.2.0-rc1 0/3] Used Memory Meter pseudo-device and related changes in MM

Quoted 42 lines · Leonid Moiseichuk

The main idea of Used Memory Meter (UMM) is to provide low-cost
interface for user-space to notify about memory consumption using
similar approach /proc/meminfo does but focusing only on "modified" pages which cannot be fogotten.

The calculation formula in terms of meminfo looks the following:
UsedMemory = (MemTotal - MemFree - Buffers - Cached - SwapCached) +
(SwapTotal - SwapFree)
It reflects well amount of system memory used in applications in heaps and shared pages.

Previously (n770..n900) we had lowmem.c [1] which used LSM and did a
lot other things,
n9 implementation based on memcg [2] which has own problems, so the proposed variant I hope is the best one for n9:
- Keeps connections from user space
- When amount of modified pages reaches crossed pointed value for particular connection makes POLLIN and allow user-space app to read it and react
- Economic as much as possible, so currently its operates if allocation higher than 487 pages or last check happened 250 ms before Of course if no
allocation happened then no activities performed, use-time must be not affected.

Testing results:
- Checkpatch produced 0 warning
- Sparse does not produce warnings
- One check costs ~20 us or less (could be checked with probe=1
insmod)
- One connection costs 20 bytes in kernel-space (see observer
structure) for 32-bit variant
- For 10K connections poll update in requested in ~10ms, but for practically device expected to will have about 10 connections (like n9 has now).

Known weak points which I do not know how to fix but will if you have a brillian idea:
- Having hook in MM is nasty but MM/shrinker cannot be used there and
LSM even worse idea
- If I made
$cat /dev/used_memory
it is produced lines in non-stop mode. Adding position check in umm_read seems doesn not help, so "head -1 /dev/used_memory" should be used if you need to quick
check
- Format of output is USED_PAGES:AVAILABLE_PAGES, primitive but enough
for tasks module does

Quoted 3 lines

Tested on ARM, x86-32 and x86-64 with and without CONFIG_SWAP. Seems works in all combinations. Sorry for wide distributions but list of names were produced by scripts/get_maintainer.pl

How does this compare with the lowmemorykiller.c driver from the android developers that is currently in the linux-next tree?

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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#30 lore raw
Quoted 6 lines · On Thu, Jan 5, 2012 at 1:47 PM, <[email protected]> wrote:

As I understand AOOM it wait until situation is reached bad conditions which required memory reclaiming, selects application according to free memory and oom_adj level and kills it. So no intermediate levels could be checked (e.g. 75% usage), nothing could be done in user-space to prevent killing, no notification for case when memory becomes OK.

Quoted 6 lines

What I try to do is to get notification in any application that memory becomes low, and do something about it like stop processing data, close unused pages or correctly shuts applications, daemons. Application(s) might have necessity to install several notification levels, so reaction could be adjusted based on current utilization level per each application, not globally.

Sure. However, from VM point of view, both have the exact same
functionality: detect when we reach low memory condition (for some configurable threshold) and notify userspace or kernel subsystem about it.

That's the part I'd like to see implemented in mm/notify.c or similar. I really don't care what Android or any other folks use it for exactly as long as the generic code is light-weight, clean, and we can reasonably assume that distros can actually enable it.

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#31 lore raw

Well, mm/notify.c seems a bit global for me. At the first step I handle inputs from Greg and try to find less destructive approach to allocation tracking rather than page_alloc. The issue is I know quite well my problem, so other guys who needs memory tracking has own requirements how account memory, how often notify/which granularity, how many clients could be and so one. If I get some inputs I will be happy to implement them.

With Best Wishes,
Leonid

-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of ext Pekka Enberg
Sent: 05 January, 2012 14:41
To: Moiseichuk Leonid (Nokia-MP/Helsinki)
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Jaaskelainen Vesa (Nokia-MP/Helsinki)
Subject: Re: [PATCH 3.2.0-rc1 0/3] Used Memory Meter pseudo-device and related changes in MM

Quoted 6 lines · On Thu, Jan 5, 2012 at 1:47 PM, <[email protected]> wrote:

As I understand AOOM it wait until situation is reached bad conditions
which required memory reclaiming, selects application according to
free memory and oom_adj level and kills it. So no intermediate levels could be checked (e.g. 75% usage), nothing could be done in user-space to prevent killing,
no notification for case when memory becomes OK.

Quoted 6 lines

What I try to do is to get notification in any application that memory becomes low, and do something about it like stop processing data, close unused pages or correctly shuts applications, daemons. Application(s) might have necessity to install several notification levels, so reaction could be adjusted based on current utilization level per each application, not globally.

Sure. However, from VM point of view, both have the exact same
functionality: detect when we reach low memory condition (for some configurable threshold) and notify userspace or kernel subsystem about it.

That's the part I'd like to see implemented in mm/notify.c or similar.
I really don't care what Android or any other folks use it for exactly as long as the generic code is light-weight, clean, and we can reasonably assume that distros can actually enable it.

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#32 lore raw

A: No.
Q: Should I include quotations after my reply?

http://daringfireball.net/2007/07/on_top

Quoted 3 lines · On Thu, Jan 05, 2012 at 01:02:23PM +0000, [email protected] wrote:

Well, mm/notify.c seems a bit global for me. At the first step I handle inputs from Greg and try to find less destructive approach to allocation tracking rather than page_alloc.

No, please listen to what people, including me, are saying, otherwise your code will be totally ignored.

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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#33 lore raw

-----Original Message-----
From: ext Greg KH [mailto:[email protected]]

Quoted 1 line

No, please listen to what people, including me, are saying, otherwise your code will be totally ignored.

I tried to sort out all inputs coming. But before doing the next step I prefer to have tests passed. Changes you proposed are strain forward and understandable. Hooking in mm/vmscan.c and mm/page-writeback.c is not so easy, I need to find proper place and make adequate proposal.
Using memcg is doesn't not look for me now as a good way because I wouldn't like to change memory accounting - memcg has strong reason to keep caches.

Best Wishes,
Leonid

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#34 lore raw
Quoted 9 lines · On Thu, 5 Jan 2012, [email protected] wrote:

I tried to sort out all inputs coming. But before doing the next step I prefer to have tests passed. Changes you proposed are strain forward and understandable.
Hooking in mm/vmscan.c and mm/page-writeback.c is not so easy, I need to find proper place and make adequate proposal.
Using memcg is doesn't not look for me now as a good way because I wouldn't like to change memory accounting - memcg has strong reason to keep caches.

If you can accept the overhead of the memory controller (increase in kernel text size and amount of metadata for page_cgroup), then you can already do this with a combination of memory thresholds with cgroup.event_control and disabling of the oom killer entirely with memory.oom_control. You can also get notified when the oom killer is triggered by using eventfd(2) on memory.oom_control even though it's disabled in the kernel. Then, the userspace task attached to that control file can send signals to applications to free their memory or, in the worst case, choose to kill an application but have all that policy be implemented in userspace.

We actually have extended that internally to have an oom killer delay, i.e. a specific amount of time must pass for userspace to react to the oom situation or the oom killer will actually be triggered. This is needed in case our userspace is blocked or can't respond for whatever reason and is a nice fallback so that we're guaranteed to never end up livelocked. That delay gets reset anytime a page is uncharged to a memcg, the memcg limit is increased, or the delay is rewritten (for userspace to say "I've handled the event"). Those patches were posted on linux-mm several months ago but never merged upstream. You should be able to use the same concept apart from the memory controller and implement it generically.

You also presented this as an alternative for "embedded or small" users so I wasn't aware that using the memory controller was an acceptable solution given its overhead.

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#35 lore raw
Quoted 4 lines

-----Original Message-----
From: ext David Rientjes [mailto:[email protected]]
Sent: 06 January, 2012 01:10

Quoted 10 lines

If you can accept the overhead of the memory controller (increase in kernel text size and amount of metadata for page_cgroup), then you can already do this with a combination of memory thresholds with cgroup.event_control and disabling of the oom killer entirely with memory.oom_control. You can also get notified when the oom killer is triggered by using eventfd(2) on memory.oom_control even though it's disabled in the kernel. Then, the userspace task attached to that control file can send signals to applications to free their memory or, in the worst case, choose to kill an application but have all that policy be implemented in userspace.

We invested in memcg notification (Kiryl Shutsemau's patches) and use the similar approach in n9 already (see libmemnotifyqt on gitorious). Unfortunately it is produces number of side effects which are related how memcg handled application injection/removal from/to group. So I like to try another approach.

Quoted 2 lines

We actually have extended that internally to have an oom killer delay, i.e. a specific amount of time must pass for userspace to react to the oom

...

Quoted 5 lines

handled the event"). Those patches were posted on linux-mm several months
ago but never merged upstream. You should be able to use the same concept
apart from the memory controller and implement it generically.

Yep. But in n9 concept OOMing some application is acceptable, so I do not see such changes as very suitable.

Quoted 3 lines

You also presented this as an alternative for "embedded or small" users so I wasn't aware that using the memory controller was an acceptable solution given its overhead.

Overhead, by the way, fully acceptable and I think in never kernels (3.x) situation will be much better.
But memcg has from my point principal problems for case when you cgroup application set is updated when application foregrounded/backgrounded, unfortunately that is how n900 and n9 software designed.

Best Wishes,
Leonid

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#36 lore raw
In reply to [email protected]
Quoted 2 lines

Android OOM (AOOM) is a different thing. Briefly Android OOM is a safety belt, but I try to introduce look-ahead radar to stop before hitting wall.

You explained why we shouldn't merge neither you nor android notification patches. Many embedded developers tried to merge their own patch and claimed "Hey! my patch is completely different from another one". That said, their patches can't be used each other use case, just for them.

Systemwide global notification itself is not bad idea. But we definitely choose just one implementation. thus, you need to get agree with other embedded people.

Again, lowmemorykiller.c should be dropped too.

Quoted 2 lines

UsedMemory = (MemTotal - MemFree - Buffers - Cached - SwapCached) +
(SwapTotal - SwapFree)

If you spent a few time to read past discuttion, you should have understand your fomula is broken and unacceptable. Think, mlocked (or pinning by other way) cache can't be discarded. And, When system is under swap thrashing, userland notification is useless. I don't think you tested w/ swap environment heavily.

While you are getting stuck to make nokia specific feature, I'm recommending you maintain your local patch yourself.

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>

#37 lore raw
Quoted 9 lines

-----Original Message-----
From: ext KOSAKI Motohiro [mailto:[email protected]]
Sent: 06 January, 2012 02:27
To: Moiseichuk Leonid (Nokia-MP/Helsinki)

Quoted 1 line

Android OOM (AOOM) is a different thing. Briefly Android OOM is a safety

belt,

Quoted 1 line

but I try to introduce look-ahead radar to stop before hitting wall.

Quoted 7 lines

You explained why we shouldn't merge neither you nor android notification patches.
Many embedded developers tried to merge their own patch and claimed "Hey! my patch
is completely different from another one". That said, their patches can't be used
each other use case, just for them.

Pardon me but these patches doing really different thing. Having notification doesn't mean all you software will handle them correct. In open platform you might have "bad entity" which will be killed by OOM. In we used default OOM killer but Android OOM probably works better in some other conditions even from my point of view it may trigger false OOMs due to base on NR_FREE_PAGES which are more interesting for kernel for than for user-space.

Quoted 3 lines

Systemwide global notification itself is not bad idea. But we definitely choose just one implementation. thus, you need to get agree with other embedded people.

Agree. That is point for discussion. One is already available through memcg but problem is in memcg and how we use it.

Quoted 7 lines
Quoted 2 lines

UsedMemory = (MemTotal - MemFree - Buffers - Cached - SwapCached) +
(SwapTotal - SwapFree)

If you spent a few time to read past discuttion, you should have understand your fomula
is broken and unacceptable. Think, mlocked (or pinning by other way) cache can't be discarded.

In theory you are right about mlocked pages. So I will add deduction for NR_MLOCK
In practice typical desktop system has mlocked = 0. Also code pages are shared, so mlocking has 0 effect. For data pages the some library like http://maemo.gitorious.org/maemo-tools/libmlocknice could be used. Anyhow, on n9 we have only 5.3 MB mlocked memory from 1024MB.

Quoted 1 line

And, When system is under swap thrashing, userland notification is useless.

Well, cgroups CPU shares and ionice seems to me better but as a quick solution extension with LRU_ACTIVE_ANON + LRU_ACTIVE_FILE could be done easily.

Quoted 1 line

I don't think you tested w/ swap environment heavily.

n770, n800, n810 have optional in-file swapping.
n900 has permanent 768 MB swap partition.
n9 uses in-RAM lzo compressed 256 MB swap.

All of them tested, tuned and works fine for majority use-cases.

Quoted 3 lines

While you are getting stuck to make nokia specific feature, I'm recommending you
maintain your local patch yourself.

Thanks for advices, but I have better idea which is less destructive for MM. Maybe it will more successful, at least for maintenance as a local patch.

--
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/ .
Fight unfair telecom internet charges in Canada: sign http://stopthemeter.ca/
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>