From: Krzysztof Kozlowski <k.kozlowski@samsung.com> To: Hugh Dickins <hughd@google.com>, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Alexander Viro <viro@zeniv.linux.org.uk>, linux-fsdevel@vger.kernel.org Cc: Kyungmin Park <kyungmin.park@samsung.com>, Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>, Marek Szyprowski <m.szyprowski@samsung.com>, Krzysztof Kozlowski <k.kozlowski@samsung.com> Subject: [RFC] shmem: Add eventfd notification on utlilization level Date: Wed, 11 Feb 2015 15:50:07 +0100 [thread overview] Message-ID: <1423666208-10681-1-git-send-email-k.kozlowski@samsung.com> (raw) 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
WARNING: multiple messages have this Message-ID (diff)
From: Krzysztof Kozlowski <k.kozlowski@samsung.com> To: Hugh Dickins <hughd@google.com>, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Alexander Viro <viro@zeniv.linux.org.uk>, linux-fsdevel@vger.kernel.org Cc: Kyungmin Park <kyungmin.park@samsung.com>, Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>, Marek Szyprowski <m.szyprowski@samsung.com>, Krzysztof Kozlowski <k.kozlowski@samsung.com> Subject: [RFC] shmem: Add eventfd notification on utlilization level Date: Wed, 11 Feb 2015 15:50:07 +0100 [thread overview] Message-ID: <1423666208-10681-1-git-send-email-k.kozlowski@samsung.com> (raw) 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@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>
next reply other threads:[~2015-02-11 14:50 UTC|newest] Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-02-11 14:50 Krzysztof Kozlowski [this message] 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-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
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1423666208-10681-1-git-send-email-k.kozlowski@samsung.com \ --to=k.kozlowski@samsung.com \ --cc=b.zolnierkie@samsung.com \ --cc=hughd@google.com \ --cc=kyungmin.park@samsung.com \ --cc=linux-fsdevel@vger.kernel.org \ --cc=linux-kernel@vger.kernel.org \ --cc=linux-mm@kvack.org \ --cc=m.szyprowski@samsung.com \ --cc=viro@zeniv.linux.org.uk \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
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.