From patchwork Wed May 1 17:26:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 13651038 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 82D5CC4345F for ; Wed, 1 May 2024 17:26:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0A7606B008A; Wed, 1 May 2024 13:26:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0565E6B008C; Wed, 1 May 2024 13:26:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E5F236B0093; Wed, 1 May 2024 13:26:33 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C61146B008C for ; Wed, 1 May 2024 13:26:33 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 7882A120891 for ; Wed, 1 May 2024 17:26:33 +0000 (UTC) X-FDA: 82070506266.28.46BF724 Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) by imf23.hostedemail.com (Postfix) with ESMTP id D5E8714000C for ; Wed, 1 May 2024 17:26:31 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=JyE8xHLG; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf23.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.178 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1714584392; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=3H2isfS8T5ps/+wLdohfpyvRT+Uuu4Hht5kCun0wQ34=; b=UUS8clx97IBUFhiEcVZ32hKmP1WeXGaEti5scIttdDv0GCLH9YV7tpsrnmPSCB3/fGKHm3 geHHe25Cuvn40dwgIM+X75H34TDGXkVCBn1k8WTLFcZ5xtHVK4qt4jCBGNyDqIotIxWJPK qLuORW96CDdn1MxQY2+zJ1SYLl7Dbyo= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=JyE8xHLG; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf23.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.178 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714584392; a=rsa-sha256; cv=none; b=gRPT0BJSepQRDd0XWmL2ONqLSJARMPM3Nr4V8x2goCxKY3at3hiiiTtXlSrnUgQ8DWRJua SHPij0k7qNaJwpVujhaozIPf1Md2cce6dM0pXPsoLL/8/Eou9hFlBKHuy5e2ZY1zpbsKpJ fYwk3QxHrUFsTaA6FdLfBAF2EcAwibA= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1714584384; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=3H2isfS8T5ps/+wLdohfpyvRT+Uuu4Hht5kCun0wQ34=; b=JyE8xHLGkW5gqwjPybskQtVSStPG8kiLG0DNwI/vpeTbL+/bcRIfHvb+unYcWN9cy1RZcF HIIMi3nj1hZfXdL3ZRvdAMZoYmV1LUuszTRbyYgEpC+wsxP/JOC5O/Kn0yYwaA3mxreoz4 NrXRai342e4YNAp/GUnVgenqHevsAJg= From: Shakeel Butt To: Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , Yosry Ahmed , "T . J . Mercier" Cc: kernel-team@meta.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 0/8] memcg: reduce memory consumption by memcg stats Date: Wed, 1 May 2024 10:26:09 -0700 Message-ID: <20240501172617.678560-1-shakeel.butt@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam01 X-Stat-Signature: xp31x3ixg9uh3xoboisn3rbct3cnfxd9 X-Rspam-User: X-Rspamd-Queue-Id: D5E8714000C X-HE-Tag: 1714584391-481751 X-HE-Meta: U2FsdGVkX18Fuo11X02sfnqEFUIjbhjtN4TDYBtHPfQBbrEqV/tHS039Nek2Fo+lXbxCFSz/6cZNEK7tJvQP+7fTMEbeGBOQcMmGfpVhaaK174GbXpIn1+/mKYAr/ti6KFhoUIwjM6DmCPDqxcNStgZGZqE9vBmpqFi5oqWVlbZF12jwB79xCF5KHtsm2nfCdRb3uYZQGOD8yoOlFALIbxs1DjVdlrN9vM9UPjiiTmJNUeMaUqmEt04rqUtnKqKCq62Dn94ow4N/4TP5WO8bFRhv4kOCP54rhA6XjN+CcDGoyEqSfrYrPSw6gf7gtEh9hwqdj6V+XJRZ5Vi/8EJewg5e5k5MVLgk71g0VT+UXGAqUvteoi+OKw1Wm8xt3Ryt89QbyNMWOcVE4PKILNaPXS03KJMRa5p5ff7QsynRIHhtNAJhUAJLqCrjGk8wCMPA7KvY4f7Bx9RZgvd8pB78PUtVNJZTknaPPZTJQCKblev79qXmSw9vXBz6VEAAPs6ulsJ+dI4TPYu4qy8XRlxJ8akrp9FFU2IXoEmcl68TMUaXCEC8oHdLoe7icCdjH/3dpIH4C7yapXR9GZN8ECS5f8vrgWp5jnuvJ4Zs2XgGY1FIvmGSwaawXYaqzRzTm+RrNC47qScMHZT2LRje1T2nduSeMpdW28+cMnB+a28UvkaLENfaRibAJrfM/b1qWVPmLDA8Xi6qb4Xkv8Ab9ZsHcKZh7uZMOEzRdBeGEs4H/56Wa8Zx+iyrFIGPsd5KYWUyx6BHwWDpltIa0dvp7ra5+0CzvSt5HZe9oUXeTPYH6R750EkcPmfUIFszJ96px11ejFWDPLgDByDlfkWQNWVgFpu8HG3Mp2So/3r/rzjHuhcpjMv6p3KgFdgjgEMCRYJsQDzXBZDVNeMwMphkXYeNc7XTzZkeVs3rCCbM28WS/U0wPShC4bbhXmrJ3xDd3e8IHd1t6BPMhgjzIZgj3kx G/nBHj6e TDb1PHfYIMUrB09x05mXVBVaLs9r+h+2/DPok7bzSGAWpaevvnoches1WUYjkw63y/69f 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: List-Subscribe: List-Unsubscribe: Most of the memory overhead of a memcg object is due to memcg stats maintained by the kernel. Since stats updates happen in performance critical codepaths, the stats are maintained per-cpu and numa specific stats are maintained per-node * per-cpu. This drastically increase the overhead on large machines i.e. large of CPUs and multiple numa nodes. This patch series tries to reduce the overhead by at least not allocating the memory for stats which are not memcg specific. Changelog since v3: Minor changes related to changing macro names and chaning the if conditions orders. Changelog since v2: Using WARN_ONCE() instead of pr_warn_once() and some changes commit log changes. Also included a patch from Roman. Changelog since v1: The main change from the v1 is the indirection approach used in this patchset instead of rearranging the members of node_stat_item. Roman Gushchin (1): mm: memcg: account memory used for memcg vmstats and lruvec stats Shakeel Butt (7): memcg: reduce memory size of mem_cgroup_events_index memcg: dynamically allocate lruvec_stats memcg: reduce memory for the lruvec and memcg stats memcg: cleanup __mod_memcg_lruvec_state mm: cleanup WORKINGSET_NODES in workingset memcg: warn for unexpected events and stats memcg: use proper type for mod_memcg_state include/linux/memcontrol.h | 75 ++---------- mm/memcontrol.c | 244 +++++++++++++++++++++++++++++++------ mm/workingset.c | 7 +- 3 files changed, 222 insertions(+), 104 deletions(-)