From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3DA1AC433E0 for ; Thu, 28 May 2020 23:30:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id EC28920663 for ; Thu, 28 May 2020 23:30:22 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="iltXc/Yk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EC28920663 Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=fb.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 21460800B8; Thu, 28 May 2020 19:30:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1C79D80010; Thu, 28 May 2020 19:30:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B820800B8; Thu, 28 May 2020 19:30:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0220.hostedemail.com [216.40.44.220]) by kanga.kvack.org (Postfix) with ESMTP id E52F280010 for ; Thu, 28 May 2020 19:30:21 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id A4CA48245578 for ; Thu, 28 May 2020 23:30:21 +0000 (UTC) X-FDA: 76867723842.19.cloth36_5a6178b344934 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 8243B1AD1B9 for ; Thu, 28 May 2020 23:30:21 +0000 (UTC) X-HE-Tag: cloth36_5a6178b344934 X-Filterd-Recvd-Size: 6850 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf26.hostedemail.com (Postfix) with ESMTP for ; Thu, 28 May 2020 23:30:20 +0000 (UTC) Received: from pps.filterd (m0044010.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 04SNFpcp012413 for ; Thu, 28 May 2020 16:30:20 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=Z9eRDf6nEjMQKo+LsFiG6uORiFACuPSukazyzY1o0Wc=; b=iltXc/YktXfnOtqvi/Vty3wneyQap6ee5mbeotWWg8ibmUWC1kOjyN9kn/bwKBMkIhvF hWNehlQscnnyGChB31k6cFcnV/svDykHIpUkBxx2zcblHyct87WM1Jr4b2bfwpVbtfki TMTF/C3zQh5358KcMB1fs2HSTbSActuQnik= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 31ajbjjp4y-6 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 28 May 2020 16:30:19 -0700 Received: from intmgw002.41.prn1.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:82::d) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1979.3; Thu, 28 May 2020 16:30:17 -0700 Received: by devvm1291.vll0.facebook.com (Postfix, from userid 111017) id 8946A16E5963; Thu, 28 May 2020 16:25:10 -0700 (PDT) Smtp-Origin-Hostprefix: devvm From: Roman Gushchin Smtp-Origin-Hostname: devvm1291.vll0.facebook.com To: Andrew Morton , Dennis Zhou , Tejun Heo , Christoph Lameter CC: Johannes Weiner , Michal Hocko , Shakeel Butt , , , , Roman Gushchin Smtp-Origin-Cluster: vll0c01 Subject: [PATCH v1 3/5] mm: memcg/percpu: per-memcg percpu memory statistics Date: Thu, 28 May 2020 16:25:06 -0700 Message-ID: <20200528232508.1132382-4-guro@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200528232508.1132382-1-guro@fb.com> References: <20200528232508.1132382-1-guro@fb.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216,18.0.687 definitions=2020-05-28_08:2020-05-28,2020-05-28 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 adultscore=0 spamscore=0 cotscore=-2147483648 bulkscore=0 impostorscore=0 mlxlogscore=999 lowpriorityscore=0 suspectscore=2 phishscore=0 priorityscore=1501 malwarescore=0 mlxscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2004280000 definitions=main-2005280148 X-FB-Internal: deliver X-Rspamd-Queue-Id: 8243B1AD1B9 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam02 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Percpu memory can represent a noticeable chunk of the total memory consumption, especially on big machines with many CPUs. Let's track percpu memory usage for each memcg and display it in memory.stat. A percpu allocation is usually scattered over multiple pages (and nodes), and can be significantly smaller than a page. So let's add a byte-sized counter on the memcg level: MEMCG_PERCPU_B. Byte-sized vmstat infra created for slabs can be perfectly reused for percpu case. Signed-off-by: Roman Gushchin --- Documentation/admin-guide/cgroup-v2.rst | 4 ++++ include/linux/memcontrol.h | 8 ++++++++ mm/memcontrol.c | 4 +++- mm/percpu.c | 10 ++++++++++ 4 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/cgroup-v2.rst b/Documentation/admi= n-guide/cgroup-v2.rst index fed4e1d2a343..aa8cb6dadadc 100644 --- a/Documentation/admin-guide/cgroup-v2.rst +++ b/Documentation/admin-guide/cgroup-v2.rst @@ -1276,6 +1276,10 @@ PAGE_SIZE multiple when read back. Amount of memory used for storing in-kernel data structures. =20 + percpu + Amount of memory used for storing per-cpu kernel + data structures. + sock Amount of memory used in network transmission buffers =20 diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index 7a84d9164449..f62a95d472f7 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -32,11 +32,19 @@ struct kmem_cache; enum memcg_stat_item { MEMCG_SWAP =3D NR_VM_NODE_STAT_ITEMS, MEMCG_SOCK, + MEMCG_PERCPU_B, /* XXX: why are these zone and not node counters? */ MEMCG_KERNEL_STACK_KB, MEMCG_NR_STAT, }; =20 +static __always_inline bool memcg_stat_item_in_bytes(enum memcg_stat_ite= m item) +{ + if (item =3D=3D MEMCG_PERCPU_B) + return true; + return vmstat_item_in_bytes(item); +} + enum memcg_memory_event { MEMCG_LOW, MEMCG_HIGH, diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 7bc3fd196210..5007d1585a4a 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -783,7 +783,7 @@ void __mod_memcg_state(struct mem_cgroup *memcg, int = idx, int val) if (mem_cgroup_disabled()) return; =20 - if (vmstat_item_in_bytes(idx)) + if (memcg_stat_item_in_bytes(idx)) threshold <<=3D PAGE_SHIFT; =20 x =3D val + __this_cpu_read(memcg->vmstats_percpu->stat[idx]); @@ -1490,6 +1490,8 @@ static char *memory_stat_format(struct mem_cgroup *= memcg) seq_buf_printf(&s, "slab %llu\n", (u64)(memcg_page_state(memcg, NR_SLAB_RECLAIMABLE_B) + memcg_page_state(memcg, NR_SLAB_UNRECLAIMABLE_B))); + seq_buf_printf(&s, "percpu %llu\n", + (u64)memcg_page_state(memcg, MEMCG_PERCPU_B)); seq_buf_printf(&s, "sock %llu\n", (u64)memcg_page_state(memcg, MEMCG_SOCK) * PAGE_SIZE); diff --git a/mm/percpu.c b/mm/percpu.c index 85f5755c9114..b4b3e9c8a6d1 100644 --- a/mm/percpu.c +++ b/mm/percpu.c @@ -1608,6 +1608,11 @@ static void pcpu_memcg_post_alloc_hook(struct obj_= cgroup *objcg, =20 if (chunk) { chunk->obj_cgroups[off >> PCPU_MIN_ALLOC_SHIFT] =3D objcg; + + rcu_read_lock(); + mod_memcg_state(obj_cgroup_memcg(objcg), MEMCG_PERCPU_B, + size * num_possible_cpus()); + rcu_read_unlock(); } else { obj_cgroup_uncharge(objcg, size * num_possible_cpus()); obj_cgroup_put(objcg); @@ -1626,6 +1631,11 @@ static void pcpu_memcg_free_hook(struct pcpu_chunk= *chunk, int off, size_t size) =20 obj_cgroup_uncharge(objcg, size * num_possible_cpus()); =20 + rcu_read_lock(); + mod_memcg_state(obj_cgroup_memcg(objcg), MEMCG_PERCPU_B, + -(size * num_possible_cpus())); + rcu_read_unlock(); + obj_cgroup_put(objcg); } =20 --=20 2.25.4