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 C8F003FFD; Tue, 29 Apr 2025 18:01:12 +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=1745949672; cv=none; b=C/+/xTXTL61NeEA9hdGb/PSBy36ba4IBB3oOMyWf2bWjU94Fpl075imbvMKAqcRlgzxRRqWQtXFhIlWqYrzT6XCZwL0SA1B33OxGrDb2JSI83oId+sOYBcbF7npRsBYGl7CJtiWSYrVjgZm9wSrweFyZY5dX3xhQbaS6Wj5Oe9Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1745949672; c=relaxed/simple; bh=Uup06BL3b2HPnlZ3XGL1PSdyjSm/cYJgoivsGgiDlu8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Sj9vQDPOUqtZf5jTgR1m7FYR7kmdhfx/iUGWmIXnaZMSDyaDlOgioVQLhokWD28AX7VuFfnMfoEAwEL2M8U85PKdBoHc1PwThiEmH7lq3kXpcDV8TVcXUbxAizmwO7GmjRatbwNvMmQU6IPXofjisLI/sVWoIp/zpEzxgNRPBVI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=N/smMmez; 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="N/smMmez" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 56960C4CEE3; Tue, 29 Apr 2025 18:01:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1745949672; bh=Uup06BL3b2HPnlZ3XGL1PSdyjSm/cYJgoivsGgiDlu8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N/smMmezaeg+wRcA1TxuX/JaUdeGROMBlxUi+m2wCt/r0ftGECBGdqaK6ZY0WJHNz HVWkFttZqxr26dGrAJuZkOriwBLIq9TuQOA9G04L3S++f1TDD02Sk8lrLAqtzXeSRG 4HOOt9RijKMQ+lRFgd/esZ02KIvu9n3RH/TZcsDM= 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.1 002/167] memcg: drain obj stock on cpu hotplug teardown Date: Tue, 29 Apr 2025 18:41:50 +0200 Message-ID: <20250429161051.846625904@linuxfoundation.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250429161051.743239894@linuxfoundation.org> References: <20250429161051.743239894@linuxfoundation.org> User-Agent: quilt/0.68 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-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 3f7cab196eb62..8c586133abb7c 100644 --- a/mm/memcontrol.c +++ b/mm/memcontrol.c @@ -2368,9 +2368,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