2019-08-22 00:17:19

by Khazhismel Kumykov

[permalink] [raw]
Subject: [PATCH 1/3] fuse: on 64-bit store time in d_fsdata directly

Implements the optimization noted in f75fdf22b0a8 ("fuse: don't use
->d_time"), as the additional memory can be significant. (In particular,
on SLAB configurations this 8-byte alloc becomes 32 bytes). Per-dentry,
this can consume significant memory.

Signed-off-by: Khazhismel Kumykov <[email protected]>
---
fs/fuse/dir.c | 19 +++++++++++++++++++
1 file changed, 19 insertions(+)

diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index dd0f64f7bc06..f9c59a296568 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -24,6 +24,18 @@ static void fuse_advise_use_readdirplus(struct inode *dir)
set_bit(FUSE_I_ADVISE_RDPLUS, &fi->state);
}

+#if BITS_PER_LONG >= 64
+static inline void fuse_dentry_settime(struct dentry *entry, u64 time)
+{
+ entry->d_fsdata = (void *) time;
+}
+
+static inline u64 fuse_dentry_time(struct dentry *entry)
+{
+ return (u64)entry->d_fsdata;
+}
+
+#else
union fuse_dentry {
u64 time;
struct rcu_head rcu;
@@ -38,6 +50,7 @@ static inline u64 fuse_dentry_time(struct dentry *entry)
{
return ((union fuse_dentry *) entry->d_fsdata)->time;
}
+#endif

/*
* FUSE caches dentries and attributes with separate timeout. The
@@ -242,6 +255,7 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
goto out;
}

+#if BITS_PER_LONG < 64
static int fuse_dentry_init(struct dentry *dentry)
{
dentry->d_fsdata = kzalloc(sizeof(union fuse_dentry), GFP_KERNEL);
@@ -254,16 +268,21 @@ static void fuse_dentry_release(struct dentry *dentry)

kfree_rcu(fd, rcu);
}
+#endif

const struct dentry_operations fuse_dentry_operations = {
.d_revalidate = fuse_dentry_revalidate,
+#if BITS_PER_LONG < 64
.d_init = fuse_dentry_init,
.d_release = fuse_dentry_release,
+#endif
};

const struct dentry_operations fuse_root_dentry_operations = {
+#if BITS_PER_LONG < 64
.d_init = fuse_dentry_init,
.d_release = fuse_dentry_release,
+#endif
};

int fuse_valid_type(int m)
--
2.23.0.187.g17f5b7556c-goog


2019-08-22 00:17:30

by Khazhismel Kumykov

[permalink] [raw]
Subject: [PATCH 2/3] fuse: kmemcg account fs data

account per-file, dentry, and inode data

accounts the per-file reserved request, adding new
fuse_request_alloc_account()

blockdev/superblock and temporary per-request data was left alone, as
this usually isn't accounted

Signed-off-by: Khazhismel Kumykov <[email protected]>
---
fs/fuse/dev.c | 6 ++++++
fs/fuse/dir.c | 3 ++-
fs/fuse/file.c | 4 ++--
fs/fuse/fuse_i.h | 2 ++
fs/fuse/inode.c | 3 ++-
5 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index ea8237513dfa..a0d166a6596f 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -97,6 +97,12 @@ struct fuse_req *fuse_request_alloc(unsigned npages)
}
EXPORT_SYMBOL_GPL(fuse_request_alloc);

+struct fuse_req *fuse_request_alloc_account(unsigned int npages)
+{
+ return __fuse_request_alloc(npages, GFP_KERNEL_ACCOUNT);
+}
+EXPORT_SYMBOL_GPL(fuse_request_alloc_account);
+
struct fuse_req *fuse_request_alloc_nofs(unsigned npages)
{
return __fuse_request_alloc(npages, GFP_NOFS);
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
index f9c59a296568..2013e1222de7 100644
--- a/fs/fuse/dir.c
+++ b/fs/fuse/dir.c
@@ -258,7 +258,8 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
#if BITS_PER_LONG < 64
static int fuse_dentry_init(struct dentry *dentry)
{
- dentry->d_fsdata = kzalloc(sizeof(union fuse_dentry), GFP_KERNEL);
+ dentry->d_fsdata = kzalloc(sizeof(union fuse_dentry),
+ GFP_KERNEL_ACCOUNT | __GFP_RECLAIMABLE);

return dentry->d_fsdata ? 0 : -ENOMEM;
}
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 5ae2828beb00..c584ad7478b3 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -45,12 +45,12 @@ struct fuse_file *fuse_file_alloc(struct fuse_conn *fc)
{
struct fuse_file *ff;

- ff = kzalloc(sizeof(struct fuse_file), GFP_KERNEL);
+ ff = kzalloc(sizeof(struct fuse_file), GFP_KERNEL_ACCOUNT);
if (unlikely(!ff))
return NULL;

ff->fc = fc;
- ff->reserved_req = fuse_request_alloc(0);
+ ff->reserved_req = fuse_request_alloc_account(0);
if (unlikely(!ff->reserved_req)) {
kfree(ff);
return NULL;
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 24dbca777775..08161b2d9b08 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -904,6 +904,8 @@ void __exit fuse_ctl_cleanup(void);
*/
struct fuse_req *fuse_request_alloc(unsigned npages);

+struct fuse_req *fuse_request_alloc_account(unsigned int npages);
+
struct fuse_req *fuse_request_alloc_nofs(unsigned npages);

bool fuse_req_realloc_pages(struct fuse_conn *fc, struct fuse_req *req,
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index 4bb885b0f032..eab44ddc68b9 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -76,7 +76,8 @@ struct fuse_mount_data {

struct fuse_forget_link *fuse_alloc_forget(void)
{
- return kzalloc(sizeof(struct fuse_forget_link), GFP_KERNEL);
+ return kzalloc(sizeof(struct fuse_forget_link),
+ GFP_KERNEL_ACCOUNT | __GFP_RECLAIMABLE);
}

static struct inode *fuse_alloc_inode(struct super_block *sb)
--
2.23.0.187.g17f5b7556c-goog

2019-08-22 00:19:19

by Shakeel Butt

[permalink] [raw]
Subject: Re: [PATCH 1/3] fuse: on 64-bit store time in d_fsdata directly

On Wed, Aug 21, 2019 at 5:09 PM Khazhismel Kumykov <[email protected]> wrote:
>
> Implements the optimization noted in f75fdf22b0a8 ("fuse: don't use
> ->d_time"), as the additional memory can be significant. (In particular,
> on SLAB configurations this 8-byte alloc becomes 32 bytes). Per-dentry,
> this can consume significant memory.
>
> Signed-off-by: Khazhismel Kumykov <[email protected]>

Actually we are seeing this in production where a job creating a lot
of fuse files cause a lot of extra system level overhead.

Reviewed-by: Shakeel Butt <[email protected]>

> ---
> fs/fuse/dir.c | 19 +++++++++++++++++++
> 1 file changed, 19 insertions(+)
>
> diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
> index dd0f64f7bc06..f9c59a296568 100644
> --- a/fs/fuse/dir.c
> +++ b/fs/fuse/dir.c
> @@ -24,6 +24,18 @@ static void fuse_advise_use_readdirplus(struct inode *dir)
> set_bit(FUSE_I_ADVISE_RDPLUS, &fi->state);
> }
>
> +#if BITS_PER_LONG >= 64
> +static inline void fuse_dentry_settime(struct dentry *entry, u64 time)
> +{
> + entry->d_fsdata = (void *) time;
> +}
> +
> +static inline u64 fuse_dentry_time(struct dentry *entry)
> +{
> + return (u64)entry->d_fsdata;
> +}
> +
> +#else
> union fuse_dentry {
> u64 time;
> struct rcu_head rcu;
> @@ -38,6 +50,7 @@ static inline u64 fuse_dentry_time(struct dentry *entry)
> {
> return ((union fuse_dentry *) entry->d_fsdata)->time;
> }
> +#endif
>
> /*
> * FUSE caches dentries and attributes with separate timeout. The
> @@ -242,6 +255,7 @@ static int fuse_dentry_revalidate(struct dentry *entry, unsigned int flags)
> goto out;
> }
>
> +#if BITS_PER_LONG < 64
> static int fuse_dentry_init(struct dentry *dentry)
> {
> dentry->d_fsdata = kzalloc(sizeof(union fuse_dentry), GFP_KERNEL);
> @@ -254,16 +268,21 @@ static void fuse_dentry_release(struct dentry *dentry)
>
> kfree_rcu(fd, rcu);
> }
> +#endif
>
> const struct dentry_operations fuse_dentry_operations = {
> .d_revalidate = fuse_dentry_revalidate,
> +#if BITS_PER_LONG < 64
> .d_init = fuse_dentry_init,
> .d_release = fuse_dentry_release,
> +#endif
> };
>
> const struct dentry_operations fuse_root_dentry_operations = {
> +#if BITS_PER_LONG < 64
> .d_init = fuse_dentry_init,
> .d_release = fuse_dentry_release,
> +#endif
> };
>
> int fuse_valid_type(int m)
> --
> 2.23.0.187.g17f5b7556c-goog
>

2019-08-22 05:06:47

by Khazhismel Kumykov

[permalink] [raw]
Subject: [PATCH 3/3] fuse: pass gfp flags to fuse_request_alloc

Instead of having a helper per flag

Signed-off-by: Khazhismel Kumykov <[email protected]>
---
fs/fuse/dev.c | 22 +++-------------------
fs/fuse/file.c | 6 +++---
fs/fuse/fuse_i.h | 6 +-----
fs/fuse/inode.c | 4 ++--
4 files changed, 9 insertions(+), 29 deletions(-)

diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index a0d166a6596f..c957620ce7ba 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -66,7 +66,7 @@ static struct page **fuse_req_pages_alloc(unsigned int npages, gfp_t flags,
return pages;
}

-static struct fuse_req *__fuse_request_alloc(unsigned npages, gfp_t flags)
+struct fuse_req *fuse_request_alloc(unsigned int npages, gfp_t flags)
{
struct fuse_req *req = kmem_cache_zalloc(fuse_req_cachep, flags);
if (req) {
@@ -90,24 +90,8 @@ static struct fuse_req *__fuse_request_alloc(unsigned npages, gfp_t flags)
}
return req;
}
-
-struct fuse_req *fuse_request_alloc(unsigned npages)
-{
- return __fuse_request_alloc(npages, GFP_KERNEL);
-}
EXPORT_SYMBOL_GPL(fuse_request_alloc);

-struct fuse_req *fuse_request_alloc_account(unsigned int npages)
-{
- return __fuse_request_alloc(npages, GFP_KERNEL_ACCOUNT);
-}
-EXPORT_SYMBOL_GPL(fuse_request_alloc_account);
-
-struct fuse_req *fuse_request_alloc_nofs(unsigned npages)
-{
- return __fuse_request_alloc(npages, GFP_NOFS);
-}
-
static void fuse_req_pages_free(struct fuse_req *req)
{
if (req->pages != req->inline_pages)
@@ -207,7 +191,7 @@ static struct fuse_req *__fuse_get_req(struct fuse_conn *fc, unsigned npages,
if (fc->conn_error)
goto out;

- req = fuse_request_alloc(npages);
+ req = fuse_request_alloc(npages, GFP_KERNEL);
err = -ENOMEM;
if (!req) {
if (for_background)
@@ -316,7 +300,7 @@ struct fuse_req *fuse_get_req_nofail_nopages(struct fuse_conn *fc,
wait_event(fc->blocked_waitq, fc->initialized);
/* Matches smp_wmb() in fuse_set_initialized() */
smp_rmb();
- req = fuse_request_alloc(0);
+ req = fuse_request_alloc(0, GFP_KERNEL);
if (!req)
req = get_reserved_req(fc, file);

diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index c584ad7478b3..ae8c8016bb8e 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -50,7 +50,7 @@ struct fuse_file *fuse_file_alloc(struct fuse_conn *fc)
return NULL;

ff->fc = fc;
- ff->reserved_req = fuse_request_alloc_account(0);
+ ff->reserved_req = fuse_request_alloc(0, GFP_KERNEL_ACCOUNT);
if (unlikely(!ff->reserved_req)) {
kfree(ff);
return NULL;
@@ -1703,7 +1703,7 @@ static int fuse_writepage_locked(struct page *page)

set_page_writeback(page);

- req = fuse_request_alloc_nofs(1);
+ req = fuse_request_alloc(1, GFP_NOFS);
if (!req)
goto err;

@@ -1923,7 +1923,7 @@ static int fuse_writepages_fill(struct page *page,
struct fuse_inode *fi = get_fuse_inode(inode);

err = -ENOMEM;
- req = fuse_request_alloc_nofs(FUSE_REQ_INLINE_PAGES);
+ req = fuse_request_alloc(FUSE_REQ_INLINE_PAGES, GFP_NOFS);
if (!req) {
__free_page(tmp_page);
goto out_unlock;
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 08161b2d9b08..8080a51096e9 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -902,11 +902,7 @@ void __exit fuse_ctl_cleanup(void);
/**
* Allocate a request
*/
-struct fuse_req *fuse_request_alloc(unsigned npages);
-
-struct fuse_req *fuse_request_alloc_account(unsigned int npages);
-
-struct fuse_req *fuse_request_alloc_nofs(unsigned npages);
+struct fuse_req *fuse_request_alloc(unsigned int npages, gfp_t flags);

bool fuse_req_realloc_pages(struct fuse_conn *fc, struct fuse_req *req,
gfp_t flags);
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c
index eab44ddc68b9..ad92e93eaddd 100644
--- a/fs/fuse/inode.c
+++ b/fs/fuse/inode.c
@@ -1178,13 +1178,13 @@ static int fuse_fill_super(struct super_block *sb, void *data, int silent)
/* Root dentry doesn't have .d_revalidate */
sb->s_d_op = &fuse_dentry_operations;

- init_req = fuse_request_alloc(0);
+ init_req = fuse_request_alloc(0, GFP_KERNEL);
if (!init_req)
goto err_put_root;
__set_bit(FR_BACKGROUND, &init_req->flags);

if (is_bdev) {
- fc->destroy_req = fuse_request_alloc(0);
+ fc->destroy_req = fuse_request_alloc(0, GFP_KERNEL);
if (!fc->destroy_req)
goto err_free_init_req;
}
--
2.23.0.187.g17f5b7556c-goog