Received: by 2002:a05:7412:3784:b0:e2:908c:2ebd with SMTP id jk4csp1598641rdb; Mon, 2 Oct 2023 15:00:46 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGvz/cDFghIiJOzBz4hzlS2Zwt6rvXV8ka7sI5gnsTRYeNxIeeNAkDUlz8QaObC917PsMqz X-Received: by 2002:a05:6a20:430a:b0:153:40c3:aa71 with SMTP id h10-20020a056a20430a00b0015340c3aa71mr15424438pzk.43.1696284046523; Mon, 02 Oct 2023 15:00:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1696284046; cv=none; d=google.com; s=arc-20160816; b=W2rpUhLKc7EH2xmdSIdEzNalDL7Ky8S7BHaeQQk2gK0Y9gqou00MXZwhsvSnFZmLd+ HSeOqdWeaFzieuy3MQSvfoRu4qjtxbL+PTOrntIq0a3K7WViDbxcahcH2u1eShBzpP3P 5OThIOPgY7RInpTtn6ymCohp3o3M+PS80T4GMd1ehx9Q7fWsxPXPnc+ATNaMVX13sWAM e6GSrP2DhS/XFatrTYIEaowoUr9weBvmR0iDfG9Pz732sry62+HG2LVvXfGToNs1sC3i 5rLd1G0lFAVNjXIxVBtewXNABVWNA4Z84rTeWEPz/Cdgh/Ai2wZVIGg4OHV+uYgYyW5Q s+NQ== 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=Z686kNiWukEPuUFPdj5Zpdh2jq/+sj08V/foqt23i+A=; fh=TM2vs+QtB9CWJvoHiOTQBlTsmRP4CFyxdrHkUqzOXdU=; b=ym445Q1L68s0IpHX+F/Ms83t8Jh2ZxPkgS/4SYomg14DXHPJkMDTPLsz0a3l7m4lQA SjOwZQYoMHgHniLyGdptTotBacBiThSGCqvU1+ITWtey+vNmDArgNOjFql1tuo+U6MmF uMFDdd9wzUCRg1bbmhH3C5gAzgo9X4u5QNf4Al8JmvJxHa6aAdxanijAsADqBLztzVfZ ZBl80kgQ+yo6NAo0UIPIopS3Dfm41DOrbr4/EaY/z4POi6PUNzOtKDTNZUK+XaVsaZ6k rvJCGf1KogU5+jZCU5i6eKUsN8yImdX+5iZ6Z3dYXs4Qx9HUTYd0I9HXzSIqiVIQ7V7N 6yCw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b="y4Lpd+/4"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id o1-20020a170902d4c100b001c59b6ed118si22193568plg.157.2023.10.02.15.00.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 15:00:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b="y4Lpd+/4"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 4FABB807C871; Mon, 2 Oct 2023 08:26:22 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238088AbjJBP0C (ORCPT + 99 others); Mon, 2 Oct 2023 11:26:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49000 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238078AbjJBP0B (ORCPT ); Mon, 2 Oct 2023 11:26:01 -0400 Received: from mail-qk1-x735.google.com (mail-qk1-x735.google.com [IPv6:2607:f8b0:4864:20::735]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13A52A9 for ; Mon, 2 Oct 2023 08:25:58 -0700 (PDT) Received: by mail-qk1-x735.google.com with SMTP id af79cd13be357-77574dec71bso480073985a.2 for ; Mon, 02 Oct 2023 08:25:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1696260357; x=1696865157; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Z686kNiWukEPuUFPdj5Zpdh2jq/+sj08V/foqt23i+A=; b=y4Lpd+/4SIcTmMP+it4zIC2bLkghe/X8cNL2Hpr66K0KhC/8NgnTKxgtiai1lq8JlT yRnNDfTjrGENFRjPNJwZ/Kx3r336mjDgS9perjkesmiZjPMq8OAOTK+v7UqkfmFy1Miz xuaJ9LEqus9y77xTAskjdm6WHdQ7naVXSvjbTtFM6qBKKZLPMHy7UYld5kpc8FzQoXzT fLzLFh4+4tYI7x+GS6ekbW9zxITAeVUAgX+qnV8W98vnP0lFXh1Cc70eMEY13mYYhQM7 9/c+pOfSkf2UZYRDZytYO8zC1lkjpmiYMmzj3ULBIHtyJi53pwUD4wbfHgnzGwGsSB2N b1eA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696260357; x=1696865157; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Z686kNiWukEPuUFPdj5Zpdh2jq/+sj08V/foqt23i+A=; b=pFBIAXsBY92EGPBWbzxqaw9v3eoNH20LMkRBh+k3cTfiuBVxfvgvCVe8tzSJL9xzBj x3qE7FoiHRN/K8v6JTKVR3B4cy5+/BBQQcmQ11lBVpr/G6m9zEKn77gQ+cWHXy72r4OO eQGwQRVDRMYtSoHvwqrMvxwFHjEe9/jcyhdXXazLxingFyqYXxalZ2Sh9rOTtSj4tb63 DaDk1w/9Y6xoPZeNye42ltKNDPpk7DcCji6JPxrA2fq2ZWZ/uaVZQeoI5aO4Ef8imEMY aZkQ0xxSd0AEmnp3WFeJ3MhIZn2NDD5yQkKD8Ee4F8Ri1nXkSsD5elyzrQe5Tfy1NqGo QILA== X-Gm-Message-State: AOJu0Yyjvl9v8dNRyKkdoKmQ3W4h76jLYuaH3sNZVng1zJaOsalz0WOe cV5eg1tvG2NRBS/Uu5IsuOK0jg== X-Received: by 2002:a05:620a:4891:b0:775:9766:cb69 with SMTP id ea17-20020a05620a489100b007759766cb69mr7612236qkb.75.1696260356936; Mon, 02 Oct 2023 08:25:56 -0700 (PDT) Received: from localhost (2603-7000-0c01-2716-3012-16a2-6bc2-2937.res6.spectrum.com. [2603:7000:c01:2716:3012:16a2:6bc2:2937]) by smtp.gmail.com with ESMTPSA id b6-20020a05620a126600b007759e9b0eb8sm1707697qkl.99.2023.10.02.08.25.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Oct 2023 08:25:56 -0700 (PDT) Date: Mon, 2 Oct 2023 11:25:55 -0400 From: Johannes Weiner To: Michal Hocko Cc: Nhat Pham , akpm@linux-foundation.org, riel@surriel.com, 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 v2 1/2] hugetlb: memcg: account hugetlb-backed memory in memory controller Message-ID: <20231002152555.GA5054@cmpxchg.org> References: <20230928005723.1709119-1-nphamcs@gmail.com> <20230928005723.1709119-2-nphamcs@gmail.com> <20231002145026.GB4414@cmpxchg.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-0.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, 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 groat.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 (groat.vger.email [0.0.0.0]); Mon, 02 Oct 2023 08:26:22 -0700 (PDT) On Mon, Oct 02, 2023 at 05:08:34PM +0200, Michal Hocko wrote: > On Mon 02-10-23 10:50:26, Johannes Weiner wrote: > > On Mon, Oct 02, 2023 at 03:43:19PM +0200, Michal Hocko wrote: > > > On Wed 27-09-23 17:57:22, Nhat Pham wrote: > [...] > > > - memcg limit reclaim doesn't assist hugetlb pages allocation when > > > hugetlb overcommit is configured (i.e. pages are not consumed from the > > > pool) which means that the page allocation might disrupt workloads > > > from other memcgs. > > > - failure to charge a hugetlb page results in SIGBUS rather > > > than memcg oom killer. That could be the case even if the > > > hugetlb pool still has pages available and there is > > > reclaimable memory in the memcg. > > > > Are these actually true? AFAICS, regardless of whether the page comes > > from the pool or the buddy allocator, the memcg code will go through > > the regular charge path, attempt reclaim, and OOM if that fails. > > OK, I should have been more explicit. Let me expand. Charges are > accounted only _after_ the actual allocation is done. So the actual > allocation is not constrained by the memcg context. It might reclaim > from the memcg at that time but the disruption could have already > happened. Not really any different from regular memory allocation > attempt but much more visible with GB pages and one could reasonably > expect that memcg should stop such a GB allocation if the local reclaim > would be hopeless to free up enough from its own consumption. > > Makes more sense? Yes, that makes sense. This should be fairly easy to address by having hugetlb do the split transaction that charge_memcg() does in one go, similar to what we do for the hugetlb controller as well. IOW, alloc_hugetlb_folio() { if (mem_cgroup_hugetlb_try_charge()) return ERR_PTR(-ENOMEM); folio = dequeue(); if (!folio) { folio = alloc_buddy(); if (!folio) goto uncharge; } mem_cgroup_hugetlb_commit_charge(); }