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) { From patchwork Wed Mar 30 23:47:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 12796519 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 CD45FC433EF for ; Wed, 30 Mar 2022 23:47:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9B5648D0006; Wed, 30 Mar 2022 19:47:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 965818D0003; Wed, 30 Mar 2022 19:47:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7E01B8D0006; Wed, 30 Mar 2022 19:47:46 -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 526A48D0003 for ; Wed, 30 Mar 2022 19:47:46 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 28EA120A3E for ; Wed, 30 Mar 2022 23:47:46 +0000 (UTC) X-FDA: 79302692532.08.BB6195C Received: from mail-ej1-f45.google.com (mail-ej1-f45.google.com [209.85.218.45]) by imf11.hostedemail.com (Postfix) with ESMTP id 928EC4000D for ; Wed, 30 Mar 2022 23:47:44 +0000 (UTC) Received: by mail-ej1-f45.google.com with SMTP id bq8so30663643ejb.10 for ; Wed, 30 Mar 2022 16:47:44 -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=6FJnqnKyYiDxw5+zHvmYhDEIHbsPH/AeIDmnSnqcv8U=; b=o5aWz+8c0XSKHv66RUMiIoR/ArVLQsHrsbZ9viJiWDel0QYolsZo+3P9o/TlWTdErM VM6LJrjtXVstBK+E+JwFdt37ex4X7hoR19Pnhxcnckr3VmFzG6JzVC6Fw+zBSi490HwX ZYiKTzS5tmQa16DJPiF7Dl5GiNAHQnXVF/DOUdjlxt/zPutCxvoWRnB2tsDK1yPy9gRu xU3yvDN9PThnJQVF2S053ymA5I4eqRir0mck8ma8Y8JW3FMWOU1adRcAFqn5DxCl4an1 glGeCvdWJOYmXzxxyc5qx08I1hzkYp2UtU+6l+Ah+4sc/q/Bad87aiQ4K4JliZ2OyhJj 5yaQ== 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=6FJnqnKyYiDxw5+zHvmYhDEIHbsPH/AeIDmnSnqcv8U=; b=MC6EARk9I+wjPsIuQZmHzIotSnunZcXKg19heSFGcyEfHjJWm5GN5gZN7SBMtPvzMA 8Q1KYwADA2d4knvu6R4x7UDaiQSBdQmV7SwZuL16WsdHVTBUQ0OG7GgPHcN5/cMbPm0P /0KnkNhkdednw8VerC3f9Dj5jv7OhDc1N2Li8JDYa6A4lj9PQtQMAHqvGK/AmtJpOwMg DuQVIDP9dPJWNsWoITU3RktqFkylAJrdGb5BZK8O1OZZ3hw1cn9sbADw+SSPU2TZVqTC 70MbNS1QThtS8cwGxPJ4St2fMF6TDOt1AZdTxngqOQkSc0s1Q35XoDD6vOIrMB6clqEy +2rQ== X-Gm-Message-State: AOAM5332nOPuW+OpIFoWFgpwfVo5rDzkXpuj6IM7uE46vVD02r56vsu5 o/45xxYtU+Rmjap9VBlaq2M= X-Google-Smtp-Source: ABdhPJxYEItkqfh9mvC3TLsa/vajXERsHMYaAPlapmfd0q/6wb4IpuO77RspaKpXhGMU7MJtoQQUOw== X-Received: by 2002:a17:907:2d88:b0:6e4:9a7f:9175 with SMTP id gt8-20020a1709072d8800b006e49a7f9175mr2316911ejc.584.1648684063395; Wed, 30 Mar 2022 16:47:43 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id b3-20020aa7d483000000b00419209d4c85sm10271351edr.66.2022.03.30.16.47.42 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Mar 2022 16:47:43 -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 2/3] mm/memcg: set pos explicitly for reclaim and !reclaim Date: Wed, 30 Mar 2022 23:47:18 +0000 Message-Id: <20220330234719.18340-3-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-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 928EC4000D X-Stat-Signature: u1aqqmiyo94hkwoeqr89firtacd5w9n1 X-Rspam-User: Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=o5aWz+8c; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf11.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.45 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com X-HE-Tag: 1648684064-562051 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: During mem_cgroup_iter, there are two ways to get iteration position: reclaim vs non-reclaim mode. Let's do it explicitly for reclaim vs non-reclaim mode. Signed-off-by: Wei Yang Reviewed-by: Roman Gushchin Acked-by: Johannes Weiner --- v2: split into two explicit part as suggested by Johannes --- mm/memcontrol.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index eed9916cdce5..5d433b79ba47 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1005,9 +1005,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) { @@ -1033,6 +1030,8 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, */ (void)cmpxchg(&iter->position, pos, NULL); } + } else if (prev) { + pos = prev; } if (pos) From patchwork Wed Mar 30 23:47:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 12796518 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 6DB1CC433FE for ; Wed, 30 Mar 2022 23:47:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0B5898D0005; Wed, 30 Mar 2022 19:47:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F333A8D0003; 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 DAC078D0005; Wed, 30 Mar 2022 19:47:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0241.hostedemail.com [216.40.44.241]) by kanga.kvack.org (Postfix) with ESMTP id BE5AF8D0003 for ; Wed, 30 Mar 2022 19:47:45 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 86462182CA8D0 for ; Wed, 30 Mar 2022 23:47:45 +0000 (UTC) X-FDA: 79302692490.18.624E3FC Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) by imf11.hostedemail.com (Postfix) with ESMTP id 2BA3440014 for ; Wed, 30 Mar 2022 23:47:44 +0000 (UTC) Received: by mail-ej1-f42.google.com with SMTP id bg10so44618579ejb.4 for ; Wed, 30 Mar 2022 16:47:44 -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=VUJcnVdgNFYpQDTJEWf7H0xzus0K/Xa4FeMP7a1KnEQ=; b=ncvvGkdIFWyKuP25ghEWF3nSN6sW8+Q7qWkT1iDxucHp0v6lYGY/ZDllouL2Y/nAUz EfKl+Yna/ir+zTvabWIpqqPHbltci3rU6r0a/FfdvzTVkf/skKhGJIz18w5ccDRwnvyU PkCYTjGdCQqDJx0pTYz+iL5ZB/pY+zf4Ib1Q5D9f2xj+T1Sb9GR92JTnrsXPdu6ybLJ6 QOKZxMy/CHs6nqkCPMHlp3Gr0FNX3f+TDadXhTC+jZM0QMdlg192xUdoD+jezjIDkBoz zEQ86AmCcX1LTF0ikiCsHDhKBWGD/mK/GxpycZ7iTVU31o0EMsfFH4hiQomO1nQr+xKL CUIw== 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=VUJcnVdgNFYpQDTJEWf7H0xzus0K/Xa4FeMP7a1KnEQ=; b=TuIl8N7HpZ6Ed/t9NkyXixQu+GRBS2ILZMn8KCdN1cWluzxVYnBs8Tmbw/AaY2/1ue HtL2q7WocrDUZFg6e0WgV2w3FjHADHNsRSrIVIFBnip3BvM1K9zdlbtC5IbnX49v7rj6 x9WLXme34tfqqU+yelhGNdBRm0bcoTNYk1LzDNWDvbEMZ7v5QkuydGcci7xDRuHnH0xg XQYRpFVKHouBDNY0u2wPcrHuDo9/35fBdseW6HBz8y8PijidV7dbE5nibP+ceRleDCRG XjRPvrY/OjebrwaGcZRKMn+V1dG3Xow/9731dJl2jqw5ahzWv5m3nUy85P9n/9rLjLl1 Ch/w== X-Gm-Message-State: AOAM530fB9o0OWOqbibiyqzAlCvXKhXdLT8PfPe7+pl8th+MXAwUavbW /E/FcRSHEDlf4TtWGSe39oUzOlbkxo8= X-Google-Smtp-Source: ABdhPJw/jBcGuEajUDutfuFfQAkzGZRZEOEI2ekZslgcYDUMcqzDRhHPQu4M3nSpuKl7u4RxhGoE6g== X-Received: by 2002:a17:907:7244:b0:6df:fb38:1d02 with SMTP id ds4-20020a170907724400b006dffb381d02mr2309148ejc.453.1648684064052; Wed, 30 Mar 2022 16:47:44 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id qa30-20020a170907869e00b006df9ff41154sm8734153ejc.141.2022.03.30.16.47.43 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 30 Mar 2022 16:47:43 -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 3/3] mm/memcg: move generation assignment and comparison together Date: Wed, 30 Mar 2022 23:47:19 +0000 Message-Id: <20220330234719.18340-4-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-Rspam-User: X-Stat-Signature: 7qcd6ig46q7occ81nhfgc44mwi57s9dm Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ncvvGkdI; spf=pass (imf11.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.42 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 2BA3440014 X-HE-Tag: 1648684064-986839 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. [hannes@cmpxchg.org: better comment to explain reclaim model] Signed-off-by: Wei Yang Acked-by: Johannes Weiner Reviewed-by: Roman Gushchin --- v2: a better comment from Johannes --- mm/memcontrol.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 5d433b79ba47..2cd8bfdec379 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -1013,7 +1013,13 @@ 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 start, join the current reclaim iteration cycle. + * Exit when a concurrent walker completes it. + */ + if (!prev) + reclaim->generation = iter->generation; + else if (reclaim->generation != iter->generation) goto out_unlock; while (1) { @@ -1075,8 +1081,6 @@ struct mem_cgroup *mem_cgroup_iter(struct mem_cgroup *root, if (!memcg) iter->generation++; - else if (!prev) - reclaim->generation = iter->generation; } out_unlock: