lkml.org 
[lkml]   [2015]   [Feb]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
Subject[RFC] shmem: Add eventfd notification on utlilization level
Date
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



\
 
 \ /
  Last update: 2015-02-11 16:21    [W:0.060 / U:9.256 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site