All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joel Becker <jlbec@evilplan.org>
To: Dmitry Bogdanov <d.bogdanov@yadro.com>
Cc: Christoph Hellwig <hch@lst.de>,
	linux-fsdevel@vger.kernel.org, linux@yadro.com
Subject: Re: [PATCH 1/2] configfs: reduce memory consumption by symlinks
Date: Mon, 1 Apr 2024 11:24:21 -0700	[thread overview]
Message-ID: <Zgr71RfStvjIVkFQ@google.com> (raw)
In-Reply-To: <20240401082655.31613-2-d.bogdanov@yadro.com>

On Mon, Apr 01, 2024 at 11:26:54AM +0300, Dmitry Bogdanov wrote:
> Instead of preallocating PAGE_SIZE for a symlink path, allocate the exact
> size of that path.
> 
> Fixes: e9c03af21cc7 (configfs: calculate the symlink target only once)
> Signed-off-by: Dmitry Bogdanov <d.bogdanov@yadro.com>

Reviewed-by: Joel Becker <jlbec@evilplan.org>

> 
> ---
> I treat this as bugfux due to reducing of enourmous memory consumption.
> ---
>  fs/configfs/symlink.c | 22 +++++++++++-----------
>  1 file changed, 11 insertions(+), 11 deletions(-)
> 
> diff --git a/fs/configfs/symlink.c b/fs/configfs/symlink.c
> index 0623c3edcfb9..224c9e4899d4 100644
> --- a/fs/configfs/symlink.c
> +++ b/fs/configfs/symlink.c
> @@ -54,7 +54,7 @@ static void fill_item_path(struct config_item * item, char * buffer, int length)
>  }
>  
>  static int configfs_get_target_path(struct config_item *item,
> -		struct config_item *target, char *path)
> +		struct config_item *target, char **path)
>  {
>  	int depth, size;
>  	char *s;
> @@ -66,11 +66,16 @@ static int configfs_get_target_path(struct config_item *item,
>  
>  	pr_debug("%s: depth = %d, size = %d\n", __func__, depth, size);
>  
> -	for (s = path; depth--; s += 3)
> +	*path = kzalloc(size, GFP_KERNEL);
> +	if (!*path)
> +		return -ENOMEM;
> +
> +
> +	for (s = *path; depth--; s += 3)
>  		strcpy(s,"../");
>  
> -	fill_item_path(target, path, size);
> -	pr_debug("%s: path = '%s'\n", __func__, path);
> +	fill_item_path(target, *path, size);
> +	pr_debug("%s: path = '%s'\n", __func__, *path);
>  	return 0;
>  }
>  
> @@ -79,27 +84,22 @@ static int create_link(struct config_item *parent_item,
>  		       struct dentry *dentry)
>  {
>  	struct configfs_dirent *target_sd = item->ci_dentry->d_fsdata;
> -	char *body;
> +	char *body = NULL;
>  	int ret;
>  
>  	if (!configfs_dirent_is_ready(target_sd))
>  		return -ENOENT;
>  
> -	body = kzalloc(PAGE_SIZE, GFP_KERNEL);
> -	if (!body)
> -		return -ENOMEM;
> -
>  	configfs_get(target_sd);
>  	spin_lock(&configfs_dirent_lock);
>  	if (target_sd->s_type & CONFIGFS_USET_DROPPING) {
>  		spin_unlock(&configfs_dirent_lock);
>  		configfs_put(target_sd);
> -		kfree(body);
>  		return -ENOENT;
>  	}
>  	target_sd->s_links++;
>  	spin_unlock(&configfs_dirent_lock);
> -	ret = configfs_get_target_path(parent_item, item, body);
> +	ret = configfs_get_target_path(parent_item, item, &body);
>  	if (!ret)
>  		ret = configfs_create_link(target_sd, parent_item->ci_dentry,
>  					   dentry, body);
> -- 
> 2.25.1
> 

-- 

"Can any of you seriously say the Bill of Rights could get through
 Congress today?  It wouldn't even get out of committee."
	- F. Lee Bailey

			http://www.jlbec.org/
			jlbec@evilplan.org

  reply	other threads:[~2024-04-01 18:24 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-01  8:26 [PATCH 0/2] configfs: reduce memory consumption by symlinks Dmitry Bogdanov
2024-04-01  8:26 ` [PATCH 1/2] " Dmitry Bogdanov
2024-04-01 18:24   ` Joel Becker [this message]
2024-04-01  8:26 ` [PATCH 2/2] configfs: make a minimal path of symlink Dmitry Bogdanov
2024-04-01 18:55   ` Joel Becker

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=Zgr71RfStvjIVkFQ@google.com \
    --to=jlbec@evilplan.org \
    --cc=d.bogdanov@yadro.com \
    --cc=hch@lst.de \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux@yadro.com \
    /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: link
Be 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.