From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0E15F211278; Wed, 7 May 2025 19:13:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746645218; cv=none; b=KkZZbD1gB/URDkeyR/HcaRSL9OsRcWlMPhZwolbBTvle4cOMMNbSJbLcJI/F66vUgZqd3FDY8YAPPVCCc6R9qbigpjbI4fMFf/cfZma1S9nccArcYlEzzxWXyc3wC1sDe4jlU3n7cfhrL1kgv/lMAaAyD04/2HfiVQuJ+FNgbXM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1746645218; c=relaxed/simple; bh=chntxT41UW8FJB2wdsd+nQyoh4YCNrH18LRxFtDLcBA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aYOv6TO/T36SEG/1rj8eC8wq5YtNPfiE0xaaTsQZNMDctcRr2A2iwkGBC8apahXouFZ9tfUn7yS0NhShdbkkr+Q2NrogzvdSLov7S46JQCce3EcSf2AISlQp8gCnnVx+aOUGPT24tqtPGp0MhSdquVel7AIHpGOKx0Fa2erpusY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=SXuggwfu; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="SXuggwfu" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8E7ECC4CEE2; Wed, 7 May 2025 19:13:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1746645217; bh=chntxT41UW8FJB2wdsd+nQyoh4YCNrH18LRxFtDLcBA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SXuggwfu6K0PqG6V5pjPtEUd9a6Qh0cb0uUQ1GMU8rWIXCfSN04W62Nx06sFrTEzh TJBX/CR/14Ir9JxBpQEHxzKOO0BFoJNO3XZyIpQ/0v0eRXQOn+LpYEvI9vmNKXpLuP qxddIvunNmwxMKW41ks0ZBSjZZuFetZzfITE1lIU= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Shakeel Butt , Roman Gushchin , Johannes Weiner , Michal Hocko , Muchun Song , Andrew Morton , Sasha Levin Subject: [PATCH 6.6 119/129] memcg: drain obj stock on cpu hotplug teardown Date: Wed, 7 May 2025 20:40:55 +0200 Message-ID: <20250507183818.409854773@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250507183813.500572371@linuxfoundation.org> References: <20250507183813.500572371@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.6-stable review patch. If anyone has any objections, please let me know. ------------------ From: Shakeel Butt [ Upstream commit 9f01b4954490d4ccdbcc2b9be34a9921ceee9cbb ] Currently on cpu hotplug teardown, only memcg stock is drained but we need to drain the obj stock as well otherwise we will miss the stats accumulated on the target cpu as well as the nr_bytes cached. The stats include MEMCG_KMEM, NR_SLAB_RECLAIMABLE_B & NR_SLAB_UNRECLAIMABLE_B. In addition we are leaking reference to struct obj_cgroup object. Link: https://lkml.kernel.org/r/20250310230934.2913113-1-shakeel.butt@linux.dev Fixes: bf4f059954dc ("mm: memcg/slab: obj_cgroup API") Signed-off-by: Shakeel Butt Reviewed-by: Roman Gushchin Acked-by: Johannes Weiner Cc: Michal Hocko Cc: Muchun Song Cc: Signed-off-by: Andrew Morton Signed-off-by: Sasha Levin --- mm/memcontrol.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mm/memcontrol.c b/mm/memcontrol.c index 9bf5a69e20d87..ab9afcd372a93 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2378,9 +2378,18 @@ static void drain_all_stock(struct mem_cgroup *root_memcg) static int memcg_hotplug_cpu_dead(unsigned int cpu) { struct memcg_stock_pcp *stock; + struct obj_cgroup *old; + unsigned long flags; stock = &per_cpu(memcg_stock, cpu); + + /* drain_obj_stock requires stock_lock */ + local_lock_irqsave(&memcg_stock.stock_lock, flags); + old = drain_obj_stock(stock); + local_unlock_irqrestore(&memcg_stock.stock_lock, flags); + drain_stock(stock); + obj_cgroup_put(old); return 0; } -- 2.39.5