Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp2962983pxj; Mon, 10 May 2021 15:06:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzaphdcJ6G1z/MH1PswOG1UyTmyITvHuIM72YrqryA8g5ws6P7+qApYpHbZa/kHA7pzY0ls X-Received: by 2002:a5d:9a8c:: with SMTP id c12mr19925542iom.166.1620684371175; Mon, 10 May 2021 15:06:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620684371; cv=none; d=google.com; s=arc-20160816; b=YDEEZpo6u2qyL1pP2EChlkDzx+RAml0B87E+Kgy/D3fvCTkP9QFtbTHhrcW7QeVawl vwrEKLOPJddEOBpnsgWwIdKE0UVoLkpebZLU+3ufYFNuCzF2jIKSY39m4Dolewf1JZJ+ snQwveKYJzZqEdu26cD7XEkley38zS6xIcr8zI4blzGK6M+hefe0NKD+9oL8m7OrUA6Z yvismDUrT/abAk0piBLcZWAGgwZUSdOp7g69sa5sMnnjkCz9HeHAt4+dlGmEHWMe+E/V 27K7XToFHRw5naERvxrJGiebz3AEPf/kCBkTcwjYi0K08JSyxKrA1r52cD5yi4AOrJV9 xlnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=KwtTE/gl2dcTlM1KY2uJwCHjgoUE9x51RcP+6cTsKk4=; b=B+YZAAorWeahZvQfYBjXe9xquq6OFaX4tG4OJPidyUGrtkhYRqM5QQOY/uaD03abxD WWmXzSdLE5ZpXX1Oct33/ioK0a5ETKFDzDTjQOeJH/EyCYxu/ya9u6X3px+LcuKLrvim TrGYobKqu5Sfqqjdmzwzh6N2qQ8Btc/RikpgmyoK3WcQd4unjFmz6RTt7FkcGNA4RkmQ T4BzLx+prIPLfH6QUMdJVmrEYMXYWbBQEcvNi9z/c98UjP3rBexOjzsEG3rdj1gABsgf sVJdyXEgE3B1NqaBI4ambSQJxDg+wiCSFTQLdmfSxl/ueVD608OdMiQunuOeXTy6KIN5 rp2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LXVG67xB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p15si19462506iov.79.2021.05.10.15.05.58; Mon, 10 May 2021 15:06:11 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=LXVG67xB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230238AbhEJWFL (ORCPT + 99 others); Mon, 10 May 2021 18:05:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230045AbhEJWFK (ORCPT ); Mon, 10 May 2021 18:05:10 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 84C83C061574 for ; Mon, 10 May 2021 15:04:04 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id j10so25597722lfb.12 for ; Mon, 10 May 2021 15:04:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=KwtTE/gl2dcTlM1KY2uJwCHjgoUE9x51RcP+6cTsKk4=; b=LXVG67xBqmulAarA32cTdz4NzSJdDEwdV8S83EpC+5jiXdNqNXg9jwGZDQMTCEGvtg 06WlAhff1zjTZTas3gGGNgEC4vus6SFpa6DxbFOxBO4KHpHJ3S174+HZBDmAGR4KrsUR VfAazMEPntUGYITmPn4Nmnlh+cfjMx+1fuGwOl5Yg7m7XvDMnPy0IS0orBjcS1UtZ6+X w99/+zvuAIUvumvVC7kXIDSaWE7N6OBDW/Jca5nF0spbNiK3MMTfc2o63i1Zxir3k5ZH nOejwYjKr6gi+772J+svQSkZBiSSU/vUXE+Z8S0zusjU8uM8E8JHZ5PQT6DHPCugjCWG DAvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=KwtTE/gl2dcTlM1KY2uJwCHjgoUE9x51RcP+6cTsKk4=; b=TarcordNiFblFuiT5nrdXrXlPVZx4oepqB+sDW2kzkLRl6p8Cz/sDPp77qlc/R2vKw +SNCas8MhK+9JJYBf6U0PhXoHQsAd/uWxUv95F/sb06ABqKDW647hVASGfEkdOTqbzsM ddHnuvgwCw0PJBnWr3LtGdwnPQrvxwDL54sJzAVqHgInVU4wuS+knUKh7UO0wt+VU/ga YD3g2sN53zU1n7qEdYR1wQVG+4FooitJF5u0SqPOSS3mB0RJBug84bHfOiq9A/UG8Sw7 Wa3LSTh/XWg3EhuqPCP+YaaGhtciWB4dz2zp6q1uYdLTQc+fsOs88VXE3kKmoqvxsSLD Pm3Q== X-Gm-Message-State: AOAM532YHOHJi4Zg7BleF3XeU+3GRORhTw5IrXnasEsqtxDh0ngNdcKq WbPJcxNlDGJvMnSGthveht7fip+F596KbFTPszjwcg== X-Received: by 2002:a05:6512:208b:: with SMTP id t11mr18182790lfr.358.1620684242850; Mon, 10 May 2021 15:04:02 -0700 (PDT) MIME-Version: 1.0 References: <20210425075410.19255-1-songmuchun@bytedance.com> In-Reply-To: <20210425075410.19255-1-songmuchun@bytedance.com> From: Shakeel Butt Date: Mon, 10 May 2021 15:03:52 -0700 Message-ID: Subject: Re: [PATCH v2] mm: memcontrol: fix root_mem_cgroup charging To: Muchun Song Cc: Roman Gushchin , Johannes Weiner , Michal Hocko , Andrew Morton , Vladimir Davydov , LKML , Linux MM , Xiongchun duan , fam.zheng@bytedance.com, zhengqi.arch@bytedance.com Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Apr 25, 2021 at 12:57 AM Muchun Song wrote: > > The below scenario can cause the page counters of the root_mem_cgroup > to be out of balance. > > CPU0: CPU1: > > objcg = get_obj_cgroup_from_current() > obj_cgroup_charge_pages(objcg) > memcg_reparent_objcgs() > // reparent to root_mem_cgroup > WRITE_ONCE(iter->memcg, parent) > // memcg == root_mem_cgroup > memcg = get_mem_cgroup_from_objcg(objcg) > // do not charge to the root_mem_cgroup > try_charge(memcg) > > obj_cgroup_uncharge_pages(objcg) > memcg = get_mem_cgroup_from_objcg(objcg) > // uncharge from the root_mem_cgroup > refill_stock(memcg) > drain_stock(memcg) > page_counter_uncharge(&memcg->memory) > > get_obj_cgroup_from_current() never returns a root_mem_cgroup's objcg, > so we never explicitly charge the root_mem_cgroup. And it's not > going to change. It's all about a race when we got an obj_cgroup > pointing at some non-root memcg, but before we were able to charge it, > the cgroup was gone, objcg was reparented to the root and so we're > skipping the charging. Then we store the objcg pointer and later use > to uncharge the root_mem_cgroup. > > This can cause the page counter to be less than the actual value. > Although we do not display the value (mem_cgroup_usage) so there > shouldn't be any actual problem, but there is a WARN_ON_ONCE in > the page_counter_cancel(). Who knows if it will trigger? So it > is better to fix it. > > Signed-off-by: Muchun Song Reviewed-by: Shakeel Butt