From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (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 635351DE8AE for ; Mon, 13 Jul 2026 10:41:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783939304; cv=none; b=UTv1sVb66dEb2yjqZJOjiL+qe03tXijEo4Tr0NFpJHQdmPYmQFGUHYN/P4VkUY8GZoOI/mhLrUXN/UDZuUcIdHq5YzjhMGcTYCtpYOpkTZrOHx/zWNjx2IRHYhypRxqQGN8rtfHICLYSGRTGcB4TyUeMZokC5oLPqJjOwABko/8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783939304; c=relaxed/simple; bh=9OwuFF7+/jzfb+mWPqzlkgj5ZqG7UgrX3Yt9wiO5b84=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Wkisfcnpu2U9XKrtL62Ot4JjC3SjemUaOE+64x1yhsMUd68QDeaJyvXCN8QOYGqju/16LUyWPmwZtZPGn+ZjGM7gHgBeT2fX5CsSc/M7mHQ+xnpaO1fyqramNT6P0fIDuueRXq5J85LRbtw+WsEBSObEE8UpcvffD9Upifg3w/I= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org; spf=pass smtp.mailfrom=cmpxchg.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b=dcB/RAqB; arc=none smtp.client-ip=209.85.221.52 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b="dcB/RAqB" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-4798bea72f9so1563229f8f.1 for ; Mon, 13 Jul 2026 03:41:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg.org; s=google; t=1783939300; x=1784544100; darn=vger.kernel.org; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=GYEvHk/YQwaSKZb15XTEhRLqDQdjnw2zpv1OC/g28DM=; b=dcB/RAqBb+PSyJKjR4JQ8zH27dKzbTL9xxlaUE0vCpAp8QbWUVzXAhBW2bmx1FaVNi P8+0CDzYPcwsadVLq09aMC7M/C34rWFmhMO/qMtm2k4nbOJxdGCEhFFeSwkq9mzs/HAU TbyJjVR97MFRn0EeVlY6vSh4WiZ5mR5GRRlREYOz0rrAS1xFifosscUg145AM+p+5e4p oHv11Tx5S9QQdfXSWPn55L365QII6LWAjyacKVGkvgZ1E1Ah7fyHwnxh3rVw/qo8HGi1 0xByqMHq635F01rdTUXXcOm+5lxITdLjy39+ooMEZmHro+UU6KeN2rlcZSQfI1lzgef4 n3rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783939300; x=1784544100; h=in-reply-to:content-disposition:content-type:mime-version :references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=GYEvHk/YQwaSKZb15XTEhRLqDQdjnw2zpv1OC/g28DM=; b=k9eU3Dkk+skA79OJFCnutwbOav3AXRr239okEWA3XSDaYtPiKfjARsjduZQgRWZz8z QSfleBFB7v3r/kK9s8WdLej3th8EAXXvjxOu1rBrjtX3Qpnp98b2MaMhlyoeXbIJj+CB +f3lMpWcBu38rB4BPR/9n8HBhMM2UqxLNaHe2g3UApWsYPRf+UZ0n4siPGkmGDlO9EBe E4e5SViIOOSxg9RuzKue6gtiaqbc2emKnKeS/j2YiF7mw4nn7vwJrSJnuadWv8kuF93E ch2jNXA0fGMiRitHFSTIiPSkzcPndbfzKmdmsu7xvLLG5J6aEekjkiUumb4iTqehHFio +Xuw== X-Forwarded-Encrypted: i=1; AHgh+RpBSUK+NOpX/QX2rXW5XsmkYdaPEAUrr9BbpXsvJ/WQUy0HbfTjWdPoI11X77d0WMJMwlNHFPWI1T4tZuw=@vger.kernel.org X-Gm-Message-State: AOJu0YzozRhgtiwqpwsCtc89KS6bXfyeLyxOxVVDPeKcGtbOvsYH17KD MLTwAXI30+FbJjknksvWzVBncdEsxvOdPlZtsFAR1JgVRGV3AxUWSyu7ilH+FlJrK14= X-Gm-Gg: AfdE7cno3VEQyIUnwpGB6e1bXyE/eaFEp15c1kOEa+QroPFPxh9Yh7KjgNJTjFOJ4Tk fN1gz3s7DwZUP/Z5yMEbzIbkNu/7AWtPJ/Kxl8kbOOmBae8rlwfbHBUyARAMlabYzv/goc5iiIC 3Ozr1UVtf0dhkHCrw0GtpT897LiLTvZ6xkbmc4S7e2GKCyOnjec9E2gD6Q3NEZpZRpNcP0fMgfU PB5/ydAqKsWV9+GSM3/7MzerMQt16TF6/eqXzWlXv9+a5dohyDeAm5SeAVzK7nDSxOVFghuElzp aWe82HDcgS80wha151W3/cZRAWbBkES47oocfzIZOOUfrHAeg6zhbD2nKP2nZYwIyKwncRfi9Fr ROAEuOA6Gz1jOtD33LDvJGAekrtJdWZa6DNSEqAgkD+qIgqfMYmorSQgui371++6n9tkR79hE44 Rj0GM0Gve70Q== X-Received: by 2002:a5d:64e7:0:b0:472:aaba:faed with SMTP id ffacd0b85a97d-47f2dcc6bd5mr9999848f8f.31.1783939299409; Mon, 13 Jul 2026 03:41:39 -0700 (PDT) Received: from localhost ([2a02:8071:6401:180:d892:bf43:a0b4:83b]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-47aa039af67sm95258224f8f.17.2026.07.13.03.41.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Jul 2026 03:41:38 -0700 (PDT) Date: Mon, 13 Jul 2026 06:41:34 -0400 From: Johannes Weiner To: Qi Zheng Cc: akpm@linux-foundation.org, david@kernel.org, kasong@tencent.com, shakeel.butt@linux.dev, baohua@kernel.org, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, harry@kernel.org, muchun.song@linux.dev, peiyang_he@smail.nju.edu.cn, mhocko@kernel.org, roman.gushchin@linux.dev, ljs@kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Qi Zheng , stable@vger.kernel.org Subject: Re: [PATCH v5] mm: mglru: fix stale batch updates after memcg reparenting Message-ID: <20260713104134.GA276793@cmpxchg.org> References: <20260710154318.75388-1-qi.zheng@linux.dev> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260710154318.75388-1-qi.zheng@linux.dev> On Fri, Jul 10, 2026 at 11:43:18PM +0800, Qi Zheng wrote: > From: Qi Zheng > > The mglru page table walker batches per-generation size deltas in > walk->nr_pages while walking page tables without holding the lruvec lock. > The reset_batch_size() later folds those deltas into walk->lruvec under > the lruvec lock. > > The page table walker can run concurrently with the memcg reparenting path > as follows: > > CPU0 CPU1 > ==== ==== > > walk_mm > --> walk_page_range > --> update_batch_size > --> walk->nr_pages += delta > > mem_cgroup_css_offline > --> memcg_reparent_objcgs > --> lock lruvec > lru_gen_reparent_memcg > --> reparent child folios to parent > unlock lruvec > > lock lruvec > reset_batch_size > --> child lrugen->nr_pages += delta > > This will trigger the following warning in lru_gen_exit_memcg(): > > VM_WARN_ON_ONCE(memchr_inv(lruvec->lrugen.nr_pages, 0, > sizeof(lruvec->lrugen.nr_pages))); > > And the user-visible impact of underestimated nr_pages in MGLRU was > premature OOMs because MGLRU does not try to reclaim memory when nr_pages > reaches zero, but there are still more pages. > > To fix it, make reset_batch_size() check CSS_DYING under RCU before > flushing the pending batch. A non-dying memcg keeps the original lruvec > stable against RCU-delayed offlining; a dying memcg redirects the deltas > to the first non-dying ancestor. > > Reported-by: Peiyang He > Closes: https://lore.kernel.org/all/5A9E929D82717101+12fcf643-efb8-4b9a-a53a-1e28cc894f0b@smail.nju.edu.cn > Fixes: f304652609ea ("mm: vmscan: prepare for reparenting MGLRU folios") > Cc: > Signed-off-by: Qi Zheng > Reviewed-by: Harry Yoo (Oracle) Acked-by: Johannes Weiner