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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45FD3E810D0 for ; Wed, 27 Sep 2023 11:21:27 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5EDB76B0191; Wed, 27 Sep 2023 07:21:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 59C956B0192; Wed, 27 Sep 2023 07:21:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 464586B0193; Wed, 27 Sep 2023 07:21:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 338C96B0191 for ; Wed, 27 Sep 2023 07:21:26 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 07A5AC10A7 for ; Wed, 27 Sep 2023 11:21:26 +0000 (UTC) X-FDA: 81282136572.11.A026AB3 Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) by imf02.hostedemail.com (Postfix) with ESMTP id 178338001F for ; Wed, 27 Sep 2023 11:21:23 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=gWDd1nXm; spf=pass (imf02.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695813684; a=rsa-sha256; cv=none; b=UO+ikDVHD1HpfIGnTKgdBXheIe6s2yMAi7nXTWL0QM2sZJFBr0DrUMN+DMiCZ3gxT7cbeF 9uvFKLFq8yTgy64DgjBYsOQENIsD4TtfeCbLyenzs+fXu2985rTwPCOUQIRhKgtMYjufD9 DCsrhT6fexrDI4I8Y+B+vjyk3I8UhaE= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=gWDd1nXm; spf=pass (imf02.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.28 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695813684; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=iheTTLd3Z1Ys92CI3hXi6CHRL4MwII17mSI0D1gw4bQ=; b=x7Xo+eqniCx3yIhT5VLjO4VyNc3B5eHUruzExriwoYnMeeGK9rC2SS9erfmoXbiC+f7tj2 IK7zDXDpoBfYpv5b9vBSdUwsZJdYK6eAXyQQFhhoZtXB9jLImYwc5VkT3+S51r+A8DlK/M 2bEJdMoQVKLp21UE0ueysY/V/CZn80U= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B8D79218EB; Wed, 27 Sep 2023 11:21:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1695813681; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=iheTTLd3Z1Ys92CI3hXi6CHRL4MwII17mSI0D1gw4bQ=; b=gWDd1nXm1nscic6L7Jwf9q2B5gbk77vFLbIn+4AfQHYLedfamb0kNbc91XohYjFCmLsDCw P4E907eIqOJ2o9wV3NumXS2a9J5XzLk1t4LfMx5Q7GszT3xbqPQWSI7KgcHmuV27wQBWNr hl+9WCXmlP0PIPHw/L0X4DpE7OVWOq0= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 949D313479; Wed, 27 Sep 2023 11:21:21 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id g406ITEQFGUpVAAAMHmgww (envelope-from ); Wed, 27 Sep 2023 11:21:21 +0000 Date: Wed, 27 Sep 2023 13:21:20 +0200 From: Michal Hocko To: Nhat Pham Cc: akpm@linux-foundation.org, riel@surriel.com, hannes@cmpxchg.org, roman.gushchin@linux.dev, shakeelb@google.com, muchun.song@linux.dev, tj@kernel.org, lizefan.x@bytedance.com, shuah@kernel.org, mike.kravetz@oracle.com, yosryahmed@google.com, linux-mm@kvack.org, kernel-team@meta.com, linux-kernel@vger.kernel.org, cgroups@vger.kernel.org Subject: Re: [PATCH 0/2] hugetlb memcg accounting Message-ID: References: <20230926194949.2637078-1-nphamcs@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230926194949.2637078-1-nphamcs@gmail.com> X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 178338001F X-Stat-Signature: hs8ditswgno9kx68hu4znkswjcg36h76 X-Rspam-User: X-HE-Tag: 1695813683-472636 X-HE-Meta: U2FsdGVkX1/4YXwZY+yDUDEYHx6c5b1foafR27ixXm6XIZnSE2G1GcZGSL+uaA5KBV+bYQI8J//t8sqRyu3bDZ/2HWogynm1W9AkuqCeoIbuf70pjUyOlgo0cKwdgkXFZTeypNVaJyyZt9ZFFaEFWEhBJtt5+qpSuUK1MuAvxUeUUKex/cpsj+TJyWee2nSt8/7afV1peybxeRs701UeRA+l5yNlWgwvezNYLda2W5lWsSm91tNWuc85q/Fxh2IXpd8Nbdp0grDek39oyLhqCl78SW4bb25BBDt4CLz5/wm7wNkYQjf80wcn/bt7Majc9McXNlkt/WXFWJZ3fREto+1E9fQG9oLqoNl1UcR+UhqakFDdi7ZAB9DWclCvc1RS09qPB+XdA+8Y6gCI9fTa5ULKaxe4uO78lo6SxQ88lUeF9FRc5xn7fvOT/t5yvtGko2PiNpuPCfKoqCUvfIuPRKetGFjd0ceLQ+k57tN3UXIiU0I15e6UsSelKaClWTWWjY20j4HGuIbbnSciCeWfPIYEZsC+cA1XFQv49SEY101cwzDYz+FHXH4ZbPnkIXxB/Gu5ZG/r9kxx9SqNnuiSfke+wxZk9bxZonGcGWkkx00m603Aa1KpBs063M2qX8KYT8Ua5fuLrVU88tg3HVEB/d/ReUBZyrMz/CKDUJC2F+Q4snU1XT9s9bJIASFCsjpQGZA2r24fFwINCmOpzj1mrymWJc/ZmGARF1D+4D+tfzPHETMYBIyYFv7PLYcow04hSOQIcKmRmeUBmbJATUA5URYPTvO5Qwuy6e+7T35deDM7JiZWqw7X2bMTtCMQIVBrvV1DZi1nf6kt7aeUfYCaxwQMkbgUfWGSgLJi6X3iXi4eDNdj23A4iGcE1qOp3H9H6e3fpGTgrY2ywN1JwfwW2OOA1/TjuSyqdkm0kFv8MyowLkCyOseDFIL9uAgEXhnWmZ7blR4TvpE1/uhzncs j1uSwxio V/BWq/tLeFKIMx2c2FWnKMDyukCCnE4HyqBMqc5lBO5y9RLT/HINpbQNxIpVL5fP2FmDcVckucZWl4gv/Uq6CIjDcVewUbiSYsyoip07yXMtPl8kJlCSDBlPKvyFJptjkBTWVATRIeUvcZe03c+8dfsHNYg== 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: On Tue 26-09-23 12:49:47, Nhat Pham wrote: > Currently, hugetlb memory usage is not acounted for in the memory > controller, which could lead to memory overprotection for cgroups with > hugetlb-backed memory. This has been observed in our production system. > > This patch series rectifies this issue by charging the memcg when the > hugetlb folio is allocated, and uncharging when the folio is freed. In > addition, a new selftest is added to demonstrate and verify this new > behavior. The primary reason why hugetlb is living outside of memcg (and the core MM as well) is that it doesn't really fit the whole scheme. In several aspects. First and the foremost it is an independently managed resource with its own pool management, use and lifetime. There is no notion of memory reclaim and this makes a huge difference for the pool that might consume considerable amount of memory. While this is the case for many kernel allocations as well they usually do not consume considerable portions of the accounted memory. This makes it really tricky to handle limit enforcement gracefully. Another important aspect comes from the lifetime semantics when a proper reservations accounting and managing needs to handle mmap time rather than than usual allocation path. While pages are allocated they do not belong to anybody and only later at the #PF time (or read for the fs backed mapping) the ownership is established. That makes it really hard to manage memory as whole under the memcg anyway as a large part of that pool sits without an ownership yet it cannot be used for any other purpose. These and more reasons where behind the earlier decision o have a dedicated hugetlb controller. Also I will also Nack involving hugetlb pages being accounted by default. This would break any setups which mix normal and hugetlb memory with memcg limits applied. -- Michal Hocko SUSE Labs