From patchwork Tue Mar 8 01:20:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 12772860 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 C03DEC433EF for ; Tue, 8 Mar 2022 01:21:59 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0966E8D0002; Mon, 7 Mar 2022 20:21:59 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 045788D0001; Mon, 7 Mar 2022 20:21:58 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E76888D0002; Mon, 7 Mar 2022 20:21:58 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0104.hostedemail.com [216.40.44.104]) by kanga.kvack.org (Postfix) with ESMTP id D8D0C8D0001 for ; Mon, 7 Mar 2022 20:21:58 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 9677E182FA95E for ; Tue, 8 Mar 2022 01:21:58 +0000 (UTC) X-FDA: 79219467516.26.380B339 Received: from mail-ed1-f43.google.com (mail-ed1-f43.google.com [209.85.208.43]) by imf13.hostedemail.com (Postfix) with ESMTP id 2C0E720004 for ; Tue, 8 Mar 2022 01:21:58 +0000 (UTC) Received: by mail-ed1-f43.google.com with SMTP id y12so8870817edt.9 for ; Mon, 07 Mar 2022 17:21:57 -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; bh=fCsAW2UJBB6c8M7QlLxk/JpB7LFkDqCihtv/AG+0X8o=; b=YNtiEQf2jKNmJlXMfNeoZdWXaEcpCVilMpTG4BBRfrU5l33H8y5awom0neQTkabjSX pBacWDo4xIUCPIHGBfw8yvFDySfav4+5cR+67pRdAYrfHCJG8s8qLWatTR7Ll2Fwh0qF kCRrRu4GRUB9MJiL+tBGkICngiZEf4MCXvacOYMjF/BHDYrwDZf87XL9JqdclDLzultF ynwtsCaghvo7fjOVtIBZ6zPFNE5BcX7AAyrIQinfAEbOknUsm9ZTEhEMWSXCrm+DAE0u YOYYaKv7BMSg0g228arxqpgpLUAwOBwl416q0s5wF5SmYlImMDxL4488GLTUc22hVd0N gTSQ== 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; bh=fCsAW2UJBB6c8M7QlLxk/JpB7LFkDqCihtv/AG+0X8o=; b=POTGGEdls+sGI8EHvBT0UjKF7rBJq+NnDMn9Zhl8hI+osY0NUZBjt2xFeQi0XmqCI4 ASLBBBvDKumN4Cir/4ZpHLpM7qUg3nD9eaUtyKmRZqKcvtuuMk2/4AiCuF73PnyphgME Vcr7qARjPnFLvmS2K/1hgP76ae4NKsvyKd+rQZB14FPYWF/PuvRi6OUkDHvHArRJyin5 fObBr4pPOCms/LQmK2b4yLbdW709dO2zBlb7JW0z8hetW0u+knZ2HkOw4+GqcQsattJd Ba05Fgp+Ii61FGsqcUA1CRVXaS9E2DKHhQawgmufsr1lshPu5NgllD5L+t9mRucKBASi tDTA== X-Gm-Message-State: AOAM530Knwbt994giT7KtwORuRjzsirzhbS9q2osbIWKM/OY63F1sMq5 7oXg8eJTyg/AYBrwxhShyKc= X-Google-Smtp-Source: ABdhPJwvisVa5usty4EopQX72ds7IuCAZBihISiLjMF6OJYOeTMKXL6KFhEI4CDbg7FKRvicNQ4X7w== X-Received: by 2002:a05:6402:f1f:b0:415:d1a3:eb4e with SMTP id i31-20020a0564020f1f00b00415d1a3eb4emr13721074eda.311.1646702516733; Mon, 07 Mar 2022 17:21:56 -0800 (PST) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id q15-20020a1709060e4f00b006cdf4535cf2sm5285490eji.67.2022.03.07.17.21.56 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Mar 2022 17:21:56 -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: mz already removed from rb_tree in mem_cgroup_largest_soft_limit_node() Date: Tue, 8 Mar 2022 01:20:45 +0000 Message-Id: <20220308012047.26638-1-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 2C0E720004 X-Stat-Signature: cyh96yu7ckwieqyohrms4pahg6k9a63u Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=YNtiEQf2; spf=pass (imf13.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-HE-Tag: 1646702518-977050 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: When mz is not NULL, mem_cgroup_largest_soft_limit_node() has removed it from rb_tree. Not necessary to call __mem_cgroup_remove_exceeded() again. Signed-off-by: Wei Yang --- mm/memcontrol.c | 1 - 1 file changed, 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index f898320b678a..d70bf5cf04eb 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3458,7 +3458,6 @@ unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order, nr_reclaimed += reclaimed; *total_scanned += nr_scanned; spin_lock_irq(&mctz->lock); - __mem_cgroup_remove_exceeded(mz, mctz); /* * If we failed to reclaim anything from this memory cgroup From patchwork Tue Mar 8 01:20:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 12772861 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 A6B9EC433FE for ; Tue, 8 Mar 2022 01:22:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 098A58D0003; Mon, 7 Mar 2022 20:22:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id EC52F8D0001; Mon, 7 Mar 2022 20:21:59 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D17148D0003; Mon, 7 Mar 2022 20:21:59 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (relay.hostedemail.com [64.99.140.26]) by kanga.kvack.org (Postfix) with ESMTP id C2A3D8D0001 for ; Mon, 7 Mar 2022 20:21:59 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 7B722456 for ; Tue, 8 Mar 2022 01:21:59 +0000 (UTC) X-FDA: 79219467558.08.B3BE6E5 Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) by imf08.hostedemail.com (Postfix) with ESMTP id 0E13F16000A for ; Tue, 8 Mar 2022 01:21:58 +0000 (UTC) Received: by mail-ej1-f47.google.com with SMTP id yy13so26968465ejb.2 for ; Mon, 07 Mar 2022 17:21:58 -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=TJpD8WbIgS+xru6bpF+N+uC+vSCiqZY6PRQI5LvMXoI=; b=Mr7bFXwRFUanMnGNnpUckpJUfAZz88L9eyoAngmHhhUmy7Hqswp/VuwagZ443cQndP oCYNfJQDtVorLVlM6sGSf1Aw7fwzcJjKa3hocgArdnUC2b8mUekANMGbZ7JYBxM1ER2N Bwv1pVU1nOKa3h9I+wd+bRWNJvymSim3EsfV01aqg571rb8b1vSnMwMVgQzwupbz4ds6 FlngrH9dFe5VxrBvaH5tLHpypB4tePgIJHkW6e3MDcukco9XUnen3VuH8mD2iDs+fa92 Uqac1l6dB+FODzmk4AEz546j7iblgAs5xOPKwCRZt77Z6pZQTSBQDhKNLnCAm66OnC50 M9QA== 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=TJpD8WbIgS+xru6bpF+N+uC+vSCiqZY6PRQI5LvMXoI=; b=4EheIgpMJKbZUGm0p1Gz0THBNzZ4aDJGcZW0Tqjl91sam12K2/WPRTT9+nx8DwdJzd zU0ahEltDqcCGbAE/7t3u/nnbIJXW+13usweDepMR1F2+HRwr6wKMc0MQ2N2cFjkcvrY eVljPo+y5By11EC8SQTUg2Mh9oFBwMrkxNx7SkTVp8YNUF2YjzH3TA605EnPnbIP/L6i Q7eyRWAXFgCUQED+I07RNOq1q+G9GZH9yAONq0agbaBIuCRLeUVzQFJpFT3G1laB3bm0 li+jSaYi42WyadQy0r+zppPEQAAFOdAPfvOA6rM/nIPnbM8jn7gpgkPMvUwtvD2v6N5I UjKw== X-Gm-Message-State: AOAM5329BfkEq2B+oZlid6EBCuart4WmtZviiE16NHVaTkt70+/XOt/m o7SQRJ0ouppDUB/7rb52Q5o= X-Google-Smtp-Source: ABdhPJx09GW0/xl9K5HY0fZYhxSqJvtB8pApBKzQSpKrpGl5Yvn4FmsY9YM+Gg+leQdC0K4o0dpNnw== X-Received: by 2002:a17:907:6d97:b0:6d7:49e:275e with SMTP id sb23-20020a1709076d9700b006d7049e275emr10969974ejc.410.1646702517716; Mon, 07 Mar 2022 17:21:57 -0800 (PST) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id x12-20020a50d9cc000000b0040f70fe78f3sm7041392edj.36.2022.03.07.17.21.57 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Mar 2022 17:21:57 -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: __mem_cgroup_remove_exceeded could handle a !on-tree mz properly Date: Tue, 8 Mar 2022 01:20:46 +0000 Message-Id: <20220308012047.26638-2-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220308012047.26638-1-richard.weiyang@gmail.com> References: <20220308012047.26638-1-richard.weiyang@gmail.com> X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 0E13F16000A X-Stat-Signature: nc7a81hdfhnkhskyb1wrtogmrxwt3cih Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Mr7bFXwR; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf08.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.47 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com X-HE-Tag: 1646702518-98792 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: There is no tree operation if mz is not on-tree. Let's remove the extra check. Signed-off-by: Wei Yang --- mm/memcontrol.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index d70bf5cf04eb..344a7e891bc5 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -545,9 +545,11 @@ static void mem_cgroup_update_tree(struct mem_cgroup *memcg, int nid) unsigned long flags; spin_lock_irqsave(&mctz->lock, flags); - /* if on-tree, remove it */ - if (mz->on_tree) - __mem_cgroup_remove_exceeded(mz, mctz); + /* + * remove it first + * If not on-tree, no tree ops. + */ + __mem_cgroup_remove_exceeded(mz, mctz); /* * Insert again. mz->usage_in_excess will be updated. * If excess is 0, no tree ops. From patchwork Tue Mar 8 01:20:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 12772862 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 731EDC433F5 for ; Tue, 8 Mar 2022 01:22:02 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8B0D88D0005; Mon, 7 Mar 2022 20:22:00 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7E7468D0001; Mon, 7 Mar 2022 20:22:00 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 688A78D0005; Mon, 7 Mar 2022 20:22:00 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0227.hostedemail.com [216.40.44.227]) by kanga.kvack.org (Postfix) with ESMTP id 59F658D0001 for ; Mon, 7 Mar 2022 20:22:00 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 21617182E52FC for ; Tue, 8 Mar 2022 01:22:00 +0000 (UTC) X-FDA: 79219467600.26.2ACF221 Received: from mail-ej1-f46.google.com (mail-ej1-f46.google.com [209.85.218.46]) by imf26.hostedemail.com (Postfix) with ESMTP id 9CA79140002 for ; Tue, 8 Mar 2022 01:21:59 +0000 (UTC) Received: by mail-ej1-f46.google.com with SMTP id a8so35791723ejc.8 for ; Mon, 07 Mar 2022 17:21:59 -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=sX5s7jKgXd2WsU9F7nau9nEnt0LTAgg+hfHcITuEuBM=; b=ENqz0NVeHdKTzIpACb7Q9gDD11SNNdauqiy2jAzmxV49Bs5xz4/6u9nc363FgnwjOc db2aQrmbgMm+JEYdPncFEX5VQQvsjRhKVbvD+muJcfiBRB3R6diHamEZVbnJUElfYMuG K3ST7QJkIRRXUetvZ6Aad9u1qs+uNVbbL396ReLYD6W7jFWTCK/au2vp1ulGBSqTS3K8 dmGAadaViT8WcX/booDtkS9outqBMSNflWKOygUbbjiOdYnZOMAuIvhB8GjmBaXUXsnZ 1uV5J5PCNTxR8Qz3h6bQzbo+ZQ0H3mI8J0TkdHHpzQwO3jTkl8rKoNKzMKtUN1DvKjcK BMJw== 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=sX5s7jKgXd2WsU9F7nau9nEnt0LTAgg+hfHcITuEuBM=; b=vCDHU2eZzOaxJV+fSS6VBhazSHhjxjj/CQGR0PvEFgcgeJk5J2CssXtmg72jhUN+8I lBH0RDFoeMVEQS6MgOWdVGR4nqVIQ0pME3hYP7q5G8y4J1KruzWczDQL5AAqs/bTMW1t 2Tr8rG+h3tgXNdrGphnnHIflTNEHLfuvFI4/rh3/Fy+64ggtBPkyhhhDHRSQ85OauSpE REfKlPQ514kdzGoh/+xzeknxCbDjVHz3+Ap4MWmfGXZyOnKrQtzJpStg651pJRmQVg6E YQsOWTwmvJjFTALErhtTHK5rtRv5nM3RuKnRxrkfPLqVGuLSMjS0By3em3GrdGw8h/fI nBpA== X-Gm-Message-State: AOAM530yA0tuGvu+6P2WGfzPJaOQE43VZC0BIGVExTwcIWCWl+9UUbOA B7lIhRT/Pqckjl+mzViQcbc= X-Google-Smtp-Source: ABdhPJwWvWbB6M4I64azTUqYp6eC7GowACebPQj8LpOgHNGq+QTdwjlKOjawgZ8a2CZH75xh5YFdGw== X-Received: by 2002:a17:907:7f2a:b0:6d6:df12:7f57 with SMTP id qf42-20020a1709077f2a00b006d6df127f57mr11161124ejc.122.1646702518516; Mon, 07 Mar 2022 17:21:58 -0800 (PST) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id q2-20020a170906144200b006ceb8723de9sm5193049ejc.120.2022.03.07.17.21.58 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 Mar 2022 17:21:58 -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: add next_mz back if not reclaimed yet Date: Tue, 8 Mar 2022 01:20:47 +0000 Message-Id: <20220308012047.26638-3-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20220308012047.26638-1-richard.weiyang@gmail.com> References: <20220308012047.26638-1-richard.weiyang@gmail.com> X-Rspamd-Queue-Id: 9CA79140002 X-Stat-Signature: iho84ojxb5ps937717jgfjmn6cd7drww X-Rspam-User: Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=ENqz0NVe; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf26.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.46 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com X-Rspamd-Server: rspam03 X-HE-Tag: 1646702519-387946 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: next_mz is removed from rb_tree, let's add it back if no reclaim has been tried. Signed-off-by: Wei Yang --- mm/memcontrol.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 344a7e891bc5..e803ff02aae2 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -3493,8 +3493,13 @@ unsigned long mem_cgroup_soft_limit_reclaim(pg_data_t *pgdat, int order, loop > MEM_CGROUP_MAX_SOFT_LIMIT_RECLAIM_LOOPS)) break; } while (!nr_reclaimed); - if (next_mz) + if (next_mz) { + spin_lock_irq(&mctz->lock); + excess = soft_limit_excess(next_mz->memcg); + __mem_cgroup_insert_exceeded(next_mz, mctz, excess); + spin_unlock_irq(&mctz->lock); css_put(&next_mz->memcg->css); + } return nr_reclaimed; }