linux-unionfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [RFC PATCH] ovl: suppress negative dentry in lookup
@ 2020-05-07  1:19 Chengguang Xu
  2020-05-08 18:39 ` Amir Goldstein
  0 siblings, 1 reply; 3+ messages in thread
From: Chengguang Xu @ 2020-05-07  1:19 UTC (permalink / raw)
  To: miklos; +Cc: linux-unionfs, Chengguang Xu

When a file is only in a lower layer, after lookup a negative
dentry will be generated in the upper layer or even worse many
negetive dentries will be generated in upper/lower layers. These
negative dentries will be useless after construction of overlayfs'
own dentry and may keep in the memory long time even after unmount
of overlayfs instance. This patch tries to kill unnecessary negative
dentry during lookup.

Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
---
 fs/overlayfs/namei.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c
index 723d17744758..cf0ec4d7bcec 100644
--- a/fs/overlayfs/namei.c
+++ b/fs/overlayfs/namei.c
@@ -200,7 +200,7 @@ static int ovl_lookup_single(struct dentry *base, struct ovl_lookup_data *d,
 	int err;
 	bool last_element = !post[0];
 
-	this = lookup_positive_unlocked(name, base, namelen);
+	this = lookup_one_len_unlocked(name, base, namelen);
 	if (IS_ERR(this)) {
 		err = PTR_ERR(this);
 		this = NULL;
@@ -209,6 +209,15 @@ static int ovl_lookup_single(struct dentry *base, struct ovl_lookup_data *d,
 		goto out_err;
 	}
 
+	/* Borrow the check from lookup_positive_unlocked */
+	if (d_flags_negative(smp_load_acquire(&this->d_flags))) {
+		d_drop(this);
+		dput(this);
+		this = NULL;
+		err = -ENOENT;
+		goto out;
+	}
+
 	if (ovl_dentry_weird(this)) {
 		/* Don't support traversing automounts and other weirdness */
 		err = -EREMOTE;
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH] ovl: suppress negative dentry in lookup
  2020-05-07  1:19 [RFC PATCH] ovl: suppress negative dentry in lookup Chengguang Xu
@ 2020-05-08 18:39 ` Amir Goldstein
  2020-05-11 12:52   ` Miklos Szeredi
  0 siblings, 1 reply; 3+ messages in thread
From: Amir Goldstein @ 2020-05-08 18:39 UTC (permalink / raw)
  To: Chengguang Xu; +Cc: Miklos Szeredi, overlayfs

On Thu, May 7, 2020 at 4:21 AM Chengguang Xu <cgxu519@mykernel.net> wrote:
>
> When a file is only in a lower layer, after lookup a negative

Or in no layer at all...

> dentry will be generated in the upper layer or even worse many
> negetive dentries will be generated in upper/lower layers. These
> negative dentries will be useless after construction of overlayfs'
> own dentry and may keep in the memory long time even after unmount
> of overlayfs instance. This patch tries to kill unnecessary negative
> dentry during lookup.
>
> Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
> ---
>  fs/overlayfs/namei.c | 11 ++++++++++-
>  1 file changed, 10 insertions(+), 1 deletion(-)
>
> diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c
> index 723d17744758..cf0ec4d7bcec 100644
> --- a/fs/overlayfs/namei.c
> +++ b/fs/overlayfs/namei.c
> @@ -200,7 +200,7 @@ static int ovl_lookup_single(struct dentry *base, struct ovl_lookup_data *d,
>         int err;
>         bool last_element = !post[0];
>
> -       this = lookup_positive_unlocked(name, base, namelen);
> +       this = lookup_one_len_unlocked(name, base, namelen);
>         if (IS_ERR(this)) {
>                 err = PTR_ERR(this);
>                 this = NULL;
> @@ -209,6 +209,15 @@ static int ovl_lookup_single(struct dentry *base, struct ovl_lookup_data *d,
>                 goto out_err;
>         }
>
> +       /* Borrow the check from lookup_positive_unlocked */
> +       if (d_flags_negative(smp_load_acquire(&this->d_flags))) {
> +               d_drop(this);
> +               dput(this);
> +               this = NULL;
> +               err = -ENOENT;
> +               goto out;
> +       }
> +

This is a nice improvement, but my feeling is that this low level code
belongs in a vfs helper with well documented semantics.

Thanks,
Amir.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [RFC PATCH] ovl: suppress negative dentry in lookup
  2020-05-08 18:39 ` Amir Goldstein
@ 2020-05-11 12:52   ` Miklos Szeredi
  0 siblings, 0 replies; 3+ messages in thread
From: Miklos Szeredi @ 2020-05-11 12:52 UTC (permalink / raw)
  To: Amir Goldstein; +Cc: Chengguang Xu, overlayfs

On Fri, May 8, 2020 at 8:39 PM Amir Goldstein <amir73il@gmail.com> wrote:
>
> On Thu, May 7, 2020 at 4:21 AM Chengguang Xu <cgxu519@mykernel.net> wrote:
> >
> > When a file is only in a lower layer, after lookup a negative
>
> Or in no layer at all...
>
> > dentry will be generated in the upper layer or even worse many
> > negetive dentries will be generated in upper/lower layers. These
> > negative dentries will be useless after construction of overlayfs'
> > own dentry and may keep in the memory long time even after unmount
> > of overlayfs instance. This patch tries to kill unnecessary negative
> > dentry during lookup.
> >
> > Signed-off-by: Chengguang Xu <cgxu519@mykernel.net>
> > ---
> >  fs/overlayfs/namei.c | 11 ++++++++++-
> >  1 file changed, 10 insertions(+), 1 deletion(-)
> >
> > diff --git a/fs/overlayfs/namei.c b/fs/overlayfs/namei.c
> > index 723d17744758..cf0ec4d7bcec 100644
> > --- a/fs/overlayfs/namei.c
> > +++ b/fs/overlayfs/namei.c
> > @@ -200,7 +200,7 @@ static int ovl_lookup_single(struct dentry *base, struct ovl_lookup_data *d,
> >         int err;
> >         bool last_element = !post[0];
> >
> > -       this = lookup_positive_unlocked(name, base, namelen);
> > +       this = lookup_one_len_unlocked(name, base, namelen);
> >         if (IS_ERR(this)) {
> >                 err = PTR_ERR(this);
> >                 this = NULL;
> > @@ -209,6 +209,15 @@ static int ovl_lookup_single(struct dentry *base, struct ovl_lookup_data *d,
> >                 goto out_err;
> >         }
> >
> > +       /* Borrow the check from lookup_positive_unlocked */
> > +       if (d_flags_negative(smp_load_acquire(&this->d_flags))) {
> > +               d_drop(this);
> > +               dput(this);
> > +               this = NULL;
> > +               err = -ENOENT;
> > +               goto out;
> > +       }
> > +
>
> This is a nice improvement, but my feeling is that this low level code
> belongs in a vfs helper with well documented semantics.

I agree.  Using d_drop() with the parent dir unlocked is not a good idea.

We need a new helper that does all of lookup_positive_unlocked() but
with a conditional d_drop() after calling __lookup_slow().  In fact
not dropping already cached negatives is probably a good idea, so
doing it only in the slowpath should be the right thing.

Thanks,
Miklos

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-05-11 12:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-07  1:19 [RFC PATCH] ovl: suppress negative dentry in lookup Chengguang Xu
2020-05-08 18:39 ` Amir Goldstein
2020-05-11 12:52   ` Miklos Szeredi

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).