All of lore.kernel.org
 help / color / mirror / Atom feed
* [sample] mem_notify v6: usage example
@ 2008-02-09 15:55 ` KOSAKI Motohiro
  0 siblings, 0 replies; 12+ messages in thread
From: KOSAKI Motohiro @ 2008-02-09 15:55 UTC (permalink / raw)
  To: linux-mm, linux-kernel
  Cc: kosaki.motohiro, Marcelo Tosatti, Daniel Spang, Rik van Riel,
	Andrew Morton, Alan Cox, linux-fsdevel, Pavel Machek, Al Boldi,
	Jon Masters, Zan Lynx

this is usage example of /dev/mem_notify.

Daniel Spang create original version.
kosaki add fasync related code.


Signed-off-by: Daniel Spang <daniel.spang@gmail.com>
Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>

---
 Documentation/mem_notify.c |  120 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 120 insertions(+)

Index: b/Documentation/mem_notify.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ b/Documentation/mem_notify.c	2008-02-10 00:44:00.000000000 +0900
@@ -0,0 +1,120 @@
+/*
+ * Allocate 10 MB each second. Exit on notification.
+ */
+
+#define _GNU_SOURCE
+
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <poll.h>
+#include <pthread.h>
+#include <errno.h>
+#include <signal.h>
+
+int count = 0;
+int size = 10;
+
+void *do_alloc()
+{
+        for(;;) {
+                int *buffer;
+                buffer = mmap(NULL,  size*1024*1024,
+                              PROT_READ | PROT_WRITE,
+                              MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+                if (buffer == MAP_FAILED) {
+                        perror("mmap");
+                        exit(EXIT_FAILURE);
+                }
+                memset(buffer, 1 , size*1024*1024);
+
+                printf("-");
+                fflush(stdout);
+
+                count++;
+                sleep(1);
+        }
+}
+
+int wait_for_notification(struct pollfd *pfd)
+{
+        int ret;
+        read(pfd->fd, 0, 0);
+        ret = poll(pfd, 1, -1);              /* wake up when low memory */
+        if (ret == -1 && errno != EINTR) {
+                perror("poll");
+                exit(EXIT_FAILURE);
+        }
+        return ret;
+}
+
+void do_free()
+{
+	int fd;
+	struct pollfd pfd;
+
+        fd = open("/dev/mem_notify", O_RDONLY);
+        if (fd == -1) {
+                perror("open");
+                exit(EXIT_FAILURE);
+        }
+
+	pfd.fd = fd;
+        pfd.events = POLLIN;
+        for(;;)
+                if (wait_for_notification(&pfd) > 0) {
+                        printf("\nGot notification, allocated %d MB\n",
+                               size * count);
+                        exit(EXIT_SUCCESS);
+                }
+}
+
+void do_free_signal()
+{
+	int fd;
+	int flags;
+
+        fd = open("/dev/mem_notify", O_RDONLY);
+        if (fd == -1) {
+                perror("open");
+                exit(EXIT_FAILURE);
+        }
+
+	fcntl(fd, F_SETOWN, getpid());
+	fcntl(fd, F_SETSIG, SIGUSR1);
+
+	flags = fcntl(fd, F_GETFL);
+	fcntl(fd, F_SETFL, flags|FASYNC); /* when low memory, receive SIGUSR1 */
+
+	for(;;)
+		sleep(1);
+}
+
+
+void daniel_exit(int signo)
+{
+	printf("\nGot notification %d, allocated %d MB\n",
+	       signo, size * count);
+	exit(EXIT_SUCCESS);
+
+}
+
+int main(int argc, char *argv[])
+{
+        pthread_t allocator;
+
+	if(argc == 2 && (strcmp(argv[1], "-sig") == 0)) {
+		printf("run signal mode\n");
+		signal(SIGUSR1, daniel_exit);
+		pthread_create(&allocator, NULL, do_alloc, NULL);
+		do_free_signal();
+	} else {
+		printf("run poll mode\n");
+		pthread_create(&allocator, NULL, do_alloc, NULL);
+		do_free();
+	}
+	return 0;
+}

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

* [sample] mem_notify v6: usage example
@ 2008-02-09 15:55 ` KOSAKI Motohiro
  0 siblings, 0 replies; 12+ messages in thread
From: KOSAKI Motohiro @ 2008-02-09 15:55 UTC (permalink / raw)
  To: linux-mm, linux-kernel
  Cc: kosaki.motohiro, Marcelo Tosatti, Daniel Spang, Rik van Riel,
	Andrew Morton, Alan Cox, linux-fsdevel, Pavel Machek, Al Boldi,
	Jon Masters, Zan Lynx

this is usage example of /dev/mem_notify.

Daniel Spang create original version.
kosaki add fasync related code.


Signed-off-by: Daniel Spang <daniel.spang@gmail.com>
Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>

---
 Documentation/mem_notify.c |  120 +++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 120 insertions(+)

Index: b/Documentation/mem_notify.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ b/Documentation/mem_notify.c	2008-02-10 00:44:00.000000000 +0900
@@ -0,0 +1,120 @@
+/*
+ * Allocate 10 MB each second. Exit on notification.
+ */
+
+#define _GNU_SOURCE
+
+#include <sys/mman.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <poll.h>
+#include <pthread.h>
+#include <errno.h>
+#include <signal.h>
+
+int count = 0;
+int size = 10;
+
+void *do_alloc()
+{
+        for(;;) {
+                int *buffer;
+                buffer = mmap(NULL,  size*1024*1024,
+                              PROT_READ | PROT_WRITE,
+                              MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
+                if (buffer == MAP_FAILED) {
+                        perror("mmap");
+                        exit(EXIT_FAILURE);
+                }
+                memset(buffer, 1 , size*1024*1024);
+
+                printf("-");
+                fflush(stdout);
+
+                count++;
+                sleep(1);
+        }
+}
+
+int wait_for_notification(struct pollfd *pfd)
+{
+        int ret;
+        read(pfd->fd, 0, 0);
+        ret = poll(pfd, 1, -1);              /* wake up when low memory */
+        if (ret == -1 && errno != EINTR) {
+                perror("poll");
+                exit(EXIT_FAILURE);
+        }
+        return ret;
+}
+
+void do_free()
+{
+	int fd;
+	struct pollfd pfd;
+
+        fd = open("/dev/mem_notify", O_RDONLY);
+        if (fd == -1) {
+                perror("open");
+                exit(EXIT_FAILURE);
+        }
+
+	pfd.fd = fd;
+        pfd.events = POLLIN;
+        for(;;)
+                if (wait_for_notification(&pfd) > 0) {
+                        printf("\nGot notification, allocated %d MB\n",
+                               size * count);
+                        exit(EXIT_SUCCESS);
+                }
+}
+
+void do_free_signal()
+{
+	int fd;
+	int flags;
+
+        fd = open("/dev/mem_notify", O_RDONLY);
+        if (fd == -1) {
+                perror("open");
+                exit(EXIT_FAILURE);
+        }
+
+	fcntl(fd, F_SETOWN, getpid());
+	fcntl(fd, F_SETSIG, SIGUSR1);
+
+	flags = fcntl(fd, F_GETFL);
+	fcntl(fd, F_SETFL, flags|FASYNC); /* when low memory, receive SIGUSR1 */
+
+	for(;;)
+		sleep(1);
+}
+
+
+void daniel_exit(int signo)
+{
+	printf("\nGot notification %d, allocated %d MB\n",
+	       signo, size * count);
+	exit(EXIT_SUCCESS);
+
+}
+
+int main(int argc, char *argv[])
+{
+        pthread_t allocator;
+
+	if(argc == 2 && (strcmp(argv[1], "-sig") == 0)) {
+		printf("run signal mode\n");
+		signal(SIGUSR1, daniel_exit);
+		pthread_create(&allocator, NULL, do_alloc, NULL);
+		do_free_signal();
+	} else {
+		printf("run poll mode\n");
+		pthread_create(&allocator, NULL, do_alloc, NULL);
+		do_free();
+	}
+	return 0;
+}

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [sample] mem_notify v6: usage example
  2008-02-09 15:55 ` KOSAKI Motohiro
@ 2008-02-09 16:07   ` Jon Masters
  -1 siblings, 0 replies; 12+ messages in thread
From: Jon Masters @ 2008-02-09 16:07 UTC (permalink / raw)
  To: KOSAKI Motohiro
  Cc: linux-mm, linux-kernel, kosaki.motohiro, Marcelo Tosatti,
	Daniel Spang, Rik van Riel, Andrew Morton, Alan Cox,
	linux-fsdevel, Pavel Machek, Al Boldi, Zan Lynx

This really needs to be triggered via a generic kernel event in the  
final version - I picture glibc having a reservation API and having  
generic support for freeing such reservations.

Jon



On Feb 9, 2008, at 10:55, "KOSAKI Motohiro" <kosaki.motohiro@jp.fujitsu.com 
 > wrote:

> this is usage example of /dev/mem_notify.
>
> Daniel Spang create original version.
> kosaki add fasync related code.
>
>
> Signed-off-by: Daniel Spang <daniel.spang@gmail.com>
> Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
>
> ---
> Documentation/mem_notify.c |  120 +++++++++++++++++++++++++++++++++++ 
> ++++++++++
> 1 file changed, 120 insertions(+)
>
> Index: b/Documentation/mem_notify.c
> ===================================================================
> --- /dev/null    1970-01-01 00:00:00.000000000 +0000
> +++ b/Documentation/mem_notify.c    2008-02-10 00:44:00.000000000  
> +0900
> @@ -0,0 +1,120 @@
> +/*
> + * Allocate 10 MB each second. Exit on notification.
> + */
> +
> +#define _GNU_SOURCE
> +
> +#include <sys/mman.h>
> +#include <fcntl.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <unistd.h>
> +#include <string.h>
> +#include <poll.h>
> +#include <pthread.h>
> +#include <errno.h>
> +#include <signal.h>
> +
> +int count = 0;
> +int size = 10;
> +
> +void *do_alloc()
> +{
> +        for(;;) {
> +                int *buffer;
> +                buffer = mmap(NULL,  size*1024*1024,
> +                              PROT_READ | PROT_WRITE,
> +                              MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> +                if (buffer == MAP_FAILED) {
> +                        perror("mmap");
> +                        exit(EXIT_FAILURE);
> +                }
> +                memset(buffer, 1 , size*1024*1024);
> +
> +                printf("-");
> +                fflush(stdout);
> +
> +                count++;
> +                sleep(1);
> +        }
> +}
> +
> +int wait_for_notification(struct pollfd *pfd)
> +{
> +        int ret;
> +        read(pfd->fd, 0, 0);
> +        ret = poll(pfd, 1, -1);              /* wake up when low  
> memory */
> +        if (ret == -1 && errno != EINTR) {
> +                perror("poll");
> +                exit(EXIT_FAILURE);
> +        }
> +        return ret;
> +}
> +
> +void do_free()
> +{
> +    int fd;
> +    struct pollfd pfd;
> +
> +        fd = open("/dev/mem_notify", O_RDONLY);
> +        if (fd == -1) {
> +                perror("open");
> +                exit(EXIT_FAILURE);
> +        }
> +
> +    pfd.fd = fd;
> +        pfd.events = POLLIN;
> +        for(;;)
> +                if (wait_for_notification(&pfd) > 0) {
> +                        printf("\nGot notification, allocated %d MB 
> \n",
> +                               size * count);
> +                        exit(EXIT_SUCCESS);
> +                }
> +}
> +
> +void do_free_signal()
> +{
> +    int fd;
> +    int flags;
> +
> +        fd = open("/dev/mem_notify", O_RDONLY);
> +        if (fd == -1) {
> +                perror("open");
> +                exit(EXIT_FAILURE);
> +        }
> +
> +    fcntl(fd, F_SETOWN, getpid());
> +    fcntl(fd, F_SETSIG, SIGUSR1);
> +
> +    flags = fcntl(fd, F_GETFL);
> +    fcntl(fd, F_SETFL, flags|FASYNC); /* when low memory, receive  
> SIGUSR1 */
> +
> +    for(;;)
> +        sleep(1);
> +}
> +
> +
> +void daniel_exit(int signo)
> +{
> +    printf("\nGot notification %d, allocated %d MB\n",
> +           signo, size * count);
> +    exit(EXIT_SUCCESS);
> +
> +}
> +
> +int main(int argc, char *argv[])
> +{
> +        pthread_t allocator;
> +
> +    if(argc == 2 && (strcmp(argv[1], "-sig") == 0)) {
> +        printf("run signal mode\n");
> +        signal(SIGUSR1, daniel_exit);
> +        pthread_create(&allocator, NULL, do_alloc, NULL);
> +        do_free_signal();
> +    } else {
> +        printf("run poll mode\n");
> +        pthread_create(&allocator, NULL, do_alloc, NULL);
> +        do_free();
> +    }
> +    return 0;
> +}
>

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

* Re: [sample] mem_notify v6: usage example
@ 2008-02-09 16:07   ` Jon Masters
  0 siblings, 0 replies; 12+ messages in thread
From: Jon Masters @ 2008-02-09 16:07 UTC (permalink / raw)
  To: KOSAKI Motohiro
  Cc: linux-mm, linux-kernel, Marcelo Tosatti, Daniel Spang,
	Rik van Riel, Andrew Morton, Alan Cox, linux-fsdevel,
	Pavel Machek, Al Boldi, Zan Lynx

This really needs to be triggered via a generic kernel event in the  
final version - I picture glibc having a reservation API and having  
generic support for freeing such reservations.

Jon



On Feb 9, 2008, at 10:55, "KOSAKI Motohiro" <kosaki.motohiro@jp.fujitsu.com 
 > wrote:

> this is usage example of /dev/mem_notify.
>
> Daniel Spang create original version.
> kosaki add fasync related code.
>
>
> Signed-off-by: Daniel Spang <daniel.spang@gmail.com>
> Signed-off-by: KOSAKI Motohiro <kosaki.motohiro@jp.fujitsu.com>
>
> ---
> Documentation/mem_notify.c |  120 +++++++++++++++++++++++++++++++++++ 
> ++++++++++
> 1 file changed, 120 insertions(+)
>
> Index: b/Documentation/mem_notify.c
> ===================================================================
> --- /dev/null    1970-01-01 00:00:00.000000000 +0000
> +++ b/Documentation/mem_notify.c    2008-02-10 00:44:00.000000000  
> +0900
> @@ -0,0 +1,120 @@
> +/*
> + * Allocate 10 MB each second. Exit on notification.
> + */
> +
> +#define _GNU_SOURCE
> +
> +#include <sys/mman.h>
> +#include <fcntl.h>
> +#include <stdio.h>
> +#include <stdlib.h>
> +#include <unistd.h>
> +#include <string.h>
> +#include <poll.h>
> +#include <pthread.h>
> +#include <errno.h>
> +#include <signal.h>
> +
> +int count = 0;
> +int size = 10;
> +
> +void *do_alloc()
> +{
> +        for(;;) {
> +                int *buffer;
> +                buffer = mmap(NULL,  size*1024*1024,
> +                              PROT_READ | PROT_WRITE,
> +                              MAP_PRIVATE | MAP_ANONYMOUS, -1, 0);
> +                if (buffer == MAP_FAILED) {
> +                        perror("mmap");
> +                        exit(EXIT_FAILURE);
> +                }
> +                memset(buffer, 1 , size*1024*1024);
> +
> +                printf("-");
> +                fflush(stdout);
> +
> +                count++;
> +                sleep(1);
> +        }
> +}
> +
> +int wait_for_notification(struct pollfd *pfd)
> +{
> +        int ret;
> +        read(pfd->fd, 0, 0);
> +        ret = poll(pfd, 1, -1);              /* wake up when low  
> memory */
> +        if (ret == -1 && errno != EINTR) {
> +                perror("poll");
> +                exit(EXIT_FAILURE);
> +        }
> +        return ret;
> +}
> +
> +void do_free()
> +{
> +    int fd;
> +    struct pollfd pfd;
> +
> +        fd = open("/dev/mem_notify", O_RDONLY);
> +        if (fd == -1) {
> +                perror("open");
> +                exit(EXIT_FAILURE);
> +        }
> +
> +    pfd.fd = fd;
> +        pfd.events = POLLIN;
> +        for(;;)
> +                if (wait_for_notification(&pfd) > 0) {
> +                        printf("\nGot notification, allocated %d MB 
> \n",
> +                               size * count);
> +                        exit(EXIT_SUCCESS);
> +                }
> +}
> +
> +void do_free_signal()
> +{
> +    int fd;
> +    int flags;
> +
> +        fd = open("/dev/mem_notify", O_RDONLY);
> +        if (fd == -1) {
> +                perror("open");
> +                exit(EXIT_FAILURE);
> +        }
> +
> +    fcntl(fd, F_SETOWN, getpid());
> +    fcntl(fd, F_SETSIG, SIGUSR1);
> +
> +    flags = fcntl(fd, F_GETFL);
> +    fcntl(fd, F_SETFL, flags|FASYNC); /* when low memory, receive  
> SIGUSR1 */
> +
> +    for(;;)
> +        sleep(1);
> +}
> +
> +
> +void daniel_exit(int signo)
> +{
> +    printf("\nGot notification %d, allocated %d MB\n",
> +           signo, size * count);
> +    exit(EXIT_SUCCESS);
> +
> +}
> +
> +int main(int argc, char *argv[])
> +{
> +        pthread_t allocator;
> +
> +    if(argc == 2 && (strcmp(argv[1], "-sig") == 0)) {
> +        printf("run signal mode\n");
> +        signal(SIGUSR1, daniel_exit);
> +        pthread_create(&allocator, NULL, do_alloc, NULL);
> +        do_free_signal();
> +    } else {
> +        printf("run poll mode\n");
> +        pthread_create(&allocator, NULL, do_alloc, NULL);
> +        do_free();
> +    }
> +    return 0;
> +}
>

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [sample] mem_notify v6: usage example
  2008-02-09 16:07   ` Jon Masters
@ 2008-02-09 16:46     ` KOSAKI Motohiro
  -1 siblings, 0 replies; 12+ messages in thread
From: KOSAKI Motohiro @ 2008-02-09 16:46 UTC (permalink / raw)
  To: Jon Masters
  Cc: linux-mm, linux-kernel, Marcelo Tosatti, Daniel Spang,
	Rik van Riel, Andrew Morton, Alan Cox, linux-fsdevel,
	Pavel Machek, Al Boldi, Zan Lynx

Hi Jon

> This really needs to be triggered via a generic kernel event in the
> final version - I picture glibc having a reservation API and having
> generic support for freeing such reservations.

to be honest, I doubt idea of generic reservation framework.

end up, we hope drop the application cache, not also dataless memory.
but, automatically drop mechanism only able to drop dataless memory.

and, many application have own memory management subsystem.
I afraid to nobody use too complex framework.

What do you think it?
I hope see your API. please post it.

Thanks!

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

* Re: [sample] mem_notify v6: usage example
@ 2008-02-09 16:46     ` KOSAKI Motohiro
  0 siblings, 0 replies; 12+ messages in thread
From: KOSAKI Motohiro @ 2008-02-09 16:46 UTC (permalink / raw)
  To: Jon Masters
  Cc: linux-mm, linux-kernel, Marcelo Tosatti, Daniel Spang,
	Rik van Riel, Andrew Morton, Alan Cox, linux-fsdevel,
	Pavel Machek, Al Boldi, Zan Lynx

Hi Jon

> This really needs to be triggered via a generic kernel event in the
> final version - I picture glibc having a reservation API and having
> generic support for freeing such reservations.

to be honest, I doubt idea of generic reservation framework.

end up, we hope drop the application cache, not also dataless memory.
but, automatically drop mechanism only able to drop dataless memory.

and, many application have own memory management subsystem.
I afraid to nobody use too complex framework.

What do you think it?
I hope see your API. please post it.

Thanks!

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [sample] mem_notify v6: usage example
  2008-02-09 16:07   ` Jon Masters
@ 2008-02-10  1:30     ` Pavel Machek
  -1 siblings, 0 replies; 12+ messages in thread
From: Pavel Machek @ 2008-02-10  1:30 UTC (permalink / raw)
  To: Jon Masters
  Cc: KOSAKI Motohiro, linux-mm, linux-kernel, Marcelo Tosatti,
	Daniel Spang, Rik van Riel, Andrew Morton, Alan Cox,
	linux-fsdevel, Al Boldi, Zan Lynx

On Sat 2008-02-09 11:07:09, Jon Masters wrote:
> This really needs to be triggered via a generic kernel 
> event in the  final version - I picture glibc having a 
> reservation API and having  generic support for freeing 
> such reservations.

Not sure what you are talking about. This seems very right to me.

We want memory-low notification, not yet another generic communication
mechanism.

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

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

* Re: [sample] mem_notify v6: usage example
@ 2008-02-10  1:30     ` Pavel Machek
  0 siblings, 0 replies; 12+ messages in thread
From: Pavel Machek @ 2008-02-10  1:30 UTC (permalink / raw)
  To: Jon Masters
  Cc: KOSAKI Motohiro, linux-mm, linux-kernel, Marcelo Tosatti,
	Daniel Spang, Rik van Riel, Andrew Morton, Alan Cox,
	linux-fsdevel, Al Boldi, Zan Lynx

On Sat 2008-02-09 11:07:09, Jon Masters wrote:
> This really needs to be triggered via a generic kernel 
> event in the  final version - I picture glibc having a 
> reservation API and having  generic support for freeing 
> such reservations.

Not sure what you are talking about. This seems very right to me.

We want memory-low notification, not yet another generic communication
mechanism.

-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [sample] mem_notify v6: usage example
  2008-02-09 16:46     ` KOSAKI Motohiro
@ 2008-02-11 18:15       ` Andreas Dilger
  -1 siblings, 0 replies; 12+ messages in thread
From: Andreas Dilger @ 2008-02-11 18:15 UTC (permalink / raw)
  To: KOSAKI Motohiro
  Cc: Jon Masters, linux-mm, linux-kernel, Marcelo Tosatti,
	Daniel Spang, Rik van Riel, Andrew Morton, Alan Cox,
	linux-fsdevel, Pavel Machek, Al Boldi, Zan Lynx

On Feb 10, 2008  01:46 +0900, KOSAKI Motohiro wrote:
> > This really needs to be triggered via a generic kernel event in the
> > final version - I picture glibc having a reservation API and having
> > generic support for freeing such reservations.
> 
> to be honest, I doubt idea of generic reservation framework.
> 
> end up, we hope drop the application cache, not also dataless memory.
> but, automatically drop mechanism only able to drop dataless memory.
> 
> and, many application have own memory management subsystem.
> I afraid to nobody use too complex framework.

Having such notification handled by glibc to free up unused malloc (or
any heap allocations) would be very useful, because even if a program
does "free" there is no guarantee the memory is returned to the kernel.

I think that having a generic reservation framework is too complex, but
hiding the details of /dev/mem_notify from applications is desirable.
A simple wrapper (possibly part of glibc) to return the poll fd, or set
up the signal is enough.

Cheers, Andreas
--
Andreas Dilger
Sr. Staff Engineer, Lustre Group
Sun Microsystems of Canada, Inc.


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

* Re: [sample] mem_notify v6: usage example
@ 2008-02-11 18:15       ` Andreas Dilger
  0 siblings, 0 replies; 12+ messages in thread
From: Andreas Dilger @ 2008-02-11 18:15 UTC (permalink / raw)
  To: KOSAKI Motohiro
  Cc: Jon Masters, linux-mm, linux-kernel, Marcelo Tosatti,
	Daniel Spang, Rik van Riel, Andrew Morton, Alan Cox,
	linux-fsdevel, Pavel Machek, Al Boldi, Zan Lynx

On Feb 10, 2008  01:46 +0900, KOSAKI Motohiro wrote:
> > This really needs to be triggered via a generic kernel event in the
> > final version - I picture glibc having a reservation API and having
> > generic support for freeing such reservations.
> 
> to be honest, I doubt idea of generic reservation framework.
> 
> end up, we hope drop the application cache, not also dataless memory.
> but, automatically drop mechanism only able to drop dataless memory.
> 
> and, many application have own memory management subsystem.
> I afraid to nobody use too complex framework.

Having such notification handled by glibc to free up unused malloc (or
any heap allocations) would be very useful, because even if a program
does "free" there is no guarantee the memory is returned to the kernel.

I think that having a generic reservation framework is too complex, but
hiding the details of /dev/mem_notify from applications is desirable.
A simple wrapper (possibly part of glibc) to return the poll fd, or set
up the signal is enough.

Cheers, Andreas
--
Andreas Dilger
Sr. Staff Engineer, Lustre Group
Sun Microsystems of Canada, Inc.

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

* Re: [sample] mem_notify v6: usage example
  2008-02-11 18:15       ` Andreas Dilger
@ 2008-02-11 18:37         ` KOSAKI Motohiro
  -1 siblings, 0 replies; 12+ messages in thread
From: KOSAKI Motohiro @ 2008-02-11 18:37 UTC (permalink / raw)
  To: Andreas Dilger
  Cc: Jon Masters, linux-mm, linux-kernel, Marcelo Tosatti,
	Daniel Spang, Rik van Riel, Andrew Morton, Alan Cox,
	linux-fsdevel, Pavel Machek, Al Boldi, Zan Lynx

Hi Andreas,

Thank you very good comment.

> Having such notification handled by glibc to free up unused malloc (or
> any heap allocations) would be very useful, because even if a program
> does "free" there is no guarantee the memory is returned to the kernel.

Yes, no guarantee.
but current glibc-malloc very frequently return memory to kernel.

glibc default behavior

1. over 1M memory: return memory just free(3)  called.
    (you can change threshold by MALLOC_MMAP_MAX_ environment)
2. more lower:         return memory when exist continuous 128k at heap tail.
    (you can change threashold by MALLOC_TRIM_THRESHOLD_ environment)

if you know very memory consumption by already freed memory situation,
please tell me situation detail and consumption memory size.

> I think that having a generic reservation framework is too complex, but
> hiding the details of /dev/mem_notify from applications is desirable.
> A simple wrapper (possibly part of glibc) to return the poll fd, or set
> up the signal is enough.

Agreed.
if large consumption situation exist, I'm behind you.


Thanks!

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

* Re: [sample] mem_notify v6: usage example
@ 2008-02-11 18:37         ` KOSAKI Motohiro
  0 siblings, 0 replies; 12+ messages in thread
From: KOSAKI Motohiro @ 2008-02-11 18:37 UTC (permalink / raw)
  To: Andreas Dilger
  Cc: Jon Masters, linux-mm, linux-kernel, Marcelo Tosatti,
	Daniel Spang, Rik van Riel, Andrew Morton, Alan Cox,
	linux-fsdevel, Pavel Machek, Al Boldi, Zan Lynx

Hi Andreas,

Thank you very good comment.

> Having such notification handled by glibc to free up unused malloc (or
> any heap allocations) would be very useful, because even if a program
> does "free" there is no guarantee the memory is returned to the kernel.

Yes, no guarantee.
but current glibc-malloc very frequently return memory to kernel.

glibc default behavior

1. over 1M memory: return memory just free(3)  called.
    (you can change threshold by MALLOC_MMAP_MAX_ environment)
2. more lower:         return memory when exist continuous 128k at heap tail.
    (you can change threashold by MALLOC_TRIM_THRESHOLD_ environment)

if you know very memory consumption by already freed memory situation,
please tell me situation detail and consumption memory size.

> I think that having a generic reservation framework is too complex, but
> hiding the details of /dev/mem_notify from applications is desirable.
> A simple wrapper (possibly part of glibc) to return the poll fd, or set
> up the signal is enough.

Agreed.
if large consumption situation exist, I'm behind you.


Thanks!

--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to majordomo@kvack.org.  For more info on Linux MM,
see: http://www.linux-mm.org/ .
Don't email: <a href=mailto:"dont@kvack.org"> email@kvack.org </a>

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

end of thread, other threads:[~2008-02-11 18:37 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-02-09 15:55 [sample] mem_notify v6: usage example KOSAKI Motohiro
2008-02-09 15:55 ` KOSAKI Motohiro
2008-02-09 16:07 ` Jon Masters
2008-02-09 16:07   ` Jon Masters
2008-02-09 16:46   ` KOSAKI Motohiro
2008-02-09 16:46     ` KOSAKI Motohiro
2008-02-11 18:15     ` Andreas Dilger
2008-02-11 18:15       ` Andreas Dilger
2008-02-11 18:37       ` KOSAKI Motohiro
2008-02-11 18:37         ` KOSAKI Motohiro
2008-02-10  1:30   ` Pavel Machek
2008-02-10  1:30     ` Pavel Machek

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