From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from out-181.mta1.migadu.com (out-181.mta1.migadu.com [95.215.58.181]) (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 543033845CE for ; Thu, 9 Jul 2026 04:17:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783570646; cv=none; b=A+R50fy8DwwotdmMwqQLpkAVgWfFLDO2V8pfUcJ5sGNbKa+kCSJlOTJYpl1p6p4z3TPBHDf5PhP4RZ9vKQFcR94qRcBXNPdczCwsXYmu63qG4jvamgNuqdQiSeGD7Fad8yP1Qhasy9gTkk3nTK6EupqPGy129AAYluRoPiQevtU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783570646; c=relaxed/simple; bh=aOdWUvlzAgvC5OCsq7N+HUUyKZx0APKH7Z2sNls4Csw=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=j7WMIuuiy7BwSwVn2qKJjs/3Ju8DNzrQA4NBW4wlsarok7mVkFhZJBYJHSG01hK06r/LnMXyNf7kgolm4FuqTDXCZEDaEdV7ijJHpwV4+ZALuYfjrZlMYf/u5MZASKbI9U+lHX4Du4S7sc4/XCcQ0YO+emvSbf4Jx3WvUnOnP7k= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=icLsN4oX; arc=none smtp.client-ip=95.215.58.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="icLsN4oX" Message-ID: DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1783570642; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=UBqGUL0+KiK1FMBVGSLXqyXS9/Lja6xJ1/PzEqDDCFY=; b=icLsN4oXxOuREtLzUD4RXdMBccXd3DogAuZu4P1fEGCT4JgDFQZq7H9tzLzb0F0iYq0bME bOQp8MNv4Xq5eO+wuHws9itPdkw19ohX6bpcS859IzbhmKMOrEMHmLCIGXPSamjlWfuvpY De4KCJBJwUMom/iyle/je2BeLnQsmEQ= Date: Thu, 9 Jul 2026 12:17:10 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Subject: Re: [PATCH v4] mm: mglru: fix stale batch updates after memcg reparenting To: akpm@linux-foundation.org, david@kernel.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Qi Zheng , stable@vger.kernel.org, kasong@tencent.com, shakeel.butt@linux.dev, baohua@kernel.org, axelrasmussen@google.com, yuanchu@google.com, weixugc@google.com, hannes@cmpxchg.org, harry@kernel.org, muchun.song@linux.dev, peiyang_he@smail.nju.edu.cn, mhocko@kernel.org, roman.gushchin@linux.dev, ljs@kernel.org References: <20260701075251.56413-1-qi.zheng@linux.dev> X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Qi Zheng In-Reply-To: <20260701075251.56413-1-qi.zheng@linux.dev> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_OUT Hi Andrew and David, Gentle ping. Is this patch good to be applied? Thanks, Qi On 7/1/26 3:52 PM, 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) > --- > Changes in v4: > - re-implement lock_batch_lruvec() in a simpler way > (suggested by Johannes and Harry) > - collect Reviewed-by > - rebase onto the next-20260630 >