Received: by 2002:a05:7412:2a8c:b0:e2:908c:2ebd with SMTP id u12csp2673364rdh; Wed, 27 Sep 2023 09:16:32 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHJ4kG8/kPeZpWCX/wuzuH95w1DyB1CreaMaKXYDT14FhU/d4vUkf1Xdc2H0h00JUGUrMA/ X-Received: by 2002:a17:902:a40c:b0:1c4:1b27:1cd6 with SMTP id p12-20020a170902a40c00b001c41b271cd6mr1958002plq.26.1695831391764; Wed, 27 Sep 2023 09:16:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1695831391; cv=none; d=google.com; s=arc-20160816; b=ATh2q2JInUO2ruY62Wx2m++0ShMZy9RAyAhDVUZATJv3/0fTF6Tt7OdyxTR0BGZEQR OQz610UX7WyITTFIk5/7k2IMMCxW/TuOnxu5uty6govMlYP9aydiPJK+hObEm+ce6Tlj FjBEf/CmjeuCJE8L6UQxzbWioCOizpd9D1FE1WHiDLlIXfCPbR0u3OtRBr8mPNExH/Ul A3fHgFvs8EAp7ntY9TlRoRFCfFV+F1eZpuCOZVfbMhBwLVF8ywfaRs/J/91GXDLL1bH+ 7sJEkir2XTBGZrsW9/m4BGiaLBp5h3+bSBktHWAsrscq5JMAqKoqqimDp+QvIMB/iNHH nIcA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=iheTTLd3Z1Ys92CI3hXi6CHRL4MwII17mSI0D1gw4bQ=; fh=6Xuc2vWg1ZqbCRrFFsNqsMRboHMFzLDhlaQTpg15qus=; b=hWfd/m7n3aZJ8gy0FpiZG54Uy00aSNgAqhJmWrkWWHwZHS29kkKAjxj803If6pEcCF 2gVpoA/IptET05yu/A7CiBfCE78RebFYrEbZmd7z+GO1sEXKcphoVUyOGCcA8go/GMX5 FcokF0xm+9ZTgreiD9ZHb8zEcDMZ782sT3oQVeILPwpoLKm+Z/CNngMtm4NtxKQ8uSlw gr/UbQZ0rHqXJDzk1X6aBJQgMKgYoVG+oYogRaZ13HCHe8YT5SGScd5MKVVQOqOTXeb+ Coz4cxYMJKeCkbPB8GrQn8YiTzBCDEzg6F3PL/Mrnkfw2IaerllsPcVIFKKUquwdG38h tVZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=gWDd1nXm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Return-Path: Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id kv8-20020a17090328c800b001b8922e82e3si7195790plb.297.2023.09.27.09.16.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Sep 2023 09:16:31 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=gWDd1nXm; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=suse.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by morse.vger.email (Postfix) with ESMTP id 10F0E80B90B1; Wed, 27 Sep 2023 04:21:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231416AbjI0LVb (ORCPT + 99 others); Wed, 27 Sep 2023 07:21:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231422AbjI0LVZ (ORCPT ); Wed, 27 Sep 2023 07:21:25 -0400 Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A93F180; Wed, 27 Sep 2023 04:21:23 -0700 (PDT) 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-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on morse.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (morse.vger.email [0.0.0.0]); Wed, 27 Sep 2023 04:21:41 -0700 (PDT) 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