low memory notify
Subsystems (5)
cover low memory notify
As you can see, it's respin of mem_notify core of KOSAKI and Marcelo. (Of course, KOSAKI's original patchset includes more logics but I didn't include all things intentionally because I want to start from beginning again) Recently, there are some requirements of notification of system memory pressure. It would be very useful for various cases.
For example, QEMU/JVM/Firefox like big memory hogger can release their memory when memory pressure happens. Another example in embedded side, they can close background application. For this, there are some trial but we need more general one and not-hacked alloc/free hot path.
I think most big problem of system slowness is swap-in operation. Swap-in is a synchronous operation so application's latency would be big. Solution for that is prevent swap-out itself. We couldn't prevent swapout totally but could reduce it with this patch.
In case of swapless system, code page is very important for system response. So we have to keep code page, too. I used very naive heuristic in this patch but welcome to any idea.
I want to make kernel logic simple if possible and just notify to user space. Of course, there are lots of thing we have to consider but for discussion this simple patch would be a good start point.
This version is totally RFC so any comments are welcome.
Minchan Kim (3):
[RFC 1/3] /dev/low_mem_notify
[RFC 2/3] vmscan hook
[RFC 3/3] test program
drivers/char/mem.c | 7 ++ include/linux/low_mem_notify.h | 6 ++ mm/Kconfig | 7 ++ mm/Makefile | 1 + mm/low_mem_notify.c | 61 ++++++++++++++++++++ mm/vmscan.c | 28 +++++++++ poll.c | 121 ++++++++++++++++++++++++++++++++++++++++ 7 files changed, 231 insertions(+), 0 deletions(-) create mode 100644 include/linux/low_mem_notify.h create mode 100644 mm/low_mem_notify.c create mode 100644 poll.c
Signature · 8 lines
1.7.7.5 -- 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>
RFC 1/3 /dev/low_mem_notify
This patch makes new device file "/dev/low_mem_notify". If application polls it, it can receive event when system memory pressure happens.
This patch is based on KOSAKI and Marcelo's long time ago work.
http://lwn.net/Articles/268732/
--- drivers/char/mem.c | 7 ++++ include/linux/low_mem_notify.h | 6 ++++ mm/Kconfig | 7 ++++ mm/Makefile | 1 + mm/low_mem_notify.c | 61 ++++++++++++++++++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 0 deletions(-) create mode 100644 include/linux/low_mem_notify.h create mode 100644 mm/low_mem_notify.c
drivers/char/mem.c +7 -0
@@ -35,6 +35,10 @@# include <linux/efi.h> #endif +#ifdef CONFIG_LOW_MEM_NOTIFY +extern struct file_operations low_mem_notify_fops; +#endif +static inline unsigned long size_inside_page (unsigned long start,unsigned long size) {
@@ -867,6 +871,9 @@ static const struct memdev { #ifdef CONFIG_CRASH_DUMP [12 ] = {"oldmem" ,0 , &oldmem_fops,NULL }, #endif +#ifdef CONFIG_LOW_MEM_NOTIFY + [13] = { "low_mem_notify",0666, &low_mem_notify_fops, NULL}, +#endif };static int memory_open (struct inode *inode,struct file *filp)
include/linux/low_mem_notify.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef _LINUX_LOW_MEM_NOTIFY_H +#define _LINUX_LOW_MEM_NOTIFY_H + +void low_memory_pressure (void ); + +#endif
mm/Kconfig +7 -0
@@ -379,3 +379,10 @@ config CLEANCACHE in a negligible performance hit. If unsure, say Y to enable cleancache + +config LOW_MEM_NOTIFY + bool "Enable low memory notification" + default n + help + If system suffer from low memory, kernel can notify it to user through + /dev/low_mem_notify.
mm/Makefile +1 -0
@@ -51,3 +51,4 @@ obj-$(CONFIG_HWPOISON_INJECT) += hwpoison-inject.o obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o obj-$(CONFIG_CLEANCACHE) += cleancache.o +obj-$(CONFIG_LOW_MEM_NOTIFY) += low_mem_notify.o
mm/low_mem_notify.c new file +61 -0
61 lines not on this page · raw message
Signature · 8 lines
1.7.7.5 -- 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>
RFC 2/3 vmscan hook
In reply to Minchan KimThis patch insert memory pressure notify point into vmscan.c Most problem in system slowness is swap-in. swap-in is a synchronous opeartion so that it affects heavily system response.
This patch alert it when reclaimer start to reclaim inactive anon list. It seems rather earlier but not bad than too late.
Other alert point is when there is few cache pages
In this implementation, if it is (cache < free pages), memory pressure notify happens. It has to need more testing and tuning or other hueristic. Any suggesion are welcome.
--- mm/vmscan.c | 28 ++++++++++++++++++++++++++++ 1 files changed, 28 insertions(+), 0 deletions(-)
mm/vmscan.c +28 -0
@@ -43,6 +43,7 @@#include <linux/sysctl.h> #include <linux/oom.h> #include <linux/prefetch.h> +#include <linux/low_mem_notify.h> #include <asm/tlbflush.h> #include <asm/div64.h>
@@ -2082,16 +2083,43 @@ static void shrink_mem_cgroup_zone(int priority, struct mem_cgroup_zone *mz, {unsigned long nr[NR_LRU_LISTS ];unsigned long nr_to_scan; +enum lru_list lru;unsigned long nr_reclaimed, nr_scanned;unsigned long nr_to_reclaim = sc->nr_to_reclaim;struct blk_plug plug; +#ifdef CONFIG_LOW_MEM_NOTIFY +bool low_mem = false; +unsigned long free, file; +#endif restart: nr_reclaimed =0 ; nr_scanned = sc->nr_scanned;get_scan_count (mz, sc, nr, priority); +#ifdef CONFIG_LOW_MEM_NOTIFY +/* We want to avoid swapout */ +if (nr[LRU_INACTIVE_ANON ]) + low_mem = true; +/* +* We want to avoid dropping page cache excessively +* in no swap system +*/ +if (nr_swap_pages <=0 ) { + free =zone_page_state (mz->zone,NR_FREE_PAGES ); + file =zone_page_state (mz->zone,NR_ACTIVE_FILE ) + +zone_page_state (mz->zone,NR_INACTIVE_FILE ); +/* +* If we have very few page cache pages, +* notify to user +*/ +if (file < free) + low_mem = true; + } +if (low_mem) +low_memory_pressure (); +#endif blk_start_plug (&plug);while (nr[LRU_INACTIVE_ANON ] || nr[LRU_ACTIVE_FILE ] || nr[LRU_INACTIVE_FILE ]) {
Signature · 8 lines
1.7.7.5 -- 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>
RFC 3/3 test program
In reply to Minchan KimThis test program allocates 10M per second and when memory pressure notify happens, it releases 20M.
I tested this patch on 512M qemu machine with 3 test program. I saw some swapout but not too many and even didn't see OOM. It obviously reduces swap out.
--- poll.c | 121 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 121 insertions(+), 0 deletions(-) create mode 100644 poll.c
poll.c new file +121 -0
@@ -0,0 +1,121 @@ +#include <poll.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <stdio.h> +#include <pthread.h> +#include <stdbool.h> +#include <stdlib.h> +#include <string.h> + +#define ALLOC_UNIT 10/* MB */ +#define FREE_UNIT 20/* MB */ + +void alloc_memory (); +void free_memory (); + +unsigned int total_memory =0 ;/* MB */ + +pthread_mutex_t mutex =PTHREAD_MUTEX_INITIALIZER ; + +/* +* If total memory is higher than 200M +*/ +bool memory_full () +{ +return total_memory >=400 ? true : false; +} + +struct alloc_chunk { +void *ptr; +struct alloc_chunk *next; +}; + +struct alloc_chunk head_chunk; + +void init_alloc_chunk (void ) +{ + head_chunk.ptr =NULL ; + head_chunk.next =NULL ; +} + +void add_memory (void *ptr) +{ +struct alloc_chunk *new_chunk =malloc (sizeof (struct alloc_chunk )); + new_chunk->ptr = ptr; + +pthread_mutex_lock (&mutex); + new_chunk->next = head_chunk.next; + head_chunk.next = new_chunk; + total_memory +=ALLOC_UNIT ; +pthread_mutex_unlock (&mutex); + +printf ("[%d] Add total memory %d(MB)\n" ,getpid (), total_memory); +} + +void alloc_memory (void ) +{ +while (1 ) { +if (memory_full ()) { +sleep (10 ); +continue ; + } + +void *new =malloc (ALLOC_UNIT *1024 *1024 ); +memset (new,0 ,ALLOC_UNIT *1024 *1024 ); +add_memory (new); +sleep (1 ); + } +} + +void free_memory (void ) +{ +int count =FREE_UNIT /ALLOC_UNIT ; +while (count--) { +struct alloc_chunk *chunk = head_chunk.next; +if (chunk ==NULL ) +break ; + +pthread_mutex_lock (&mutex); + head_chunk.next = chunk->next; + total_memory -=ALLOC_UNIT ; +pthread_mutex_unlock (&mutex); + +free (chunk->ptr); +free (chunk); + +printf ("[%d] Free total memory %d(MB)\n" ,getpid (), total_memory); + } +} + +void *poll_thread (void *dummy) +{ +struct pollfd pfd; +int fd =open ("/dev/low_mem_notify" ,O_RDONLY ); +if (fd ==-1 ) { +fprintf (stderr,"Fail to open\n" ); +return ; + } + + pfd.fd = fd; + pfd.events =POLLIN ; + +while (1 ) { +poll (&pfd,1 ,-1 ); +free_memory (); + } +} + +int main () +{ +pthread_t threadid; +init_alloc_chunk (); + +if (pthread_create (&threadid,NULL , poll_thread,NULL )) { +fprintf (stderr,"pthread create fail\n" ); +return 1 ; + } + +alloc_memory (); +return 0 ; +}
Signature · 8 lines
1.7.7.5 -- 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>
Re: [RFC 2/3] vmscan hook
In reply to Minchan KimQuoted 7 lines · On Tue, 17 Jan 2012 17:13:57 +0900 Minchan Kim <[email protected]> wrote:
This patch insert memory pressure notify point into
vmscan.cMost problem in system slowness is swap-in. swap-in is a synchronous opeartion so that it affects heavily system response.This patch alert it when reclaimer start to reclaim inactive anon list. It seems rather earlier but not bad than too late.
Quoted 6 lines
Other alert point is when there is few cache pages
In this implementation, if it is (cache < free pages), memory pressure notify happens. It has to need more testing and tuning or other hueristic. Any suggesion are welcome.Signed-off-by Minchan Kim <[email protected]>
In my 1st impression, isn't this too simple ?
Quoted 28 lines
--- mm/vmscan.c | 28 ++++++++++++++++++++++++++++ 1 files changed, 28 insertions(+), 0 deletions(-)mm/vmscan.c +5
-0@@ -43,6 +43,7 @@#include <linux/sysctl.h> #include <linux/oom.h> #include <linux/prefetch.h> +#include <linux/low_mem_notify.h> #include <asm/tlbflush.h> #include <asm/div64.h> @@ -2082,16 +2083,43 @@ static void shrink_mem_cgroup_zone(int priority, struct mem_cgroup_zone *mz, {unsigned long nr[NR_LRU_LISTS ];unsigned long nr_to_scan; +enum lru_list lru;unsigned long nr_reclaimed, nr_scanned;unsigned long nr_to_reclaim = sc->nr_to_reclaim;struct blk_plug plug; +#ifdef CONFIG_LOW_MEM_NOTIFY +bool low_mem = false; +unsigned long free, file;
mm/vmscan.c static void shrink_mem_cgroup_zone(int priority, struct mem_cgroup_zone *mz, · line 2103
Quoted 10 lines
mm/vmscan.c +5
-0+#endif restart: nr_reclaimed =0 ; nr_scanned = sc->nr_scanned;get_scan_count (mz, sc, nr, priority); +#ifdef CONFIG_LOW_MEM_NOTIFY +/* We want to avoid swapout */ +if (nr[LRU_INACTIVE_ANON ]) + low_mem = true;
IIUC, nr[LRU_INACTIVE_ANON] can be easily > 0.
And get_scan_count() now check per-memcg-lru. So, this only works when memcg is not used.
Quoted 5 lines
mm/vmscan.c +5
-0+/* +* We want to avoid dropping page cache excessively +* in no swap system +*/ +if (nr_swap_pages <=0 ) {
mm/vmscan.c static void shrink_mem_cgroup_zone(int priority, struct mem_cgroup_zone *mz, · line 2118
Quoted 10 lines
mm/vmscan.c +10
-0+ free =zone_page_state (mz->zone,NR_FREE_PAGES ); + file =zone_page_state (mz->zone,NR_ACTIVE_FILE ) + +zone_page_state (mz->zone,NR_INACTIVE_FILE ); +/* +* If we have very few page cache pages, +* notify to user +*/ +if (file < free) + low_mem = true; + }
I can't understand why you think you can check lowmem condition by "file < free". And I don't think using per-zone data is good.
(I'm not sure how many zones embeded guys using..)
Another idea:
1. can't we use some technique like cleancache to detect the condition ?
2. can't we measure page-in/page-out distance by recording something ?
3. NR_ANON + NR_FILE_MAPPED can't mean the amount of core memory if we can ignore the data file cache ?
4. how about checking kswapd's busy status ?
Thanks,
-Kame
--
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>
Re: [RFC 2/3] vmscan hook
Quoted 10 lines · KAMEZAWA Hiroyuki
Quoted 7 lines · On Tue, 17 Jan 2012 17:13:57 +0900 Minchan Kim <[email protected]> wrote:
This patch insert memory pressure notify point into
vmscan.cMost problem in system slowness is swap-in. swap-in is a synchronous opeartion so that it affects heavily system response.This patch alert it when reclaimer start to reclaim inactive anon list. It seems rather earlier but not bad than too late.
Quoted 8 lines
Quoted 6 lines
Other alert point is when there is few cache pages
In this implementation, if it is (cache < free pages), memory pressure notify happens. It has to need more testing and tuning or other hueristic. Any suggesion are welcome.Signed-off-by Minchan Kim <[email protected]>In my 1st impression, isn't this too simple ?
I agree It's too simple. It would be good start point rather than unnecessary complicated things.
Quoted 32 lines
Quoted 32 lines
--- mm/vmscan.c | 28 ++++++++++++++++++++++++++++ 1 files changed, 28 insertions(+), 0 deletions(-)mm/vmscan.c +6
-0@@ -43,6 +43,7 @@#include <linux/sysctl.h> #include <linux/oom.h> #include <linux/prefetch.h> +#include <linux/low_mem_notify.h> #include <asm/tlbflush.h> #include <asm/div64.h> @@ -2082,16 +2083,43 @@ static void shrink_mem_cgroup_zone(int priority, struct mem_cgroup_zone *mz, {unsigned long nr[NR_LRU_LISTS ];unsigned long nr_to_scan; +enum lru_list lru;unsigned long nr_reclaimed, nr_scanned;unsigned long nr_to_reclaim = sc->nr_to_reclaim;struct blk_plug plug; +#ifdef CONFIG_LOW_MEM_NOTIFY +bool low_mem = false; +unsigned long free, file; +#endif
Quoted 10 lines
mm/vmscan.c static void shrink_mem_cgroup_zone(int priority, struct mem_cgroup_zone *mz, · line 2103
Quoted 8 lines
mm/vmscan.c +4
-0restart: nr_reclaimed =0 ; nr_scanned = sc->nr_scanned;get_scan_count (mz, sc, nr, priority); +#ifdef CONFIG_LOW_MEM_NOTIFY +/* We want to avoid swapout */ +if (nr[LRU_INACTIVE_ANON ]) + low_mem = true;IIUC, nr[LRU_INACTIVE_ANON] can be easily > 0.
Yes. But I thought it would be better than late notification. Late notification ends up swap out which is a big concern about this patch. More proper timing suggestion helps me a lot.
Quoted 2 lines
And
get_scan_count()now check per-memcg-lru. So, this only works when memcg is not used.
Hmm, I didn't look at recent memcg/global reclaim unify patch of Johannes. I need time to look at it.
Thanks.
Quoted 11 lines
Quoted 11 lines
mm/vmscan.c +9
-0+/* +* We want to avoid dropping page cache excessively +* in no swap system +*/ +if (nr_swap_pages <=0 ) { + free =zone_page_state (mz->zone,NR_FREE_PAGES ); + file =zone_page_state (mz->zone,NR_ACTIVE_FILE ) + +zone_page_state (mz->zone,NR_INACTIVE_FILE ); +/*
Quoted 8 lines
mm/vmscan.c static void shrink_mem_cgroup_zone(int priority, struct mem_cgroup_zone *mz, · line 2118
Quoted 6 lines
mm/vmscan.c +6
-0+* If we have very few page cache pages, +* notify to user +*/ +if (file < free) + low_mem = true; + }I can't understand why you think you can check lowmem condition by "file < free".
The reason I thought so is I want to maintain some page cache to some degree. But I admit It's very naive heuristic and should be improved.
Quoted 2 lines
And I don't think using per-zone data is good. (I'm not sure how many zones embeded guys using..)
Agree. In case of swapless system, we need another heuristic.
Quoted 3 lines
Another idea:
1. can't we use some technique like cleancache to detect the condition ?
I totally forgot cleancache approach. Could you remind that?
Quoted 1 line
2. can't we measure page-in/page-out distance by recording something ?
I can't understand your point. What's relation does it with swapout prevent?
Quoted 2 lines
3.
NR_ANON+NR_FILE_MAPPEDcan't mean the amount of core memory if we can ignore the data file cache ?
It's good but how do we define some amount?
It's very vague but I guess we can get a good idea from that. Perhaps, you already has it.
Quoted 1 line
4. how about checking kswapd's busy status ?
Could you elaborate on your idea?
Kame, Thanks for reply,
Quoted 6 lines
Thanks,
-Kame
--
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>
Re: [RFC 1/3] /dev/low_mem_notify
In reply to Minchan Kimmm/low_mem_notify.c line 54
Quoted 13 lines · Minchan Kim
mm/low_mem_notify.c new file +13
-0+static unsigned int low_mem_notify_poll (struct file *file,poll_table *wait) +{ + unsigned int ret = 0; + + poll_wait(file, &low_mem_wait, wait); + + if (atomic_read(&nr_low_mem) != 0) { + ret = POLLIN; + atomic_set(&nr_low_mem, 0); + } + + return ret; +}
Doesn't this mean that only one application will receive the notification?
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>
Re: [RFC 1/3] /dev/low_mem_notify
In reply to Minchan KimQuoted 6 lines · Minchan Kim
This patch makes new device file "
/dev/low_mem_notify". If application polls it, it can receive event when system memory pressure happens.This patch is based on KOSAKI and Marcelo's long time ago work.
http://lwn.net/Articles/268732/
I'm not loving the ABI. Alternative solutions:
- SIGDANGER + signalfd() for poll
- sys_eventfd()
- sys_mem_notify_open() similar to sys_perf_event_open()
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>
Re: [RFC 2/3] vmscan hook
In reply to Minchan KimQuoted 29 lines · On Tue, 17 Jan 2012 18:13:56 +0900 Minchan Kim <[email protected]> wrote:
Quoted 13 lines · KAMEZAWA Hiroyuki
Quoted 9 lines · On Tue, 17 Jan 2012 17:13:57 +0900 Minchan Kim <[email protected]> wrote:
mm/vmscan.c +9
-0+/* +* We want to avoid dropping page cache excessively +* in no swap system +*/ +if (nr_swap_pages <=0 ) { + free =zone_page_state (mz->zone,NR_FREE_PAGES ); + file =zone_page_state (mz->zone,NR_ACTIVE_FILE ) + +zone_page_state (mz->zone,NR_INACTIVE_FILE ); +/* Quoted 8 lines
mm/vmscan.c static void shrink_mem_cgroup_zone(int priority, struct mem_cgroup_zone *mz, · line 2118
Quoted 6 lines
mm/vmscan.c +6
-0+* If we have very few page cache pages, +* notify to user +*/ +if (file < free) + low_mem = true; + }I can't understand why you think you can check lowmem condition by "file < free".
The reason I thought so is I want to maintain some page cache to some degree. But I admit It's very naive heuristic and should be improved.
Quoted 2 lines
And I don't think using per-zone data is good. (I'm not sure how many zones embeded guys using..)
Quoted 8 lines
Agree. In case of swapless system, we need another heuristic.
Quoted 3 lines
Another idea:
1. can't we use some technique like cleancache to detect the condition ?I totally forgot cleancache approach. Could you remind that?
Similar to 'victim cache'. Then, cache some clean pages somewhere when vmscan pageout it.
page -> vmscan's pageout -> cleancache -> may be discarded.
If a filesystem look up a page which is in a cleancache, cache-hit and bring it back to radix-tree. If not, read from disk again. And cleancache for swap(frontswap) was posted, too.
Quoted 4 lines
Quoted 1 line
2. can't we measure page-in/page-out distance by recording something ?
I can't understand your point. What's relation does it with swapout prevent?
If distance between pageout -> pagein is short, it means thrashing. For example, recoding the timestamp when the page(mapping, index) was paged-out, and check it at page-in.
Quoted 7 lines
Quoted 2 lines
3.
NR_ANON+NR_FILE_MAPPEDcan't mean the amount of core memory if we can ignore the data file cache ?It's good but how do we define some amount?
It's very vague but I guess we can get a good idea from that. Perhaps, you already has it.
Hm, a rough idea is...
- we now have rss counter per mm.
- mapped anon
- mapped file
- swapents
Ok, here, add one more counter.
- paged-out file. (I think this can be recorded in pte.) +1 when try_to_unmap_file() unmaps it.
-1 when a page is back or unmapped.
Then, scanning all tasks. Then,
mapped_anon + mapped_fileactive_map_ratio = ----------------------------------------------------- * 100
mapped_anon + mapped_file + swapents + paged_out_file
Ok, how to use this value...
Like memcg's threshold notify interface, you can change the mem_notify interface to use eventfd() as
<event_fd, fd of /dev/mem_notify, threshold of active_map_ratio>
This will inform you an event when active_map_ratio crosses passed threshold.
complicated ?
Quoted 4 lines
Quoted 1 line
4. how about checking kswapd's busy status ?
Could you elaborate on your idea?
I just thought kswapd may not stop when the situation is very bad.
Thanks,
-Kame
--
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>
Quoted 5 lines · Minchan Kim
As you can see, it's respin of
mem_notifycore of KOSAKI and Marcelo. (Of course, KOSAKI's original patchset includes more logics but I didn't include all things intentionally because I want to start from beginning again) Recently, there are some requirements of notification of system memory pressure.
How does this relate to the existing cgroups memory notifications? See Documentation/cgroups/memory.txt under "10. OOM Control"
Quoted 3 lines
It would be very useful for various cases.
For example, QEMU/JVM/Firefox like big memory hogger can release their memory when memory pressure happens.
I don't know about QEMU, but the key characteristic of the JVM and Firefox is that they use garbage collection. Which also applies to Python, Ruby, Google Go, Haskell, OCaml...
So what you really want to be investigating here is integration between a garbage collector and the system VM. Your test program looks nothing like a garbage collector. I'd expect most of the performance tradeoffs to be similar between these runtimes. The Azul people have been doing something like this: http://www.managedruntime.org/
In Firefox' case though it can also drop other caches, e.g.:
http://people.gnome.org/~federico/news-2007-09.html#firefox-memory-1
As far as the desktop goes, I want to get notified if we're going to hit swap, not if we're close to exhausting the total of RAM+swap. While swap may make sense for servers that care about throughput mainly, I care a lot about latency.
--
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>
Quoted 5 lines · Colin Walters
So what you really want to be investigating here is integration between a garbage collector and the system VM. Your test program looks nothing like a garbage collector. I'd expect most of the performance tradeoffs to be similar between these runtimes. The Azul people have been doing something like this: http://www.managedruntime.org/
The interraction isn't all that complex, really. I'd expect most VMs to simply wake up the GC thread when poll() returns. GCs that are able to compact the heap can madvise(MADV_DONTNEED) or even munmap() unused parts of the heap.
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>
Re: [RFC 1/3] /dev/low_mem_notify
In reply to Pekka EnbergQuoted 16 lines · Pekka Enberg
mm/low_mem_notify.c line 54
Quoted 13 lines · Minchan Kim
mm/low_mem_notify.c new file +13
-0+static unsigned int low_mem_notify_poll (struct file *file,poll_table *wait) +{ +unsigned int ret =0 ; + +poll_wait (file,&low_mem_wait, wait); + +if (atomic_read (&nr_low_mem) !=0 ) { + ret =POLLIN ; +atomic_set (&nr_low_mem,0 ); + } + +return ret; +}Doesn't this mean that only one application will receive the notification?
One at a time, which could be a good thing since the last thing we want to do when the system is under memory pressure is create a thundering herd.
OTOH, we do need to ensure that programs take turns getting the memory pressure notification. I do not know whether poll_wait automatically takes care of that...
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>
Quoted 7 lines · Colin Walters
How does this relate to the existing cgroups memory notifications? See
Documentation/cgroups/memory.txtunder "10. OOM Control"As far as the desktop goes, I want to get notified if we're going to hit swap, not if we're close to exhausting the total of RAM+swap. While swap may make sense for servers that care about throughput mainly, I care a lot about latency.
You just answered your own question :)
This code is indeed meant to avoid/reduce swap use and improve userspace latencies.
Minchan posted a very simple example patch set, so we can get an idea in what direction people would want the code to go. This often beats working on complex code for weeks, and then having people tell you they wanted something else :)
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>
Hi,
Quoted 15 lines · Minchan Kim
As you can see, it's respin of
mem_notifycore of KOSAKI and Marcelo. (Of course, KOSAKI's original patchset includes more logics but I didn't include all things intentionally because I want to start from beginning again) Recently, there are some requirements of notification of system memory pressure. It would be very useful for various cases.
For example, QEMU/JVM/Firefox like big memory hogger can release their memory when memory pressure happens. Another example in embedded side, they can close background application. For this, there are some trial but we need more general one and not-hacked alloc/free hot path.I think most big problem of system slowness is swap-in operation. Swap-in is a synchronous operation so application's latency would be big. Solution for that is prevent swap-out itself. We couldn't prevent swapout totally but could reduce it with this patch.
Quoted 7 lines
In case of swapless system, code page is very important for system response. So we have to keep code page, too. I used very naive heuristic in this patch but welcome to any idea.
I want to make kernel logic simple if possible and just notify to user space. Of course, there are lots of thing we have to consider but for discussion this simple patch would be a good start point.
This is almost exactly what we've been looking at doing for Chrome OS (which is swapless). In our case, the browser is by far the largest memory consumer on the system, and we have for quite a while been playing tricks with OOM scores trying to make the interaction between the VM and the application happen right such that if we're OOM, the "right" tab process gets killed, etc. But it's not enough (and it's not always accurate enough). Chrome definitely knows already what it would prefer to do to release memory, so having a simple notifier for low memory condition is preferred.
We have considered doing it through cgroups but it adds a level of complexity that we don't need for this use case (we do already use cgroups for other reasons though). If this simpler solution is heading towards inclusion we'll probably use it instead.
-Olof
--
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>
Re: [RFC 1/3] /dev/low_mem_notify
In reply to Rik van RielHello,
Ok, so here's a proof of concept patch that implements sample-base per-process free threshold VM event watching using perf-like syscall ABI. I'd really like to see something like this that's much more extensible and clean than the /dev based ABIs that people have proposed so far.
Pekka
------------------->
Re: [RFC 1/3] /dev/low_mem_notify
Quoted 7 lines · Pekka Enberg
Hello,
Ok, so here's a proof of concept patch that implements sample-base per-process free threshold VM event watching using perf-like syscall ABI. I'd really like to see something like this that's much more extensible and clean than the /dev based ABIs that people have proposed so far.
Looks like a nice extensible interface to me.
The only thing is, I expect we will not want to wake up processes most of the time, when there is no memory pressure, because that would just waste battery power and/or cpu time that could be used for something else.
The desire to avoid such wakeups makes it harder to wake up processes at arbitrary points set by the API.
Another issue is that we might be running two programs on the system, each with a different threshold for "lets free some of my cache". Say one program sets the threshold at 20% free/cache memory, the other program at 10%.
We could end up with the first process continually throwing away its caches, while the second process never gives its unused memory back to the kernel.
I am not sure what the right thing to do would be...
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>
Re: [RFC 1/3] /dev/low_mem_notify
Quoted 9 lines · Rik van Riel
Looks like a nice extensible interface to me.
The only thing is, I expect we will not want to wake up processes most of the time, when there is no memory pressure, because that would just waste battery power and/or cpu time that could be used for something else.
The desire to avoid such wakeups makes it harder to wake up processes at arbitrary points set by the API.
Sure. You could either bump up the threshold or use Minchan's hooks - or both.
Quoted 11 lines · Rik van Riel
Another issue is that we might be running two programs on the system, each with a different threshold for "lets free some of my cache". Say one program sets the threshold at 20% free/cache memory, the other program at 10%.
We could end up with the first process continually throwing away its caches, while the second process never gives its unused memory back to the kernel.
I am not sure what the right thing to do would be...
One option is to use per-process thresholds on RSS, for example, and also support system-wide thresholds.
That said, I'd really like to see the N9 and Android policies supported with this ABI. It's much easier to make it generic once we support real-world use cases.
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>
Re: [RFC 1/3] /dev/low_mem_notify
Quoted 3 lines · Pekka Enberg
That said, I'd really like to see the N9 and Android policies supported with this ABI. It's much easier to make it generic once we support real-world use cases.
If people are interested in hacking on the thing, I pushed the commit in 'vmnotify/core' branch of
git://github.com/penberg/linux.git
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>
Re: [RFC 1/3] /dev/low_mem_notify
In reply to Pekka EnbergQuoted 4 lines · Pekka Enberg
Quoted 2 lines
The desire to avoid such wakeups makes it harder to wake up processes at arbitrary points set by the API.
Sure. You could either bump up the threshold or use Minchan's hooks - or both.
s/threshold/sample period/g
--
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>
Re: [RFC 2/3] vmscan hook
In reply to KAMEZAWA HiroyukiQuoted 41 lines · KAMEZAWA Hiroyuki
Quoted 29 lines · On Tue, 17 Jan 2012 18:13:56 +0900 Minchan Kim <[email protected]> wrote:
Quoted 13 lines · KAMEZAWA Hiroyuki
Quoted 9 lines · On Tue, 17 Jan 2012 17:13:57 +0900 Minchan Kim <[email protected]> wrote:
mm/vmscan.c +9
-0+/* +* We want to avoid dropping page cache excessively +* in no swap system +*/ +if (nr_swap_pages <=0 ) { + free =zone_page_state (mz->zone,NR_FREE_PAGES ); + file =zone_page_state (mz->zone,NR_ACTIVE_FILE ) + +zone_page_state (mz->zone,NR_INACTIVE_FILE ); +/* Quoted 8 lines
mm/vmscan.c static void shrink_mem_cgroup_zone(int priority, struct mem_cgroup_zone *mz, · line 2118
Quoted 6 lines
mm/vmscan.c +6
-0+* If we have very few page cache pages, +* notify to user +*/ +if (file < free) + low_mem = true; + }I can't understand why you think you can check lowmem condition by "file < free".
The reason I thought so is I want to maintain some page cache to some degree. But I admit It's very naive heuristic and should be improved.
Quoted 2 lines
And I don't think using per-zone data is good. (I'm not sure how many zones embeded guys using..)
Quoted 8 lines
Agree. In case of swapless system, we need another heuristic.
Quoted 3 lines
Another idea:
1. can't we use some technique like cleancache to detect the condition ?I totally forgot cleancache approach. Could you remind that?
Quoted 8 lines
Similar to 'victim cache'. Then, cache some clean pages somewhere when vmscan pageout it.
page -> vmscan's pageout -> cleancache -> may be discarded.
If a filesystem look up a page which is in a cleancache, cache-hit and bring it back to radix-tree. If not, read from disk again. And cleancache for swap(frontswap) was posted, too.
I am not sure this can prevent swapout.
I think it ends up evicting pages into swap devices.
Quoted 10 lines
Quoted 6 lines
Quoted 3 lines
2. can't we measure page-in/page-out distance by recording something ?
I can't understand your point. What's relation does it with swapout prevent?
If distance between pageout -> pagein is short, it means thrashing. For example, recoding the timestamp when the
page(mapping, index)was paged-out, and check it at page-in.
Our goal is prevent swapout. When we found thrashing, it's too late.
Quoted 31 lines
Quoted 9 lines
Quoted 4 lines
3.
NR_ANON+NR_FILE_MAPPEDcan't mean the amount of core memory if we can ignore the data file cache ?It's good but how do we define some amount?
It's very vague but I guess we can get a good idea from that. Perhaps, you already has it.Hm, a rough idea is...
- we now have rss counter per mm.
- mapped anon
- mapped file
- swapentsOk, here, add one more counter.
- paged-out file. (I think this can be recorded in pte.) +1 when
try_to_unmap_file()unmaps it.
-1 when a page is back or unmapped.Then, scanning all tasks. Then,
mapped_anon+mapped_fileactive_map_ratio= ----------------------------------------------------- * 100
mapped_anon+mapped_file+ swapents +paged_out_fileOk, how to use this value...
Quoted 8 lines
Like memcg's threshold notify interface, you can change the
mem_notifyinterface to useeventfd()as<
event_fd, fd of/dev/mem_notify, threshold ofactive_map_ratio>This will inform you an event when
active_map_ratiocrosses passed threshold.complicated ?
Yes. :)
I want to make simple if possible.
Quoted 8 lines
Quoted 6 lines
Quoted 3 lines
4. how about checking kswapd's busy status ?
Could you elaborate on your idea?
I just thought kswapd may not stop when the situation is very bad.
As I said eariler, the goal is prevent swap.
When we found kswapd is busy, it might many pages are already swapped-out so it's too late.
Quoted 6 lines
Thanks,
-Kame
Quoted 6 lines
--
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>
--
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>
Re: [RFC 1/3] /dev/low_mem_notify
In reply to Pekka EnbergQuoted 42 lines · Pekka Enberg
Hello,
Ok, so here's a proof of concept patch that implements sample-base per-process free threshold VM event watching using perf-like syscall ABI. I'd really like to see something like this that's much more extensible and clean than the /dev based ABIs that people have proposed so far.
Pekka
------------------->
From
a07f93fdca360b20daef4a5d66f2a5746f31f6a6Mon Sep 17 00:00:00 2001
From: Pekka Enberg <[email protected]>
Date: Tue, 17 Jan 2012 17:51:48 +0200
Subject: [PATCH] vmnotify: VM event notification systemThis patch implements a new
sys_vmnotify_fd()system call that returns a pollable file descriptor that can be used to watch VM events.For example, to watch for VM event when free memory is below 99% of available memory using 1 second sample period, you'd do something like this:
struct vmnotify_config config; struct vmnotify_event event; struct pollfd pollfd; int fd; config = (struct vmnotify_config) { .type = VMNOTIFY_TYPE_SAMPLE|VMNOTIFY_TYPE_FREE_THRESHOLD, .sample_period_ns = 1000000000L, .free_threshold = 99, }; fd = sys_vmnotify_fd(&config); pollfd.fd = fd; pollfd.events = POLLIN; if (poll(&pollfd, 1, -1) < 0) { perror("poll failed"); exit(1);
Quoted 8 lines
}
memset(&event, 0, sizeof(event));
if (read(fd, &event, sizeof(event)) < 0) {
perror("read failed");
exit(1);
}Hi Pekka,
I didn't look into your code(will do) but as I read description, still I don't convince we need really some process specific threshold like 99% I think application can know it by polling /proc/meminfo without this mechanism if they really want.
I would like to notify when system has a trobule with memory pressure without some process specific threshold. Of course, applicatoin can't expect it.(ie, application can know system memory pressure by /proc/meminfo but it can't know when swapout really happens). Kernel low mem notify have to give such notification to user space, I think.
Quoted 418 lines
Signed-off-by Pekka Enberg <[email protected]>--- arch/x86/include/asm/unistd_64.h | 2 + include/linux/vmnotify.h | 44 ++++++ mm/Kconfig | 6 + mm/Makefile | 1 + mm/vmnotify.c | 235 ++++++++++++++++++++++++++++++++ tools/testing/vmnotify/vmnotify-test.c | 68 +++++++++ 6 files changed, 356 insertions(+), 0 deletions(-) create mode 100644 include/linux/vmnotify.h create mode 100644 mm/vmnotify.c create mode 100644 tools/testing/vmnotify/vmnotify-test.carch/x86/include/asm/unistd_64.h +2
-0@@ -686,6 +686,8 @@ __SYSCALL(__NR_getcpu, sys_getcpu) __SYSCALL(__NR_process_vm_readv, sys_process_vm_readv)#define __NR_process_vm_writev 311 __SYSCALL(__NR_process_vm_writev, sys_process_vm_writev) +#define __NR_vmnotify_fd 312 +__SYSCALL(__NR_vmnotify_fd, sys_vmnotify_fd)#ifndef __NO_STUBS#define __ARCH_WANT_OLD_READDIRinclude/linux/vmnotify.h new file +44
-0@@ -0,0 +1,44 @@ +#ifndef _LINUX_VMNOTIFY_H +#define _LINUX_VMNOTIFY_H + +#include <linux/types.h> + +enum { +VMNOTIFY_TYPE_FREE_THRESHOLD =1ULL <<0 , +VMNOTIFY_TYPE_SAMPLE =1ULL <<1 , +}; + +struct vmnotify_config { +/* +* Size of the struct for ABI extensibility. +*/ +__u32 size; + +/* +* Notification type bitmask +*/ +__u64 type; + +/* +* Free memory threshold in percentages [1..99] +*/ +__u32 free_threshold; + +/* +* Sample period in nanoseconds +*/ +__u64 sample_period_ns; +}; + +struct vmnotify_event { +/* Size of the struct for ABI extensibility. */ +__u32 size; + +__u64 nr_avail_pages; + +__u64 nr_swap_pages; + +__u64 nr_free_pages; +}; + +#endif /* _LINUX_VMNOTIFY_H */ mm/Kconfig +6
-0@@ -373,3 +373,9 @@ config CLEANCACHE in a negligible performance hit. If unsure, say Y to enable cleancache + +config VMNOTIFY + bool "Enable VM event notification system" + default n + help + If unsure, say N to disable vmnotifymm/Makefile +1
-0@@ -51,3 +51,4 @@ obj-$(CONFIG_HWPOISON_INJECT) += hwpoison-inject.o obj-$(CONFIG_DEBUG_KMEMLEAK) += kmemleak.o obj-$(CONFIG_DEBUG_KMEMLEAK_TEST) += kmemleak-test.o obj-$(CONFIG_CLEANCACHE) += cleancache.o +obj-$(CONFIG_VMNOTIFY) += vmnotify.omm/vmnotify.c new file +235
-0@@ -0,0 +1,235 @@ +#include <linux/anon_inodes.h> +#include <linux/vmnotify.h> +#include <linux/syscalls.h> +#include <linux/file.h> +#include <linux/list.h> +#include <linux/poll.h> +#include <linux/slab.h> +#include <linux/swap.h> + +#define VMNOTIFY_MAX_FREE_THRESHOD 100 + +struct vmnotify_watch { +struct vmnotify_config config; + +struct mutex mutex; +bool pending; +struct vmnotify_event event; + +/* sampling */ +struct hrtimer timer; + +/* poll */ +wait_queue_head_t waitq; +}; + +static bool vmnotify_match (struct vmnotify_watch *watch,struct vmnotify_event *event) +{ +if (watch->config.type &VMNOTIFY_TYPE_FREE_THRESHOLD ) { +u64 threshold; + +if (!event->nr_avail_pages) +return false; + + threshold = event->nr_free_pages *100 / event->nr_avail_pages; +if (threshold > watch->config.free_threshold) +return false; + } + +return true; +} + +static void vmnotify_sample (struct vmnotify_watch *watch) +{ +struct vmnotify_event event; +struct sysinfo si; + +memset (&event,0 ,sizeof (event)); + + event.size =sizeof (event); + event.nr_free_pages =global_page_state (NR_FREE_PAGES ); + +si_meminfo (&si); + event.nr_avail_pages = si.totalram; + +#ifdef CONFIG_SWAP +si_swapinfo (&si); + event.nr_swap_pages = si.totalswap; +#endif + +if (!vmnotify_match (watch, &event)) +return ; + +mutex_lock (&watch->mutex); + + watch->pending = true; + +memcpy (&watch->event, &event,sizeof (event)); + +mutex_unlock (&watch->mutex); +} + +static enum hrtimer_restart vmnotify_timer_fn (struct hrtimer *hrtimer) +{ + struct vmnotify_watch *watch = container_of(hrtimer, struct vmnotify_watch, timer); +u64 sample_period = watch->config.sample_period_ns; + +vmnotify_sample (watch); + +hrtimer_forward_now (hrtimer,ns_to_ktime (sample_period)); + +wake_up (&watch->waitq); + +return HRTIMER_RESTART ; +} + +static void vmnotify_start_timer (struct vmnotify_watch *watch) +{ +u64 sample_period = watch->config.sample_period_ns; + +hrtimer_init (&watch->timer,CLOCK_MONOTONIC ,HRTIMER_MODE_REL ); + watch->timer.function = vmnotify_timer_fn; + +hrtimer_start (&watch->timer,ns_to_ktime (sample_period),HRTIMER_MODE_REL_PINNED ); +} + +static unsigned int vmnotify_poll (struct file *file,poll_table *wait) +{ +struct vmnotify_watch *watch = file->private_data; +unsigned int events =0 ; + +poll_wait (file, &watch->waitq, wait); + +mutex_lock (&watch->mutex); + +if (watch->pending) + events |=POLLIN ; + +mutex_unlock (&watch->mutex); + +return events; +} + +static ssize_t vmnotify_read (struct file *file,char __user *buf,size_t count,loff_t *ppos) +{ +struct vmnotify_watch *watch = file->private_data; +int ret =0 ; + +mutex_lock (&watch->mutex); + +if (!watch->pending) + goto out_unlock; + +if (copy_to_user (buf, &watch->event,sizeof (struct vmnotify_event ))) { + ret = -EFAULT ; + goto out_unlock; + } + + ret = watch->event.size; + + watch->pending = false; + +out_unlock: +mutex_unlock (&watch->mutex); + +return ret; +} + +static int vmnotify_release (struct inode *inode,struct file *file) +{ +struct vmnotify_watch *watch = file->private_data; + +hrtimer_cancel (&watch->timer); + +kfree (watch); + +return 0 ; +} + +static const struct file_operations vmnotify_fops = { + .poll = vmnotify_poll, + .read = vmnotify_read, + .release = vmnotify_release, +}; + +static struct vmnotify_watch *vmnotify_watch_alloc (void ) +{ +struct vmnotify_watch *watch; + + watch =kzalloc (sizeof *watch,GFP_KERNEL ); +if (!watch) +return NULL ; + +mutex_init (&watch->mutex); + +init_waitqueue_head (&watch->waitq); + +return watch; +} + +static int vmnotify_copy_config (struct vmnotify_config __user *uconfig, +struct vmnotify_config *config) +{ +int ret; + + ret =copy_from_user (config, uconfig,sizeof (struct vmnotify_config )); +if (ret) +return -EFAULT ; + +if (!config->type) +return -EINVAL ; + +if (config->type &VMNOTIFY_TYPE_SAMPLE ) { +if (config->sample_period_ns <NSEC_PER_MSEC ) +return -EINVAL ; + } + +if (config->type &VMNOTIFY_TYPE_FREE_THRESHOLD ) { +if (config->free_threshold >VMNOTIFY_MAX_FREE_THRESHOD ) +return -EINVAL ; + } + +return 0 ; +} + +SYSCALL_DEFINE1 (vmnotify_fd, + struct vmnotify_config __user *, uconfig) +{ +struct vmnotify_watch *watch; +struct file *file; +int err; +int fd; + + watch =vmnotify_watch_alloc (); +if (!watch) +return -ENOMEM ; + + err =vmnotify_copy_config (uconfig, &watch->config); +if (err) + goto err_free; + + fd =get_unused_fd_flags (O_RDONLY ); +if (fd <0 ) { + err = fd; + goto err_free; + } + + file =anon_inode_getfile ("[vmnotify]" , &vmnotify_fops, watch,O_RDONLY ); +if (IS_ERR (file)) { + err =PTR_ERR (file); + goto err_fd; + } + +fd_install (fd, file); + +if (watch->config.type &VMNOTIFY_TYPE_SAMPLE ) +vmnotify_start_timer (watch); + +return fd; + +err_fd: +put_unused_fd (fd); +err_free: +kfree (watch); +return err; +}tools/testing/vmnotify/vmnotify-test.c new file +68
-0@@ -0,0 +1,68 @@ +#include "../../../include/linux/vmnotify.h" + +#if defined(__x86_64__) +#include "../../../arch/x86/include/asm/unistd.h" +#endif + +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <stdio.h> +#include <poll.h> + +static int sys_vmnotify_fd (struct vmnotify_config *config) +{ + config->size =sizeof (*config); + +return syscall (__NR_vmnotify_fd, config); +} + +int main (int argc,char *argv[]) +{ +struct vmnotify_config config; +struct vmnotify_event event; +struct pollfd pollfd; +int i; +int fd; + + config = (struct vmnotify_config ) { + .type =VMNOTIFY_TYPE_SAMPLE |VMNOTIFY_TYPE_FREE_THRESHOLD , + .sample_period_ns =1000000000L , + .free_threshold =99 , + }; + + fd =sys_vmnotify_fd (&config); +if (fd <0 ) { +perror ("vmnotify_fd failed" ); +exit (1 ); + } + +for (i =0 ; i <10 ; i++) { + pollfd.fd = fd; + pollfd.events =POLLIN ; + +if (poll (&pollfd,1 ,-1 ) <0 ) { +perror ("poll failed" ); +exit (1 ); + } + +memset (&event,0 ,sizeof (event)); + +if (read (fd, &event,sizeof (event)) <0 ) { +perror ("read failed" ); +exit (1 ); + } + +printf ("VM event:\n" ); +printf ("\tsize=%lu\n" , event.size); +printf ("\tnr_avail_pages=%Lu\n" , event.nr_avail_pages); +printf ("\tnr_swap_pages=%Lu\n" , event.nr_swap_pages); +printf ("\tnr_free_pages=%Lu\n" , event.nr_free_pages); + } +if (close (fd) <0 ) { +perror ("close failed" ); +exit (1 ); + } + +return 0 ; +}Signature · 1 line
1.7.6.4
--
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>
Re: [RFC 2/3] vmscan hook
In reply to Minchan KimQuoted 4 lines · On Wed, 18 Jan 2012 08:08:01 +0900 Minchan Kim <[email protected]> wrote:
Quoted 4 lines
Quoted 4 lines
Quoted 3 lines
2. can't we measure page-in/page-out distance by recording something ?
Quoted 9 lines
Quoted 6 lines
Quoted 2 lines
I can't understand your point. What's relation does it with swapout prevent?
If distance between pageout -> pagein is short, it means thrashing. For example, recoding the timestamp when the
page(mapping, index)was paged-out, and check it at page-in.Our goal is prevent swapout. When we found thrashing, it's too late.
If you want to prevent swap-out, don't swapon any. That's all. Then, you can check the number of FILE_CACHE and have threshold.
Thanks,
-Kame
--
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>
Re: [RFC 1/3] /dev/low_mem_notify
In reply to Minchan KimQuoted 4 lines · Minchan Kim
I didn't look into your code(will do) but as I read description, still I don't convince we need really some process specific threshold like 99% I think application can know it by polling
/proc/meminfowithout this mechanism if they really want.
I'm not sure if we need arbitrary threshold either. However, we need to support the following cases:
- We're about to swap
- We're about to run out of memory
- We're about to start OOM killing
and I don't think your patch solves that. One possibility is to implement:
VMNOTIFY_TYPE_ABOUT_TO_SWAP
VMNOTIFY_TYPE_ABOUT_TO_OOM
VMNOTIFY_TYPE_ABOUT_TO_OOM_KILL
and maybe rip out support for arbitrary thresholds. Does that more reasonable?
As for polling /proc/meminfo, I'd much rather deliver stats as part of vmnotify_read() because it's easier to extend the ABI rather than adding new fields to /proc/meminfo.
Quoted 5 lines · Minchan Kim
I would like to notify when system has a trobule with memory pressure without some process specific threshold. Of course, applicatoin can't expect it.(ie, application can know system memory pressure by
/proc/meminfobut it can't know when swapout really happens). Kernel low mem notify have to give such notification to user space, I think.
It should be simple to add support for VMNOTIFY_TYPE_MEM_PRESSURE that uses your hooks.
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>
Re: [RFC 1/3] /dev/low_mem_notify
Quoted 9 lines · Pekka Enberg
Quoted 4 lines · Minchan Kim
I didn't look into your code(will do) but as I read description, still I don't convince we need really some process specific threshold like 99% I think application can know it by polling
/proc/meminfowithout this mechanism if they really want.I'm not sure if we need arbitrary threshold either. However, we need to support the following cases:
Quoted 7 lines
- We're about to swap
- We're about to run out of memory
- We're about to start OOM killing
and I don't think your patch solves that. One possibility is to implement:
I think my patch can extend it but your ABI looks good to me than my approach.
Quoted 4 lines
VMNOTIFY_TYPE_ABOUT_TO_SWAP
VMNOTIFY_TYPE_ABOUT_TO_OOM
VMNOTIFY_TYPE_ABOUT_TO_OOM_KILL
Yes. We can define some levels.
1. page cache reclaim
2. code page reclaim
3. anonymous page swap out
4. OOM kill.
Application might handle it differenlty by the memory pressure level.
Quoted 3 lines
and maybe rip out support for arbitrary thresholds. Does that more reasonable?
Currently, Nokia people seem to want process specific thresholds so we might need it.
Quoted 4 lines
As for polling
/proc/meminfo, I'd much rather deliver stats as part ofvmnotify_read()because it's easier to extend the ABI rather than adding new fields to/proc/meminfo.
Agree.
Quoted 10 lines · Minchan Kim
Quoted 5 lines
I would like to notify when system has a trobule with memory pressure without some process specific threshold. Of course, applicatoin can't expect it.(ie, application can know system memory pressure by
/proc/meminfobut it can't know when swapout really happens). Kernel low mem notify have to give such notification to user space, I think.It should be simple to add support for
VMNOTIFY_TYPE_MEM_PRESSUREthat uses your hooks.
Indeed.
Quoted 2 lines
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>
RE: [RFC 1/3] /dev/low_mem_notify
In reply to Pekka EnbergHi,
Just couple of observations, which maybe wrong below
Quoted 4 lines
-----Original Message-----
From: Pekka Enberg [mailto:[email protected]] On Behalf Of ext Pekka Enberg
Sent: 17 January, 2012 20:51
....
Quoted 5 lines
(quoted diff) +5
-0+struct vmnotify_config { + /* + * Size of the struct for ABI extensibility. + */ + __u32 size;
Review
Quoted 10 lines
(quoted diff) +10
-0+ + /* + * Notification type bitmask + */ + __u64 type; + + /* + * Free memory threshold in percentages [1..99] + */ + __u32 free_threshold;
Would be possible to not use percents for thesholds? Accounting in pages even not so difficult to user-space.
Also, looking on vmnotify_match I understand that events propagated to user-space only in case threshold trigger change state from 0 to 1 but not back, 1-> 0 is very useful event as well.
Would be possible to use for threshold pointed value(s) e.g. according to enum zone_state_item, because kinds of memory to track could be different? E.g. to tracking paging activity NR_ACTIVE_ANON and NR_ACTIVE_FILE could be interesting, not only free.
Quoted 7 lines
(quoted diff) +7
-0+ + /* + * Sample period in nanoseconds + */ + __u64 sample_period_ns; +}; +
....
Review
Quoted 10 lines
(quoted diff) +10
-0+struct vmnotify_event { + /* Size of the struct for ABI extensibility. */ + __u32 size; + + __u64 nr_avail_pages; + + __u64 nr_swap_pages; + + __u64 nr_free_pages; +};
Two fields here most likely session-constant, (nr_avail_pages and nr_swap_pages), seems not much sense to report them in every event. If we have memory/swap hotplug user-space can use sysinfo() call.
Quoted 1 line
+static void
vmnotify_sample(struct vmnotify_watch *watch){
...
Review
Quoted 8 lines
(quoted diff) +8
-0+ si_meminfo(&si); + event.nr_avail_pages = si.totalram; + +#ifdef CONFIG_SWAP + si_swapinfo(&si); + event.nr_swap_pages = si.totalswap; +#endif +
Why not to use global_page_state() directly? si_meminfo() and especial si_swapinfo are quite expensive call.
Review
Quoted 9 lines
(quoted diff) +4
-0+static void vmnotify_start_timer(struct vmnotify_watch *watch) { + u64 sample_period = watch->config.sample_period_ns; + + hrtimer_init(&watch->timer, CLOCK_MONOTONIC,
HRTIMER_MODE_REL);(quoted diff) +4
-0+ watch->timer.function = vmnotify_timer_fn; + + hrtimer_start(&watch->timer, ns_to_ktime(sample_period), +HRTIMER_MODE_REL_PINNED); }
Do I understand correct you allocate timer for every user-space client and propagate events every pointed interval?
What will happened with system if we have a timer but need to turn CPU off? The timer must not be a reason to wakeup if user-space is sleeping.
--
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>
Re: [RFC 1/3] /dev/low_mem_notify
Quoted 2 lines · On Wed, Jan 18, 2012 at 11:06 AM, <[email protected]> wrote:
Would be possible to not use percents for thesholds? Accounting in pages even not so difficult to user-space.
How does that work with memory hotplug?
Quoted 8 lines · On Wed, Jan 18, 2012 at 11:06 AM, <[email protected]> wrote:
Also, looking on
vmnotify_matchI understand that events propagated to user-space only in case threshold trigger change state from 0 to 1 but not back, 1-> 0 is very useful event as well.Would be possible to use for threshold pointed value(s) e.g. according to enum
zone_state_item, because kinds of memory to track could be different? E.g. to tracking paging activityNR_ACTIVE_ANONandNR_ACTIVE_FILEcould be interesting, not only free.
I don't think there's anything in the ABI that would prevent that.
Quoted 6 lines
Quoted 6 lines
(quoted diff) +6
-0+struct vmnotify_event { + /* Size of the struct for ABI extensibility. */ + __u32 size; + + __u64 nr_avail_pages; +
Quoted 8 lines
mm/low_mem_notify.c line 12
Quoted 4 lines
mm/low_mem_notify.c new file +4
-0+__u64 nr_swap_pages; + +__u64 nr_free_pages; +};Two fields here most likely session-constant, (
nr_avail_pagesandnr_swap_pages), seems not much sense to report them in every event. If we have memory/swap hotplug user-space can usesysinfo()call.
I actually changed the ABI to look like this:
struct vmnotify_event {
/*
* Size of the struct for ABI extensibility.
*/
__u32 size;
__u64 attrs;
__u64 attr_values[];
};So userspace can decide which fields to include in notifications.
Quoted 13 lines · On Wed, Jan 18, 2012 at 11:06 AM, <[email protected]> wrote:
Quoted 1 line
+static void
vmnotify_sample(struct vmnotify_watch *watch){...
Review
Quoted 8 lines
(quoted diff) +8
-0+ si_meminfo(&si); + event.nr_avail_pages = si.totalram; + +#ifdef CONFIG_SWAP + si_swapinfo(&si); + event.nr_swap_pages = si.totalswap; +#endif +Why not to use
global_page_state()directly?si_meminfo()and especialsi_swapinfoare quite expensive call.
Sure, we can do that. Feel free to send a patch :-).
Quoted 6 lines
Quoted 6 lines
(quoted diff) +4
-0+static void vmnotify_start_timer(struct vmnotify_watch *watch) { + u64 sample_period = watch->config.sample_period_ns; + + hrtimer_init(&watch->timer, CLOCK_MONOTONIC,
HRTIMER_MODE_REL);
+watch->timer.function=vmnotify_timer_fn;
Quoted 8 lines
Review
Quoted 3 lines
(quoted diff) +3
-0+ + hrtimer_start(&watch->timer, ns_to_ktime(sample_period), +HRTIMER_MODE_REL_PINNED); }Do I understand correct you allocate timer for every user-space client and propagate events every pointed interval? What will happened with system if we have a timer but need to turn CPU off? The timer must not be a reason to wakeup if user-space is sleeping.
No idea what happens. The sampling code is just a proof of concept thing and I expect it to be buggy as hell. :-)
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>
RE: [RFC 1/3] /dev/low_mem_notify
Quoted 4 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of ext Pekka Enberg
Sent: 18 January, 2012 11:16
...
Quoted 5 lines
Quoted 1 line
Would be possible to not use percents for thesholds? Accounting in pages
even
Quoted 1 line
not so difficult to user-space.
How does that work with memory hotplug?
Not worse than %%. For example you had 10% free memory threshold for 512 MB RAM meaning 51.2 MB in absolute number.
Then hotplug turned off 256 MB, you for sure must update threshold for %% because these 10% for 25.6 MB most likely will be not suitable for different operating mode. Using pages makes calculations must simpler.
Quoted 5 lines · On Wed, Jan 18, 2012 at 11:06 AM, <[email protected]> wrote:
Quoted 3 lines
Also, looking on
vmnotify_matchI understand that events propagated to user-space only in case threshold trigger change state from 0 to 1 but not back, 1-> 0 is very useful event as well
(*)
Quoted 9 lines
Quoted 3 lines
Would be possible to use for threshold pointed value(s) e.g. according to enum
zone_state_item, because kinds of memory to track could bedifferent?
Quoted 1 line
E.g. to tracking paging activity
NR_ACTIVE_ANONandNR_ACTIVE_FILEcould be
Quoted 1 line
interesting, not only free.
I don't think there's anything in the ABI that would prevent that.
If this statement also related my question (*) I have to point need to track attributes history, otherwise user-space will be constantly kicked with updates.
Quoted 13 lines
I actually changed the ABI to look like this:
struct vmnotify_event { /* * Size of the struct for ABI extensibility. */ __u32 size; __u64 attrs; __u64 attr_values[]; };
Quoted 1 line
So userspace can decide which fields to include in notifications.
Good. But how you can provide current status of attributes to user-space? Need to have read() call support to deliver all supported attr_values[] on demand.
Quoted 11 lines
Quoted 9 lines
Review
Quoted 6 lines
(quoted diff) +6
-0+ +#ifdef CONFIG_SWAP + si_swapinfo(&si); + event.nr_swap_pages = si.totalswap; +#endif +Why not to use
global_page_state()directly?si_meminfo()and especialsi_swapinfoare quite expensive call.Sure, we can do that. Feel free to send a patch :-).
When I see code because from emails it is quite difficult to understand.
For short-term I need to focus on integration "memnotify" version internally which is kind of work for me already and provides all required interfaces n9 needs.
Btw, when API starts to work with pointed thresholds logically it is not anymore low_mem_notify, you need to invent some other name.
Quoted 4 lines
No idea what happens. The sampling code is just a proof of concept thing and I expect it to be buggy as hell. :-)
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>
Re: [RFC 1/3] /dev/low_mem_notify
Quoted 9 lines · On Wed, Jan 18, 2012 at 11:41 AM, <[email protected]> wrote:
Quoted 4 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of ext Pekka Enberg
Sent: 18 January, 2012 11:16...
Quoted 4 lines
Quoted 1 line
Would be possible to not use percents for thesholds? Accounting in pages
even
Quoted 1 line
not so difficult to user-space.
Quoted 7 lines
Quoted 1 line
How does that work with memory hotplug?
Not worse than %%. For example you had 10% free memory threshold for 512 MB RAM meaning 51.2 MB in absolute number. Then hotplug turned off 256 MB, you for sure must update threshold for %% because these 10% for 25.6 MB most likely will be not suitable for different operating mode.
Using pages makes calculations must simpler.
Right. Does threshold in percentages make any sense then? Is it enough to use number of free pages?
Quoted 10 lines · On Wed, Jan 18, 2012 at 11:06 AM, <[email protected]> wrote:
Quoted 3 lines
Quoted 3 lines
Also, looking on
vmnotify_matchI understand that events propagated to user-space only in case threshold trigger change state from 0 to 1 but not back, 1-> 0 is very useful event as well(*)
Quoted 5 lines
Quoted 3 lines
Would be possible to use for threshold pointed value(s) e.g. according to enum
zone_state_item, because kinds of memory to track could bedifferent?
Quoted 1 line
E.g. to tracking paging activity
NR_ACTIVE_ANONandNR_ACTIVE_FILE
Quoted 8 lines
Quoted 4 lines
could be
Quoted 1 line
interesting, not only free.
I don't think there's anything in the ABI that would prevent that.
If this statement also related my question (*) I have to point need to track attributes history, otherwise user-space will be constantly kicked with updates.
Well sure, I think it makes sense to support state change to both directions.
Quoted 4 lines
When I see code because from emails it is quite difficult to understand. For short-term I need to focus on integration "memnotify" version internally which is kind of work for me already and provides all required interfaces n9 needs.
Sure. I'm only talking about mainline here.
Quoted 1 line
Btw, when API starts to work with pointed thresholds logically it is not
Definitely, it's about generic VM event notification now.
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>
RE: [RFC 1/3] /dev/low_mem_notify
Quoted 4 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of ext Pekka Enberg
Sent: 18 January, 2012 12:40
...
Quoted 9 lines
Quoted 4 lines
Not worse than %%. For example you had 10% free memory threshold for 512 MB RAM meaning 51.2 MB in absolute number. Then hotplug turned off 256 MB, you for sure must update threshold for %% because these 10% for 25.6 MB most likely will be not suitable for different operating
mode.
Quoted 1 line
Using pages makes calculations must simpler.
Right. Does threshold in percentages make any sense then? Is it enough to use number of free pages?
Paul Mundt noticed that and we stopped use percentage in 2006 for n770 update. He was right.
Percents are useless and do not correlate with other kernel APIs like sysinfo().
--
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>
Re: [RFC 2/3] vmscan hook
In reply to KAMEZAWA HiroyukiQuoted 8 lines · KAMEZAWA Hiroyuki
Quoted 5 lines · On Wed, 18 Jan 2012 08:08:01 +0900 Minchan Kim<[email protected]> wrote:
Quoted 5 lines
Quoted 4 lines
Quoted 1 line
2. can't we measure page-in/page-out distance by recording something ?
I can't understand your point. What's relation does it with swapout prevent?
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
If distance between pageout -> pagein is short, it means thrashing. For example, recoding the timestamp when the
page(mapping, index)was paged-out, and check it at page-in.Our goal is prevent swapout. When we found thrashing, it's too late.
If you want to prevent swap-out, don't swapon any. That's all. Then, you can check the number of
FILE_CACHEand have threshold.
I think you are getting hung up on a word here.
As I understand it, the goal is to push out the point where we start doing heavier swap IO, allowing us to overcommit memory more heavily before things start really slowing down.
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>
Re: [RFC 1/3] /dev/low_mem_notify
In reply to [email protected]Quoted 2 lines · On 01/18/2012 04:06 AM, [email protected] wrote:
Would be possible to use for threshold pointed value(s) e.g. according to enum
zone_state_item, because kinds of memory to track could be different? E.g. to tracking paging activityNR_ACTIVE_ANONandNR_ACTIVE_FILEcould be interesting, not only free.
That seems like a horrible idea, because there is no guarantee that the kernel will continue to use NR_ACTIVE_ANON and NR_ACTIVE_FILE internally in the future.
What is exported to userspace must be somewhat independent of the specifics of how the kernel implements things internally.
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>
Re: [RFC 1/3] /dev/low_mem_notify
Quoted 6 lines · Rik van Riel
That seems like a horrible idea, because there is no guarantee that the kernel will continue to use
NR_ACTIVE_ANONandNR_ACTIVE_FILEinternally in the future.What is exported to userspace must be somewhat independent of the specifics of how the kernel implements things internally.
Exactly, that's what I'm also interested in.
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>
Re: [RFC 1/3] /dev/low_mem_notify
In reply to [email protected]Quoted 9 lines · On 01/18/2012 12:44 PM, [email protected] wrote:
Quoted 4 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of ext Pekka Enberg
Sent: 18 January, 2012 12:40...
Quoted 4 lines
Quoted 4 lines
Not worse than %%. For example you had 10% free memory threshold for 512 MB RAM meaning 51.2 MB in absolute number. Then hotplug turned off 256 MB, you for sure must update threshold for %% because these 10% for 25.6 MB most likely will be not suitable for different operating
Quoted 7 lines
Quoted 4 lines
mode.
Quoted 1 line
Using pages makes calculations must simpler.
Right. Does threshold in percentages make any sense then? Is it enough to use number of free pages?
Paul Mundt noticed that and we stopped use percentage in 2006 for n770 update. He was right.
Percents are useless and do not correlate with other kernel APIs likesysinfo().
I believe that it will be best if the kernel publishes an ideal number_of_free_pages (in /proc/meminfo or whatever). Such number is easy to work with since this is what applications do, they free pages. Applications will be able to refer to this number from their garbage collector, or before allocating memory also if they did not get a notification, and it is also useful if several applications free memory at the same time.
Ronen.
Quoted 6 lines
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
--
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>
Re: [RFC 2/3] vmscan hook
In reply to Rik van RielQuoted 15 lines · On Wed, 18 Jan 2012 09:17:17 -0500 Rik van Riel <[email protected]> wrote:
Quoted 14 lines · KAMEZAWA Hiroyuki
Quoted 10 lines · On Wed, 18 Jan 2012 08:08:01 +0900 Minchan Kim<[email protected]> wrote:
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
2. can't we measure page-in/page-out distance by recording something ?
I can't understand your point. What's relation does it with swapout prevent?
If distance between pageout -> pagein is short, it means thrashing. For example, recoding the timestamp when the
page(mapping, index)was paged-out, and check it at page-in.Our goal is prevent swapout. When we found thrashing, it's too late.
Quoted 9 lines
Quoted 2 lines
If you want to prevent swap-out, don't swapon any. That's all. Then, you can check the number of
FILE_CACHEand have threshold.I think you are getting hung up on a word here.
As I understand it, the goal is to push out the point where we start doing heavier swap IO, allowing us to overcommit memory more heavily before things start really slowing down.
Yes.
Hmm, considering that the issue is slow down,
time values as
- 'cpu time used for memory reclaim'
- 'latency of page allocation'
- 'application execution speed' ?
may be a better score to see rather than just seeing lru's stat.
Thanks,
-Kame
--
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>
Re: [RFC 1/3] /dev/low_mem_notify
In reply to Ronen HodQuoted 1 line · Ronen Hod
I believe that it will be best if the kernel publishes an ideal
number_of_free_pages(in/proc/meminfoor whatever). Such number is easy to work with since this is what applications do, they free pages. Applications will be able to refer to this number from their garbage collector, or before allocating memory also if they did not get a notification, and it is also useful if several applications free memory at the same time.
Isn't
/proc/sys/vm/min_free_kbytes
pretty much just that?
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>
RE: [RFC 1/3] /dev/low_mem_notify
In reply to [email protected]Quoted 3 lines · On Wed, 18 Jan 2012, [email protected] wrote:
Paul Mundt noticed that and we stopped use percentage in 2006 for n770 update. He was right.
Percents are useless and do not correlate with other kernel APIs likesysinfo().
I changed the code to use number of pages. Thanks!
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>
Re: [RFC 1/3] /dev/low_mem_notify
In reply to Pekka EnbergQuoted 10 lines · Pekka Enberg
Quoted 1 line · Ronen Hod
I believe that it will be best if the kernel publishes an ideal
number_of_free_pages(in/proc/meminfoor whatever). Such number is easy to work with since this is what applications do, they free pages. Applications will be able to refer to this number from their garbage collector, or before allocating memory also if they did not get a notification, and it is also useful if several applications free memory at the same time.Isn't
/proc/sys/vm/min_free_kbytespretty much just that?
Pekka
Would you suggest to use min_free_kbytes as the threshold for sending low_memory_notifications to applications, and separately as a target value for the applications' memory giveaway?
Thanks, Ronen.
--
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>
Re: [RFC 1/3] /dev/low_mem_notify
Quoted 9 lines · Ronen Hod
Quoted 9 lines
Quoted 6 lines
I believe that it will be best if the kernel publishes an ideal
number_of_free_pages(in/proc/meminfoor whatever). Such number is easy to work with since this is what applications do, they free pages. Applications will be able to refer to this number from their garbage collector, or before allocating memory also if they did not get a notification, and it is also useful if several applications free memory at the same time.Isn't
Quoted 7 lines
Quoted 3 lines
/proc/sys/vm/min_free_kbytespretty much just that?
Would you suggest to use
min_free_kbytesas the threshold for sendinglow_memory_notificationsto applications, and separately as a target value for the applications' memory giveaway?
I'm not saying that the kernel should use it directly but it seems like the kind of "ideal number of free pages" threshold you're suggesting. So userspace can read that value and use it as the "number of free pages" threshold for VM events, no?
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>
Re: [RFC 1/3] /dev/low_mem_notify
Quoted 11 lines · Pekka Enberg
Quoted 10 lines · Ronen Hod
Quoted 10 lines
Quoted 6 lines
I believe that it will be best if the kernel publishes an ideal
number_of_free_pages(in/proc/meminfoor whatever). Such number is easy to work with since this is what applications do, they free pages. Applications will be able to refer to this number from their garbage collector, or before allocating memory also if they did not get a notification, and it is also useful if several applications free memory at the same time.Isn't
/proc/sys/vm/min_free_kbytes
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
pretty much just that?
Would you suggest to use
min_free_kbytesas the threshold for sendinglow_memory_notificationsto applications, and separately as a target value for the applications' memory giveaway?I'm not saying that the kernel should use it directly but it seems like the kind of "ideal number of free pages" threshold you're suggesting. So userspace can read that value and use it as the "number of free pages" threshold for VM events, no?
Yes, I like it. The rules of the game are simple and consistent all over, be it the alert threshold, voluntary poling by the apps, and for concurrent work by several applications. Well, as long as it provides a good indication for low_mem_pressure.
Thanks, Ronen.
Quoted 2 lines
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>
RE: [RFC 1/3] /dev/low_mem_notify
Quoted 4 lines
-----Original Message-----
From: ext Ronen Hod [mailto:[email protected]]
Sent: 19 January, 2012 11:20
To: Pekka Enberg
...
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Isn't
/proc/sys/vm/min_free_kbytesQuoted 8 lines
Quoted 4 lines
Quoted 1 line
pretty much just that?
Would you suggest to use
min_free_kbytesas the threshold for sendinglow_memory_notificationsto applications, and separately as a target value for the applications' memory giveaway?I'm not saying that the kernel should use it directly but it seems like the kind of "ideal number of free pages" threshold you're suggesting. So userspace can read that value and use it as the "number of free pages" threshold for VM events, no?
Quoted 4 lines
Yes, I like it. The rules of the game are simple and consistent all over, be it the alert threshold, voluntary poling by the apps, and for concurrent work by several applications.
Well, as long as it provides a good indication forlow_mem_pressure.
For me it doesn't look that have much sense. min_free_kbytes could be set from user-space (or auto-tuned by kernel) to keep some amount of memory available for GFP_ATOMIC allocations. In case situation comes under pointed level kernel will reclaim memory from e.g. caches.
Quoted 1 line
From potential user point of view the proposed API has number of lacks which would be nice to have implemented:
1. rename this API from low_mem_pressure to something more related to notification and memory situation in system: memory_pressure, memnotify, memory_level etc. The word "low" is misleading here
2. API must use deferred timers to prevent use-time impact. Deferred timer will be triggered only in case HW event or non-deferrable timer, so if device sleeps timer might be skipped and that is what expected for user-space
3. API should be tunable for propagate changes when level is Up or Down, maybe both ways.
4. to avoid triggering too much events probably has sense to filter according to amount of change but that is optional. If subscriber set timer to 1s the amount of events should not be very big.
5. API must provide interface to request parameters e.g. available swap or free memory just to have some base.
6. I do not understand how work with attributes performed ( ) but it has sense to use mask and fill requested attributes using mask and callback table i.e. if free pages requested - they are reported, otherwise not.
7. would have sense to backport couple of attributes from memnotify.c
I can submit couple of patches if some of proposals looks sane for everyone.
--
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>
Re: [RFC 1/3] /dev/low_mem_notify
Quoted 2 lines · On Thu, Jan 19, 2012 at 12:53 PM, <[email protected]> wrote:
From potential user point of view the proposed API has number of lacks which would be nice to have implemented:
Quoted 6 lines · On Thu, Jan 19, 2012 at 12:53 PM, <[email protected]> wrote:
From potential user point of view the proposed API has number of lacks which would be nice to have implemented:
1. rename this API from
low_mem_pressureto something more related to notification and memory situation in system:memory_pressure, memnotify,memory_leveletc. The word "low" is misleading here
The thing is called vmevent:
http://git.kernel.org/?p=linux/kernel/git/penberg/linux.git;a=shortlog;h=refs/heads/vmevent/core
[penberg@tux ~]$ vi
[penberg@tux ~]$ cat email
Quoted 6 lines · On Thu, Jan 19, 2012 at 12:53 PM, <[email protected]> wrote:
From potential user point of view the proposed API has number of lacks which would be nice to have implemented:
1. rename this API from
low_mem_pressureto something more related to notification and memory situation in system:memory_pressure, memnotify,memory_leveletc. The word "low" is misleading here
The thing is called vmevent:
http://git.kernel.org/?p=linux/kernel/git/penberg/linux.git;a=shortlog;h=refs/heads/vmevent/core
I haven't used "low mem" at all in the patches.
Quoted 3 lines · On Thu, Jan 19, 2012 at 12:53 PM, <[email protected]> wrote:
2. API must use deferred timers to prevent use-time impact. Deferred timer will be triggered only in case HW event or non-deferrable timer, so if device sleeps timer might be skipped and that is what expected for user-space
I'm currently looking at the possibility of hooking VM events to perf which also uses hrtimers. Can't we make hrtimers do the right thing?
Quoted 2 lines · On Thu, Jan 19, 2012 at 12:53 PM, <[email protected]> wrote:
3. API should be tunable for propagate changes when level is Up or Down, maybe both ways.
Agreed.
Quoted 3 lines · On Thu, Jan 19, 2012 at 12:53 PM, <[email protected]> wrote:
4. to avoid triggering too much events probably has sense to filter according to amount of change but that is optional. If subscriber set timer to 1s the amount of events should not be very big.
Agreed.
Quoted 2 lines · On Thu, Jan 19, 2012 at 12:53 PM, <[email protected]> wrote:
5. API must provide interface to request parameters e.g. available swap or free memory just to have some base.
The current ABI already supports that. You can specify which attributes you're interested in and they will be delivered as part of th event.
Quoted 3 lines · On Thu, Jan 19, 2012 at 12:53 PM, <[email protected]> wrote:
6. I do not understand how work with attributes performed ( ) but it has sense to use mask and fill requested attributes using mask and callback table i.e. if free pages requested - they are reported, otherwise not.
That's how it works now in the git tree.
Quoted 3 lines · On Thu, Jan 19, 2012 at 12:53 PM, <[email protected]> wrote:
7. would have sense to backport couple of attributes from
memnotify.cI can submit couple of patches if some of proposals looks sane for everyone.
Feel free to do that.
I'm currently looking at how to support Minchan's non-sampled events. It seems to me integrating with perf would be nice because we could simply use tracepoints 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>
RE: [RFC 1/3] /dev/low_mem_notify
Quoted 4 lines
-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf Of ext Pekka Enberg
Sent: 19 January, 2012 13:08
...
Quoted 5 lines
Quoted 3 lines
1. rename this API from
low_mem_pressureto something more related to notification and memory situation in system:memory_pressure, memnotify,memory_leveletc. The word "low" is misleading hereThe thing is called vmevent:
Yes, I see it. But I was a bit confused with vmnotify_fops and was sure it is mapped through dev. Now it anonymous inode.
Quoted 9 lines · On Thu, Jan 19, 2012 at 12:53 PM, <[email protected]> wrote:
Quoted 4 lines
2. API must use deferred timers to prevent use-time impact. Deferred timer will be triggered only in case HW event or non-deferrable timer, so if device sleeps timer might be skipped and that is what expected for user-space
I'm currently looking at the possibility of hooking VM events to perf which also uses hrtimers. Can't we make hrtimers do the right thing?
I had no answer for this question. According to hrtimer_cpu_notify the cpu state is tracked but timer may set HW event to wake up. In this case use-time will be affected due to you will have too much HW events and reasons to wakeup.
At least powertop reports hrtimers in relation to <kernel core> as an activities sources.
Quoted 12 lines · On Thu, Jan 19, 2012 at 12:53 PM, <[email protected]> wrote:
Quoted 2 lines
3. API should be tunable for propagate changes when level is Up or Down, maybe both ways.
Agreed.
Quoted 3 lines · On Thu, Jan 19, 2012 at 12:53 PM, <[email protected]> wrote:
4. to avoid triggering too much events probably has sense to filter according to amount of change but that is optional. If subscriber set timer to 1s the amount of events should not be very big.
Quoted 8 lines
Agreed.
Quoted 2 lines · On Thu, Jan 19, 2012 at 12:53 PM, <[email protected]> wrote:
5. API must provide interface to request parameters e.g. available swap or free memory just to have some base.
The current ABI already supports that. You can specify which attributes you're interested in and they will be delivered as part of th event.
But you have in vmnotify.h suspicious free_pages_threshold field.
Quoted 8 lines · On Thu, Jan 19, 2012 at 12:53 PM, <[email protected]> wrote:
Quoted 3 lines
6. I do not understand how work with attributes performed ( ) but it has sense to use mask and fill requested attributes using mask and callback table i.e. if free pages requested - they are reported, otherwise
not.
That's how it works now in the git tree.
Vmnotify.c has vmnotify_watch_event which collects fixed set of parameters.
Quoted 3 lines
I'm currently looking at how to support Minchan's non-sampled events. It seems to me integrating with perf would be nice because we could simply use tracepoints for this.
If tracepoints not jeopardize use time has sense to do it.
Quoted 2 lines
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>
Re: [RFC 1/3] /dev/low_mem_notify
Quoted 4 lines · On Thu, Jan 19, 2012 at 1:54 PM, <[email protected]> wrote:
Quoted 2 lines
The current ABI already supports that. You can specify which attributes you're interested in and they will be delivered as part of th event.
But you have in
vmnotify.hsuspiciousfree_pages_thresholdfield.
Aah, I was actually talking about the events userspace _reads_.
The free_pages_threshold field is only used if VMEVENT_TYPE_FREE_THRESHOLD bit is set. It should be cleaned up a bit but it in theory it supports watching other attributes as well. I've postponed the cleanup until I've figured out whether we can use perf which would make the whole syscall go away.
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>
Re: [RFC 1/3] /dev/low_mem_notify
In reply to [email protected]Quoted 9 lines · On Thu, Jan 19, 2012 at 1:54 PM, <[email protected]> wrote:
Quoted 7 lines · On Thu, Jan 19, 2012 at 12:53 PM, <[email protected]> wrote:
Quoted 3 lines
6. I do not understand how work with attributes performed ( ) but it has sense to use mask and fill requested attributes using mask and callback table i.e. if free pages requested - they are reported, otherwise
not.
That's how it works now in the git tree.
Vmnotify.chasvmnotify_watch_eventwhich collects fixed set of parameters.
That's would be a bug. We should check event_attrs like we do for NR_SWAP_PAGES.
--
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>
Re: [RFC 2/3] vmscan hook
In reply to KAMEZAWA HiroyukiQuoted 32 lines · KAMEZAWA Hiroyuki
Quoted 15 lines · On Wed, 18 Jan 2012 09:17:17 -0500 Rik van Riel<[email protected]> wrote:
Quoted 14 lines · KAMEZAWA Hiroyuki
Quoted 10 lines · On Wed, 18 Jan 2012 08:08:01 +0900 Minchan Kim<[email protected]> wrote:
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
2. can't we measure page-in/page-out distance by recording something ?
I can't understand your point. What's relation does it with swapout prevent?
If distance between pageout -> pagein is short, it means thrashing.
For example, recoding the timestamp when thepage(mapping, index)was paged-out, and check it at page-in.Our goal is prevent swapout. When we found thrashing, it's too late.
Quoted 9 lines
Quoted 2 lines
If you want to prevent swap-out, don't swapon any. That's all. Then, you can check the number of
FILE_CACHEand have threshold.I think you are getting hung up on a word here.
As I understand it, the goal is to push out the point where we start doing heavier swap IO, allowing us to overcommit memory more heavily before things start really slowing down.
Yes.
Hmm, considering that the issue is slow down,
Quoted 7 lines
time values as
- 'cpu time used for memory reclaim'
- 'latency of page allocation'
- 'application execution speed' ?may be a better score to see rather than just seeing lru's stat.
I believe those all qualify as "too late".
We want to prevent things from becoming bad, for as long as we (easily) can.
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>
Re: [RFC 2/3] vmscan hook
Quoted 39 lines · On Thu, 19 Jan 2012 09:42:59 -0500 Rik van Riel <[email protected]> wrote:
Quoted 38 lines · KAMEZAWA Hiroyuki
Quoted 15 lines · On Wed, 18 Jan 2012 09:17:17 -0500 Rik van Riel<[email protected]> wrote:
Quoted 14 lines · KAMEZAWA Hiroyuki
Quoted 10 lines · On Wed, 18 Jan 2012 08:08:01 +0900 Minchan Kim<[email protected]> wrote:
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
2. can't we measure page-in/page-out distance by recording something ?
I can't understand your point. What's relation does it with swapout prevent?
If distance between pageout -> pagein is short, it means thrashing.
For example, recoding the timestamp when thepage(mapping, index)was paged-out, and check it at page-in.Our goal is prevent swapout. When we found thrashing, it's too late.
Quoted 9 lines
Quoted 2 lines
If you want to prevent swap-out, don't swapon any. That's all. Then, you can check the number of
FILE_CACHEand have threshold.I think you are getting hung up on a word here.
As I understand it, the goal is to push out the point where we start doing heavier swap IO, allowing us to overcommit memory more heavily before things start really slowing down.
Yes.
Hmm, considering that the issue is slow down,
time values as
- 'cpu time used for memory reclaim'
- 'latency of page allocation'
- 'application execution speed' ?
Quoted 7 lines
Quoted 1 line
may be a better score to see rather than just seeing lru's stat.
I believe those all qualify as "too late".
We want to prevent things from becoming bad, for as long as we (easily) can.
Hmm, then some threshold-notifier interface will be required. Problem is how to know free + page_can_be_freed_without_risk.
Thanks,
-Kame
--
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>
Re: [RFC 1/3] /dev/low_mem_notify
In reply to [email protected]Quoted 23 lines · On Thu, Jan 19, 2012 at 10:53:29AM +0000, [email protected] wrote:
Quoted 4 lines
-----Original Message-----
From: ext Ronen Hod [mailto:[email protected]]
Sent: 19 January, 2012 11:20
To: Pekka Enberg...
Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Isn't
/proc/sys/vm/min_free_kbytesQuoted 8 lines
Quoted 4 lines
Quoted 1 line
pretty much just that?
Would you suggest to use
min_free_kbytesas the threshold for sendinglow_memory_notificationsto applications, and separately as a target value for the applications' memory giveaway?I'm not saying that the kernel should use it directly but it seems like the kind of "ideal number of free pages" threshold you're suggesting. So userspace can read that value and use it as the "number of free pages" threshold for VM events, no?
Quoted 4 lines
Yes, I like it. The rules of the game are simple and consistent all over, be it the alert threshold, voluntary poling by the apps, and for concurrent work by several applications.
Well, as long as it provides a good indication forlow_mem_pressure.
Quoted 6 lines
For me it doesn't look that have much sense.
min_free_kbytescould be set from user-space (or auto-tuned by kernel) to keep some amount of memory available forGFP_ATOMICallocations. In case situation comes under pointed level kernel will reclaim memory from e.g. caches.Quoted 1 line
From potential user point of view the proposed API has number of lacks which would be nice to have implemented:
1. rename this API from
low_mem_pressureto something more related to notification and memory situation in system:memory_pressure, memnotify,memory_leveletc. The word "low" is misleading here
2. API must use deferred timers to prevent use-time impact. Deferred timer will be triggered only in case HW event or non-deferrable timer, so if device sleeps timer might be skipped and that is what expected for user-space
Having userspace specify the "sample period" for low memory notification makes no sense. The frequency of notifications is a function of the memory pressure.
Quoted 5 lines
3. API should be tunable for propagate changes when level is Up or Down, maybe both ways.
4. to avoid triggering too much events probably has sense to filter according to amount of change but that is optional. If subscriber set timer to 1s the amount of events should not be very big.
5. API must provide interface to request parameters e.g. available swap or free memory just to have some base.
It would make the interface easier to use if it provided the number of pages to free, in the notification (kernel can calculate that as the delta between current_free_pages -> comfortable_free_pages relative to process RSS).
Quoted 4 lines
6. I do not understand how work with attributes performed ( ) but it has sense to use mask and fill requested attributes using mask and callback table i.e. if free pages requested - they are reported, otherwise not.
7. would have sense to backport couple of attributes frommemnotify.cI can submit couple of patches if some of proposals looks sane for everyone.
--
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>
Re: [RFC 1/3] /dev/low_mem_notify
In reply to Pekka EnbergQuoted 9 lines · Pekka Enberg
Hello,
Ok, so here's a proof of concept patch that implements sample-base per-process free threshold VM event watching using perf-like syscall ABI. I'd really like to see something like this that's much more extensible and clean than the /dev based ABIs that people have proposed so far.
Pekka
What is the practical advantage of a syscall, again?
--
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>
Re: [RFC 1/3] /dev/low_mem_notify
Quoted 1 line · Marcelo Tosatti
What is the practical advantage of a syscall, again?
Why do you ask? The advantage for this particular case is not needing to add ioctls() for configuration and keeping the file read/write ABI simple.
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>
Re: [RFC 1/3] /dev/low_mem_notify
In reply to Marcelo TosattiQuoted 32 lines · Marcelo Tosatti
Quoted 21 lines · On Thu, Jan 19, 2012 at 10:53:29AM +0000, [email protected] wrote:
Quoted 4 lines
-----Original Message-----
From: ext Ronen Hod [mailto:[email protected]]
Sent: 19 January, 2012 11:20
To: Pekka Enberg...
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Isn't
/proc/sys/vm/min_free_kbytespretty much just that?
Would you suggest to use
min_free_kbytesas the threshold for sendinglow_memory_notificationsto applications, and separately as a target value for the applications' memory giveaway?Quoted 8 lines
Quoted 4 lines
I'm not saying that the kernel should use it directly but it seems like the kind of "ideal number of free pages" threshold you're suggesting. So userspace can read that value and use it as the "number of free pages" threshold for VM events, no?
Yes, I like it. The rules of the game are simple and consistent all over, be it the alert threshold, voluntary poling by the apps, and for concurrent work by several applications.
Well, as long as it provides a good indication forlow_mem_pressure.Quoted 6 lines
For me it doesn't look that have much sense.
min_free_kbytescould be set from user-space (or auto-tuned by kernel) to keep some amount of memory available forGFP_ATOMICallocations. In case situation comes under pointed level kernel will reclaim memory from e.g. caches.Quoted 1 line
From potential user point of view the proposed API has number of lacks which would be nice to have implemented:
1. rename this API from
low_mem_pressureto something more related to notification and memory situation in system:memory_pressure, memnotify,memory_leveletc. The word "low" is misleading here
2. API must use deferred timers to prevent use-time impact. Deferred timer will be triggered only in case HW event or non-deferrable timer, so if device sleeps timer might be skipped and that is what expected for user-spaceHaving userspace specify the "sample period" for low memory notification makes no sense. The frequency of notifications is a function of the memory pressure.
Quoted 8 lines
Quoted 4 lines
3. API should be tunable for propagate changes when level is Up or Down, maybe both ways.
4. to avoid triggering too much events probably has sense to filter according to amount of change but that is optional. If subscriber set timer to 1s the amount of events should not be very big.
5. API must provide interface to request parameters e.g. available swap or free memory just to have some base.It would make the interface easier to use if it provided the number of pages to free, in the notification (kernel can calculate that as the delta between
current_free_pages->comfortable_free_pagesrelative to process RSS).
If you rely on the notification's argument you lose several features:
- Handling of notifications by several applications in parallel
- Voluntary application's decisions, such as cleanup or avoiding allocations, at the application's convenience.
- Iterative release loops, until there are enough free pages.
I believe that the notification should only serve as a trigger to run the cleanup.
Ronen.
Quoted 10 lines
Quoted 5 lines
6. I do not understand how work with attributes performed ( ) but it has sense to use mask and fill requested attributes using mask and callback table i.e. if free pages requested - they are reported, otherwise not.
7. would have sense to backport couple of attributes frommemnotify.cI can submit couple of patches if some of proposals looks sane for everyone.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
--
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>
Re: [RFC 1/3] /dev/low_mem_notify
In reply to Marcelo TosattiQuoted 3 lines · Marcelo Tosatti
Having userspace specify the "sample period" for low memory notification makes no sense. The frequency of notifications is a function of the memory pressure.
Sure, it makes sense to autotune sample period. I don't see the problem with letting userspace decide it for themselves if they want to.
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>
Arnd Bergmann
maintainerRe: [RFC 1/3] /dev/low_mem_notify
In reply to Pekka EnbergQuoted 28 lines · Pekka Enberg
Quoted 6 lines
Quoted 6 lines
(quoted diff) +6
-0+struct vmnotify_event { + /* Size of the struct for ABI extensibility. */ + __u32 size; + + __u64 nr_avail_pages; +Quoted 8 lines
mm/low_mem_notify.c line 12
Quoted 4 lines
mm/low_mem_notify.c new file +4
-0+__u64 nr_swap_pages; + +__u64 nr_free_pages; +};Two fields here most likely session-constant, (
nr_avail_pagesandnr_swap_pages), seems not much sense to report them in every event. If we have memory/swap hotplug user-space can usesysinfo()call.I actually changed the ABI to look like this:
struct vmnotify_event { /* * Size of the struct for ABI extensibility. */ __u32 size; __u64 attrs; __u64 attr_values[]; };
Quoted 1 line
So userspace can decide which fields to include in notifications.
Please make the first member a __u64 instead of a __u32. This will avoid incompatibility between 32 and 64 bit processes, which have different alignment rules on x86: x86-32 would implicitly pack the struct while x86-64 would add padding with your layout.
Arnd
Arnd Bergmann
maintainerRe: [RFC 1/3] /dev/low_mem_notify
In reply to Pekka EnbergQuoted 6 lines · Pekka Enberg
Quoted 1 line · Marcelo Tosatti
What is the practical advantage of a syscall, again?
Why do you ask? The advantage for this particular case is not needing to add
ioctls()for configuration and keeping the file read/write ABI simple.
The two are obviously equivalent and there is no reason to avoid ioctl in general. However I agree that the syscall would be better in this case, because that is what we tend to use for core kernel functionality, while character devices tend to be used for I/O device drivers that need stuff like enumeration and permission management.
Arnd
--
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>
Re: [RFC 1/3] /dev/low_mem_notify
In reply to Pekka EnbergQuoted 9 lines · Pekka Enberg
Quoted 3 lines · Marcelo Tosatti
Having userspace specify the "sample period" for low memory notification makes no sense. The frequency of notifications is a function of the memory pressure.
Sure, it makes sense to autotune sample period. I don't see the problem with letting userspace decide it for themselves if they want to.
Pekka
Application polls on a file descriptor waiting for asynchronous events, particular conditions of memory reclaim upon which an action is necessary.
These signalled conditions are not simply percentages of free memory, but depend on the amount of freeable cache available, etc. Otherwise applications could monitor /proc/mem_info and act on that.
What is the point of sampling in the interface as you have it? Application can read() from the file descriptor to retrieve the current status, if it wishes.
The objective in this argument is to make the API as simple and easy to use as possible.
--
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>
Re: [RFC 1/3] /dev/low_mem_notify
In reply to Ronen HodQuoted 37 lines · Ronen Hod
Quoted 36 lines · Marcelo Tosatti
Quoted 21 lines · On Thu, Jan 19, 2012 at 10:53:29AM +0000, [email protected] wrote:
Quoted 4 lines
-----Original Message-----
From: ext Ronen Hod [mailto:[email protected]]
Sent: 19 January, 2012 11:20
To: Pekka Enberg...
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Isn't
/proc/sys/vm/min_free_kbytespretty much just that?
Would you suggest to use
min_free_kbytesas the threshold for sendinglow_memory_notificationsto applications, and separately as a target value for the applications' memory giveaway?Quoted 8 lines
Quoted 4 lines
I'm not saying that the kernel should use it directly but it seems like the kind of "ideal number of free pages" threshold you're suggesting. So userspace can read that value and use it as the "number of free pages" threshold for VM events, no?
Yes, I like it. The rules of the game are simple and consistent all over, be it the alert threshold, voluntary poling by the apps, and for concurrent work by several applications.
Well, as long as it provides a good indication forlow_mem_pressure.Quoted 6 lines
For me it doesn't look that have much sense.
min_free_kbytescould be set from user-space (or auto-tuned by kernel) to keep some amount of memory available forGFP_ATOMICallocations. In case situation comes under pointed level kernel will reclaim memory from e.g. caches.Quoted 1 line
From potential user point of view the proposed API has number of lacks which would be nice to have implemented:
1. rename this API from
low_mem_pressureto something more related to notification and memory situation in system:memory_pressure, memnotify,memory_leveletc. The word "low" is misleading here
2. API must use deferred timers to prevent use-time impact. Deferred timer will be triggered only in case HW event or non-deferrable timer, so if device sleeps timer might be skipped and that is what expected for user-spaceHaving userspace specify the "sample period" for low memory notification makes no sense. The frequency of notifications is a function of the memory pressure.
Quoted 4 lines
3. API should be tunable for propagate changes when level is Up or Down, maybe both ways.
4. to avoid triggering too much events probably has sense to filter according to amount of change but that is optional. If subscriber set timer to 1s the amount of events should not be very big.
5. API must provide interface to request parameters e.g. available swap or free memory just to have some base.
Quoted 7 lines
Quoted 4 lines
It would make the interface easier to use if it provided the number of pages to free, in the notification (kernel can calculate that as the delta between
current_free_pages->comfortable_free_pagesrelative to process RSS).If you rely on the notification's argument you lose several features:
- Handling of notifications by several applications in parallel
Each application has its argument built in a custom fashion (pages_to_free = delta between current_free_pages -> comfortable_free_pages relative to process RSS), or something to that effect. It is compatible with parallel notifications.
Quoted 1 line
- Voluntary application's decisions, such as cleanup or avoiding allocations, at the application's convenience.
I am suggesting an additional field in the notification data so that the freeing routine has a goal. But it is not mandatory.
Quoted 1 line
- Iterative release loops, until there are enough free pages.
What is the advantage versus releasing the necessary amount of memory in a given moment?
Quoted 1 line
I believe that the notification should only serve as a trigger to run the cleanup.
Agree.
--
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>
Re: [RFC 1/3] /dev/low_mem_notify
In reply to Arnd BergmannQuoted 8 lines · Arnd Bergmann
Quoted 6 lines · Pekka Enberg
Quoted 1 line · Marcelo Tosatti
What is the practical advantage of a syscall, again?
Why do you ask? The advantage for this particular case is not needing to add
ioctls()for configuration and keeping the file read/write ABI simple.
Quoted 7 lines
The two are obviously equivalent and there is no reason to avoid ioctl in general. However I agree that the syscall would be better in this case, because that is what we tend to use for core kernel functionality, while character devices tend to be used for I/O device drivers that need stuff like enumeration and permission management.
Arnd
Makes sense.
--
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>
Re: [RFC 1/3] /dev/low_mem_notify
In reply to Pekka EnbergQuoted 4 lines · On Tue, 17 Jan 2012 20:51:13 +0200 (EET) Pekka Enberg <[email protected]>…
Ok, so here's a proof of concept patch that implements sample-base per-process free threshold VM event watching using perf-like syscall ABI. I'd really like to see something like this that's much more extensible and clean than the /dev based ABIs that people have proposed so far.
OK, so I'm slow, but better late than never. I plead travel.
I guess the thing that surprises me is that nobody has said this yet: this looks a lot like an event-reporting mechanism like perf. Is there a reason these can't be perf-style events integrated with all the rest?
Quoted 5 lines
(quoted diff) +5
-0+struct vmnotify_config { + /* + * Size of the struct for ABI extensibility. + */ + __u32 size;
Review
Quoted 10 lines
(quoted diff) +10
-0+ + /* + * Notification type bitmask + */ + __u64 type; + + /* + * Free memory threshold in percentages [1..99] + */ + __u32 free_threshold;
Is this an upper-bound threshold or a lower-bound threshold? From your example, it looks like "free_threshold" is "the amount of memory that is not free", which seems confusing.
[...]
Quoted 5 lines
new file mode 100644
index 0000000..6800450
mm/vmnotify.c line 10
Quoted 10 lines
mm/vmnotify.c new file +10
-0@@ -0,0 +1,235 @@ +#include <linux/anon_inodes.h> +#include <linux/vmnotify.h> +#include <linux/syscalls.h> +#include <linux/file.h> +#include <linux/list.h> +#include <linux/poll.h> +#include <linux/slab.h> +#include <linux/swap.h> + +#define VMNOTIFY_MAX_FREE_THRESHOD 100
Did we run out of L's here? :)
Quoted 14 lines
mm/vmnotify.c new file +14
-0+static ssize_t vmnotify_read (struct file *file,char __user *buf,size_t count,loff_t *ppos) +{ +struct vmnotify_watch *watch = file->private_data; +int ret =0 ; + +mutex_lock (&watch->mutex); + +if (!watch->pending) + goto out_unlock; + +if (copy_to_user (buf, &watch->event,sizeof (struct vmnotify_event ))) { + ret = -EFAULT ; + goto out_unlock; + }
mm/vmnotify.c line 34
Quoted 10 lines
mm/vmnotify.c new file +10
-0+ + ret = watch->event.size; + + watch->pending = false; + +out_unlock: +mutex_unlock (&watch->mutex); + +return ret; +}
So this is a nonblocking-only interface? That may surprise some developers. You already have a wait queue, why not wait on it if need be?
Quoted 6 lines
mm/vmnotify.c new file +6
-0+static int vmnotify_copy_config (struct vmnotify_config __user *uconfig, +struct vmnotify_config *config) +{ +int ret; + + ret =copy_from_user (config, uconfig,sizeof (struct vmnotify_config ));
mm/vmnotify.c line 50
Quoted 10 lines
mm/vmnotify.c new file +10
-0+if (ret) +return -EFAULT ; + +if (!config->type) +return -EINVAL ; + +if (config->type &VMNOTIFY_TYPE_SAMPLE ) { +if (config->sample_period_ns <NSEC_PER_MSEC ) +return -EINVAL ; + }
What happens if the sample period is zero?
jon
--
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>
RE: [RFC 1/3] /dev/low_mem_notify
In reply to Pekka EnbergQuoted 4 lines
-----Original Message-----
From: ext Pekka Enberg [mailto:[email protected]]
Sent: 24 January, 2012 18:11
To: Marcelo Tosatti
....
Quoted 9 lines · Marcelo Tosatti
Quoted 3 lines
Having userspace specify the "sample period" for low memory notification makes no sense. The frequency of notifications is a function of the memory pressure.
Sure, it makes sense to autotune sample period. I don't see the problem with letting userspace decide it for themselves if they want to.
Pekka
Good point, but you must take into account that reaction time in user-space depends how SW stack is organized. So for some components 1s is good enough update time, for another cases 10ms.
If changes on VM happened too often they had no sense for user-space.
Thus from practical point of view having sampling period is not a bad idea.
--
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>
Re: [RFC 1/3] /dev/low_mem_notify
In reply to Marcelo TosattiQuoted 41 lines · Marcelo Tosatti
Quoted 40 lines · Ronen Hod
Quoted 39 lines · Marcelo Tosatti
Quoted 21 lines · On Thu, Jan 19, 2012 at 10:53:29AM +0000, [email protected] wrote:
Quoted 4 lines
-----Original Message-----
From: ext Ronen Hod [mailto:[email protected]]
Sent: 19 January, 2012 11:20
To: Pekka Enberg...
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Isn't
/proc/sys/vm/min_free_kbytespretty much just that?
Would you suggest to use
min_free_kbytesas the threshold for sendinglow_memory_notificationsto applications, and separately as a target value for the applications' memory giveaway?Quoted 8 lines
Quoted 4 lines
I'm not saying that the kernel should use it directly but it seems like the kind of "ideal number of free pages" threshold you're suggesting. So userspace can read that value and use it as the "number of free pages" threshold for VM events, no?
Yes, I like it. The rules of the game are simple and consistent all over, be it the alert threshold, voluntary poling by the apps, and for concurrent work by several applications.
Well, as long as it provides a good indication forlow_mem_pressure.Quoted 6 lines
For me it doesn't look that have much sense.
min_free_kbytescould be set from user-space (or auto-tuned by kernel) to keep some amount of memory available forGFP_ATOMICallocations. In case situation comes under pointed level kernel will reclaim memory from e.g. caches.Quoted 1 line
From potential user point of view the proposed API has number of lacks which would be nice to have implemented:
1. rename this API from
low_mem_pressureto something more related to notification and memory situation in system:memory_pressure, memnotify,memory_leveletc. The word "low" is misleading here
2. API must use deferred timers to prevent use-time impact. Deferred timer will be triggered only in case HW event or non-deferrable timer, so if device sleeps timer might be skipped and that is what expected for user-spaceHaving userspace specify the "sample period" for low memory notification makes no sense. The frequency of notifications is a function of the memory pressure.
Quoted 3 lines
3. API should be tunable for propagate changes when level is Up or Down, maybe both ways.
4. to avoid triggering too much events probably has sense to filter according to amount of change but that is optional. If subscriber set timer to 1s the amount of events should not be very big.
5. API must provide interface to request parameters e.g. available swap or free memory just to have some base.It would make the interface easier to use if it provided the number of pages to free, in the notification (kernel can calculate that as the
delta betweencurrent_free_pages->comfortable_free_pagesrelative to
process RSS).
Quoted 6 lines
Quoted 2 lines
If you rely on the notification's argument you lose several features:
- Handling of notifications by several applications in parallelEach application has its argument built in a custom fashion (
pages_to_free= delta betweencurrent_free_pages->comfortable_free_pagesrelative to process RSS), or something to that effect. It is compatible with parallel notifications.
Not sure that I got it. Do you suggest to ask all the applications to free say 3% of their memory?. Some may be able to free more, and some cannot free any. Isn't it more practical to just notify them, and let each app contribute its part to the global moving target?
Quoted 3 lines
Quoted 1 line
- Voluntary application's decisions, such as cleanup or avoiding allocations, at the application's convenience.
I am suggesting an additional field in the notification data so that the freeing routine has a goal. But it is not mandatory.
If you do want to support voluntary (notification less) app decisions, based on the current status, then why not satisfy with this API and only use the notifications to trigger this procedure?
Quoted 4 lines
Quoted 2 lines
- Iterative release loops, until there are enough free pages.
What is the advantage versus releasing the necessary amount of memory in a given moment?
The cleanup logic may be unaware of the page-level effects of its alloc and free, more so when freeing complex internal data structures (such as cached web pages), and this way you let it free until things settle down.
Ronen.
Quoted 5 lines
Quoted 2 lines
I believe that the notification should only serve as a trigger to run the cleanup.
Agree.
--
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>
Re: [RFC 1/3] /dev/low_mem_notify
Quoted 44 lines · Ronen Hod
Quoted 43 lines · Marcelo Tosatti
Quoted 42 lines · Ronen Hod
Quoted 32 lines · Marcelo Tosatti
Quoted 21 lines · On Thu, Jan 19, 2012 at 10:53:29AM +0000, [email protected] wrote:
Quoted 4 lines
-----Original Message-----
From: ext Ronen Hod [mailto:[email protected]]
Sent: 19 January, 2012 11:20
To: Pekka Enberg...
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Isn't
/proc/sys/vm/min_free_kbytespretty much just that?
Would you suggest to use
min_free_kbytesas the threshold for sendinglow_memory_notificationsto applications, and separately as a target value for the applications' memory giveaway?Quoted 8 lines
Quoted 4 lines
I'm not saying that the kernel should use it directly but it seems like the kind of "ideal number of free pages" threshold you're suggesting. So userspace can read that value and use it as the "number of free pages" threshold for VM events, no?
Yes, I like it. The rules of the game are simple and consistent all over, be it the alert threshold, voluntary poling by the apps, and for concurrent work by several applications.
Well, as long as it provides a good indication forlow_mem_pressure.Quoted 6 lines
For me it doesn't look that have much sense.
min_free_kbytescould be set from user-space (or auto-tuned by kernel) to keep some amount of memory available forGFP_ATOMICallocations. In case situation comes under pointed level kernel will reclaim memory from e.g. caches.Quoted 1 line
From potential user point of view the proposed API has number of lacks which would be nice to have implemented:
1. rename this API from
low_mem_pressureto something more related to notification and memory situation in system:memory_pressure, memnotify,memory_leveletc. The word "low" is misleading here
2. API must use deferred timers to prevent use-time impact. Deferred timer will be triggered only in case HW event or non-deferrable timer, so if device sleeps timer might be skipped and that is what expected for user-spaceHaving userspace specify the "sample period" for low memory notification makes no sense. The frequency of notifications is a function of the memory pressure.
Quoted 7 lines
Quoted 3 lines
3. API should be tunable for propagate changes when level is Up or Down, maybe both ways.
4. to avoid triggering too much events probably has sense to filter according to amount of change but that is optional. If subscriber set timer to 1s the amount of events should not be very big.
5. API must provide interface to request parameters e.g. available swap or free memory just to have some base.It would make the interface easier to use if it provided the number of pages to free, in the notification (kernel can calculate that as the
delta betweencurrent_free_pages->comfortable_free_pagesrelative to
process RSS).If you rely on the notification's argument you lose several features:
- Handling of notifications by several applications in parallel
Quoted 7 lines
Quoted 4 lines
Each application has its argument built in a custom fashion (
pages_to_free= delta betweencurrent_free_pages->comfortable_free_pagesrelative to process RSS), or something to that effect. It is compatible with parallel notifications.Not sure that I got it. Do you suggest to ask all the applications to free say 3% of their memory?.
Some may be able to free more, and some cannot free any. Isn't it more practical to just notify them, and let each app contribute its part to the global moving target?
The problem is, how is each process supposed to know how much memory it should free for each notification received, that is, its part?
Its easier if there is a goal, a hint of how many pages the process should release.
Quoted 7 lines
Quoted 3 lines
Quoted 1 line
- Voluntary application's decisions, such as cleanup or avoiding allocations, at the application's convenience.
I am suggesting an additional field in the notification data so that the freeing routine has a goal. But it is not mandatory.
If you do want to support voluntary (notification less) app decisions, based on the current status, then why not satisfy with this API and only use the notifications to trigger this procedure?
Quoted 1 line
Quoted 13 lines
Quoted 3 lines
Quoted 1 line
- Iterative release loops, until there are enough free pages.
What is the advantage versus releasing the necessary amount of memory in a given moment?
The cleanup logic may be unaware of the page-level effects of its alloc and free, more so when freeing complex internal data structures (such as cached web pages), and this way you let it free until things settle down.
Ronen.
Quoted 5 lines
Quoted 2 lines
I believe that the notification should only serve as a trigger to run the cleanup.
Agree.
--
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>
Re: [RFC 1/3] /dev/low_mem_notify
Quoted 49 lines · Marcelo Tosatti
Quoted 48 lines · Ronen Hod
Quoted 47 lines · Marcelo Tosatti
Quoted 36 lines · Ronen Hod
Quoted 35 lines · Marcelo Tosatti
Quoted 21 lines · On Thu, Jan 19, 2012 at 10:53:29AM +0000, [email protected] wrote:
Quoted 4 lines
-----Original Message-----
From: ext Ronen Hod [mailto:[email protected]]
Sent: 19 January, 2012 11:20
To: Pekka Enberg...
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Quoted 5 lines
Isn't
/proc/sys/vm/min_free_kbytespretty much just that?
Would you suggest to use
min_free_kbytesas the threshold for sendinglow_memory_notificationsto applications, and separately as a target value for the applications' memory giveaway?Quoted 8 lines
Quoted 4 lines
I'm not saying that the kernel should use it directly but it seems like the kind of "ideal number of free pages" threshold you're suggesting. So userspace can read that value and use it as the "number of free pages" threshold for VM events, no?
Yes, I like it. The rules of the game are simple and consistent all over, be it the alert threshold, voluntary poling by the apps, and for concurrent work by several applications.
Well, as long as it provides a good indication forlow_mem_pressure.Quoted 6 lines
For me it doesn't look that have much sense.
min_free_kbytescould be set from user-space (or auto-tuned by kernel) to keep some amount of memory available forGFP_ATOMICallocations. In case situation comes under pointed level kernel will reclaim memory from e.g. caches.Quoted 1 line
From potential user point of view the proposed API has number of lacks which would be nice to have implemented:
1. rename this API from
low_mem_pressureto something more related to notification and memory situation in system:memory_pressure, memnotify,memory_leveletc. The word "low" is misleading here
2. API must use deferred timers to prevent use-time impact. Deferred timer will be triggered only in case HW event or non-deferrable timer, so if device sleeps timer might be skipped and that is what expected for user-spaceHaving userspace specify the "sample period" for low memory notification makes no sense. The frequency of notifications is a function of the memory pressure.
Quoted 3 lines
3. API should be tunable for propagate changes when level is Up or Down, maybe both ways.
4. to avoid triggering too much events probably has sense to filter according to amount of change but that is optional. If subscriber set timer to 1s the amount of events should not be very big.
5. API must provide interface to request parameters e.g. available swap or free memory just to have some base.Quoted 6 lines
Quoted 4 lines
It would make the interface easier to use if it provided the number of pages to free, in the notification (kernel can calculate that as the
delta betweencurrent_free_pages->comfortable_free_pagesrelative to
process RSS).If you rely on the notification's argument you lose several features:
- Handling of notifications by several applications in parallelEach application has its argument built in a custom fashion (
pages_to_free= delta betweencurrent_free_pages->comfortable_free_pagesrelative to process RSS), or something to that effect. It is compatible with parallel notifications.
Quoted 7 lines
Quoted 2 lines
Not sure that I got it. Do you suggest to ask all the applications to free say 3% of their memory?.
Some may be able to free more, and some cannot free any. Isn't it more practical to just notify them, and let each app contribute its part to the global moving target?The problem is, how is each process supposed to know how much memory it should free for each notification received, that is, its part?
Its easier if there is a goal, a hint of how many pages the process should release.
I have to agree.
Still, the amount of memory that an app should free per memory-pressure-level can be best calculated inside the application (based on comfortable_free_pages relative to process RSS, as you suggested). Fairness is also an issue. And, if in the meantime the memory pressure ended, would you recommend that the application will continue with its work?
Ronen.
Quoted 14 lines
Quoted 14 lines
Quoted 4 lines
Quoted 2 lines
- Voluntary application's decisions, such as cleanup or avoiding allocations, at the application's convenience.
I am suggesting an additional field in the notification data so that the freeing routine has a goal. But it is not mandatory.
If you do want to support voluntary (notification less) app decisions, based on the current status, then why not satisfy with this API and only use the notifications to trigger this procedure?
Quoted 3 lines
Quoted 1 line
- Iterative release loops, until there are enough free pages.
What is the advantage versus releasing the necessary amount of memory in a given moment?
The cleanup logic may be unaware of the page-level effects of its alloc and free, more so when freeing complex internal data structures (such as cached web pages), and this way you let it free until things settle down.
Ronen.
Quoted 1 line
Quoted 1 line
I believe that the notification should only serve as a trigger to run the cleanup.
Quoted 8 lines
Quoted 3 lines
Quoted 3 lines
Agree.
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
--
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>
Re: [RFC 1/3] /dev/low_mem_notify
Quoted 7 lines
Quoted 4 lines
it should free for each notification received, that is, its part?
Its easier if there is a goal, a hint of how many pages the process should release.
I have to agree.
Still, the amount of memory that an app should free per memory-pressure-level can be best calculated inside the application (based oncomfortable_free_pagesrelative to process RSS, as you suggested).
It is easier if the kernel calculates the target (the application is free to ignore the hint, of course), because it depends on information not readily available in userspace.
Quoted 2 lines
Fairness is also an issue.
And, if in the meantime the memory pressure ended, would you recommend that the application will continue with its work?
There appears to be interest in an event to notify that higher levels of memory are available (see Leonid's email).
--
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>