Skip to contentSkip to conversation

ovl: replace dget/dput with d_drop in ovl_cleanup()

PATCH In review Miklos Szeredi 4 participants 5 messages Oct 25, 2024 – Nov 5, 2024

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 ovl: replace dget/dput with d_drop in ovl_cleanup()

The reason for the dget/dput pair was to force the upperdentry to be dropped from the cache instead of turning it negative and keeping it cached.

Simpler and cleaner way to achieve the same effect is to just drop the dentry after unlink/rmdir if it was turned negative.

---
v2:
- use d_drop()

 fs/overlayfs/dir.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/overlayfs/dir.c +4 -2
index ab65e98a1def..c7548c2bbc12 100644
@@ -28,12 +28,14 @@ int ovl_cleanup(struct ovl_fs *ofs, struct inode *wdir, struct dentry *wdentry)
 {
 	int err;
 
-	dget(wdentry);
 	if (d_is_dir(wdentry))
 		err = ovl_do_rmdir(ofs, wdir, wdentry);
 	else
 		err = ovl_do_unlink(ofs, wdir, wdentry);
-	dput(wdentry);
+
+	/* A cached negative upper dentry is generally not useful, so drop it. */
+	if (d_is_negative(wdentry))
+		d_drop(wdentry);
 
 	if (err) {
 		pr_err("cleanup of '%pd2' failed (%i)\n",
Signature · 1 line
2.47.0
maintainer
#1 lore raw
Quoted 9 lines · Miklos Szeredi

The reason for the dget/dput pair was to force the upperdentry to be dropped from the cache instead of turning it negative and keeping it cached.

Simpler and cleaner way to achieve the same effect is to just drop the dentry after unlink/rmdir if it was turned negative.

Looks sane.
Applied to overlayfs-next for testing.

Thanks,
Amir.

Quoted 31 lines

---
v2:
- use d_drop()

 fs/overlayfs/dir.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
fs/overlayfs/dir.c +4 -3
index ab65e98a1def..c7548c2bbc12 100644
@@ -28,12 +28,14 @@ int ovl_cleanup(struct ovl_fs *ofs, struct inode *wdir, struct dentry *wdentry)
 {
        int err;
 
-       dget(wdentry);
        if (d_is_dir(wdentry))
                err = ovl_do_rmdir(ofs, wdir, wdentry);
        else
                err = ovl_do_unlink(ofs, wdir, wdentry);
-       dput(wdentry);
+
+       /* A cached negative upper dentry is generally not useful, so drop it. */
+       if (d_is_negative(wdentry))
+               d_drop(wdentry);
 
        if (err) {
                pr_err("cleanup of '%pd2' failed (%i)\n",
--

2.47.0

maintainer
#2 lore raw
Quoted 6 lines · Amir Goldstein
Quoted 5 lines · Miklos Szeredi

The reason for the dget/dput pair was to force the upperdentry to be dropped from the cache instead of turning it negative and keeping it cached.

Quoted 7 lines
Quoted 4 lines

Simpler and cleaner way to achieve the same effect is to just drop the dentry after unlink/rmdir if it was turned negative.

Looks sane.
Applied to overlayfs-next for testing.

I thought it was about preventing an overlayfs objects with negative ->__upperdentry; why would a negative dentry in upper layer be a problem otherwise?

maintainer
#3 lore raw
Quoted 11 lines · Al Viro
Quoted 9 lines · Amir Goldstein
Quoted 8 lines · Miklos Szeredi

The reason for the dget/dput pair was to force the upperdentry to be dropped from the cache instead of turning it negative and keeping it cached.

Simpler and cleaner way to achieve the same effect is to just drop the dentry after unlink/rmdir if it was turned negative.

Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Looks sane.
Applied to overlayfs-next for testing.

I thought it was about preventing an overlayfs objects with negative ->__upperdentry;

Yeah, I overlooked that aspect. Amir, please drop this patch.

Quoted 1 line

why would a negative dentry in upper layer be a problem otherwise?

Double caching, see this commit:

commit 1434a65ea625c51317ccdf06dabf4bd27d20fa10

Author: Chengguang Xu <[email protected]>
Date:   Tue May 26 09:35:57 2020 +0800

ovl: drop negative dentry in upper layer

Negative dentries of upper layer are 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 drop unnecessary negative dentry of upper layer to effectively reclaim memory.

The reason lower dentries are different is that lower layers could be (and often are) shared, while the upper layer is always private.

Thanks,
Miklos

maintainer
#4 lore raw
Quoted 13 lines · Miklos Szeredi
Quoted 11 lines · Al Viro
Quoted 9 lines · Amir Goldstein
Quoted 8 lines · Miklos Szeredi

The reason for the dget/dput pair was to force the upperdentry to be dropped from the cache instead of turning it negative and keeping it cached.

Simpler and cleaner way to achieve the same effect is to just drop the dentry after unlink/rmdir if it was turned negative.

Quoted 9 lines
Quoted 6 lines
Quoted 4 lines
Quoted 1 line

Looks sane.
Applied to overlayfs-next for testing.

I thought it was about preventing an overlayfs objects with negative ->__upperdentry;

Yeah, I overlooked that aspect. Amir, please drop this patch.

Dropped.

Thanks,
Amir.