Linux filesystem development
 help / color / mirror / Atom feed
From: Paulo Alcantara <pc@manguebit.org>
To: David Howells <dhowells@redhat.com>,
	Christian Brauner <christian@brauner.io>
Cc: David Howells <dhowells@redhat.com>,
	Matthew Wilcox <willy@infradead.org>,
	Namjae Jeon <linkinjeon@kernel.org>,
	Marc Dionne <marc.dionne@auristor.com>,
	Stefan Metzmacher <metze@samba.org>,
	Eric Van Hensbergen <ericvh@kernel.org>,
	Dominique Martinet <asmadeus@codewreck.org>,
	Ilya Dryomov <idryomov@gmail.com>,
	netfs@lists.linux.dev, linux-afs@lists.infradead.org,
	linux-cifs@vger.kernel.org, linux-nfs@vger.kernel.org,
	ceph-devel@vger.kernel.org, v9fs@lists.linux.dev,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v12 5/5] cachefiles: Preset the state xattr when creating a new file
Date: Fri, 11 Sep 2026 17:21:38 -0300	[thread overview]
Message-ID: <920f0b50480231f1af8a9c8e7f118f5c@manguebit.org> (raw)
In-Reply-To: <20260910220242.2165023-6-dhowells@redhat.com>

David Howells <dhowells@redhat.com> writes:

> With a really small cache, cachefiles is likely to see a lot of writes
> hitting ENOSPC - and this can include setxattr that sets the state xattr on
> a cachefile - but we don't really want to successfully fill a cache file
> only to have to scrap it because we can't set the xattr.
>
> Instead, preset the xattr when we create the tmpfile we're going to use,
> and scrap the file at that point if we get ENOSPC.  Only if setxattr
> succeeds do we allow data to be written to the file.
>
> Note that there is a potential performance loss in that writes to the cache
> have to be delayed until this is completed - but we do the tmpfile/setxattr
> in parallel, starting when the file is opened and only have to wait once
> writeback occurs.
>
> Signed-off-by: David Howells <dhowells@redhat.com>
> cc: Marc Dionne <marc.dionne@auristor.com>
> cc: Paulo Alcantara <pc@manguebit.org>
> cc: netfs@lists.linux.dev
> cc: linux-fsdevel@vger.kernel.org
> ---
>  fs/cachefiles/internal.h |  1 +
>  fs/cachefiles/namei.c    |  5 ++++
>  fs/cachefiles/xattr.c    | 59 +++++++++++++++++++++++++++++++++++++++-
>  3 files changed, 64 insertions(+), 1 deletion(-)
>
> diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
> index b2605111fd56..664be64ab538 100644
> --- a/fs/cachefiles/internal.h
> +++ b/fs/cachefiles/internal.h
> @@ -283,6 +283,7 @@ void cachefiles_withdraw_volume(struct cachefiles_volume *volume);
>  /*
>   * xattr.c
>   */
> +int cachefiles_preset_object_xattr(struct cachefiles_object *object, struct file *file);
>  extern int cachefiles_set_object_xattr(struct cachefiles_object *object);
>  extern int cachefiles_check_auxdata(struct cachefiles_object *object,
>  				    struct file *file);
> diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
> index ca093840e577..ef656a319ede 100644
> --- a/fs/cachefiles/namei.c
> +++ b/fs/cachefiles/namei.c
> @@ -450,6 +450,11 @@ struct file *cachefiles_create_tmpfile(struct cachefiles_object *object)
>  		pr_notice("Cache does not support read_iter and write_iter\n");
>  		goto err_unuse;
>  	}
> +
> +	/* Preallocate space for the xattr. */
> +	ret = cachefiles_preset_object_xattr(object, file);
> +	if (ret < 0)
> +		goto err_unuse;
>  out:
>  	cachefiles_end_secure(cache, saved_cred);
>  	object->content_info = CACHEFILES_CONTENT_ALL;
> diff --git a/fs/cachefiles/xattr.c b/fs/cachefiles/xattr.c
> index 551a3b0069c2..8ebb713482e3 100644
> --- a/fs/cachefiles/xattr.c
> +++ b/fs/cachefiles/xattr.c
> @@ -34,6 +34,57 @@ struct cachefiles_vol_xattr {
>  	__u8	data[];		/* netfs volume coherency data */
>  } __packed;
>  
> +/*
> + * Preset the state xattr on a cache file to allocate space for it.
> + */
> +int cachefiles_preset_object_xattr(struct cachefiles_object *object, struct file *file)
> +{
> +	struct cachefiles_xattr *buf;
> +	struct dentry *dentry = file->f_path.dentry;
> +	unsigned int len = object->cookie->aux_len;
> +	int ret;
> +
> +	buf = kzalloc(sizeof(struct cachefiles_xattr) + min(len, sizeof(__be64)), GFP_KERNEL);

You should use max() here.

Otherwise looks good,

Reviewed-by: Paulo Alcantara <pc@manguebit.org>

      reply	other threads:[~2026-09-11 20:21 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-10 22:02 [PATCH v12 0/5] netfs, cachefiles: Changes for next, primarily occupancy tracking-related David Howells
2026-09-10 22:02 ` [PATCH v12 1/5] cachefiles: Clean up cachefiles_do_prepare_read() David Howells
2026-09-11 20:19   ` Paulo Alcantara
2026-09-10 22:02 ` [PATCH v12 2/5] netfs, cachefiles: Add a couple of traces for write failure David Howells
2026-09-11 20:19   ` Paulo Alcantara
2026-09-10 22:02 ` [PATCH v12 3/5] cachefiles: Add a tracepoint to log insufficient space errors David Howells
2026-09-11 20:19   ` Paulo Alcantara
2026-09-10 22:02 ` [PATCH v12 4/5] cachefiles: Don't rely on backing fs storage map for most use cases David Howells
2026-09-10 22:02 ` [PATCH v12 5/5] cachefiles: Preset the state xattr when creating a new file David Howells
2026-09-11 20:21   ` Paulo Alcantara [this message]

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=920f0b50480231f1af8a9c8e7f118f5c@manguebit.org \
    --to=pc@manguebit.org \
    --cc=asmadeus@codewreck.org \
    --cc=ceph-devel@vger.kernel.org \
    --cc=christian@brauner.io \
    --cc=dhowells@redhat.com \
    --cc=ericvh@kernel.org \
    --cc=idryomov@gmail.com \
    --cc=linkinjeon@kernel.org \
    --cc=linux-afs@lists.infradead.org \
    --cc=linux-cifs@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nfs@vger.kernel.org \
    --cc=marc.dionne@auristor.com \
    --cc=metze@samba.org \
    --cc=netfs@lists.linux.dev \
    --cc=v9fs@lists.linux.dev \
    --cc=willy@infradead.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox