From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753088AbbBKOu3 (ORCPT ); Wed, 11 Feb 2015 09:50:29 -0500 Received: from mailout4.w1.samsung.com ([210.118.77.14]:24493 "EHLO mailout4.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752055AbbBKOu0 (ORCPT ); Wed, 11 Feb 2015 09:50:26 -0500 X-AuditID: cbfec7f5-b7fc86d0000066b7-c0-54db6b9c57f3 From: Krzysztof Kozlowski To: Hugh Dickins , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Alexander Viro , linux-fsdevel@vger.kernel.org Cc: Kyungmin Park , Bartlomiej Zolnierkiewicz , Marek Szyprowski , Krzysztof Kozlowski Subject: [RFC] shmem: Add eventfd notification on utlilization level Date: Wed, 11 Feb 2015 15:50:07 +0100 Message-id: <1423666208-10681-1-git-send-email-k.kozlowski@samsung.com> X-Mailer: git-send-email 1.9.1 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFnrGJMWRmVeSWpSXmKPExsVy+t/xy7pzsm+HGHz/pGaxccZ6Vounn/pY LF6/MLQ42/SG3WLP3pMsFpd3zWGzuLfmP6vF2iN32S3O/z3O6sDpsWBTqcemT5PYPfq2rGL0 +LxJzmPTk7dMAaxRXDYpqTmZZalF+nYJXBmfdz9gLvjPX/GzYTp7A+Mpni5GTg4JAROJKXvm skLYYhIX7q1n62Lk4hASWMoo0bb+OhtIQkigj0liQ5MgiM0mYCyxefkSsCIRgUWMEpMWtLOD OMwCRxklbsy6y9TFyMEhLOAi8X6rNkgDi4CqxOZPNxlBbF4Bd4nph1rYIbbJSZw8Npl1AiP3 AkaGVYyiqaXJBcVJ6blGesWJucWleel6yfm5mxghYfN1B+PSY1aHGAU4GJV4eC1iboUIsSaW FVfmHmKU4GBWEuHlz7odIsSbklhZlVqUH19UmpNafIiRiYNTqoFRz7Ll58d5V1ctbno6c43z yk1rfp4+1bnve5bh2cCgjGLVo2Gbe81fp6svDBfSMJVk3ZR98cN71eRnHyO2dQtt/X7H851j oNMf61m9e6eJ3dF40X/5gERqkVodw6l/MRVpu+bdnJS9oaRz9rY9SedNm1af+bdk3op9M195 L8uYt9Qy7tPVl2fyryqxFGckGmoxFxUnAgDpxA3G+QEAAA== Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 #include #include #include #include #include #include #include #include /* 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 From mboxrd@z Thu Jan 1 00:00:00 1970 From: Krzysztof Kozlowski Subject: [RFC] shmem: Add eventfd notification on utlilization level Date: Wed, 11 Feb 2015 15:50:07 +0100 Message-ID: <1423666208-10681-1-git-send-email-k.kozlowski@samsung.com> Cc: Kyungmin Park , Bartlomiej Zolnierkiewicz , Marek Szyprowski , Krzysztof Kozlowski To: Hugh Dickins , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Alexander Viro , linux-fsdevel@vger.kernel.org Return-path: Sender: owner-linux-mm@kvack.org List-Id: linux-fsdevel.vger.kernel.org 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 #include #include #include #include #include #include #include #include /* 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: email@kvack.org