Re: [RFC] shmem: Add eventfd notification on utlilization level
On Tue, Mar 10, 2015 at 11:22 PM, Jan Kara wrote: > On Tue 10-03-15 06:03:23, Christoph Hellwig wrote: >> On Tue, Mar 10, 2015 at 10:51:41AM +0900, Kyungmin Park wrote: >> > Any updates? >> >> Please just add disk quota support to tmpfs so thast the standard quota >> netlink notifications can be used. > If I understand the problem at hand, they are really interested in > notification when running out of free space. Using quota for that doesn't > seem ideal since that tracks used space per user, not free space on fs as a > whole. > > But if I remember right there were discussions about ENOSPC notification > from filesystem for thin provisioning usecases. It would be good to make > this consistent with those but I'm not sure if it went anywhere. In mobile case, it provides two warning messages when it remains 5% and 0.1% respectively. to achieve it, some daemon call statfs periodically. right it's inefficient. that's reason we need some notification method from filesystem. tmpfs is different story. some malicious app fills tmpfs then system goes slow. so it has to check it periodically. to avoid it, this patch is developed and want to get feedback. we considered quota but it's not desired one. other can't write tmpfs even though it has 20% remaining. Thank you, Kyungmin Park -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [RFC] shmem: Add eventfd notification on utlilization level
On Tue, 10 Mar 2015, Beata Michalska wrote: > Date: Tue, 10 Mar 2015 16:25:12 +0100 > From: Beata Michalska > To: Jan Kara > Cc: Christoph Hellwig , > Kyungmin Park , > Krzysztof Kozlowski , > Hugh Dickins , linux-mm , > Linux Kernel Mailing List , > Alexander Viro , > Linux Filesystem Mailing List , > Bartlomiej Zolnierkiewicz , > Marek Szyprowski > Subject: Re: [RFC] shmem: Add eventfd notification on utlilization level > > On 03/10/2015 03:22 PM, Jan Kara wrote: > > On Tue 10-03-15 06:03:23, Christoph Hellwig wrote: > >> On Tue, Mar 10, 2015 at 10:51:41AM +0900, Kyungmin Park wrote: > >>> Any updates? > >> Please just add disk quota support to tmpfs so thast the standard quota > >> netlink notifications can be used. > > If I understand the problem at hand, they are really interested in > > notification when running out of free space. Using quota for that doesn't > > seem ideal since that tracks used space per user, not free space on fs as a > > whole. > > > > But if I remember right there were discussions about ENOSPC notification > > from filesystem for thin provisioning usecases. It would be good to make > > this consistent with those but I'm not sure if it went anywhere. > > > > Honza > > The ideal case here, would be to get the notification, despite the type > of the actual filesystem, whenever the amount of free space drops below > a certain level. Quota doesn't seem to be the right approach here. > > BR > Beata Michalska A while back I was prototyping a netlink notification interface for file systems, but it went nowhere. https://lkml.org/lkml/2011/8/18/170 So maybe it's time get back to the drawing board and finish the idea, since it seems to be some interest in this now. -Lukas > > -- > To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in > the body of a message to majord...@vger.kernel.org > More majordomo info at http://vger.kernel.org/majordomo-info.html > -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [RFC] shmem: Add eventfd notification on utlilization level
On 03/10/2015 03:22 PM, Jan Kara wrote: > On Tue 10-03-15 06:03:23, Christoph Hellwig wrote: >> On Tue, Mar 10, 2015 at 10:51:41AM +0900, Kyungmin Park wrote: >>> Any updates? >> Please just add disk quota support to tmpfs so thast the standard quota >> netlink notifications can be used. > If I understand the problem at hand, they are really interested in > notification when running out of free space. Using quota for that doesn't > seem ideal since that tracks used space per user, not free space on fs as a > whole. > > But if I remember right there were discussions about ENOSPC notification > from filesystem for thin provisioning usecases. It would be good to make > this consistent with those but I'm not sure if it went anywhere. > > Honza The ideal case here, would be to get the notification, despite the type of the actual filesystem, whenever the amount of free space drops below a certain level. Quota doesn't seem to be the right approach here. BR Beata Michalska -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [RFC] shmem: Add eventfd notification on utlilization level
On Tue 10-03-15 06:03:23, Christoph Hellwig wrote: > On Tue, Mar 10, 2015 at 10:51:41AM +0900, Kyungmin Park wrote: > > Any updates? > > Please just add disk quota support to tmpfs so thast the standard quota > netlink notifications can be used. If I understand the problem at hand, they are really interested in notification when running out of free space. Using quota for that doesn't seem ideal since that tracks used space per user, not free space on fs as a whole. But if I remember right there were discussions about ENOSPC notification from filesystem for thin provisioning usecases. It would be good to make this consistent with those but I'm not sure if it went anywhere. Honza -- Jan Kara SUSE Labs, CR -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [RFC] shmem: Add eventfd notification on utlilization level
On Tue, Mar 10, 2015 at 10:51:41AM +0900, Kyungmin Park wrote: > Any updates? Please just add disk quota support to tmpfs so thast the standard quota netlink notifications can be used. -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [RFC] shmem: Add eventfd notification on utlilization level
On Tue 10-03-15 06:03:23, Christoph Hellwig wrote: On Tue, Mar 10, 2015 at 10:51:41AM +0900, Kyungmin Park wrote: Any updates? Please just add disk quota support to tmpfs so thast the standard quota netlink notifications can be used. If I understand the problem at hand, they are really interested in notification when running out of free space. Using quota for that doesn't seem ideal since that tracks used space per user, not free space on fs as a whole. But if I remember right there were discussions about ENOSPC notification from filesystem for thin provisioning usecases. It would be good to make this consistent with those but I'm not sure if it went anywhere. Honza -- Jan Kara j...@suse.cz SUSE Labs, CR -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [RFC] shmem: Add eventfd notification on utlilization level
On Tue, Mar 10, 2015 at 10:51:41AM +0900, Kyungmin Park wrote: Any updates? Please just add disk quota support to tmpfs so thast the standard quota netlink notifications can be used. -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [RFC] shmem: Add eventfd notification on utlilization level
On Tue, Mar 10, 2015 at 11:22 PM, Jan Kara j...@suse.cz wrote: On Tue 10-03-15 06:03:23, Christoph Hellwig wrote: On Tue, Mar 10, 2015 at 10:51:41AM +0900, Kyungmin Park wrote: Any updates? Please just add disk quota support to tmpfs so thast the standard quota netlink notifications can be used. If I understand the problem at hand, they are really interested in notification when running out of free space. Using quota for that doesn't seem ideal since that tracks used space per user, not free space on fs as a whole. But if I remember right there were discussions about ENOSPC notification from filesystem for thin provisioning usecases. It would be good to make this consistent with those but I'm not sure if it went anywhere. In mobile case, it provides two warning messages when it remains 5% and 0.1% respectively. to achieve it, some daemon call statfs periodically. right it's inefficient. that's reason we need some notification method from filesystem. tmpfs is different story. some malicious app fills tmpfs then system goes slow. so it has to check it periodically. to avoid it, this patch is developed and want to get feedback. we considered quota but it's not desired one. other can't write tmpfs even though it has 20% remaining. Thank you, Kyungmin Park -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [RFC] shmem: Add eventfd notification on utlilization level
On Tue, 10 Mar 2015, Beata Michalska wrote: Date: Tue, 10 Mar 2015 16:25:12 +0100 From: Beata Michalska b.k.m.de...@gmail.com To: Jan Kara j...@suse.cz Cc: Christoph Hellwig h...@infradead.org, Kyungmin Park kmp...@infradead.org, Krzysztof Kozlowski k.kozlow...@samsung.com, Hugh Dickins hu...@google.com, linux-mm linux...@kvack.org, Linux Kernel Mailing List linux-kernel@vger.kernel.org, Alexander Viro v...@zeniv.linux.org.uk, Linux Filesystem Mailing List linux-fsde...@vger.kernel.org, Bartlomiej Zolnierkiewicz b.zolnier...@samsung.com, Marek Szyprowski m.szyprow...@samsung.com Subject: Re: [RFC] shmem: Add eventfd notification on utlilization level On 03/10/2015 03:22 PM, Jan Kara wrote: On Tue 10-03-15 06:03:23, Christoph Hellwig wrote: On Tue, Mar 10, 2015 at 10:51:41AM +0900, Kyungmin Park wrote: Any updates? Please just add disk quota support to tmpfs so thast the standard quota netlink notifications can be used. If I understand the problem at hand, they are really interested in notification when running out of free space. Using quota for that doesn't seem ideal since that tracks used space per user, not free space on fs as a whole. But if I remember right there were discussions about ENOSPC notification from filesystem for thin provisioning usecases. It would be good to make this consistent with those but I'm not sure if it went anywhere. Honza The ideal case here, would be to get the notification, despite the type of the actual filesystem, whenever the amount of free space drops below a certain level. Quota doesn't seem to be the right approach here. BR Beata Michalska A while back I was prototyping a netlink notification interface for file systems, but it went nowhere. https://lkml.org/lkml/2011/8/18/170 So maybe it's time get back to the drawing board and finish the idea, since it seems to be some interest in this now. -Lukas -- To unsubscribe from this list: send the line unsubscribe linux-fsdevel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [RFC] shmem: Add eventfd notification on utlilization level
On 03/10/2015 03:22 PM, Jan Kara wrote: On Tue 10-03-15 06:03:23, Christoph Hellwig wrote: On Tue, Mar 10, 2015 at 10:51:41AM +0900, Kyungmin Park wrote: Any updates? Please just add disk quota support to tmpfs so thast the standard quota netlink notifications can be used. If I understand the problem at hand, they are really interested in notification when running out of free space. Using quota for that doesn't seem ideal since that tracks used space per user, not free space on fs as a whole. But if I remember right there were discussions about ENOSPC notification from filesystem for thin provisioning usecases. It would be good to make this consistent with those but I'm not sure if it went anywhere. Honza The ideal case here, would be to get the notification, despite the type of the actual filesystem, whenever the amount of free space drops below a certain level. Quota doesn't seem to be the right approach here. BR Beata Michalska -- To unsubscribe from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Re: [RFC] shmem: Add eventfd notification on utlilization level
Any updates? Thank you, Kyungmin Park On Wed, Feb 11, 2015 at 11:50 PM, Krzysztof Kozlowski wrote: > Allow notifying user space when used space of tmpfs exceeds specified > level. > > The utilization level is passed as mount option 'warn_used'. The kernel > will notify user-space through eventfd after exceeding this number of > used blocks. > > The eventfd descriptor has to be passed through sysfs file: > /sys/fs/tmpfs/tmpfs-[0-9]+/warn_used_blocks_efd > > Signed-off-by: Krzysztof Kozlowski > --- > include/linux/shmem_fs.h | 4 ++ > mm/shmem.c | 138 > ++- > 2 files changed, 140 insertions(+), 2 deletions(-) > > diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h > index 50777b5b1e4c..c2ec9909da95 100644 > --- a/include/linux/shmem_fs.h > +++ b/include/linux/shmem_fs.h > @@ -35,6 +35,10 @@ struct shmem_sb_info { > kgid_t gid; /* Mount gid for root directory */ > umode_t mode; /* Mount mode for root directory */ > struct mempolicy *mpol; /* default memory policy for mappings */ > + unsigned long warn_used;/* Warn on reaching used blocks */ > + struct kobject s_kobj; /* kobj for sysfs attributes */ > + struct completion s_kobj_unregister; /* synchronization for put_super > */ > + struct eventfd_ctx *warn_used_efd; /* user-space passed eventfd */ > }; > > static inline struct shmem_inode_info *SHMEM_I(struct inode *inode) > diff --git a/mm/shmem.c b/mm/shmem.c > index f69d296bd0a3..b559adcef3b3 100644 > --- a/mm/shmem.c > +++ b/mm/shmem.c > @@ -34,6 +34,7 @@ > #include > > static struct vfsmount *shm_mnt; > +static struct kset *shmem_kset; > > #ifdef CONFIG_SHMEM > /* > @@ -69,6 +70,7 @@ static struct vfsmount *shm_mnt; > #include > #include > #include > +#include > > #include > #include > @@ -199,6 +201,106 @@ static struct backing_dev_info shmem_backing_dev_info > __read_mostly = { > static LIST_HEAD(shmem_swaplist); > static DEFINE_MUTEX(shmem_swaplist_mutex); > > + > +struct shmem_attr { > + struct attribute attr; > + ssize_t (*show)(struct shmem_attr *, struct shmem_sb_info *, char *); > + ssize_t (*store)(struct shmem_attr *, struct shmem_sb_info *, > +const char *, size_t); > +}; > + > +static int shmem_setup_warn_used_blocks_eventfd(struct shmem_sb_info *sbinfo, > + unsigned int efd) > +{ > + int ret = 0; > + > + if (sbinfo->warn_used_efd) { > + eventfd_ctx_put(sbinfo->warn_used_efd); > + sbinfo->warn_used_efd = NULL; > + } > + > + sbinfo->warn_used_efd = eventfd_ctx_fdget(efd); > + if (IS_ERR(sbinfo->warn_used_efd)) { > + ret = PTR_ERR(sbinfo->warn_used_efd); > + sbinfo->warn_used_efd = NULL; > + } > + > + return ret; > +} > + > +static int parse_strtouint(const char *buf, > + unsigned long long max, unsigned int *value) > +{ > + int ret; > + > + ret = kstrtouint(skip_spaces(buf), 0, value); > + if (!ret && *value > max) > + ret = -EINVAL; > + return ret; > +} > + > +static ssize_t warn_used_blocks_efd_store(struct shmem_attr *a, > + struct shmem_sb_info *sbinfo, > + const char *buf, size_t count) > +{ > + unsigned int val; > + int ret; > + > + if (parse_strtouint(buf, -1ULL, )) > + return -EINVAL; > + > + ret = shmem_setup_warn_used_blocks_eventfd(sbinfo, val); > + > + return ret ? ret : count; > +} > + > +static struct shmem_attr > +shmem_attr_warn_used_blocks_efd = __ATTR_WO(warn_used_blocks_efd); > + > +static struct attribute *shmem_attrs[] = { > + _attr_warn_used_blocks_efd.attr, > + NULL, > +}; > + > +static ssize_t shmem_attr_show(struct kobject *kobj, > + struct attribute *attr, char *buf) > +{ > + struct shmem_sb_info *sbinfo = container_of(kobj, struct > shmem_sb_info, > + s_kobj); > + struct shmem_attr *a = container_of(attr, struct shmem_attr, attr); > + > + return a->show ? a->show(a, sbinfo, buf) : 0; > +} > + > +static ssize_t shmem_attr_store(struct kobject *kobj, > + struct attribute *attr, > + const char *buf, size_t len) > +{ > + struct shmem_sb_info *sbinfo = container_of(kobj, struct > shmem_sb_info, > + s_kobj); > + struct shmem_attr *a = container_of(attr, struct shmem_attr, attr); > + > + return a->store ? a->store(a, sbinfo, buf, len) : 0; > +} > + > +static void shmem_sb_release(struct kobject *kobj) > +{ > + struct shmem_sb_info *sbinfo = container_of(kobj, struct > shmem_sb_info, > +
Re: [RFC] shmem: Add eventfd notification on utlilization level
Any updates? Thank you, Kyungmin Park On Wed, Feb 11, 2015 at 11:50 PM, Krzysztof Kozlowski k.kozlow...@samsung.com wrote: Allow notifying user space when used space of tmpfs exceeds specified level. The utilization level is passed as mount option 'warn_used'. The kernel will notify user-space through eventfd after exceeding this number of used blocks. The eventfd descriptor has to be passed through sysfs file: /sys/fs/tmpfs/tmpfs-[0-9]+/warn_used_blocks_efd Signed-off-by: Krzysztof Kozlowski k.kozlow...@samsung.com --- include/linux/shmem_fs.h | 4 ++ mm/shmem.c | 138 ++- 2 files changed, 140 insertions(+), 2 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 50777b5b1e4c..c2ec9909da95 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -35,6 +35,10 @@ struct shmem_sb_info { kgid_t gid; /* Mount gid for root directory */ umode_t mode; /* Mount mode for root directory */ struct mempolicy *mpol; /* default memory policy for mappings */ + unsigned long warn_used;/* Warn on reaching used blocks */ + struct kobject s_kobj; /* kobj for sysfs attributes */ + struct completion s_kobj_unregister; /* synchronization for put_super */ + struct eventfd_ctx *warn_used_efd; /* user-space passed eventfd */ }; static inline struct shmem_inode_info *SHMEM_I(struct inode *inode) diff --git a/mm/shmem.c b/mm/shmem.c index f69d296bd0a3..b559adcef3b3 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -34,6 +34,7 @@ #include linux/aio.h static struct vfsmount *shm_mnt; +static struct kset *shmem_kset; #ifdef CONFIG_SHMEM /* @@ -69,6 +70,7 @@ static struct vfsmount *shm_mnt; #include linux/syscalls.h #include linux/fcntl.h #include uapi/linux/memfd.h +#include linux/eventfd.h #include asm/uaccess.h #include asm/pgtable.h @@ -199,6 +201,106 @@ static struct backing_dev_info shmem_backing_dev_info __read_mostly = { static LIST_HEAD(shmem_swaplist); static DEFINE_MUTEX(shmem_swaplist_mutex); + +struct shmem_attr { + struct attribute attr; + ssize_t (*show)(struct shmem_attr *, struct shmem_sb_info *, char *); + ssize_t (*store)(struct shmem_attr *, struct shmem_sb_info *, +const char *, size_t); +}; + +static int shmem_setup_warn_used_blocks_eventfd(struct shmem_sb_info *sbinfo, + unsigned int efd) +{ + int ret = 0; + + if (sbinfo-warn_used_efd) { + eventfd_ctx_put(sbinfo-warn_used_efd); + sbinfo-warn_used_efd = NULL; + } + + sbinfo-warn_used_efd = eventfd_ctx_fdget(efd); + if (IS_ERR(sbinfo-warn_used_efd)) { + ret = PTR_ERR(sbinfo-warn_used_efd); + sbinfo-warn_used_efd = NULL; + } + + return ret; +} + +static int parse_strtouint(const char *buf, + unsigned long long max, unsigned int *value) +{ + int ret; + + ret = kstrtouint(skip_spaces(buf), 0, value); + if (!ret *value max) + ret = -EINVAL; + return ret; +} + +static ssize_t warn_used_blocks_efd_store(struct shmem_attr *a, + struct shmem_sb_info *sbinfo, + const char *buf, size_t count) +{ + unsigned int val; + int ret; + + if (parse_strtouint(buf, -1ULL, val)) + return -EINVAL; + + ret = shmem_setup_warn_used_blocks_eventfd(sbinfo, val); + + return ret ? ret : count; +} + +static struct shmem_attr +shmem_attr_warn_used_blocks_efd = __ATTR_WO(warn_used_blocks_efd); + +static struct attribute *shmem_attrs[] = { + shmem_attr_warn_used_blocks_efd.attr, + NULL, +}; + +static ssize_t shmem_attr_show(struct kobject *kobj, + struct attribute *attr, char *buf) +{ + struct shmem_sb_info *sbinfo = container_of(kobj, struct shmem_sb_info, + s_kobj); + struct shmem_attr *a = container_of(attr, struct shmem_attr, attr); + + return a-show ? a-show(a, sbinfo, buf) : 0; +} + +static ssize_t shmem_attr_store(struct kobject *kobj, + struct attribute *attr, + const char *buf, size_t len) +{ + struct shmem_sb_info *sbinfo = container_of(kobj, struct shmem_sb_info, + s_kobj); + struct shmem_attr *a = container_of(attr, struct shmem_attr, attr); + + return a-store ? a-store(a, sbinfo, buf, len) : 0; +} + +static void shmem_sb_release(struct kobject *kobj) +{ + struct shmem_sb_info *sbinfo = container_of(kobj, struct shmem_sb_info, +
[RFC] shmem: Add eventfd notification on utlilization level
Allow notifying user space when used space of tmpfs exceeds specified level. The utilization level is passed as mount option 'warn_used'. The kernel will notify user-space through eventfd after exceeding this number of used blocks. The eventfd descriptor has to be passed through sysfs file: /sys/fs/tmpfs/tmpfs-[0-9]+/warn_used_blocks_efd Signed-off-by: Krzysztof Kozlowski --- include/linux/shmem_fs.h | 4 ++ mm/shmem.c | 138 ++- 2 files changed, 140 insertions(+), 2 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 50777b5b1e4c..c2ec9909da95 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -35,6 +35,10 @@ struct shmem_sb_info { kgid_t gid; /* Mount gid for root directory */ umode_t mode; /* Mount mode for root directory */ struct mempolicy *mpol; /* default memory policy for mappings */ + unsigned long warn_used;/* Warn on reaching used blocks */ + struct kobject s_kobj; /* kobj for sysfs attributes */ + struct completion s_kobj_unregister; /* synchronization for put_super */ + struct eventfd_ctx *warn_used_efd; /* user-space passed eventfd */ }; static inline struct shmem_inode_info *SHMEM_I(struct inode *inode) diff --git a/mm/shmem.c b/mm/shmem.c index f69d296bd0a3..b559adcef3b3 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -34,6 +34,7 @@ #include static struct vfsmount *shm_mnt; +static struct kset *shmem_kset; #ifdef CONFIG_SHMEM /* @@ -69,6 +70,7 @@ static struct vfsmount *shm_mnt; #include #include #include +#include #include #include @@ -199,6 +201,106 @@ static struct backing_dev_info shmem_backing_dev_info __read_mostly = { static LIST_HEAD(shmem_swaplist); static DEFINE_MUTEX(shmem_swaplist_mutex); + +struct shmem_attr { + struct attribute attr; + ssize_t (*show)(struct shmem_attr *, struct shmem_sb_info *, char *); + ssize_t (*store)(struct shmem_attr *, struct shmem_sb_info *, +const char *, size_t); +}; + +static int shmem_setup_warn_used_blocks_eventfd(struct shmem_sb_info *sbinfo, + unsigned int efd) +{ + int ret = 0; + + if (sbinfo->warn_used_efd) { + eventfd_ctx_put(sbinfo->warn_used_efd); + sbinfo->warn_used_efd = NULL; + } + + sbinfo->warn_used_efd = eventfd_ctx_fdget(efd); + if (IS_ERR(sbinfo->warn_used_efd)) { + ret = PTR_ERR(sbinfo->warn_used_efd); + sbinfo->warn_used_efd = NULL; + } + + return ret; +} + +static int parse_strtouint(const char *buf, + unsigned long long max, unsigned int *value) +{ + int ret; + + ret = kstrtouint(skip_spaces(buf), 0, value); + if (!ret && *value > max) + ret = -EINVAL; + return ret; +} + +static ssize_t warn_used_blocks_efd_store(struct shmem_attr *a, + struct shmem_sb_info *sbinfo, + const char *buf, size_t count) +{ + unsigned int val; + int ret; + + if (parse_strtouint(buf, -1ULL, )) + return -EINVAL; + + ret = shmem_setup_warn_used_blocks_eventfd(sbinfo, val); + + return ret ? ret : count; +} + +static struct shmem_attr +shmem_attr_warn_used_blocks_efd = __ATTR_WO(warn_used_blocks_efd); + +static struct attribute *shmem_attrs[] = { + _attr_warn_used_blocks_efd.attr, + NULL, +}; + +static ssize_t shmem_attr_show(struct kobject *kobj, + struct attribute *attr, char *buf) +{ + struct shmem_sb_info *sbinfo = container_of(kobj, struct shmem_sb_info, + s_kobj); + struct shmem_attr *a = container_of(attr, struct shmem_attr, attr); + + return a->show ? a->show(a, sbinfo, buf) : 0; +} + +static ssize_t shmem_attr_store(struct kobject *kobj, + struct attribute *attr, + const char *buf, size_t len) +{ + struct shmem_sb_info *sbinfo = container_of(kobj, struct shmem_sb_info, + s_kobj); + struct shmem_attr *a = container_of(attr, struct shmem_attr, attr); + + return a->store ? a->store(a, sbinfo, buf, len) : 0; +} + +static void shmem_sb_release(struct kobject *kobj) +{ + struct shmem_sb_info *sbinfo = container_of(kobj, struct shmem_sb_info, + s_kobj); + complete(>s_kobj_unregister); +} + +static const struct sysfs_ops shmem_attr_ops = { + .show = shmem_attr_show, + .store = shmem_attr_store, +}; + +static struct kobj_type shmem_ktype = { + .default_attrs = shmem_attrs, + .sysfs_ops = _attr_ops, + .release= shmem_sb_release, +}; + static int
[RFC] shmem: Add eventfd notification on utlilization level
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, , 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 from this list: send the line "unsubscribe linux-kernel" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
[RFC] shmem: Add eventfd notification on utlilization level
Allow notifying user space when used space of tmpfs exceeds specified level. The utilization level is passed as mount option 'warn_used'. The kernel will notify user-space through eventfd after exceeding this number of used blocks. The eventfd descriptor has to be passed through sysfs file: /sys/fs/tmpfs/tmpfs-[0-9]+/warn_used_blocks_efd Signed-off-by: Krzysztof Kozlowski k.kozlow...@samsung.com --- include/linux/shmem_fs.h | 4 ++ mm/shmem.c | 138 ++- 2 files changed, 140 insertions(+), 2 deletions(-) diff --git a/include/linux/shmem_fs.h b/include/linux/shmem_fs.h index 50777b5b1e4c..c2ec9909da95 100644 --- a/include/linux/shmem_fs.h +++ b/include/linux/shmem_fs.h @@ -35,6 +35,10 @@ struct shmem_sb_info { kgid_t gid; /* Mount gid for root directory */ umode_t mode; /* Mount mode for root directory */ struct mempolicy *mpol; /* default memory policy for mappings */ + unsigned long warn_used;/* Warn on reaching used blocks */ + struct kobject s_kobj; /* kobj for sysfs attributes */ + struct completion s_kobj_unregister; /* synchronization for put_super */ + struct eventfd_ctx *warn_used_efd; /* user-space passed eventfd */ }; static inline struct shmem_inode_info *SHMEM_I(struct inode *inode) diff --git a/mm/shmem.c b/mm/shmem.c index f69d296bd0a3..b559adcef3b3 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -34,6 +34,7 @@ #include linux/aio.h static struct vfsmount *shm_mnt; +static struct kset *shmem_kset; #ifdef CONFIG_SHMEM /* @@ -69,6 +70,7 @@ static struct vfsmount *shm_mnt; #include linux/syscalls.h #include linux/fcntl.h #include uapi/linux/memfd.h +#include linux/eventfd.h #include asm/uaccess.h #include asm/pgtable.h @@ -199,6 +201,106 @@ static struct backing_dev_info shmem_backing_dev_info __read_mostly = { static LIST_HEAD(shmem_swaplist); static DEFINE_MUTEX(shmem_swaplist_mutex); + +struct shmem_attr { + struct attribute attr; + ssize_t (*show)(struct shmem_attr *, struct shmem_sb_info *, char *); + ssize_t (*store)(struct shmem_attr *, struct shmem_sb_info *, +const char *, size_t); +}; + +static int shmem_setup_warn_used_blocks_eventfd(struct shmem_sb_info *sbinfo, + unsigned int efd) +{ + int ret = 0; + + if (sbinfo-warn_used_efd) { + eventfd_ctx_put(sbinfo-warn_used_efd); + sbinfo-warn_used_efd = NULL; + } + + sbinfo-warn_used_efd = eventfd_ctx_fdget(efd); + if (IS_ERR(sbinfo-warn_used_efd)) { + ret = PTR_ERR(sbinfo-warn_used_efd); + sbinfo-warn_used_efd = NULL; + } + + return ret; +} + +static int parse_strtouint(const char *buf, + unsigned long long max, unsigned int *value) +{ + int ret; + + ret = kstrtouint(skip_spaces(buf), 0, value); + if (!ret *value max) + ret = -EINVAL; + return ret; +} + +static ssize_t warn_used_blocks_efd_store(struct shmem_attr *a, + struct shmem_sb_info *sbinfo, + const char *buf, size_t count) +{ + unsigned int val; + int ret; + + if (parse_strtouint(buf, -1ULL, val)) + return -EINVAL; + + ret = shmem_setup_warn_used_blocks_eventfd(sbinfo, val); + + return ret ? ret : count; +} + +static struct shmem_attr +shmem_attr_warn_used_blocks_efd = __ATTR_WO(warn_used_blocks_efd); + +static struct attribute *shmem_attrs[] = { + shmem_attr_warn_used_blocks_efd.attr, + NULL, +}; + +static ssize_t shmem_attr_show(struct kobject *kobj, + struct attribute *attr, char *buf) +{ + struct shmem_sb_info *sbinfo = container_of(kobj, struct shmem_sb_info, + s_kobj); + struct shmem_attr *a = container_of(attr, struct shmem_attr, attr); + + return a-show ? a-show(a, sbinfo, buf) : 0; +} + +static ssize_t shmem_attr_store(struct kobject *kobj, + struct attribute *attr, + const char *buf, size_t len) +{ + struct shmem_sb_info *sbinfo = container_of(kobj, struct shmem_sb_info, + s_kobj); + struct shmem_attr *a = container_of(attr, struct shmem_attr, attr); + + return a-store ? a-store(a, sbinfo, buf, len) : 0; +} + +static void shmem_sb_release(struct kobject *kobj) +{ + struct shmem_sb_info *sbinfo = container_of(kobj, struct shmem_sb_info, + s_kobj); + complete(sbinfo-s_kobj_unregister); +} + +static const struct sysfs_ops shmem_attr_ops = { + .show = shmem_attr_show, + .store = shmem_attr_store, +}; + +static struct kobj_type shmem_ktype = { + .default_attrs
[RFC] shmem: Add eventfd notification on utlilization level
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 from this list: send the line unsubscribe linux-kernel in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/