All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC] shmem: Add eventfd notification on utlilization level
@ 2015-02-11 14:50 ` Krzysztof Kozlowski
  0 siblings, 0 replies; 16+ messages in thread
From: Krzysztof Kozlowski @ 2015-02-11 14:50 UTC (permalink / raw)
  To: Hugh Dickins, linux-mm, linux-kernel, Alexander Viro, linux-fsdevel
  Cc: Kyungmin Park, Bartlomiej Zolnierkiewicz, Marek Szyprowski,
	Krzysztof Kozlowski

Hi,


We have a need of getting notifications from kernel to user-space
when tmpfs runs out of free space. I used here a term 'utilization'
in the meaning of percent of free space.

The idea I got is to use eventfd. Proof of concept attached:
1. Patch for kernel.
2. Sample C program (at the end of cover letter).

Usage:
$ mount -t tmpfs -o warn_used=1k,nr_blocks=2k none /path
$ ( sleep 5 && dd if=/dev/zero of=/path/file bs=1M count=4 ) &
$ ./eventfd-wait /sys/fs/tmpfs/tmpfs-6/warn_used_blocks_efd


What do you think about this? Maybe there are simpler ways
of achieving this?

Best regards,
Krzysztof


------------[ cut here ]------------
#include <sys/eventfd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>				 /* Definition of uint64_t */

#define handle_error(msg) \
	do { perror(msg); exit(EXIT_FAILURE); } while (0)

int
main(int argc, char *argv[])
{
	int efd;
	uint64_t u;
	ssize_t s;
	int fd;
	char buf[10];

	if (argc != 2) {
		printf("Usage: %s PATH\n", argv[0]);
		exit(EXIT_FAILURE);
	}

	efd = eventfd(0, 0);
	if (efd == -1)
		 handle_error("eventfd");

	fd = open(argv[1], O_WRONLY);
	if (fd < 0)
		handle_error("sysfs open");

	snprintf(buf, sizeof(buf), "%d", efd);

	s = write(fd, buf, strlen(buf));
	if (s < 0)
		handle_error("sysfs write");

	close(fd);
	
	printf("Waiting for usage notification:\n");
	s = read(efd, &u, sizeof(uint64_t));
	if (s != sizeof(uint64_t))
		 handle_error("read");
	printf("Usage threshold reached: %llu\n",
			  (unsigned long long) u, (unsigned long long) u);
	exit(EXIT_SUCCESS);
}
------------[ cut here ]------------


Krzysztof Kozlowski (1):
  shmem: Add eventfd notification on utlilization level

 include/linux/shmem_fs.h |   4 ++
 mm/shmem.c               | 138 ++++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 140 insertions(+), 2 deletions(-)

-- 
1.9.1


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

end of thread, other threads:[~2015-03-11  4:35 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-11 14:50 [RFC] shmem: Add eventfd notification on utlilization level Krzysztof Kozlowski
2015-02-11 14:50 ` Krzysztof Kozlowski
2015-02-11 14:50 ` Krzysztof Kozlowski
2015-02-11 14:50   ` Krzysztof Kozlowski
2015-03-10  1:51   ` Kyungmin Park
2015-03-10  1:51     ` Kyungmin Park
2015-03-10 13:03     ` Christoph Hellwig
2015-03-10 13:03       ` Christoph Hellwig
2015-03-10 14:22       ` Jan Kara
2015-03-10 14:22         ` Jan Kara
2015-03-10 15:25         ` Beata Michalska
2015-03-10 15:25           ` Beata Michalska
2015-03-10 16:13           ` Lukáš Czerner
2015-03-10 16:13             ` Lukáš Czerner
2015-03-11  4:35         ` Kyungmin Park
2015-03-11  4:35           ` Kyungmin Park

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.