Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4870794pxb; Mon, 15 Feb 2021 03:36:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJzfZ6PiVEL9idxxKuoNGaafGRsgqUDo/ifkPnVzhx+qU/059LJ2I7T3FNe31vJfWxVtnOlK X-Received: by 2002:a17:906:708e:: with SMTP id b14mr8397873ejk.325.1613388983475; Mon, 15 Feb 2021 03:36:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613388983; cv=none; d=google.com; s=arc-20160816; b=S+zMWWhUCXsHQhL9EXtWtF6aY8r6DqhJ/0i8VuSA3Dj8MxdpguPhX+vLLGmRLa6uBD 27q5DuqL/IhziAGehjUGwamWSWuITYFKnJVq+FdsQl8RQxUpDige5QcmPU59O+98JbWS 65xdDSGouGQete+1P3VnI/EcVUVbWWoUVJHU+XPsl/3uYxMkJCys6anv+5+iHeduDPoH XIjGb40mXVDvlEZ/J36/EXuhOAXTkAWYANpmN/t13tBLCYrMbJnCJrszAabCjIHcxvtE gg0VZ617EFMWNOkTzYm4ru1Lb9xhYR3FScSEmeHO3MKcc5P+he2bXoPmCZEkEUNgVLSe colA== 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=l865vVupJANTr8r5LWdTPagS4MMpwqLzjm7i9kZsffo=; b=diBaMZ6xZGduRygvJpocmw8JAo0fzymIzlKm//3ObIw/24Cn9C2bMf0ch/1L3dAe38 Gm1f8IUHpCf3iiWncTyCqZvk+/hjIXKbRwjxLXkoQ5xrR1OpCG4jKh4yPlV8035um9Xx I4euADxsEplklZt0oaDnPCgAXi323sUo2wPF+DY2DjSk+zsHIz+MChafy0lQHoSXcnsa iO5Hw/EfRaXFEpzC285T2YhDaRr/8O1L10OHHucHak6oyW0zxOLes8j+lKR5C2Tx2B0F 8MsuO2GSmiErBdN18V+p9PKFRLKEnz+2wB+1TOpTOmH9hHelNsqwZMpEP0tzJBXb6DW5 kD5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=DIldKF3h; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bx24si12410510ejb.98.2021.02.15.03.36.00; Mon, 15 Feb 2021 03:36:23 -0800 (PST) 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=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=DIldKF3h; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229916AbhBOLff (ORCPT + 99 others); Mon, 15 Feb 2021 06:35:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229802AbhBOLfb (ORCPT ); Mon, 15 Feb 2021 06:35:31 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD8E1C0613D6 for ; Mon, 15 Feb 2021 03:34:50 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id gx20so3751122pjb.1 for ; Mon, 15 Feb 2021 03:34:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=l865vVupJANTr8r5LWdTPagS4MMpwqLzjm7i9kZsffo=; b=DIldKF3h+HGUTTkXdgO1HcOE27rqK13KgreCr9rYNZM8vICXYReY2h1jmZuKluHWy6 u0OVEHaui4daB/x4TMYYhtClWcVjd1m0fdqohXkkGUvciosAGNz19JMJKwZjpgsgVYun on/KKfyItRgN7nvYufhX57/gHvVHvbYZ85k5wudAbXNnIkIYvWm3I+a1huWJHa/WETt+ T3XhrQqmyWPiGhhIldBpdvNYQe8AVk5kWi2g7mr8bcIlLaXchSl9uV+bYshA2SdQP43t LhLaWW0/L8V7oh/rZ7cmJNLPSF9/zdfqgLlci7t0NEXtRvi0YuqKCmENP0WrKrJ+Awnv 5k7Q== 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=l865vVupJANTr8r5LWdTPagS4MMpwqLzjm7i9kZsffo=; b=WYo0Ebp2sNj/YQuX3Eo2FzzLYizSc52a1MABHKIRKwWbf1u6dWbDmykCWZ38723n/X SEhFBU4nn6bnZY7tv3GRSCWS3ts7x4IuMYhSEUmr+H0w+Di1hNRnW+qJKXuZSMibxIGZ K/7W/IF042rj3S1Oyxk/pRkYwDrxHvW1RpCq4eMuHvfKwiOdWS7CcHEGWklkIkf985CZ YitXv/QjpEVxtVUYLWKWoGRWr0Rlgf8XJp02B2bCmjQpXGMHu+b9RZoUNgwhE5O+auqA R83ugO8lDzKwUICDeYfohkaleLznwthKQQtHUoXVOFZ+H7iKGSc+mvy5jSundbUk2KbW Q8xg== X-Gm-Message-State: AOAM5338OHNYjhYDGL5Oc+fCjSD+6bMHYIYFApryBqSQ7i0TTC0lo/5e 32VArpDtKKY8AtcBuZ4abBquoA9i1yaDw+xIP9uJ/A== X-Received: by 2002:a17:902:9341:b029:e1:7b4e:57a8 with SMTP id g1-20020a1709029341b02900e17b4e57a8mr14845364plp.34.1613388890312; Mon, 15 Feb 2021 03:34:50 -0800 (PST) MIME-Version: 1.0 References: <20210212170159.32153-1-songmuchun@bytedance.com> <20210212170159.32153-3-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Mon, 15 Feb 2021 19:34:13 +0800 Message-ID: Subject: Re: [External] Re: [PATCH 3/4] mm: memcontrol: bail out early when id is zero To: Michal Hocko Cc: Johannes Weiner , Vladimir Davydov , Andrew Morton , Cgroups , Linux Memory Management List , LKML Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 15, 2021 at 6:27 PM Michal Hocko wrote: > > On Mon 15-02-21 18:09:44, Muchun Song wrote: > > On Mon, Feb 15, 2021 at 5:39 PM Michal Hocko wrote: > > > > > > On Sat 13-02-21 01:01:58, Muchun Song wrote: > > > > The memcg ID cannot be zero, but we can pass zero to mem_cgroup_from_id, > > > > so idr_find() is pointless and wastes CPU cycles. > > > > > > Is this possible at all to happen? If not why should we add a test for > > > _all_ invocations? > > > > Yeah, this indeed can happen. If we allocate a new swap cache page > > and charge it via mem_cgroup_charge, then the page will uncharge > > the swap counter via mem_cgroup_uncharge_swap. When the swap > > entry is indeed freed, we will call mem_cgroup_uncharge_swap again, > > In this routine, we can pass zero to mem_cgroup_from_id. Right? > > If the above claim is correct, which I would need to double check then > it should have been part of the changelog! Please think of your poor > reviewers and the time they have to invest into the review. The easy way may be adding a printk to mem_cgroup_from_id when the parameter is zero. > > I would also like to see your waste of CPU cycles argument to be backed > by something. Are we talking about cycles due to an additional function Yeah, when the parameter is already zero, idr_find() must return zero. So I think that the additional function call is unnecessary. I have added a printk to mem_cgroup_from_id, I found the parameter can be zero several times. > call? Is this really something we should even care about? Maybe not. Just my thoughts. Thanks. > > > > > > > > > Signed-off-by: Muchun Song > > > > --- > > > > mm/memcontrol.c | 3 +++ > > > > 1 file changed, 3 insertions(+) > > > > > > > > diff --git a/mm/memcontrol.c b/mm/memcontrol.c > > > > index a3f26522765a..68ed4b297c13 100644 > > > > --- a/mm/memcontrol.c > > > > +++ b/mm/memcontrol.c > > > > @@ -5173,6 +5173,9 @@ static inline void mem_cgroup_id_put(struct mem_cgroup *memcg) > > > > struct mem_cgroup *mem_cgroup_from_id(unsigned short id) > > > > { > > > > WARN_ON_ONCE(!rcu_read_lock_held()); > > > > + /* The memcg ID cannot be zero. */ > > > > + if (id == 0) > > > > + return NULL; > > > > return idr_find(&mem_cgroup_idr, id); > > > > } > > > > > > > > -- > > > > 2.11.0 > > > > > > -- > > > Michal Hocko > > > SUSE Labs > > -- > Michal Hocko > SUSE Labs