Skip to contentSkip to conversation

mm: Add helper to recharge kmalloc'ed address

RFC PATCH Yafang Shao 1 participant 1 message Jun 20, 2022 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 225 lines · kernel test robot

Hi Yafang,

[FYI, it's a private test report for your RFC patch.] [auto build test ERROR on bpf-next/master]

url:    https://github.com/intel-lab-lkp/linux/commits/Yafang-Shao/bpf-mm-Recharge-pages-when-reuse-bpf-map/20220619-235157
base:   https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git master
config: alpha-defconfig (https://download.01.org/0day-ci/archive/20220620/202206200104.ZbChHTQp-lkp(a)intel.com/config)
compiler: alpha-linux-gcc (GCC) 11.3.0

reproduce (this is a W=1 build):
wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# https://github.com/intel-lab-lkp/linux/commit/073fb6551497e11b2cfeec317b1729eb83ec7400
git remote add linux-review https://github.com/intel-lab-lkp/linux
git fetch --no-tags linux-review Yafang-Shao/bpf-mm-Recharge-pages-when-reuse-bpf-map/20220619-235157 git checkout 073fb6551497e11b2cfeec317b1729eb83ec7400
# save the config file
mkdir build_dir && cp config build_dir/.config
COMPILER_INSTALL_PATH=$HOME/0day COMPILER=gcc-11.3.0 make.cross W=1 O=build_dir ARCH=alpha SHELL=/bin/bash

If you fix the issue, kindly add following tag where applicable

All error/warnings (new ones prefixed by >>):

mm/slub.c: In function 'krecharge':

Quoted 1 line
Quoted 1 line

mm/slub.c:4585:37: error: implicit declaration of function 'get_obj_cgroup_from_current'; did you mean 'get_obj_cgroup_from_page'? [-Werror=implicit-function-declaration]

    4585 |                         objcg_new = get_obj_cgroup_from_current();
         |                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~
         |                                     get_obj_cgroup_from_page
Quoted 1 line
Quoted 1 line

mm/slub.c:4585:35: warning: assignment to 'struct obj_cgroup *' from 'int' makes pointer from integer without a cast [-Wint-conversion]

    4585 |                         objcg_new = get_obj_cgroup_from_current();
         |                                   ^
Quoted 1 line
Quoted 1 line

mm/slub.c:4588:29: error: implicit declaration of function 'obj_cgroup_charge_pages'; did you mean 'obj_cgroup_charge_zswap'? [-Werror=implicit-function-declaration]

    4588 |                         if (obj_cgroup_charge_pages(objcg_new, GFP_KERNEL,
         |                             ^~~~~~~~~~~~~~~~~~~~~~~
         |                             obj_cgroup_charge_zswap
Quoted 1 line
Quoted 1 line

mm/slub.c:4596:37: error: implicit declaration of function '__folio_objcg'; did you mean '__folio_lock'? [-Werror=implicit-function-declaration]

    4596 |                         objcg_old = __folio_objcg(folio);
         |                                     ^~~~~~~~~~~~~
         |                                     __folio_lock
   mm/slub.c:4596:35: warning: assignment to 'struct obj_cgroup *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
    4596 |                         objcg_old = __folio_objcg(folio);
         |                                   ^
Quoted 1 line
Quoted 1 line

mm/slub.c:4599:25: error: implicit declaration of function 'obj_cgroup_uncharge_pages'; did you mean 'obj_cgroup_uncharge_zswap'? [-Werror=implicit-function-declaration]

    4599 |                         obj_cgroup_uncharge_pages(objcg_old, 1 << order);
         |                         ^~~~~~~~~~~~~~~~~~~~~~~~~
         |                         obj_cgroup_uncharge_zswap
Quoted 1 line
Quoted 1 line

mm/slub.c:4602:29: error: 'struct page' has no member named 'memcg_data'

    4602 |                         page->memcg_data = 0;
         |                             ^~
Quoted 1 line
Quoted 1 line

mm/slub.c:4607:37: error: implicit declaration of function 'obj_cgroup_from_current' [-Werror=implicit-function-declaration]

    4607 |                         objcg_new = obj_cgroup_from_current();
         |                                     ^~~~~~~~~~~~~~~~~~~~~~~
   mm/slub.c:4607:35: warning: assignment to 'struct obj_cgroup *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
    4607 |                         objcg_new = obj_cgroup_from_current();
         |                                   ^
   mm/slub.c:4609:29: error: 'struct page' has no member named 'memcg_data'
    4609 |                         page->memcg_data = (unsigned long)objcg_new | MEMCG_DATA_KMEM;
         |                             ^~
Quoted 1 line
Quoted 1 line

mm/slub.c:4609:71: error: 'MEMCG_DATA_KMEM' undeclared (first use in this function); did you mean 'MEMCG_KMEM'?

    4609 |                         page->memcg_data = (unsigned long)objcg_new | MEMCG_DATA_KMEM;
         |                                                                       ^~~~~~~~~~~~~~~
         |                                                                       MEMCG_KMEM
   mm/slub.c:4609:71: note: each undeclared identifier is reported only once for each function it appears in
   mm/slub.c:4614:35: warning: assignment to 'struct obj_cgroup *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
    4614 |                         objcg_new = obj_cgroup_from_current();
         |                                   ^
   mm/slub.c:4652:27: warning: assignment to 'struct obj_cgroup *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
    4652 |                 objcg_new = get_obj_cgroup_from_current();
         |                           ^
Quoted 1 line
Quoted 1 line

mm/slub.c:4654:21: error: implicit declaration of function 'obj_cgroup_charge'; did you mean 'mem_cgroup_charge'? [-Werror=implicit-function-declaration]

    4654 |                 if (obj_cgroup_charge(objcg_new, GFP_KERNEL, obj_full_size(s))) {
         |                     ^~~~~~~~~~~~~~~~~
         |                     mem_cgroup_charge
Quoted 1 line
Quoted 1 line

mm/slub.c:4654:62: error: implicit declaration of function 'obj_full_size' [-Werror=implicit-function-declaration]

    4654 |                 if (obj_cgroup_charge(objcg_new, GFP_KERNEL, obj_full_size(s))) {
         |                                                              ^~~~~~~~~~~~~
Quoted 1 line
Quoted 1 line

mm/slub.c:4661:17: error: implicit declaration of function 'obj_cgroup_uncharge'; did you mean 'mem_cgroup_uncharge'? [-Werror=implicit-function-declaration]

    4661 |                 obj_cgroup_uncharge(objcg_old, obj_full_size(s));
         |                 ^~~~~~~~~~~~~~~~~~~
         |                 mem_cgroup_uncharge
Quoted 1 line
Quoted 1 line

mm/slub.c:4663:17: error: implicit declaration of function 'mod_objcg_state'; did you mean 'mod_memcg_state'? [-Werror=implicit-function-declaration]

    4663 |                 mod_objcg_state(objcg_old, slab_pgdat(slab), cache_vmstat_idx(s),
         |                 ^~~~~~~~~~~~~~~
         |                 mod_memcg_state
   mm/slub.c:4669:27: warning: assignment to 'struct obj_cgroup *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
    4669 |                 objcg_new = obj_cgroup_from_current();
         |                           ^
   mm/slub.c:4674:27: warning: assignment to 'struct obj_cgroup *' from 'int' makes pointer from integer without a cast [-Wint-conversion]
    4674 |                 objcg_new = obj_cgroup_from_current();
         |                           ^

cc1: some warnings being treated as errors

vim +4585 mm/slub.c

4558
4559 bool krecharge(const void *x, int step)
4560 {

  4561          void *object = (void *)x;
  4562          struct obj_cgroup *objcg_old;
  4563          struct obj_cgroup *objcg_new;
  4564          struct obj_cgroup **objcgs;
  4565          struct kmem_cache *s;
  4566          struct folio *folio;
  4567          struct slab *slab;
  4568          unsigned int off;

4569
4570 WARN_ON(!in_task());
4571
4572 if (!memcg_kmem_enabled())
4573 return true;
4574
4575 if (unlikely(ZERO_OR_NULL_PTR(x)))
4576 return true;
4577
4578 folio = virt_to_folio(x);
4579 if (unlikely(!folio_test_slab(folio))) {
4580 unsigned int order = folio_order(folio);
4581 struct page *page;
4582
4583 switch (step) {
4584 case MEMCG_KMEM_PRE_CHARGE:

Quoted 1 line

4585 objcg_new = get_obj_cgroup_from_current();

  4586                          WARN_ON(!objcg_new);
  4587                          /* Try charge current memcg */
> 4588                          if (obj_cgroup_charge_pages(objcg_new, GFP_KERNEL,
  4589                                                      1 << order)) {
  4590                                  obj_cgroup_put(objcg_new);
  4591                                  return false;
  4592                          }
  4593                          break;
  4594                  case MEMCG_KMEM_UNCHARGE:
  4595                          /* Uncharge folio memcg */
> 4596                          objcg_old = __folio_objcg(folio);
  4597                          page = folio_page(folio, 0);
  4598                          WARN_ON(!objcg_old);
> 4599                          obj_cgroup_uncharge_pages(objcg_old, 1 << order);
  4600                          mod_lruvec_page_state(page, NR_SLAB_UNRECLAIMABLE_B,

4601 -(PAGE_SIZE << order));

Quoted 1 line

4602 page->memcg_data = 0;

4603 obj_cgroup_put(objcg_old);
4604 break;
4605 case MEMCG_KMEM_POST_CHARGE:

  4606                          /* Set current memcg to folio page */
> 4607                          objcg_new = obj_cgroup_from_current();
  4608                          page = folio_page(folio, 0);
> 4609                          page->memcg_data = (unsigned long)objcg_new | MEMCG_DATA_KMEM;
  4610                          mod_lruvec_page_state(page, NR_SLAB_UNRECLAIMABLE_B,
  4611                                                  -(PAGE_SIZE << order));
  4612                          break;
  4613                  case MEMCG_KMEM_CHARGE_ERR:
  4614                          objcg_new = obj_cgroup_from_current();
  4615                          obj_cgroup_uncharge_pages(objcg_new, 1 << order);
  4616                          obj_cgroup_put(objcg_new);
  4617                          break;
  4618                  }
  4619                  return true;
  4620          }
  4621
  4622          slab = folio_slab(folio);
  4623          if (!slab)
  4624                  return true;
  4625
  4626          s = slab->slab_cache;
  4627          if (!(s->flags & SLAB_ACCOUNT))
  4628                  return true;
  4629
  4630          objcgs = slab_objcgs(slab);
  4631          if (!objcgs)
  4632                  return true;
  4633          off = obj_to_index(s, slab, object);
  4634          objcg_old = objcgs[off];
  4635          /* In step MEMCG_KMEM_UNCHARGE, the objcg will set to NULL. */
  4636          if (!objcg_old && step != MEMCG_KMEM_POST_CHARGE)
  4637                  return true;
  4638
  4639          /*
  4640           *  The recharge can be separated into three steps,
  4641           *  1. Pre charge to the new memcg
  4642           *  2. Uncharge from the old memcg
  4643           *  3. Charge to the new memcg
  4644           */
  4645          switch (step) {
  4646          case MEMCG_KMEM_PRE_CHARGE:
  4647                  /*
  4648                   * Before uncharge from the old memcg, we must pre charge the new memcg
  4649                   * first, to make sure it always succeed to recharge to the new memcg
  4650                   * after uncharge from the old memcg.
  4651                   */
  4652                  objcg_new = get_obj_cgroup_from_current();
  4653                  WARN_ON(!objcg_new);
> 4654                  if (obj_cgroup_charge(objcg_new, GFP_KERNEL, obj_full_size(s))) {
  4655                          obj_cgroup_put(objcg_new);
  4656                          return false;
  4657                  }
  4658                  break;
  4659          case MEMCG_KMEM_UNCHARGE:
  4660                  /* Uncharge from old memcg */
> 4661                  obj_cgroup_uncharge(objcg_old, obj_full_size(s));
  4662                  objcgs[off] = NULL;
> 4663                  mod_objcg_state(objcg_old, slab_pgdat(slab), cache_vmstat_idx(s),
  4664                                  -obj_full_size(s));
  4665                  obj_cgroup_put(objcg_old);
  4666                  break;
  4667          case MEMCG_KMEM_POST_CHARGE:
  4668                  /* Charge to the new memcg */
  4669                  objcg_new = obj_cgroup_from_current();
  4670                  objcgs[off] = objcg_new;
  4671                  mod_objcg_state(objcg_new, slab_pgdat(slab), cache_vmstat_idx(s), obj_full_size(s));
  4672                  break;
  4673          case MEMCG_KMEM_CHARGE_ERR:
  4674                  objcg_new = obj_cgroup_from_current();
  4675                  obj_cgroup_uncharge(objcg_new, obj_full_size(s));
  4676                  obj_cgroup_put(objcg_new);
  4677                  break;

4678 }
4679
4680 return true;
4681 }
4682 EXPORT_SYMBOL(krecharge);
4683

Quoted 3 lines

--
0-DAY CI Kernel Test Service
https://01.org/lkp

Thanks for the report.
I will fix this error and the other errors reported by you in the next version.

Signature · 2 lines
Regards
Yafang