Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp1392120ybl; Wed, 14 Aug 2019 16:22:02 -0700 (PDT) X-Google-Smtp-Source: APXvYqzK3KZ5SJ+zdACsMhbHnBiTxNLWP+OYU2tCTkoVuBNQL2zrSFDzKmMtq70N3a+BwoWTvtKz X-Received: by 2002:a17:902:e106:: with SMTP id cc6mr1627686plb.255.1565824922874; Wed, 14 Aug 2019 16:22:02 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1565824922; cv=pass; d=google.com; s=arc-20160816; b=eTzVzFCeRZ8UgJedmoWSLyX5r0PhZDEO91SSaYhdN9lp+CNn4Xz+ptvLrneg8s4gnv ZiGTJ/vTAopfLIANFU3deyzdyIuHD3wvqJjQg/ju61Y0nxaNXqAN6AZnPFTpta7hVtqJ XC+r/Bld5Rt60wwySpYBXZGQt4txeJ4E7/94NsBIgZj8w/zjBAHEwOMfCxV2NucEDdeg 6+Om1nqa4ZbJihe2iTKgz8pm+9qSvsA+7GDGKXM3r9sA882KZ6NQUnqaa0mlPWWjV8Gd 5AfELelpSy0uC28hGwh+CY8w+MbeHhBmGVk0A84bGshXwJELL9hFYjpXnZfxNCEqAXEh 5qxA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-id:content-language:accept-language:in-reply-to:references :message-id:date:thread-index:thread-topic:subject:cc:to:from :dkim-signature:dkim-signature; bh=1kkyzVk2jHlfVRKXiUBTb3FpFJi8KTgZoFWEasjroUU=; b=srnE/oIaFdLOk+JAynGkwsAY7bU6S61syBQKar6JPXD+5SkYQ23iWeCxSnzy+yfS6S RAn9hx1cGSDShVBIQaMVLJ6ZfgmNIFHG7e1QBebWVjJmr/oDJfCEgEfBre1bSxjnFp/6 woNpW73w7Hn3uNxhGVXdvPy51UBXmc3Bkm2rHmRlh3DI7+m/+6tSkSvBsTnZf6Ipewum i0PoJu6ApXvkKmEn2XKl9Ru6jIRHsxm4BsRjkJiLE1JC/dglGlPnwPRxdRipy3bdAicW anZ0Qx3C0i3A6cx6u491rqgbY1nZbi75j8U666J4bdGnd7wbB317vPTREgrB6tHyVpkg RBMg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=nDc52NDQ; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector2-fb-onmicrosoft-com header.b=EmqEA843; arc=pass (i=1 spf=pass spfdomain=fb.com dkim=pass dkdomain=fb.com dmarc=pass fromdomain=fb.com); spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n23si759995plp.273.2019.08.14.16.21.46; Wed, 14 Aug 2019 16:22:02 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@fb.com header.s=facebook header.b=nDc52NDQ; dkim=pass header.i=@fb.onmicrosoft.com header.s=selector2-fb-onmicrosoft-com header.b=EmqEA843; arc=pass (i=1 spf=pass spfdomain=fb.com dkim=pass dkdomain=fb.com dmarc=pass fromdomain=fb.com); spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=fb.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729157AbfHNV63 (ORCPT + 99 others); Wed, 14 Aug 2019 17:58:29 -0400 Received: from mx0a-00082601.pphosted.com ([67.231.145.42]:23404 "EHLO mx0a-00082601.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727414AbfHNV62 (ORCPT ); Wed, 14 Aug 2019 17:58:28 -0400 Received: from pps.filterd (m0109333.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x7ELsmwQ025219; Wed, 14 Aug 2019 14:58:23 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : references : in-reply-to : content-type : content-id : content-transfer-encoding : mime-version; s=facebook; bh=1kkyzVk2jHlfVRKXiUBTb3FpFJi8KTgZoFWEasjroUU=; b=nDc52NDQWEjwspnIEZpY4WKbsZLPa035EoIkKd108TzrpqAWlMhUHEDg/kc1nuAwiE/z agMQHiov5GlCatim2LK9idj3sw16+Y7g2STur83KRNYRzqMiZ8jyKJEG85FHisIkjJun gCJUJqfIilCBDkrGKOA4t08a6A2diQtbENE= Received: from mail.thefacebook.com (mailout.thefacebook.com [199.201.64.23]) by mx0a-00082601.pphosted.com with ESMTP id 2ucrp2gfqb-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-SHA384 bits=256 verify=NOT); Wed, 14 Aug 2019 14:58:23 -0700 Received: from prn-hub04.TheFacebook.com (2620:10d:c081:35::128) by prn-hub04.TheFacebook.com (2620:10d:c081:35::128) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.1.1713.5; Wed, 14 Aug 2019 14:54:14 -0700 Received: from NAM02-CY1-obe.outbound.protection.outlook.com (192.168.54.28) by o365-in.thefacebook.com (192.168.16.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.1.1713.5 via Frontend Transport; Wed, 14 Aug 2019 14:54:14 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WYQnYrjGJ6nVMTkVEpc+uDGE7djIP+huq5F8Ij2arRwwsUzgHDEDEA7LLN7EK9CmCRWT+mfXPr94NJPfxmY1YRTp/yhcUCE3ixqeTdpbZWi6IADZ2oBMXmgcBOJ1wQgyyH0q56ei0RmOikf7LVJRhX2ozs7mydrMf/QiEWBE6v3+yMePWzbG9x3iXiFGg46J205EXfhtfb7jvZiWOFrRPKqBI2c3m3Tb6/kDvXwQDClQhA6lnjpt6LrecyKSwXmckhbQTS1ZaF8gr+ffe3y15f8NxGze8guBfASSDyJ+ZXmVmtojvbmmxGwXTXUU3i5bXUPbUrNYNA5UVAav9aUMUQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1kkyzVk2jHlfVRKXiUBTb3FpFJi8KTgZoFWEasjroUU=; b=bEcXPBp+843hwLpaXeXbjirnTSesTp8GyyOR3N2Esrk7uUyp6QenLQtUQAsR7r9sQmB5vhXu8UKjkrO9/85AbiVMjjMHwPcpr5avjCckudIfeGcESeJ5819jl5lRQXUxM2eHyvAyi1UW2AXILNW5Htxup33lBE0Xw5LGozC3oSIAQVsmlX2RStNlhywqPmoAOeF4begugm22kFB0HU25xAC0zNkpEGTx+KlMAEMNuamjQhjn4sx2MK0Rl6Ix8ZAT60qs6MmO1ypcfNO/kGNkQQ+LQf5CoEwaohuB3ZsGuzof1LB6wSzcFvjHkEr+dheMLLuIm1W5YnX6q/118HQXiA== ARC-Authentication-Results: i=1; mx.microsoft.com 1;spf=pass smtp.mailfrom=fb.com;dmarc=pass action=none header.from=fb.com;dkim=pass header.d=fb.com;arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.onmicrosoft.com; s=selector2-fb-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1kkyzVk2jHlfVRKXiUBTb3FpFJi8KTgZoFWEasjroUU=; b=EmqEA843TT1ISqQY/RaaIL/2crr6G6rPWtHlW0KqKJ09DI2N4qgEXU6WfNmuTB2PNkRmkixLXmHzh+G943yltB3k9NWga/evHkgzTBDti/VWZm//gUw3rtLNxWRpWOa7bQTklvIW/d4WpE9qQcVptPSSztR0lKXGaAKxx+UGwNg= Received: from DM6PR15MB2635.namprd15.prod.outlook.com (20.179.161.152) by DM6PR15MB3033.namprd15.prod.outlook.com (20.179.16.27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2136.14; Wed, 14 Aug 2019 21:54:13 +0000 Received: from DM6PR15MB2635.namprd15.prod.outlook.com ([fe80::d1fc:b5c5:59a1:bd7e]) by DM6PR15MB2635.namprd15.prod.outlook.com ([fe80::d1fc:b5c5:59a1:bd7e%3]) with mapi id 15.20.2157.022; Wed, 14 Aug 2019 21:54:13 +0000 From: Roman Gushchin To: Michal Hocko CC: Andrew Morton , "linux-mm@kvack.org" , Johannes Weiner , "linux-kernel@vger.kernel.org" , Kernel Team Subject: Re: [PATCH 2/2] mm: memcontrol: flush percpu slab vmstats on kmem offlining Thread-Topic: [PATCH 2/2] mm: memcontrol: flush percpu slab vmstats on kmem offlining Thread-Index: AQHVUV1hvAVvSRmwcUimEiQ4N3nZcqb6hT0AgACtoAA= Date: Wed, 14 Aug 2019 21:54:12 +0000 Message-ID: <20190814215408.GA5584@tower.dhcp.thefacebook.com> References: <20190812222911.2364802-1-guro@fb.com> <20190812222911.2364802-3-guro@fb.com> <20190814113242.GV17933@dhcp22.suse.cz> In-Reply-To: <20190814113242.GV17933@dhcp22.suse.cz> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: MWHPR0201CA0058.namprd02.prod.outlook.com (2603:10b6:301:73::35) To DM6PR15MB2635.namprd15.prod.outlook.com (2603:10b6:5:1a6::24) x-ms-exchange-messagesentrepresentingtype: 1 x-originating-ip: [2620:10d:c090:200::1:42e9] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: a5e01cea-861c-478a-f6e6-08d72101f183 x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600148)(711020)(4605104)(1401327)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7193020);SRVR:DM6PR15MB3033; x-ms-traffictypediagnostic: DM6PR15MB3033: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1091; x-forefront-prvs: 01294F875B x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(39860400002)(136003)(346002)(366004)(396003)(54534003)(189003)(199004)(53936002)(486006)(81166006)(229853002)(8676002)(446003)(7736002)(54906003)(46003)(66446008)(66946007)(14444005)(476003)(2906002)(305945005)(6512007)(11346002)(86362001)(256004)(25786009)(9686003)(8936002)(64756008)(66476007)(66556008)(81156014)(316002)(99286004)(6916009)(6116002)(6506007)(386003)(5660300002)(478600001)(71190400001)(33656002)(71200400001)(102836004)(6436002)(186003)(6246003)(76176011)(4326008)(1076003)(6486002)(14454004)(52116002);DIR:OUT;SFP:1102;SCL:1;SRVR:DM6PR15MB3033;H:DM6PR15MB2635.namprd15.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;MX:1;A:1; received-spf: None (protection.outlook.com: fb.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: Kgzyti8swt3PssWZ3EEYvoBVKMeVgE4871TcwmDRcyTahZFUxTyOlB+/PcqXRTH7OkbCa8Sf/xlDjNY0ydM2Bs0nIiEMzPvyrKRvXXMaaMMpvYa7Uf/7OCjdS2bnX+7Slc6aQu2Lq0VUlrUZnw6jePK8FZmOxIMIzK3NrccSB5yx1ec7lXv9ibGE+h2tGDyF+I/31owQhXlTQWd7NWqkgWqnzIioVkrbw1H42TJr3YiD0fBG29qPQK49sgBj+YZuRf/LUnYZvOg7LFVcKSXM99VcsdDCfd6uIgptz5cv0t9zyW/FeQyJobPpWoG+3b+JS1O5YV5uu6Du/uo90OyowKo5zqZN6sbjnnTX37CrU+Uhec4sPAFgF1sD+52phGTNBt1Y5VAzBwWsNf1qPTsl+HtkUPtzVOvH53k2D64kVJY= Content-Type: text/plain; charset="us-ascii" Content-ID: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-MS-Exchange-CrossTenant-Network-Message-Id: a5e01cea-861c-478a-f6e6-08d72101f183 X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Aug 2019 21:54:12.8964 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 8ae927fe-1255-47a7-a2af-5f3a069daaa2 X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: qlWJgczNVsF+tOzWjAM138j2cuLR7xBvXIc1NlcewpR/U/xgyF4SuMGf45+Ke1mz X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR15MB3033 X-OriginatorOrg: fb.com X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-08-14_07:,, signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=776 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1908140199 X-FB-Internal: deliver Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Aug 14, 2019 at 01:32:42PM +0200, Michal Hocko wrote: > On Mon 12-08-19 15:29:11, Roman Gushchin wrote: > > I've noticed that the "slab" value in memory.stat is sometimes 0, > > even if some children memory cgroups have a non-zero "slab" value. > > The following investigation showed that this is the result > > of the kmem_cache reparenting in combination with the per-cpu > > batching of slab vmstats. > >=20 > > At the offlining some vmstat value may leave in the percpu cache, > > not being propagated upwards by the cgroup hierarchy. It means > > that stats on ancestor levels are lower than actual. Later when > > slab pages are released, the precise number of pages is substracted > > on the parent level, making the value negative. We don't show negative > > values, 0 is printed instead. >=20 > So the difference with other counters is that slab ones are reparented > and that's why we have treat them specially? I guess that is what the > comment in the code suggest but being explicit in the changelog would be > nice. Right. And I believe the list can be extended further. Objects which are often outliving the origin memory cgroup (e.g. pagecache pages) are pinning dead cgroups, so it will be cool to reparent them all. >=20 > [...] > > -static void memcg_flush_percpu_vmstats(struct mem_cgroup *memcg) > > +static void memcg_flush_percpu_vmstats(struct mem_cgroup *memcg, bool = slab_only) > > { > > unsigned long stat[MEMCG_NR_STAT]; > > struct mem_cgroup *mi; > > int node, cpu, i; > > + int min_idx, max_idx; > > =20 > > - for (i =3D 0; i < MEMCG_NR_STAT; i++) > > + if (slab_only) { > > + min_idx =3D NR_SLAB_RECLAIMABLE; > > + max_idx =3D NR_SLAB_UNRECLAIMABLE; > > + } else { > > + min_idx =3D 0; > > + max_idx =3D MEMCG_NR_STAT; > > + } >=20 > This is just ugly has hell! I really detest how this implicitly makes > counters value very special without any note in the node_stat_item > definition. Is it such a big deal to have a per counter flush and do > the loop over all counters resp. specific counters around it so much > worse? This should be really a slow path to safe few instructions or > cache misses, no? I believe that it is a big deal, because it's NR_VMSTAT_ITEMS * all memory cgroups * online cpus * numa nodes. If the goal is to merge it with cpu hotplug code, I'd think about passing cpumask to it, and do the opposite. Also I'm not sure I understand why reordering loops will make it less ugly. But you're right, a comment nearby NR_SLAB_(UN)RECLAIMABLE definition is totaly worth it. How about something like: diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h index 8b5f758942a2..231bcbe5dcc6 100644 --- a/include/linux/mmzone.h +++ b/include/linux/mmzone.h @@ -215,8 +215,9 @@ enum node_stat_item { NR_INACTIVE_FILE, /* " " " " " */ NR_ACTIVE_FILE, /* " " " " " */ NR_UNEVICTABLE, /* " " " " " */ - NR_SLAB_RECLAIMABLE, - NR_SLAB_UNRECLAIMABLE, + NR_SLAB_RECLAIMABLE, /* Please, do not reorder this item */ + NR_SLAB_UNRECLAIMABLE, /* and this one without looking at + * memcg_flush_percpu_vmstats() first. */ NR_ISOLATED_ANON, /* Temporary isolated pages from anon lru *= / NR_ISOLATED_FILE, /* Temporary isolated pages from file lru *= / WORKINGSET_NODES, -- Thanks!