From nobody Sat Feb 7 15:35:27 2026 Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 784FD14D43D for ; Mon, 23 Dec 2024 15:09:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.44 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734966565; cv=none; b=Y6Obaj6u59E+eLoI/fd5XOsmRdRk9JtRxwC1GmXL21YLFrzsmV2W9gQmBegTkBSemA01a+Gfl90x/30jr3ZsxHDb/EkMQ0+9eQT4Bvnar8q2wzYIm2KIqOHDzp+JAzLu7k0LbUgblHAdxevbHJf4BMy92Nj1WDcAI1TP1covy7w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1734966565; c=relaxed/simple; bh=32tJoMHgb1KP1HNUx0IuGWk7JqIsdchO2WNf2gJ6QuI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=M5oxXHG9TClckGfXn+f13A4Ft9xaNAY5LalD+rl0ULQuMgbSrdkeqMv/5HYgnaDlAP3dN4iVaB31XmsQ66g3Xrv7fUc1CTC2u7haAPfHP6sGMOHWiZt9FrHzOpfjv+Jhh3io9MmSc1raYAzDAF8im0XReiv5tIprdwEc2dmJ8lQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=OVulsDYK; arc=none smtp.client-ip=209.85.216.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="OVulsDYK" Received: by mail-pj1-f44.google.com with SMTP id 98e67ed59e1d1-2f4409fc8fdso3261171a91.1 for ; Mon, 23 Dec 2024 07:09:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734966563; x=1735571363; darn=vger.kernel.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=OVulsDYKy5F9SqhRhSPng25siQY8I/dIDKxR9Y4poFvGPc+FkbC1+IKGc7ZgJxgvGP 27DlM9krwinAK2uYaM3z4Nkg2xQvlbwIO6o5eWlgWn+2zKL9TzYkkRqeohad3Tb+2jkZ LMv3c2bsKO5DbXI+crYRWLKUqcELHwREpDMl/15B8Oa7Tjl+8bmiMM8JJV9hc+bdxuWG U0Jdz1kK3DzMx2tzk2aI8zcLOM8LcUmwXR/+iiR9tUhsvSZcDP32j5Q/V+i6laVLcg5h 83LI8ae3EgxNvSsXQrhR5yGLij1cDF9iQ3lfxTxztBOUHI7yrhoBWOmYd1/9J5+sfX8O MYpQ== 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=vlLtORTPrhTbWsU2NCwCyQhp8SB4o83ginOCXQCDiMsrdLWXCO/Exh3n0EWLLmwq/V ewqpj0XChPeuuTMncFsEQPV0EtUnCmqmTNx/UeE9fsDeC9YfapgxXc7meMJ6TejaGubM eFJzLnqWrvSrOE+O1W7z17SShpG9IH2O3RS8p3nXSD2QSmdw7UPMhw7hHoPmrRtZSrVG +eND5xQTlMsrZVIdTjv5snPsDxtFA3kHMmizhAkMxQCRsORSteGUL1I+K5ayz+Is58pB ZwLpUejHe2QaxulfXl6E5FnI65PGja+HXhQYbsdyWPwZB6Beyd5x/QhWxjZ7ssuVGoVA pIjQ== X-Forwarded-Encrypted: i=1; AJvYcCXW8/h5cEZG3z+lvKj4ZwvrkIDuFCml3ZZ/l4HyNPCzMxXqb1jBHwJWlw47nNW8P2Bf+/NEtuITruL/x/c=@vger.kernel.org X-Gm-Message-State: AOJu0Yx0jPi5BEwV5XKy9UJehFXbFXr4INeysvUHMkMDfglATkIiWRvy Zc1B3izBSVDkiCd2GKgFJLnOARR6zq/5kh/MCdmzUWpQFzHKnL1X X-Gm-Gg: ASbGncuSPfrzhxousS8Qod1ss/1b/raB/a/gPcrGD5wjseGWB3fFuiuewZ/teI6qUuU 06qy9ViZG4LGPqsyijIESFODbci94TIZCe6O6WW5YwcFjNvP/jSJwtVeaP2fYapoXV2ps30dl+c RIrlHhQq2bTI2O+4PVX+HKUegKG4F0c2VcWdy9JbNeVi7JJO6dB6MQZG8pAqe+ORIeK2rirpJQy 7+ho6RZU7oRXJsuNE4pS6ImEDkS3dMq37O7F5+fMTI4fZLzV4oa7uVYrL/6tW9pRRp6btMym1RU 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 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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, str= uct mem_cgroup *memcg, spin_lock(&l->lock); nr_items =3D READ_ONCE(l->nr_items); if (likely(nr_items !=3D 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, =20 list_splice_init(&src->list, &dst->list); if (src->nr_items) { + WARN_ON(src->nr_items < 0); dst->nr_items +=3D src->nr_items; set_shrinker_bit(dst_memcg, nid, lru_shrinker_id(lru)); } --=20 2.47.1