From patchwork Tue Apr 30 06:06:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Shakeel Butt X-Patchwork-Id: 13648286 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 E5A75C4345F for ; Tue, 30 Apr 2024 06:06:26 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 71B476B0092; Tue, 30 Apr 2024 02:06:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6A3BA6B0093; Tue, 30 Apr 2024 02:06:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 543856B0095; Tue, 30 Apr 2024 02:06:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 35F606B0092 for ; Tue, 30 Apr 2024 02:06:26 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id BDA03140618 for ; Tue, 30 Apr 2024 06:06:25 +0000 (UTC) X-FDA: 82065163530.08.C0B79D3 Received: from out-171.mta0.migadu.com (out-171.mta0.migadu.com [91.218.175.171]) by imf07.hostedemail.com (Postfix) with ESMTP id 00C7F40020 for ; Tue, 30 Apr 2024 06:06:23 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=m35tfVAE; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf07.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.171 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=1714457184; 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=PXNo4uDkvXkGowWyfavQ/wvT4lCKFMctusOOMGZYPL4=; b=0q8/3KnHvLCLWBORPz5lP+eBAYS7CotIsXk0pQxCWgHMRc5cspJlf7BlozQH/MC3Ojr5UB uITJKtGVA/4cHtyqZdw/o+wfOHgzW10rS6mPTWQDR1OHFJkhGL/XBZqBCDKMkkElgCMqXr C9HJ9t4x+g37Rv35+Ate41gaEB56hY0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1714457184; a=rsa-sha256; cv=none; b=ttf4AIgY6hIQzvj5nTEwAqElzAmnK/o3CqNWRTMEXUW3JWbuoCKKLY6oeki0aq0WKbDqxD vYMjCcnRFS4mVeOTv0wvybajq4ZYg8v47QHNnGy5erBvbrPZBVjPDAgePnY/kgIr6fGVRI L3srFkoOfmUGf20pYbYySva7A8pclnI= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=m35tfVAE; dmarc=pass (policy=none) header.from=linux.dev; spf=pass (imf07.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.171 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev 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=1714457181; 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=PXNo4uDkvXkGowWyfavQ/wvT4lCKFMctusOOMGZYPL4=; b=m35tfVAE4Y0Uh5X9Q0T/7eI9OEwXIlToUjoo3IBcXMIkxE3yPu/M+V8skCMNcqs6iYCxEp 0BmG/cM3LDSnVSL5TJXLj0XVVgYDmXKj1NVjT9DGumiEowCHm1RpRAWuMDWohGcG8Ga1xt 8bJtEsJrWTU89Y6mKsUuaGo8/IGKckM= 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 v3 0/8] memcg: reduce memory consumption by memcg stats Date: Mon, 29 Apr 2024 23:06:04 -0700 Message-ID: <20240430060612.2171650-1-shakeel.butt@linux.dev> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 00C7F40020 X-Stat-Signature: 7oedgjiw7sn3p1gxhxykqd1j8deidcff X-Rspam-User: X-HE-Tag: 1714457183-158363 X-HE-Meta: U2FsdGVkX191DC+ZjlGSkVbFKRMhHdP9SR1QquLJkMxaMQDtXlla4X44oad7gGEpsKLlRxly2nlDcuTRJn0m2S7rABF5gYqR/ySOyNvgLyn15GfLKRtE5YhP3qOPbpIIqieZlLBER33vQVKKEb1a1p1llkNj+49cw2UZNyjuiUdsZDDGAA879Y7z92wBZ+lggvQ1s+rd3oZ90DdPXql0rRq5fnENBZigBIuhcAiKwK4SovDYYRS63BPhtMTVTUdSX3ZtCC8wmHeOb7VUiHQppVvJOvRfmn4Z9qPBOeSCBuvf1s4C4gq+iQKBNkjMzN+XvemxCyCqZ2KzSw8ImkoiPnvuBjcAHvG2bJOnFAXWsbxSRx7zWAfeDLIq1rFh+PEROZRBJUzGTR9aFTnVTkEferzhyTYlOCnfokS/bhlMl7u0xrFpX+n+jGBDLi8LH9YJ3J3n1qi83OPpwVpcXHA9hkpM63uvURAhkqHTTA82NsNc6EZD/g4/oRFV5hfyUpPKCApKgakULR0nPhu+IIt4Rmib55xhv2/mxNimNJtxTGbxL6rwSIEzc/iYhIG6XoxvjZMNa5BjF+AqVf2FT+q4lEF/uIZ2ZHw3Wsv9X/lhOYR8ATwdXhrJDLTPLqA8y/nusI5ohrXFEmcGHBv3r+KW9tUSq+9ig76lZmVrdRY8QFKxJ6NT5uEbbI4vqpk1IRwpYIU9kkrk7aNou+7Z455heoj9PmrwtUTpoown1QtqSuUB01KChlF1SufdbOY4m7c/ASGxPVWj7NaJZFNlkf7/tSJ5maN8dgvVFz8vn9pVTqWPhGiAcfG7Tdv2VwBzT6AMnrMxu0lyuF2eVdOs/hA+9DfJ+tuNlyNbskwWVZL79ijTvQSC6OyinQKPIUX99X7StF/17aIbyay1eOcrYulrvXfH20sNE3alOQ08kUCfc86UbLufUHBMJNiJqtMQ58CT3AtmO2B7Agt5Vslde5B mqZHDIpN 7t8dRnYdo1NjPRq4Mdj5s61Um4B3CAoh6sHrQwvMndnmvTA+nERIn8u1Dz7GIjI06VQxZ 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 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(-)