Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp541280pxb; Thu, 15 Apr 2021 00:10:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyLjTfvar60jK1sI0VbjRLXTR5d4ingr8MIe1KfZxUCSsL9whodmRnSlJG87SCFzsNFMocb X-Received: by 2002:a17:90a:dc13:: with SMTP id i19mr2310025pjv.194.1618470652095; Thu, 15 Apr 2021 00:10:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618470652; cv=none; d=google.com; s=arc-20160816; b=QSIkiUOPFd5ZwI4mkoIao1u9VOhOze9fWc7F+BWD2MTcnHVfFxUilBlBYa1rxv+b9E IjO0sDly/cb+xNm/oyG1eRFQkU0YDR3kZc3j9zY3pyq5P9HyYsTLLBBfoxPhj9qAixLY vnl0DumG+C7Yf95AgMW/3MtYZUT8AsmQC5EtAAHg+IhWs37hPCf4rLDJWsfmI+aa8PhI pUvtK9fHXL0SPosa4S2gsByqQs6yMIJl+o72qKJ9Di6WhxdFH0lGhLD3PigghWD8RhUO puTvba7V3EzD3aW2nQu6BwNo+Ka+efu57IJWNZNCQV94+NHg75BMs7MvZql+QzPOujt9 /GGw== 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=O34oorYRMDyrmgMKgoTmWvClmcyXSz4Fkb1f6zWfq3Q=; b=r5/21G/Y+Y5gga/woFf0lyf8Bck0A0/wmrNeKSXq1XA9jTBjPw2NImiYcFnk3DMktF Aj/ZOa8ZFOuagwIaBZhuAuJaTTPOJoG7ItpUNI5JGdZUWWogWLIfkugwhHeP04dOtsLS 0LuTPfNj29+3sMFY9GN/3ZEDWwuquq4jMTRmL6dfhNlEw01yQ5nwUlLStnUjLl0pVTqb euYM1iaY98/g9lRrt6Eteb+b74b0tgPsaCB4eXyZ7/DiOc8ln2W1t1SSoAYqkVR17Azr sos3T6bgD6LEzJfHlhuF7gSHaoOkp4d+Qw/ERtrNc68kL3B9bEPxpXox38PEL/j/Zw1b rRiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.com header.s=susede1 header.b=fvy9hkrg; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n11si2207765pjp.23.2021.04.15.00.10.39; Thu, 15 Apr 2021 00:10:52 -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=@suse.com header.s=susede1 header.b=fvy9hkrg; 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=QUARANTINE sp=NONE dis=NONE) header.from=suse.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230491AbhDOHKX (ORCPT + 99 others); Thu, 15 Apr 2021 03:10:23 -0400 Received: from mx2.suse.de ([195.135.220.15]:45180 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230056AbhDOHKX (ORCPT ); Thu, 15 Apr 2021 03:10:23 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1618470599; 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=O34oorYRMDyrmgMKgoTmWvClmcyXSz4Fkb1f6zWfq3Q=; b=fvy9hkrg6pvauC7J6sX3c0DpPTulBZKkWEgtvmoT/CWRahIA80V+vk61CToRBkWrSxg+46 YsVzsVRg2zJ4rRPg4zkn/OL3KZVVD3mSH6kbzu+rJFEb32te56AZc1+xIYoZfGtfC0Tqh8 K9NkH9o6wR8ypiYnL2jqIG6il7PqIAY= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id B257DB035; Thu, 15 Apr 2021 07:09:59 +0000 (UTC) Date: Thu, 15 Apr 2021 09:09:59 +0200 From: Michal Hocko To: Muchun Song Cc: guro@fb.com, hannes@cmpxchg.org, akpm@linux-foundation.org, shakeelb@google.com, vdavydov.dev@gmail.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, duanxiongchun@bytedance.com, fam.zheng@bytedance.com Subject: Re: [External] Re: [PATCH 2/7] mm: memcontrol: bail out early when !mm in get_mem_cgroup_from_mm Message-ID: References: <20210413065153.63431-1-songmuchun@bytedance.com> <20210413065153.63431-3-songmuchun@bytedance.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu 15-04-21 11:13:16, Muchun Song wrote: > On Wed, Apr 14, 2021 at 6:15 PM Michal Hocko wrote: > > > > On Wed 14-04-21 18:04:35, Muchun Song wrote: > > > On Wed, Apr 14, 2021 at 5:24 PM Michal Hocko wrote: > > > > > > > > On Tue 13-04-21 14:51:48, Muchun Song wrote: > > > > > When mm is NULL, we do not need to hold rcu lock and call css_tryget for > > > > > the root memcg. And we also do not need to check !mm in every loop of > > > > > while. So bail out early when !mm. > > > > > > > > mem_cgroup_charge and other callers unconditionally drop the reference > > > > so how come this does not underflow reference count? > > > > > > For the root memcg, the CSS_NO_REF flag is set, so css_get > > > and css_put do not get or put reference. > > > > Ohh, right you are. I must have forgot about that special case. I am > > pretty sure I (and likely few more) will stumble over that in the future > > again. A small comment explaining that the reference can be safely > > ignore would be helpful. > > OK. Will do. I would go with the following if that helps /* * No need to css_get on root memcg as the reference counting is * disabled on the root level in the cgroup core. See CSS_NO_REF */ Thanks -- Michal Hocko SUSE Labs