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 X-Spam-Level: X-Spam-Status: No, score=-13.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 31876C433E0 for ; Thu, 18 Feb 2021 05:56:07 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 5A88364E33 for ; Thu, 18 Feb 2021 05:56:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5A88364E33 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cmpxchg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 98FBE6B006E; Thu, 18 Feb 2021 00:56:05 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9677B8D0002; Thu, 18 Feb 2021 00:56:05 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 82FA98D0001; Thu, 18 Feb 2021 00:56:05 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0242.hostedemail.com [216.40.44.242]) by kanga.kvack.org (Postfix) with ESMTP id 6DF696B006E for ; Thu, 18 Feb 2021 00:56:05 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 39121181AEF3F for ; Thu, 18 Feb 2021 05:56:05 +0000 (UTC) X-FDA: 77830327890.30.nail29_24125d927652 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id 16ACD180B3C83 for ; Thu, 18 Feb 2021 05:56:05 +0000 (UTC) X-HE-Tag: nail29_24125d927652 X-Filterd-Recvd-Size: 6437 Received: from mail-qv1-f53.google.com (mail-qv1-f53.google.com [209.85.219.53]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Thu, 18 Feb 2021 05:56:04 +0000 (UTC) Received: by mail-qv1-f53.google.com with SMTP id gi9so433841qvb.10 for ; Wed, 17 Feb 2021 21:56:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=97xepu+H893Qn2oD7QzEQlF0nqYf2pV6us14XKtvHxU=; b=mgbz52W0JN7xwQftwEtM6NGsY/g84xRLA4xkhTjEINN5my44bcXRu6XD/L38sC1qfB fFk0r+RCj1e1clOhXV7+g4RwblTqhm4rMAYlgBga522+NSBTxYmvRQBy1Wby31qUxspS 2o1DQPJXVPiyJh6aiJRdpzWtHvBAg8XR4lxxIg1tkZhIUN+CxS34HLATPmSjYMbryzYh L3gZ0Bmtz2aLr/fB2xjsFlEgfigT7X0md89CHZzGaIwcsqT+wP+5w7Yh09lA+jl/U8NS 5ZI43x8+XjOGS5AddwtIoX1G0f0hze4USrUbCr7PTJ7ElbZRW957RBC1kocJFd96cIPp w/sw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=97xepu+H893Qn2oD7QzEQlF0nqYf2pV6us14XKtvHxU=; b=fni6QRMVizXfmqr8cCibPVK+IywobsftzClZR7c7ZxZxJ2RIpUuPRqrZYirB8ZqE8C 5bg1pBXWgee7Gy3+emazovElkrpEI9NdpG49Q15ijsgrTSGmPvkT594Q4FxLQvxFG3fJ rncTFCLKyEiedSReqi7K0S8D5xB3xTzbbOiWPw4DGpQhtfFGzgHPKGHsjRj3pAV+PGAS keGvZ2H60ykdYE7ZdiO2QbVRWFt7OAliex0AGwike17ilkYDEEhixpkz58WzWFQ4pUo6 WQay6SpDIgXTsInGtis8aByRFmilFLe2oo6294uebsYjuwxtkL2V5tc34ZwH9S7P9P1O ofYA== X-Gm-Message-State: AOAM5327dX6aLqnkSddP0fW2gWopeRXGQJOtXmB/kSm1VAwmhj5wRqzJ kB4d0LmrC5pPdnItU75zq5/dZg== X-Google-Smtp-Source: ABdhPJwsk5IUVrVDg92pl5EyX/4pmGD+gOB1OV30TBrbHpR+IPLGYf7+2OWQg1V2jKga9UiKmLOINw== X-Received: by 2002:a05:6214:242f:: with SMTP id gy15mr2624583qvb.17.1613627763640; Wed, 17 Feb 2021 21:56:03 -0800 (PST) Received: from localhost (70.44.39.90.res-cmts.bus.ptd.net. [70.44.39.90]) by smtp.gmail.com with ESMTPSA id p6sm3245805qkg.36.2021.02.17.21.56.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 21:56:03 -0800 (PST) Date: Thu, 18 Feb 2021 00:56:02 -0500 From: Johannes Weiner To: Tim Chen Cc: Andrew Morton , Michal Hocko , Vladimir Davydov , Dave Hansen , Ying Huang , linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 3/3] mm: Fix missing mem cgroup soft limit tree updates Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Wed, Feb 17, 2021 at 12:41:36PM -0800, Tim Chen wrote: > On a per node basis, the mem cgroup soft limit tree on each node tracks > how much a cgroup has exceeded its soft limit memory limit and sorts > the cgroup by its excess usage. On page release, the trees are not > updated right away, until we have gathered a batch of pages belonging to > the same cgroup. This reduces the frequency of updating the soft limit tree > and locking of the tree and associated cgroup. > > However, the batch of pages could contain pages from multiple nodes but > only the soft limit tree from one node would get updated. Change the > logic so that we update the tree in batch of pages, with each batch of > pages all in the same mem cgroup and memory node. An update is issued for > the batch of pages of a node collected till now whenever we encounter > a page belonging to a different node. Note that this batching for > the same node logic is only relevant for v1 cgroup that has a memory > soft limit. > > Reviewed-by: Ying Huang > Signed-off-by: Tim Chen > --- > mm/memcontrol.c | 10 +++++++++- > 1 file changed, 9 insertions(+), 1 deletion(-) > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > index d72449eeb85a..8bddee75f5cb 100644 > --- a/mm/memcontrol.c > +++ b/mm/memcontrol.c > @@ -6804,6 +6804,7 @@ struct uncharge_gather { > unsigned long pgpgout; > unsigned long nr_kmem; > struct page *dummy_page; > + int nid; > }; > > static inline void uncharge_gather_clear(struct uncharge_gather *ug) > @@ -6849,7 +6850,13 @@ static void uncharge_page(struct page *page, struct uncharge_gather *ug) > * exclusive access to the page. > */ > > - if (ug->memcg != page_memcg(page)) { > + if (ug->memcg != page_memcg(page) || > + /* > + * Update soft limit tree used in v1 cgroup in page batch for > + * the same node. Relevant only to v1 cgroup with a soft limit. > + */ > + (ug->dummy_page && ug->nid != page_to_nid(page) && > + ug->memcg->soft_limit != PAGE_COUNTER_MAX)) { Sorry, I used weird phrasing in my last email. Can you please preface the checks you're adding with a !cgroup_subsys_on_dfl(memory_cgrp_subsys) to static branch for cgroup1? The uncharge path is pretty hot, and this would avoid the runtime overhead on cgroup2 at least, which doesn't have the SL. Also, do we need the ug->dummy_page check? It's only NULL on the first loop - where ug->memcg is NULL as well and the branch is taken anyway. The soft limit check is also slightly cheaper than the nid check, as page_to_nid() might be out-of-line, so we should do it first. This? /* * Batch-uncharge all pages of the same memcg. * * Unless we're looking at a cgroup1 with a softlimit * set: the soft limit trees are maintained per-node * and updated on uncharge (via dummy_page), so keep * batches confined to a single node as well. */ if (ug->memcg != page_memcg(page) || (!cgroup_subsys_on_dfl(memory_cgrp_subsys) && ug->memcg->soft_limit != PAGE_COUNTER_MAX && ug->nid != page_to_nid(page)))