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) { From patchwork Fri Feb 25 00:34:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 12759479 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 18F82C433F5 for ; Fri, 25 Feb 2022 00:34:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A9D9A8D0006; Thu, 24 Feb 2022 19:34:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A4F718D0001; Thu, 24 Feb 2022 19:34:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8EDDE8D0006; Thu, 24 Feb 2022 19:34:45 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0051.hostedemail.com [216.40.44.51]) by kanga.kvack.org (Postfix) with ESMTP id 7E5758D0001 for ; Thu, 24 Feb 2022 19:34:45 -0500 (EST) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 923D89F33D for ; Fri, 25 Feb 2022 00:34:43 +0000 (UTC) X-FDA: 79179431646.22.2595B96 Received: from mail-ed1-f48.google.com (mail-ed1-f48.google.com [209.85.208.48]) by imf19.hostedemail.com (Postfix) with ESMTP id 329B41A0008 for ; Fri, 25 Feb 2022 00:34:43 +0000 (UTC) Received: by mail-ed1-f48.google.com with SMTP id cm8so5236621edb.3 for ; Thu, 24 Feb 2022 16:34:42 -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=uV4wBUWA2UECsFZTXgl5VjPgFRRqp+MEQd9SNZm1H5k=; b=a6Vnlb+DXvatZ1kODfxsl4neHMsRZDeRD7PR3nUDh+j1AyWLtpam8eSKeAKpB7+2tx K283KMzgr1d7YmT6BpKMBWNBjK/AbqGXSgoAYFd1XPSC5QzRDch5RhpeI+EvMXFCv/ht H67m6Oj03Z7rnpxO2scQmQ5AC/DV8lEKCT4T1Qr1/HenZEtC4hkFTZKMfZDWhpgZ70LM T0+ZcMd3F2C/ZFIaJlh5+4tpwfGoFPG12Yh/MWAh4c9HxdVrCLDhyI5qKcBfSlXXPijP PzKY2w+OfX5pLMziBPbIevhlkHMHG6QNplCeS1qXYwpH4LR8aZwiKXwG8iGtIdB+JC6a 0JzQ== 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=uV4wBUWA2UECsFZTXgl5VjPgFRRqp+MEQd9SNZm1H5k=; b=s3vcusBZERHMpNp8lodipjrIx+XPxgiX7QDzzlYcSn6QQU5vDqSCyNdTk/Lalkl/oN tr3ZDbz9+qa0Up4dKElLmZ/MYUtZABhIuMK+NhP2CIMqyCHXrVp8SbEw/d9x/asM2Bb7 S45E7ADMbV1RMwcGZFqk0+PFVOQMgp2+VeyMQOhWHu2GgI1pQU2ajEsq+zgncTDQyIam RmBUqKBZPv+tSPGLXoL2iy4kc08xz3cNOYLQpza1zbu09O8W2rQ9NkFS7Wrox0xY4GLg gGDouc8Oj5gP6oC7/wUSOjV6SUGM8Oh0WpvEaUyvShsLHgedtXJbZzQt4eSjugecvtGe xTlw== X-Gm-Message-State: AOAM532BxD8TapiXtb8SmnA7c3X00EeaEQrvg2j05Yar9mnEuIvvBYDw LYA4r7u6wZPC2yGthE40eFI= X-Google-Smtp-Source: ABdhPJyt8lkUIMqItrJ/qgRwB3FiJ3nB/EIBnPDeJ8equOOsrEMp4CSPfOLuDO1HxBd3h70Q0HCSRg== X-Received: by 2002:a05:6402:1d54:b0:410:f02d:4765 with SMTP id dz20-20020a0564021d5400b00410f02d4765mr4719468edb.28.1645749281926; Thu, 24 Feb 2022 16:34:41 -0800 (PST) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id r11-20020aa7cfcb000000b00412c58c43ccsm528200edy.37.2022.02.24.16.34.41 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Feb 2022 16:34:41 -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 2/3] mm/memcg: set pos to prev unconditionally Date: Fri, 25 Feb 2022 00:34:36 +0000 Message-Id: <20220225003437.12620-3-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-Server: rspam01 X-Rspamd-Queue-Id: 329B41A0008 X-Rspam-User: Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=a6Vnlb+D; spf=pass (imf19.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.48 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: 44xh456h416361rz63p77s7j5gm7a9pk X-HE-Tag: 1645749283-883047 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Current code set pos to prev based on condition (prev && !reclaim), while we can do this unconditionally. Since: * If !reclaim, pos is the same as prev no matter it is NULL or not. * If reclaim, pos would be set properly from iter->position. Signed-off-by: Wei Yang --- mm/memcontrol.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 9464fe2aa329..03399146168f 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -980,7 +980,7 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, struct mem_cgroup_reclaim_iter *iter; struct cgroup_subsys_state *css = NULL; struct mem_cgroup *memcg = NULL; - struct mem_cgroup *pos = NULL; + struct mem_cgroup *pos = prev; if (mem_cgroup_disabled()) return NULL; @@ -988,9 +988,6 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, if (!root) root = root_mem_cgroup; - if (prev && !reclaim) - pos = prev; - rcu_read_lock(); if (reclaim) { From patchwork Fri Feb 25 00:34:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 12759478 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 0F2CBC433F5 for ; Fri, 25 Feb 2022 00:34:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 25E9F8D0005; Thu, 24 Feb 2022 19:34:45 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1E89A8D0001; Thu, 24 Feb 2022 19:34:45 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB8A58D0005; Thu, 24 Feb 2022 19:34:44 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.28]) by kanga.kvack.org (Postfix) with ESMTP id DB8EE8D0001 for ; Thu, 24 Feb 2022 19:34:44 -0500 (EST) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id AB438804F6 for ; Fri, 25 Feb 2022 00:34:44 +0000 (UTC) X-FDA: 79179431688.10.A2E9411 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) by imf06.hostedemail.com (Postfix) with ESMTP id 2E5C7180006 for ; Fri, 25 Feb 2022 00:34:43 +0000 (UTC) Received: by mail-ed1-f43.google.com with SMTP id h15so5210002edv.7 for ; Thu, 24 Feb 2022 16:34:43 -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=ilQGiGw+cHHnWYdpNd2TsqiqLrmn72vknxopCrZER/Q=; b=EXhP+YADKLWYCXD23XUiXLkpefnymxGvQ/D3MVz2Nk0z3XGGwRNe8I8uITmCtQwIFm 4VBod9Tn78bwab2BZ6kHXnt2BwHZ8uUEHy7OzOAKBSZJ6fc1QETVMyQqbXCcNsyyNHmj 97dZX0Epb88JPt0lOOpWx5jvJ4XY959jv7wVBuSoVSgpqg8I0ylEXoDrTok1pLCiMh5F tXdlQvD1HPzeefQzeA955geaPEZK76a0puWvb624G1Uk60kRkYJM9LXDRiEGmrQ7jnYq 0HtNtCuP/AO4ipwxFWETbeAfyVM1DbdZnpvq2VBPheijzUBcevHVMOJzgQp4VUcYlosT Qe9w== 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=ilQGiGw+cHHnWYdpNd2TsqiqLrmn72vknxopCrZER/Q=; b=CP7rtZ4BF77MOloYI3OzGMYWSS0eptUznTQt8jyXyOIpoE988UKzfry8qVGyA9a8d5 jrU8ph6mNLcKvC5k7hE5f8CQlA6HpAZTDE4QzyG34uJtRcHPo9DcOuFp1aGSo6RBokml CGyO879NcIx34rKb0/nfosvsuYhMC3RSa4+NkvA715jm3D12Tt8GFIIxIIJXOUOuQ0Y3 sMEKKqllhJbMGcBtFQPi08q9x0ur9eu4P6YtVQ9xVomLCVCbhwTE6u4uvVzZY/gWm1Ti TJlFVv8i3oR4eJ0vCgi5VVHdizxrCoQJWAYaHB4BviVsiJZ5Lcy3vSbmA3VIgZHTsZzV PAyA== X-Gm-Message-State: AOAM5332ZDTah5sparcXRVzX70Joi7r16e3RVrbK9c1Wc7OY3Ol+QqkR Pxtlrr9sdwYTk7QJ5tj8m94= X-Google-Smtp-Source: ABdhPJyuoa5ezgs1FJUFIN4JTKE1OZe4PXfPQZ6hNFf3F6TNXGWk9P7dqdy+drSU3xm8bap1JfloTQ== X-Received: by 2002:aa7:cc82:0:b0:410:d2b0:1a07 with SMTP id p2-20020aa7cc82000000b00410d2b01a07mr4691617edt.359.1645749282998; Thu, 24 Feb 2022 16:34:42 -0800 (PST) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id dc4-20020a170906c7c400b006a9bca854c2sm337086ejb.37.2022.02.24.16.34.42 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Thu, 24 Feb 2022 16:34:42 -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 3/3] mm/memcg: move generation assignment and comparison together Date: Fri, 25 Feb 2022 00:34:37 +0000 Message-Id: <20220225003437.12620-4-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: 2E5C7180006 X-Stat-Signature: 1dkdw65o5yidy6xsdj6zpfcdfqipxx9d X-Rspam-User: Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=EXhP+YAD; spf=pass (imf06.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.43 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam05 X-HE-Tag: 1645749283-895156 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: For each round-trip, we assign generation on first invocation and compare it on subsequent invocations. Let's move them together to make it more self-explaining. Also this reduce a check on prev. Signed-off-by: Wei Yang Acked-by: Johannes Weiner --- mm/memcontrol.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 03399146168f..17da93c2f94e 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -996,7 +996,14 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, mz = root->nodeinfo[reclaim->pgdat->node_id]; iter = &mz->iter; - if (prev && reclaim->generation != iter->generation) + /* + * On first invocation, assign iter->generation to + * reclaim->generation. + * On subsequent invocations, make sure no one else jump in. + */ + if (!prev) + reclaim->generation = iter->generation; + else if (reclaim->generation != iter->generation) goto out_unlock; while (1) { @@ -1056,8 +1063,6 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, if (!memcg) iter->generation++; - else if (!prev) - reclaim->generation = iter->generation; } out_unlock: