Skip to contentSkip to conversation

overlayfs: inherit SB_NOSEC flag from upperdir

PATCH In review Jeffle Xu 2 participants 2 messages Apr 23, 2020 Overlay filesystem

lore
Share & tools
lore

Jeffle Xu

author
#0 lore raw

PATCH v2 1/1 overlayfs: inherit SB_NOSEC flag from upperdir

Since the stacking of regular file operations [1], the overlayfs edition of write_iter() is called when writing regular files.

Since then, xattr lookup is needed on every write since file_remove_privs() is called from ovl_write_iter(), which would become the performance bottleneck when writing small chunks of data. In my test case, file_remove_privs() would consume ~15% CPU when running fstime of unixbench (the workload is repeadly writing 1 KB to the same file) [2].

Inherit the SB_NOSEC flag from upperdir. Since then xattr lookup would be done only once on the first write. Unixbench fstime gets a ~20% performance gain with this patch.

[1] https://lore.kernel.org/lkml/20180606150905.GC9426@magnolia/T/
[2] https://www.spinics.net/lists/linux-unionfs/msg07153.html

---
 fs/overlayfs/super.c | 4 ++++
 1 file changed, 4 insertions(+)
fs/overlayfs/super.c +4 -0
index 732ad54..1934f71 100644
@@ -1052,6 +1052,10 @@ static int ovl_get_upper(struct super_block *sb, struct ovl_fs *ofs,
 	upper_mnt->mnt_flags &= ~(MNT_NOATIME | MNT_NODIRATIME | MNT_RELATIME);
 	ofs->upper_mnt = upper_mnt;
 
+	/* inherit SB_NOSEC flag from upperdir */
+	if (upper_mnt->mnt_sb->s_flags & SB_NOSEC)
+		sb->s_flags |= SB_NOSEC;
+
 	if (ovl_inuse_trylock(ofs->upper_mnt->mnt_root)) {
 		ofs->upperdir_locked = true;
 	} else {
Signature · 1 line
1.8.3.1
maintainer
#1 lore raw
Quoted 11 lines · Jeffle Xu

Since the stacking of regular file operations [1], the overlayfs edition of write_iter() is called when writing regular files.

Since then, xattr lookup is needed on every write since file_remove_privs() is called from ovl_write_iter(), which would become the performance bottleneck when writing small chunks of data. In my test case, file_remove_privs() would consume ~15% CPU when running fstime of unixbench (the workload is repeadly writing 1 KB to the same file) [2].

Inherit the SB_NOSEC flag from upperdir.

Yes, I think this is safe if we assume no changes to the upper while
it is part of overlay; which is a documented assumption. Once we
relax that no-change rule things become tricky, since it's difficult to propagate the removal of S_NOSEC on upper to the overlay...

Quoted 3 lines

Since then xattr lookup would be
done only once on the first write. Unixbench fstime gets a ~20% performance gain with this patch.

I'll apply this, with an additional comment on the effect of changes to upper.

Thanks,
Miklos