From patchwork Wed Mar 30 23:47:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 12796517 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 F0F3DC433F5 for ; Wed, 30 Mar 2022 23:47:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 105A46B0072; Wed, 30 Mar 2022 19:47:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0B40F8D0003; Wed, 30 Mar 2022 19:47:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E6FDC6B0073; Wed, 30 Mar 2022 19:47:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.a.hostedemail.com [64.99.140.24]) by kanga.kvack.org (Postfix) with ESMTP id BE3458D0003 for ; Wed, 30 Mar 2022 19:47:44 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 823ED2052B for ; Wed, 30 Mar 2022 23:47:44 +0000 (UTC) X-FDA: 79302692448.15.BC13EA6 Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) by imf01.hostedemail.com (Postfix) with ESMTP id EFC3140009 for ; Wed, 30 Mar 2022 23:47:43 +0000 (UTC) Received: by mail-ej1-f42.google.com with SMTP id bg10so44618513ejb.4 for ; Wed, 30 Mar 2022 16:47:43 -0700 (PDT) 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=F2sr6A+74F0K682i5KfFbDfyxE+MQpH5kf2WVRDaVIg=; b=DXlRh9VdTEpO7NS8UN7I/7xFcNqWI9MpkZUOkkXQrKpqPO+/o7s8ip5/V3wuJlw9OC N3JRk5k243KQRIuZCPQP2fwXOTj3I89ZdtinJXIsTV+Yyy1E8T+vW0I7IB2dOco/Idn9 CG3tUrd4r5OzGyJRPpU3422sei2X2oIgWsBz6S6wAlgwQzPlkMw+E2SMYoOWVJ9v9nrM FFT3i2i6zxf7106D+R9OFTCDqr58JFeYzzWuOWg6KtBG6Qr1KppDZNE1fes9Kaguf5Z9 Rj5p1RThizy2W3wNBRgnN6gGxCIGyH6cq10Ur8eWx9EWyHWotIdxRDSCOlXYEPUBXlA+ 31yQ== 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=F2sr6A+74F0K682i5KfFbDfyxE+MQpH5kf2WVRDaVIg=; b=0gkwRtl9s5yQF9QMJglWcxNWB+AtbrBDhSWvIg1Tx8xwkRCsiwl2jihCErhj5IXKkY but8+508fVx1pcXqZqWEc5r2eLHN7Cl+2AbvfsMG5YFchmiHdlrWZTGVSSrB5gvYd3df RM0bFCxhVz4CCYSp36Oj2chBQxrR3BX2bKzmpD7YEhE1RyPV/SR3wOLkhKRtiH4yOf/D oCjcbfayKM4BV7nmoZoTVBbu2mDnazArnuJGWcNnaiZJJnp9oln0qrbmLsRdxI2Q1YFP fc1BHTCi6QQEtdr0EMfqkera+7aHpxATrq048L0owLksDCMBr1w882ZWuhRgZuqCLeLO PE/Q== X-Gm-Message-State: AOAM533Z19v3yTEg0C0mZfPTmNAuTmuabS6rm/l5qqRIFZ2yEddg09ut 7JmOxWHUBoyYA9bMy5K8GzA= X-Google-Smtp-Source: ABdhPJxzxxKzXun8q1D4jDTvVnY2R6tSETGwmLXnIvxFv5FeES3d4jdl2vhSvZHTjQQ6vZQ4adTvKQ== X-Received: by 2002:a17:906:4fd5:b0:6e1:2084:99d2 with SMTP id i21-20020a1709064fd500b006e1208499d2mr2245403ejw.639.1648684062588; Wed, 30 Mar 2022 16:47:42 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id e28-20020a170906649c00b006df6dfeb557sm8719049ejm.49.2022.03.30.16.47.42 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Mar 2022 16:47:42 -0700 (PDT) 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 v2 1/3] mm/memcg: set memcg after css verified and got reference Date: Wed, 30 Mar 2022 23:47:17 +0000 Message-Id: <20220330234719.18340-2-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220330234719.18340-1-richard.weiyang@gmail.com> References: <20220330234719.18340-1-richard.weiyang@gmail.com> X-Stat-Signature: ang8hidaait9uxyew1gi58qo9bcb315q Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=DXlRh9Vd; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf01.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.42 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com X-Rspam-User: X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: EFC3140009 X-HE-Tag: 1648684063-820534 X-Bogosity: Ham, tests=bogofilter, spamicity=0.004468, 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 Reviewed-by: Roman Gushchin --- mm/memcontrol.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index dc193e83794d..eed9916cdce5 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1057,15 +1057,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) {