From patchwork Fri Feb 25 00:34:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 12759477 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2E4A5C433EF for ; Fri, 25 Feb 2022 00:34:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2AD068D0003; Thu, 24 Feb 2022 19:34:43 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 25B798D0001; Thu, 24 Feb 2022 19:34:43 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 14B358D0003; Thu, 24 Feb 2022 19:34:43 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0203.hostedemail.com [216.40.44.203]) by kanga.kvack.org (Postfix) with ESMTP id 05C928D0001 for ; Thu, 24 Feb 2022 19:34:43 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id BD966181C49AD for ; Fri, 25 Feb 2022 00:34:42 +0000 (UTC) X-FDA: 79179431604.23.310BBA2 Received: from mail-ed1-f53.google.com (mail-ed1-f53.google.com [209.85.208.53]) by imf01.hostedemail.com (Postfix) with ESMTP id 4E13640008 for ; Fri, 25 Feb 2022 00:34:42 +0000 (UTC) Received: by mail-ed1-f53.google.com with SMTP id h15so5209897edv.7 for ; Thu, 24 Feb 2022 16:34:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=S87rTjKN5bfLSWPPikhQAx5WdDBuNstKMGrhVDOGPDk=; b=PN2wcsqgc+wbNZTHug2Cw1wY8pOFK7Hpan6j6WTlSX5V9URldyHCNJkFFGWSZ7PlJ/ A/DzETsq2Ts1WOB3cSzjv61qGt7yBLz0RfXfRgiACddXKDki8cq8tDbYZXwgxe8vpgLX uv3kB74ECDqTy3bLUkKnRSNnRo0fYx+lp3rrO6f0kzyZr2JInCpgHY9TrZcDOLznVzIr mIm2ZnByOOX4kpajylS6pPLOqY8zXihSAtBDBLE5NZX4ieRcM8CSRg0xEzPhfbzyT+mM oiJZDXxDbZbjj/I1PNYWkgY8BNjz6s7i1T6cfxQNoodJgX9z9AoOX7Bg9PvjBlbtAb47 gCaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=S87rTjKN5bfLSWPPikhQAx5WdDBuNstKMGrhVDOGPDk=; b=AnSExT66c61D7i8K0N9FjqslsIn+AfLPQpHYVjua67nEE/UjwqaPVeSESacUTi45ag 9zPhxD9Smq35xAn7wmX0UWtkU2akimE8r2bE0kbbmnYDuWalVIsatttaU4HwWHtxjEr/ v5cXSIVA7TtTuVHZ+3JD4ZjCL083iDHwyS/CcBqHAM1g5buFqJ0N6FVHRQ1sBNF+XTfQ Eaik/AtjNb594PV+CZK++RKKgqIw20oLcT1QyY8wpxSaoKJwGcSRwb0XKf2PvvEYIq91 8pbO8XzVjFnIc7iaoct8VlWEzbhTU1/aq4iFxrRHa5Pa86LbFEJnEwVkOMHaaKMazY6e Rqzg== X-Gm-Message-State: AOAM5312if8LtqDfqXJUC5llqpHaLhjxLW3+OWkfxv56gSvMYXpyXnca dt/wDwC/d8zpGBo/oG5O1+E= X-Google-Smtp-Source: ABdhPJyO23TMTH2aYds++piBZiCTWAzo1M4Tw77mM4ZTQSZeiryiZ5eLosIY3YK/+g8vi+5AEs+81Q== X-Received: by 2002:a50:bf0f:0:b0:410:c512:cb6f with SMTP id f15-20020a50bf0f000000b00410c512cb6fmr4702289edk.262.1645749281060; Thu, 24 Feb 2022 16:34:41 -0800 (PST) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id j18-20020a50d012000000b0040e3ea64d4asm524845edf.31.2022.02.24.16.34.40 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Feb 2022 16:34:40 -0800 (PST) From: Wei Yang To: hannes@cmpxchg.org, mhocko@kernel.org, vdavydov.dev@gmail.com, akpm@linux-foundation.org Cc: cgroups@vger.kernel.org, linux-mm@kvack.org, Wei Yang Subject: [PATCH 1/3] mm/memcg: set memcg after css verified and got reference Date: Fri, 25 Feb 2022 00:34:35 +0000 Message-Id: <20220225003437.12620-2-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220225003437.12620-1-richard.weiyang@gmail.com> References: <20220225003437.12620-1-richard.weiyang@gmail.com> X-Rspamd-Queue-Id: 4E13640008 X-Stat-Signature: q64uamud1skcsa764bnghphqqsegwff7 Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=PN2wcsqg; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf01.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.53 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1645749282-422872 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000748, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Instead of reset memcg when css is either not verified or not got reference, we can set it after these process. No functional change, just simplified the code a little. Signed-off-by: Wei Yang Acked-by: Johannes Weiner --- mm/memcontrol.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 36e9f38c919d..9464fe2aa329 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1040,15 +1040,10 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, * is provided by the caller, so we know it's alive * and kicking, and don't take an extra reference. */ - memcg = mem_cgroup_from_css(css); - - if (css == &root->css) - break; - - if (css_tryget(css)) + if (css == &root->css || css_tryget(css)) { + memcg = mem_cgroup_from_css(css); break; - - memcg = NULL; + } } if (reclaim) {