All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC v2 0/4] overlayfs: Optimize override/revert creds
@ 2024-01-25 23:57 Vinicius Costa Gomes
  2024-01-25 23:57 ` [RFC v2 1/4] cleanup: Fix discarded const warning when defining guards Vinicius Costa Gomes
                   ` (4 more replies)
  0 siblings, 5 replies; 15+ messages in thread
From: Vinicius Costa Gomes @ 2024-01-25 23:57 UTC (permalink / raw)
  To: brauner, amir73il, hu1.chen
  Cc: miklos, malini.bhandaru, tim.c.chen, mikko.ylinen, lizhen.you,
	linux-unionfs, linux-kernel, Vinicius Costa Gomes

Hi,

It was noticed that some workloads suffer from contention on
increasing/decrementing the ->usage counter in their credentials,
those refcount operations are associated with overriding/reverting the
current task credentials. (the linked thread adds more context)

In some specialized cases, overlayfs is one of them, the credentials
in question have a longer lifetime than the override/revert "critical
section". In the overlayfs case, the credentials are created when the
fs is mounted and destroyed when it's unmounted. In this case of long
lived credentials, the usage counter doesn't need to be
incremented/decremented.

Add a lighter version of credentials override/revert to be used in
these specialized cases. To make sure that the override/revert calls
are paired, add a cleanup guard macro. This was suggested here:

https://lore.kernel.org/all/20231219-marken-pochen-26d888fb9bb9@brauner/

With a small number of tweaks:
 - Used inline functions instead of macros;
 - A small change to store the credentials into the passed argument,
   the guard is now defined as (note the added '_T ='):
   
      DEFINE_GUARD(cred, const struct cred *, _T = override_creds_light(_T),
                  revert_creds_light(_T));

 - Allow "const" arguments to be used with these kind of guards;

Some comments:
 - If patch 1/4 is not a good idea (adding the cast), the alternative
   I can see is using some kind of container for the credentials;
 - The only user for the backing file ops is overlayfs, so these
   changes make sense, but may not make sense in the most general
   case;

For the numbers, some from 'perf c2c', before this series:
(edited to fit)

#
#        ----- HITM -----                                        Shared                          
#   Num  RmtHitm  LclHitm                      Symbol            Object         Source:Line  Node
# .....  .......  .......  ..........................  ................  ..................  ....
#
  -------------------------
      0      412     1028  
  -------------------------
          41.50%   42.22%  [k] revert_creds            [kernel.vmlinux]  atomic64_64.h:39     0  1
          15.05%   10.60%  [k] override_creds          [kernel.vmlinux]  atomic64_64.h:25     0  1
           0.73%    0.58%  [k] init_file               [kernel.vmlinux]  atomic64_64.h:25     0  1
           0.24%    0.10%  [k] revert_creds            [kernel.vmlinux]  cred.h:266           0  1
          32.28%   37.16%  [k] generic_permission      [kernel.vmlinux]  mnt_idmapping.h:81   0  1
           9.47%    8.75%  [k] generic_permission      [kernel.vmlinux]  mnt_idmapping.h:81   0  1
           0.49%    0.58%  [k] inode_owner_or_capable  [kernel.vmlinux]  mnt_idmapping.h:81   0  1
           0.24%    0.00%  [k] generic_permission      [kernel.vmlinux]  namei.c:354          0

  -------------------------
      1       50      103  
  -------------------------
         100.00%  100.00%  [k] update_cfs_group  [kernel.vmlinux]  atomic64_64.h:15   0  1

  -------------------------
      2       50       98  
  -------------------------
          96.00%   96.94%  [k] update_cfs_group  [kernel.vmlinux]  atomic64_64.h:15   0  1
           2.00%    1.02%  [k] update_load_avg   [kernel.vmlinux]  atomic64_64.h:25   0  1
           0.00%    2.04%  [k] update_load_avg   [kernel.vmlinux]  fair.c:4118        0
           2.00%    0.00%  [k] update_cfs_group  [kernel.vmlinux]  fair.c:3932        0  1

after this series:

#
#        ----- HITM -----                                   Shared                        
#   Num  RmtHitm  LclHitm                 Symbol            Object       Source:Line  Node
# .....  .......  .......   ....................  ................  ................  ....
#
  -------------------------
      0       54       88  
  -------------------------
         100.00%  100.00%   [k] update_cfs_group  [kernel.vmlinux]  atomic64_64.h:15   0  1

  -------------------------
      1       48       83  
  -------------------------
          97.92%   97.59%   [k] update_cfs_group  [kernel.vmlinux]  atomic64_64.h:15   0  1
           2.08%    1.20%   [k] update_load_avg   [kernel.vmlinux]  atomic64_64.h:25   0  1
           0.00%    1.20%   [k] update_load_avg   [kernel.vmlinux]  fair.c:4118        0  1

  -------------------------
      2       28       44  
  -------------------------
          85.71%   79.55%   [k] generic_permission      [kernel.vmlinux]  mnt_idmapping.h:81   0  1
          14.29%   20.45%   [k] generic_permission      [kernel.vmlinux]  mnt_idmapping.h:81   0  1


The contention is practically gone.

Link: https://lore.kernel.org/all/20231018074553.41333-1-hu1.chen@intel.com/

Vinicius Costa Gomes (4):
  cleanup: Fix discarded const warning when defining guards
  cred: Add a light version of override/revert_creds()
  overlayfs: Optimize credentials usage
  fs: Optimize credentials reference count for backing file ops

 fs/backing-file.c       | 124 +++++++++++++++++++---------------------
 fs/overlayfs/copy_up.c  |   4 +-
 fs/overlayfs/dir.c      |  22 +++----
 fs/overlayfs/file.c     |  70 ++++++++++++-----------
 fs/overlayfs/inode.c    |  60 ++++++++++---------
 fs/overlayfs/namei.c    |  21 ++++---
 fs/overlayfs/readdir.c  |  18 +++---
 fs/overlayfs/util.c     |  23 ++++----
 fs/overlayfs/xattrs.c   |  34 +++++------
 include/linux/cleanup.h |   2 +-
 include/linux/cred.h    |  21 +++++++
 kernel/cred.c           |   6 +-
 12 files changed, 215 insertions(+), 190 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 15+ messages in thread
* Re: [RFC v2 3/4] overlayfs: Optimize credentials usage
@ 2024-01-28  8:01 kernel test robot
  0 siblings, 0 replies; 15+ messages in thread
From: kernel test robot @ 2024-01-28  8:01 UTC (permalink / raw)
  To: oe-kbuild; +Cc: lkp, Dan Carpenter

BCC: lkp@intel.com
CC: oe-kbuild-all@lists.linux.dev
In-Reply-To: <20240125235723.39507-4-vinicius.gomes@intel.com>
References: <20240125235723.39507-4-vinicius.gomes@intel.com>
TO: Vinicius Costa Gomes <vinicius.gomes@intel.com>

Hi Vinicius,

[This is a private test report for your RFC patch.]
kernel test robot noticed the following build warnings:

[auto build test WARNING on brauner-vfs/vfs.all]
[also build test WARNING on linus/master v6.8-rc1 next-20240125]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Vinicius-Costa-Gomes/cleanup-Fix-discarded-const-warning-when-defining-guards/20240126-080128
base:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git vfs.all
patch link:    https://lore.kernel.org/r/20240125235723.39507-4-vinicius.gomes%40intel.com
patch subject: [RFC v2 3/4] overlayfs: Optimize credentials usage
:::::: branch date: 2 days ago
:::::: commit date: 2 days ago
config: i386-randconfig-141-20240128 (https://download.01.org/0day-ci/archive/20240128/202401281540.6nl399om-lkp@intel.com/config)
compiler: clang version 17.0.6 (https://github.com/llvm/llvm-project 6009708b4367171ccdbf4b5905cb6a803753fe18)

If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Reported-by: Dan Carpenter <error27@gmail.com>
| Closes: https://lore.kernel.org/r/202401281540.6nl399om-lkp@intel.com/

New smatch warnings:
fs/overlayfs/readdir.c:990 ovl_check_empty_dir() error: uninitialized symbol 'err'.
fs/overlayfs/inode.c:506 ovl_set_or_remove_acl() error: uninitialized symbol 'real_acl'.
fs/overlayfs/xattrs.c:51 ovl_xattr_set() error: uninitialized symbol 'err'.
fs/overlayfs/xattrs.c:126 ovl_listxattr() error: uninitialized symbol 'res'.

Old smatch warnings:
fs/overlayfs/readdir.c:922 ovl_dir_fsync() warn: 'realfile' is an error pointer or valid
fs/overlayfs/inode.c:1221 ovl_get_inode() error: we previously assumed 'lowerpath' could be null (see line 1218)

vim +/err +990 fs/overlayfs/readdir.c

e9be9d5e76e348 Miklos Szeredi       2014-10-24   979  
e9be9d5e76e348 Miklos Szeredi       2014-10-24   980  int ovl_check_empty_dir(struct dentry *dentry, struct list_head *list)
e9be9d5e76e348 Miklos Szeredi       2014-10-24   981  {
e9be9d5e76e348 Miklos Szeredi       2014-10-24   982  	int err;
95e598e7ace2d8 zhangyi (F           2017-10-31   983) 	struct ovl_cache_entry *p, *n;
4edb83bb1041e2 Miklos Szeredi       2017-07-27   984  	struct rb_root root = RB_ROOT;
6d0a8a90a5bbfd Amir Goldstein       2017-11-10   985  	const struct cred *old_cred;
e9be9d5e76e348 Miklos Szeredi       2014-10-24   986  
659396b09f494f Vinicius Costa Gomes 2024-01-25   987  	old_cred = ovl_creds(dentry->d_sb);
659396b09f494f Vinicius Costa Gomes 2024-01-25   988  	scoped_guard(cred, old_cred)
4edb83bb1041e2 Miklos Szeredi       2017-07-27   989  		err = ovl_dir_read_merged(dentry, list, &root);
e9be9d5e76e348 Miklos Szeredi       2014-10-24  @990  	if (err)
e9be9d5e76e348 Miklos Szeredi       2014-10-24   991  		return err;
e9be9d5e76e348 Miklos Szeredi       2014-10-24   992  
e9be9d5e76e348 Miklos Szeredi       2014-10-24   993  	err = 0;
e9be9d5e76e348 Miklos Szeredi       2014-10-24   994  
95e598e7ace2d8 zhangyi (F           2017-10-31   995) 	list_for_each_entry_safe(p, n, list, l_node) {
95e598e7ace2d8 zhangyi (F           2017-10-31   996) 		/*
95e598e7ace2d8 zhangyi (F           2017-10-31   997) 		 * Select whiteouts in upperdir, they should
95e598e7ace2d8 zhangyi (F           2017-10-31   998) 		 * be cleared when deleting this directory.
95e598e7ace2d8 zhangyi (F           2017-10-31   999) 		 */
95e598e7ace2d8 zhangyi (F           2017-10-31  1000) 		if (p->is_whiteout) {
95e598e7ace2d8 zhangyi (F           2017-10-31  1001) 			if (p->is_upper)
e9be9d5e76e348 Miklos Szeredi       2014-10-24  1002  				continue;
95e598e7ace2d8 zhangyi (F           2017-10-31  1003) 			goto del_entry;
95e598e7ace2d8 zhangyi (F           2017-10-31  1004) 		}
e9be9d5e76e348 Miklos Szeredi       2014-10-24  1005  
e9be9d5e76e348 Miklos Szeredi       2014-10-24  1006  		if (p->name[0] == '.') {
e9be9d5e76e348 Miklos Szeredi       2014-10-24  1007  			if (p->len == 1)
95e598e7ace2d8 zhangyi (F           2017-10-31  1008) 				goto del_entry;
e9be9d5e76e348 Miklos Szeredi       2014-10-24  1009  			if (p->len == 2 && p->name[1] == '.')
95e598e7ace2d8 zhangyi (F           2017-10-31  1010) 				goto del_entry;
e9be9d5e76e348 Miklos Szeredi       2014-10-24  1011  		}
e9be9d5e76e348 Miklos Szeredi       2014-10-24  1012  		err = -ENOTEMPTY;
e9be9d5e76e348 Miklos Szeredi       2014-10-24  1013  		break;
95e598e7ace2d8 zhangyi (F           2017-10-31  1014) 
95e598e7ace2d8 zhangyi (F           2017-10-31  1015) del_entry:
95e598e7ace2d8 zhangyi (F           2017-10-31  1016) 		list_del(&p->l_node);
95e598e7ace2d8 zhangyi (F           2017-10-31  1017) 		kfree(p);
e9be9d5e76e348 Miklos Szeredi       2014-10-24  1018  	}
e9be9d5e76e348 Miklos Szeredi       2014-10-24  1019  
e9be9d5e76e348 Miklos Szeredi       2014-10-24  1020  	return err;
e9be9d5e76e348 Miklos Szeredi       2014-10-24  1021  }
e9be9d5e76e348 Miklos Szeredi       2014-10-24  1022  

-- 
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki

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

end of thread, other threads:[~2024-01-28  8:01 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-25 23:57 [RFC v2 0/4] overlayfs: Optimize override/revert creds Vinicius Costa Gomes
2024-01-25 23:57 ` [RFC v2 1/4] cleanup: Fix discarded const warning when defining guards Vinicius Costa Gomes
2024-01-26 14:46   ` Amir Goldstein
2024-01-25 23:57 ` [RFC v2 2/4] cred: Add a light version of override/revert_creds() Vinicius Costa Gomes
2024-01-26 14:34   ` Amir Goldstein
2024-01-27  0:16     ` Vinicius Costa Gomes
2024-01-25 23:57 ` [RFC v2 3/4] overlayfs: Optimize credentials usage Vinicius Costa Gomes
2024-01-26 17:22   ` Amir Goldstein
2024-01-27  0:34     ` Vinicius Costa Gomes
2024-01-25 23:57 ` [RFC v2 4/4] fs: Optimize credentials reference count for backing file ops Vinicius Costa Gomes
2024-01-26 14:50   ` Amir Goldstein
2024-01-27  0:25     ` Vinicius Costa Gomes
2024-01-26 11:40 ` [RFC v2 0/4] overlayfs: Optimize override/revert creds Amir Goldstein
2024-01-27  0:02   ` Vinicius Costa Gomes
  -- strict thread matches above, loose matches on Subject: below --
2024-01-28  8:01 [RFC v2 3/4] overlayfs: Optimize credentials usage kernel test robot

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.