From patchwork Mon Dec 23 15:09:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kairui Song X-Patchwork-Id: 13919119 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 2C79BE7718B for ; Mon, 23 Dec 2024 15:09:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 782276B00A6; Mon, 23 Dec 2024 10:09:27 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 730B56B00A8; Mon, 23 Dec 2024 10:09:27 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D1BC8D0001; Mon, 23 Dec 2024 10:09:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 3F2EA6B00A6 for ; Mon, 23 Dec 2024 10:09:27 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id E165612192E for ; Mon, 23 Dec 2024 15:09:26 +0000 (UTC) X-FDA: 82926555684.03.AB243C2 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by imf17.hostedemail.com (Postfix) with ESMTP id 16A2B40005 for ; Mon, 23 Dec 2024 15:08:55 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="j0/TGF2g"; spf=pass (imf17.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.216.48 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734966525; h=from:from:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=qZTXRsp1Mci+PylZUWXVzd0aOPXiwmhHY2/tQBTCP9U=; b=hcqisH0Iz3Z1nxtcRpkOi3AvamLEGFbIeGiy22yHmIwXmE6diok+7Kr3kaESse94cmptFK O+tNwARvvdemul/BXZ6otol3PBBEwC/jWnCloWpFzcYOhQ8enDeovh2+WfnoRui63VXYFf VTeWfCJIIg4CfQKOk+xDhClv8T8ZUHg= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="j0/TGF2g"; spf=pass (imf17.hostedemail.com: domain of ryncsn@gmail.com designates 209.85.216.48 as permitted sender) smtp.mailfrom=ryncsn@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734966525; a=rsa-sha256; cv=none; b=azpe0DdmBIYEB0a/xHPqWdlDSKzgfIiluyoOYheYgJkzgSEsXitOmswD6o8Up51NO2cyO3 Jp5t/dvNEXtqG4dMUY04engTK8a6WsAMm8//8kQD++oet6ZkND1Ui+oXZygbbmjvIjaUzJ oriuNRs3JJp2UT3knOk2KkfeVHnIryg= Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-2f13acbe29bso4182257a91.1 for ; Mon, 23 Dec 2024 07:09:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734966563; x=1735571363; darn=kvack.org; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to; bh=qZTXRsp1Mci+PylZUWXVzd0aOPXiwmhHY2/tQBTCP9U=; b=j0/TGF2gKkj2WvmI1Rk03SztqVw6LzxUCGuKHz+w8FLv8UGALrazJyxPdAW8XsECjP P1jCuXnFnjihT5IKtsPEmtJev4GrJkETb4aS/9mzdeW+jT9M7MahxqsuYZx3MmC80LZn YtQIGrRqOowILHzmjyEMu+EiZqMT1S8tejZsMXxS6wAhyzj7xUTQuntSMf6WUs1/5UAG BQ3Fc1s53l2AGvr1YwHf1i5fbunAQDjuVa5Avxds7LPoPi2nkp7ByKkpKNOwIMmsAEG6 0KfGY2K1H9NSG+EgqUfPuuh6qVqARrKIwZw4HS1y6+UVYx2GZra1tFtRcmtZw/xiNZOa 6BYw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734966563; x=1735571363; h=content-transfer-encoding:mime-version:reply-to:message-id:date :subject:cc:to:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=qZTXRsp1Mci+PylZUWXVzd0aOPXiwmhHY2/tQBTCP9U=; b=X0VJ9HX0kRvBUZ6P96JeKEELMMdPTEirdbdyRCVAPy+zBWir/0xsnyBIlWbOYx8eRB KTBLGgT+Eccg4RmR/aUHMGgohUyUmVuCMIDp18qEN/PqGdx+HbbRWgNyTd/mDUMzuWlk CgD2uQNMCVyWcfSTCTIZvtqCHFGAxsS+kYS3dTgS01hkReJ8gHUfcqY13cvQYc98Zvz1 sRVPe6WRFhTOh2l4FEsJId2Dn1778USODp4j5joQcs49UD43XUZj3iy3ONfPN9SXm6ba V0foIGIk/uPZB4ymimNsDSPoNJb4ySgRdgX/bpGP5zA+c03m9Lfb0Ce2LcqEwhSSYjEF JNow== X-Gm-Message-State: AOJu0Yx8It3b7HOGNkrAY4Cft+b7z5q6NBLyHPfFn+SouMZ8FUSvl1Ho D4k/bWUjGmN2JfGzSOx5rhnU3fqI07Fjm0wdv+JSyT0lg0lvTNajIqjQLzvpTsXNBA== X-Gm-Gg: ASbGnctK2HV05e7lkERljEaPJeUjitN1e2ANXQjNDxU6jnwnR+jVLhuHvTou1DwBATg wwaG7Ikez7IyD/XZWufrh3cwV9yE4St3LHdSuMhJzS9ykNycvIRFXaLm+gt/tE4blnpqwzOKBlS pOj33xyFfz5k4JKIMEjBN/Lc71X0L3euQjtMwh/sPG/rmBsCfTcw4nft5+7kl/q4O3t35WEWYcN 0DNpO676VpM1hY4DGU6yL4EbS3WiW+mTMBeXGMN8wt9Qlucf3QKDRX3afQNFt0WT5fapN9ZEUt/ X-Google-Smtp-Source: AGHT+IEpQTPRSLxt00ob+ODXI+wtTByAsMj3LL2dcDcYR5CyXrp9nZFsxBor51x0WSUZdv/6LnYECw== X-Received: by 2002:a17:90a:c2c4:b0:2ee:463d:8e8d with SMTP id 98e67ed59e1d1-2f4437bf735mr26580327a91.14.1734966562630; Mon, 23 Dec 2024 07:09:22 -0800 (PST) Received: from KASONG-MC4.tencent.com ([114.254.0.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2f447882ad8sm8563068a91.35.2024.12.23.07.09.17 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 23 Dec 2024 07:09:22 -0800 (PST) From: Kairui Song To: linux-mm@kvack.org Cc: Andrew Morton , Matthew Wilcox , Johannes Weiner , Roman Gushchin , Shakeel Butt , Michal Hocko , Chengming Zhou , Qi Zheng , Muchun Song , Yu Zhao , Sasha Levin , linux-kernel@vger.kernel.org, Kairui Song Subject: [PATCH] mm/list_lru: fix false warning of negative counter Date: Mon, 23 Dec 2024 23:09:07 +0800 Message-ID: <20241223150907.1591-1-ryncsn@gmail.com> X-Mailer: git-send-email 2.47.1 Reply-To: Kairui Song MIME-Version: 1.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 16A2B40005 X-Rspam-User: X-Stat-Signature: 4qwoitpeahuuuqfr6x88m719xrmruuwe X-HE-Tag: 1734966535-278951 X-HE-Meta: U2FsdGVkX18S3gOrujCV3pyCI+eZy/lF4f5Dj6i/incz/yJRBoTqUgI0XFcj9FQJF4j5Ajy6ryZlw7+T2wOhgR1La/94HFoVbRIfLi/KuXGPjv+P6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XJoVOrlikkljyyQg0onNPMHoo+BeA0vWCRpzov2uYKW6NyjfDwwteb8nd3dsmtpKrFcQEkcftJJCAgKX8z2fF+0L514hkW2o7vzLhDLWbvo/NGzUTbwaS6tdQoLC0pz+j1JVlcUKNyr4Du89Bd3599yh1JcAUX+PPMZ8m6l/WKBzs5eXsEWALikoCNScFitWA4NEcIJWLuHjV3IS0URkWi4X1PWAuCt2NxIMOGA1MDsUCt5H3tS7Kzs6VHjdBats//hkOVXxnI1DPcRYf4YpbtdVMsfm+s+DkrlzTGGomeGrFjLUub5Naxqjqnj/vzy8PD1dtD2Ea/dF+/7Xs8ay/ziQ+iR/fLnrAKJxLo5I7TY1cDF+iJ9p1lEzU+3OElt6+JjP/t2SrxVpBuCtUmsgWAD0J9hO2E7/DaIKuGhgql X-Bogosity: Ham, tests=bogofilter, spamicity=0.001043, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Kairui Song commit 2788cf0c401c ("memcg: reparent list_lrus and free kmemcg_id on css offline") removed sanity checks for the nr_items counter's value because it implemented list_lru re-parenting in a way that will redirect children's list_lru to the parent before re-parenting the items in list_lru. This will make item counter uncharging happen in the parent while the item is still being held by the child. As a result, the parent's counter value may become negative. This is acceptable because re-parenting will sum up the children's counter values, and the parent's counter will be fixed. Later commit fb56fdf8b9a2 ("mm/list_lru: split the lock to per-cgroup scope") reworked the re-parenting process, and removed the redirect. So it added the sanity check back, assuming that as long as items are still in the children's list_lru, parent's counter will not be uncharged. But that assumption is incorrect. The xas_store in memcg_reparent_list_lrus will set children's list_lru to NULL before re-parenting the items, it redirects list_lru helpers to use parent's list_lru just like before. But still, it's not a problem as re-parenting will fix the counter. Therefore, remove this sanity check, but add a new check to ensure that the counter won't go negative in a different way: the child's list_lru being re-parented should never have a negative counter, since re-parenting should occur in order and fixes counters. Fixes: fb56fdf8b9a2 ("mm/list_lru: split the lock to per-cgroup scope") Closes: https://lore.kernel.org/lkml/Z2Bz9t92Be9l1xqj@lappy/ Signed-off-by: Kairui Song --- mm/list_lru.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mm/list_lru.c b/mm/list_lru.c index f93ada6a207b..7d69434c70e0 100644 --- a/mm/list_lru.c +++ b/mm/list_lru.c @@ -77,7 +77,6 @@ lock_list_lru_of_memcg(struct list_lru *lru, int nid, struct mem_cgroup *memcg, spin_lock(&l->lock); nr_items = READ_ONCE(l->nr_items); if (likely(nr_items != LONG_MIN)) { - WARN_ON(nr_items < 0); rcu_read_unlock(); return l; } @@ -450,6 +449,7 @@ static void memcg_reparent_list_lru_one(struct list_lru *lru, int nid, list_splice_init(&src->list, &dst->list); if (src->nr_items) { + WARN_ON(src->nr_items < 0); dst->nr_items += src->nr_items; set_shrinker_bit(dst_memcg, nid, lru_shrinker_id(lru)); }