From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) (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 4510315E8B for ; Wed, 18 Mar 2026 03:41:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.175 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773805310; cv=none; b=iz0Z//aecUnpTXV5JKBPAFvzj76cuUMamF8OMwp3x03G79LmLOMS/fMUhqFVRKfXlxmRZsKSegqB+RFYbbJulteOkbdYz88C9Qmp6R7pdv04kTH/nrDlEhGln71o91UJjqQ6dbh4Eu1Oof8cBLoWzsVhbesu7z7ICgEwavKwatg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1773805310; c=relaxed/simple; bh=XCFceCYLJxuwJYrqMumGAfH9tk1nMRZW4f7mCsbujfk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=XHmioNN4LukgfiMHM68AHYCTk4Aw7ICDGXd/g0k54c7UfZa557pWOuBUqu7XqeQQU8rvHfA4ky75u7SzJThUH/1XrBulYpY41mPASil1toumWl5eyxFmLd2nu0MGSRA8FF6BtWiLfSXabkK3bx+tZOGZRrSciAm6us/V8Bupftg= 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=gfdvOGyl; arc=none smtp.client-ip=209.85.214.175 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="gfdvOGyl" Received: by mail-pl1-f175.google.com with SMTP id d9443c01a7336-2a8fba3f769so30769615ad.2 for ; Tue, 17 Mar 2026 20:41:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773805308; x=1774410108; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=vMRQlUwh7SoN2vG3dg8bnvwroHZhAIcNOCrjAUVtcpI=; b=gfdvOGylDMj69FOhBp1rcfTdWWiy22EIOfBLHIWBNcT4Iqp+lMIQdAghCdzt6YOk/p nyenBHOD0vd7L7D8JbN4aDAqSVS7Ah51dC9IT+qEgaizCy30WmufpFLS5m24fgSLNB0q +vnsoGLAblchV7c4WiFOtSK1X8hPa9o+p/t93KUY/egrzU2MX+KtESxx2mm4q8yh7OCs JyR/TzcW6tDkAems+iBBiKS9HD+MsNbDyefLU0v0fGszZP0OsMsMLzu6pTZb38DDC55y HimVCFrg0V62X1R8ScozsPkKkzYB35scMifhrh7qJIQhhGWdwzec7kZkcHItyQTgwhpe j1vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773805308; x=1774410108; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=vMRQlUwh7SoN2vG3dg8bnvwroHZhAIcNOCrjAUVtcpI=; b=J8lPizbw0YrxC1OLmYq+PCnwtgrcuJm5u9Wpk1E7VOBBlDu1JPp+350grzBVeGeEHX CjVW3cmdGEArskNseaPTfsPY7LiRyjdlcF/n9jPC7e61UjHYOD+kbnDlVdBBEeZHGAWW d5NyU8h1uzt0SwxQHrxqSdW1+BIRYZY7a9AEO4QQshERnd03gvzgyNk7iZUoPVb43b9F QvLmY0mrVxEAKd5W1I4nzTyHHKub4mVi+vGC4EDywbek9yre6ZztyQrvQ4xiAEAo9StO OSkYHgg4OjIv+8DQoFVU3cr+idf3umyY3YyRK3ucgwuyedqBEIqEXI0k2RLzERTiQmZW jIJg== X-Forwarded-Encrypted: i=1; AJvYcCUPvuNR/bsEvWbHDvL7ad8ViDIKdAoEvneUQKPiwxFnLc3B2BhAUelzfQRpXxCxYyxhbpxdIhbQLWN9bQ4=@vger.kernel.org X-Gm-Message-State: AOJu0YzqHPh/5wLltfXeZM/P86R7rqvDlf7zIGYV+K9i3Q43nLyBtIRZ INKD4ktJ57+/LSZQ1RFADDDlB7pjADD4+/n/JtNds/kb9NbDn44IEJ5a X-Gm-Gg: ATEYQzxvuTVjLNM53CaEqLMNjg6qxebzBYQnAnob2Hvd66Ufc4ZaAjoLzGiJfUK7qRD LMBgKfQ86XgeVwGKNuVaC4k0aNViSKZAPt46QOfFfivsss9t38/6EnLgy2AkfRvPpWLeDKUAezr 7tas7PI3gE/jeuW+zCPOci4fFCaZz24NuIawQdk7P6M9GL5GpniDtx2sA6TvSiyuIu+jUD/tRd6 XlxO1Vn1yIirg6fb/ZV0GM4r7flY6Nx+LRYO9pNn8Rbl9m+j2cJQvU0E9NPicCLTmOQ7OfPwtaf 8778c+Ku7cCkEuTrXiz6ZbYda4HU3FpO7dMEK+2Ag49AyE1dQJEeI4mTkqFGKFtw5gZKVD4hNKd jy2lbbB/wxhCNDJ7JyrAQOPO0B8RKBvUATOkRGCA/3xCRWaMRJ5ndWVdu2x5PlJn5AV9Cy0zCA1 FqwLujXMWPUXd/LUdzZjj7rUhdMKbz4BJBE0noL3uX5Mii4nJZGc4cq1G4zmpuLFHQAiCCKe4Ls jJzFHHktD3ujhzWGkdCdX2WO1NqYRv4NsaPrZ1cJHVBG5T963WQzWVzqQ== X-Received: by 2002:a17:902:e5d2:b0:2ae:5629:ac55 with SMTP id d9443c01a7336-2b06e385ab9mr17099755ad.21.1773805308125; Tue, 17 Mar 2026 20:41:48 -0700 (PDT) Received: from ?IPV6:2408:84e2:440:5e9c:c1cd:90c:afa8:9d55? ([2408:84e2:440:5e9c:c1cd:90c:afa8:9d55]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2b06e454a8fsm9978305ad.37.2026.03.17.20.41.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 17 Mar 2026 20:41:47 -0700 (PDT) Message-ID: Date: Wed, 18 Mar 2026 11:41:40 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 2/2] mm/mglru: maintain workingset refault context across state transitions To: Kairui Song Cc: Andrew Morton , Axel Rasmussen , Yuanchu Xie , Wei Xu , Jialing Wang , Yafang Shao , Yu Zhao , Bingfang Guo , Barry Song , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20260316-b4-switch-mglru-v2-v3-0-c846ce9a2321@gmail.com> <20260316-b4-switch-mglru-v2-v3-2-c846ce9a2321@gmail.com> Content-Language: en-US From: Leno Hou In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 3/18/26 11:30 AM, Kairui Song wrote: > On Mon, Mar 16, 2026 at 1:56 PM Leno Hou via B4 Relay > wrote: >> >> From: Leno Hou >> >> When MGLRU state is toggled dynamically, existing shadow entries (eviction >> tokens) lose their context. Traditional LRU and MGLRU handle workingset >> refaults using different logic. Without context, shadow entries >> re-activated by the "wrong" reclaim logic trigger excessive page >> activations (pgactivate) and system thrashing, as the kernel cannot >> correctly distinguish if a refaulted page was originally managed by >> MGLRU or the traditional LRU. >> >> This patch introduces shadow entry context tracking: >> >> - Encode MGLRU origin: Introduce WORKINGSET_MGLRU_SHIFT into the shadow >> entry (eviction token) encoding. This adds an 'is_mglru' bit to shadow >> entries, allowing the kernel to correctly identify the originating >> reclaim logic for a page even after the global MGLRU state has been >> toggled. > > Hi Leno, > > I really don't think it's a good idea to waste one bit there just for > the transition state which is rarely used. And if you switched between > MGLRU / non-MGLRU then the refault distance check is already kind of > meaning less unless we unify their logic of reactivation. > > BTW I tried that sometime ago: https://lwn.net/Articles/945266/ > >> >> - Refault logic dispatch: Use this 'is_mglru' bit in workingset_refault() >> and workingset_test_recent() to dispatch refault events to the correct >> handler (lru_gen_refault vs. traditional workingset refault). > > Hmm, restoring the folio ref count in MGLRU is not the same thing as > reactivation or restoring the workingset flag in non-MGLRU case, and > not really comparable. Not sure this will be helpful. > > Maybe for now we just igore this part, shadow is just a hint after > all, switch the LRU at runtime is already a huge performance impact > factor and not recommend, that the shadow part is trivial compared to > that. Hi Kairui, Thank you for the insightful feedback. I completely agree with your assessment: the workingset refault context is indeed just a hint, and trying to align or convert these tokens between MGLRU and non-MGLRU states is overly complex and likely unnecessary, especially given that runtime switching is an extreme and infrequent operation. I have decided to take your advice and completely remove the patches related to workingset refault context tracking and folio_lru_gen state checking. My revised patch will focus solely on the lru_drain_core state machine, which is the minimal and robust approach to address the primary issue: preventing cgroup OOMs caused by the race condition during state transitions. This should significantly reduce the complexity and risk of the patch series. I've sent a simplified v4 patch series that focuses strictly on the lru_drain_core logic, removing all the disputed context-tracking code. And this patch was tested on latest 7.0.0-rc1 with 1000 iterations toggle on/off and no OOM. Thank you for helping me sharpen the focus of this fix. Best regards, Leno Hou