Re: [PATCH v1 09/12] mm: memcontrol: use obj_cgroup APIs to charge the LRU pages

From: kernel test robot
Date: Sat Aug 14 2021 - 10:09:48 EST


Hi Muchun,

Thank you for the patch! Perhaps something to improve:

[auto build test WARNING on next-20210813]
[cannot apply to hnaz-linux-mm/master cgroup/for-next linus/master v5.14-rc5 v5.14-rc4 v5.14-rc3 v5.14-rc5]
[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]

url: https://github.com/0day-ci/linux/commits/Muchun-Song/Use-obj_cgroup-APIs-to-charge-the-LRU-pages/20210814-132844
base: 4b358aabb93a2c654cd1dcab1a25a589f6e2b153
config: i386-randconfig-s032-20210814 (attached as .config)
compiler: gcc-9 (Debian 9.3.0-22) 9.3.0
reproduce:
# apt-get install sparse
# sparse version: v0.6.3-348-gf0e6938b-dirty
# https://github.com/0day-ci/linux/commit/33aa30f8c508696b533f8817a5212d6efdd424bb
git remote add linux-review https://github.com/0day-ci/linux
git fetch --no-tags linux-review Muchun-Song/Use-obj_cgroup-APIs-to-charge-the-LRU-pages/20210814-132844
git checkout 33aa30f8c508696b533f8817a5212d6efdd424bb
# save the attached .config to linux build tree
make W=1 C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' ARCH=i386

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@xxxxxxxxx>


sparse warnings: (new ones prefixed by >>)
mm/memcontrol.c:4231:21: sparse: sparse: incompatible types in comparison expression (different address spaces):
mm/memcontrol.c:4231:21: sparse: struct mem_cgroup_threshold_ary [noderef] __rcu *
mm/memcontrol.c:4231:21: sparse: struct mem_cgroup_threshold_ary *
mm/memcontrol.c:4233:21: sparse: sparse: incompatible types in comparison expression (different address spaces):
mm/memcontrol.c:4233:21: sparse: struct mem_cgroup_threshold_ary [noderef] __rcu *
mm/memcontrol.c:4233:21: sparse: struct mem_cgroup_threshold_ary *
mm/memcontrol.c:4389:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
mm/memcontrol.c:4389:9: sparse: struct mem_cgroup_threshold_ary [noderef] __rcu *
mm/memcontrol.c:4389:9: sparse: struct mem_cgroup_threshold_ary *
mm/memcontrol.c:4483:9: sparse: sparse: incompatible types in comparison expression (different address spaces):
mm/memcontrol.c:4483:9: sparse: struct mem_cgroup_threshold_ary [noderef] __rcu *
mm/memcontrol.c:4483:9: sparse: struct mem_cgroup_threshold_ary *
>> mm/memcontrol.c:5836:26: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct obj_cgroup *objcg @@ got struct obj_cgroup [noderef] __rcu *objcg @@
mm/memcontrol.c:5837:28: sparse: sparse: incorrect type in argument 1 (different address spaces) @@ expected struct obj_cgroup *objcg @@ got struct obj_cgroup [noderef] __rcu *objcg @@
mm/memcontrol.c:6133:23: sparse: sparse: incompatible types in comparison expression (different address spaces):
mm/memcontrol.c:6133:23: sparse: struct task_struct [noderef] __rcu *
mm/memcontrol.c:6133:23: sparse: struct task_struct *
mm/memcontrol.c: note: in included file:
include/linux/memcontrol.h:780:9: sparse: sparse: context imbalance in 'memcg_reparent_lruvec_lock' - wrong count at exit
include/linux/memcontrol.h:780:9: sparse: sparse: context imbalance in 'memcg_reparent_lruvec_unlock' - unexpected unlock
mm/memcontrol.c: note: in included file (through include/linux/rculist.h, include/linux/pid.h, include/linux/sched.h, ...):
include/linux/rcupdate.h:718:9: sparse: sparse: context imbalance in 'folio_lruvec_lock' - wrong count at exit
include/linux/rcupdate.h:718:9: sparse: sparse: context imbalance in 'folio_lruvec_lock_irq' - wrong count at exit
include/linux/rcupdate.h:718:9: sparse: sparse: context imbalance in 'folio_lruvec_lock_irqsave' - wrong count at exit
mm/memcontrol.c:2098:6: sparse: sparse: context imbalance in 'folio_memcg_lock' - wrong count at exit
mm/memcontrol.c:2154:17: sparse: sparse: context imbalance in '__folio_memcg_unlock' - unexpected unlock

vim +5836 mm/memcontrol.c

5733
5734 /**
5735 * mem_cgroup_move_account - move account of the page
5736 * @page: the page
5737 * @compound: charge the page as compound or small page
5738 * @from: mem_cgroup which the page is moved from.
5739 * @to: mem_cgroup which the page is moved to. @from != @to.
5740 *
5741 * The caller must make sure the page is not on LRU (isolate_page() is useful.)
5742 *
5743 * This function doesn't do "charge" to new cgroup and doesn't do "uncharge"
5744 * from old cgroup.
5745 */
5746 static int mem_cgroup_move_account(struct page *page,
5747 bool compound,
5748 struct mem_cgroup *from,
5749 struct mem_cgroup *to)
5750 {
5751 struct folio *folio = page_folio(page);
5752 struct lruvec *from_vec, *to_vec;
5753 struct pglist_data *pgdat;
5754 unsigned int nr_pages = compound ? folio_nr_pages(folio) : 1;
5755 int nid, ret;
5756
5757 VM_BUG_ON(from == to);
5758 VM_BUG_ON_FOLIO(folio_test_lru(folio), folio);
5759 VM_BUG_ON(compound && !folio_test_multi(folio));
5760
5761 /*
5762 * Prevent mem_cgroup_migrate() from looking at
5763 * page's memory cgroup of its source page while we change it.
5764 */
5765 ret = -EBUSY;
5766 if (!folio_trylock(folio))
5767 goto out;
5768
5769 ret = -EINVAL;
5770 if (folio_memcg(folio) != from)
5771 goto out_unlock;
5772
5773 pgdat = folio_pgdat(folio);
5774 from_vec = mem_cgroup_lruvec(from, pgdat);
5775 to_vec = mem_cgroup_lruvec(to, pgdat);
5776
5777 folio_memcg_lock(folio);
5778
5779 if (folio_test_anon(folio)) {
5780 if (folio_mapped(folio)) {
5781 __mod_lruvec_state(from_vec, NR_ANON_MAPPED, -nr_pages);
5782 __mod_lruvec_state(to_vec, NR_ANON_MAPPED, nr_pages);
5783 if (folio_test_transhuge(folio)) {
5784 __mod_lruvec_state(from_vec, NR_ANON_THPS,
5785 -nr_pages);
5786 __mod_lruvec_state(to_vec, NR_ANON_THPS,
5787 nr_pages);
5788 }
5789 }
5790 } else {
5791 __mod_lruvec_state(from_vec, NR_FILE_PAGES, -nr_pages);
5792 __mod_lruvec_state(to_vec, NR_FILE_PAGES, nr_pages);
5793
5794 if (folio_test_swapbacked(folio)) {
5795 __mod_lruvec_state(from_vec, NR_SHMEM, -nr_pages);
5796 __mod_lruvec_state(to_vec, NR_SHMEM, nr_pages);
5797 }
5798
5799 if (folio_mapped(folio)) {
5800 __mod_lruvec_state(from_vec, NR_FILE_MAPPED, -nr_pages);
5801 __mod_lruvec_state(to_vec, NR_FILE_MAPPED, nr_pages);
5802 }
5803
5804 if (folio_test_dirty(folio)) {
5805 struct address_space *mapping = folio_mapping(folio);
5806
5807 if (mapping_can_writeback(mapping)) {
5808 __mod_lruvec_state(from_vec, NR_FILE_DIRTY,
5809 -nr_pages);
5810 __mod_lruvec_state(to_vec, NR_FILE_DIRTY,
5811 nr_pages);
5812 }
5813 }
5814 }
5815
5816 if (folio_test_writeback(folio)) {
5817 __mod_lruvec_state(from_vec, NR_WRITEBACK, -nr_pages);
5818 __mod_lruvec_state(to_vec, NR_WRITEBACK, nr_pages);
5819 }
5820
5821 /*
5822 * All state has been migrated, let's switch to the new memcg.
5823 *
5824 * It is safe to change page's memcg here because the page
5825 * is referenced, charged, isolated, and locked: we can't race
5826 * with (un)charging, migration, LRU putback, or anything else
5827 * that would rely on a stable page's memory cgroup.
5828 *
5829 * Note that lock_page_memcg is a memcg lock, not a page lock,
5830 * to save space. As soon as we switch page's memory cgroup to a
5831 * new memcg that isn't locked, the above state can change
5832 * concurrently again. Make sure we're truly done with it.
5833 */
5834 smp_mb();
5835
> 5836 obj_cgroup_get(to->objcg);
5837 obj_cgroup_put(from->objcg);
5838
5839 folio->memcg_data = (unsigned long)to->objcg;
5840
5841 __folio_memcg_unlock(from);
5842
5843 ret = 0;
5844 nid = folio_nid(folio);
5845
5846 local_irq_disable();
5847 mem_cgroup_charge_statistics(to, nr_pages);
5848 memcg_check_events(to, nid);
5849 mem_cgroup_charge_statistics(from, -nr_pages);
5850 memcg_check_events(from, nid);
5851 local_irq_enable();
5852 out_unlock:
5853 folio_unlock(folio);
5854 out:
5855 return ret;
5856 }
5857

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@xxxxxxxxxxxx

Attachment: .config.gz
Description: application/gzip