[RFC] shmem: Add eventfd notification on utlilization level

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

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




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]