From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 697C1C83013 for ; Wed, 2 Jul 2025 05:45:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E06256B00AF; Wed, 2 Jul 2025 01:45:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DDC9E8E0001; Wed, 2 Jul 2025 01:45:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D193A6B00B1; Wed, 2 Jul 2025 01:45:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C36B76B00AF for ; Wed, 2 Jul 2025 01:45:05 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 7245DBB32E for ; Wed, 2 Jul 2025 05:45:05 +0000 (UTC) X-FDA: 83618236170.28.76D00DE Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by imf11.hostedemail.com (Postfix) with ESMTP id 8629F40005 for ; Wed, 2 Jul 2025 05:45:03 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=J+0u2jKx; spf=pass (imf11.hostedemail.com: domain of jiahao.kernel@gmail.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=jiahao.kernel@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1751435103; h=from:from:sender: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:dkim-signature; bh=PRMbU9uRH/MlRGEh01copkBiW5W/F/fCF6AC2yx8CfY=; b=hbk/DA1HlPFiR0xlNto9t/PZZ1EHbPzy0dRHH++U5h6lnMAVksXM45shQyuyYs3D/iOpou pa/7LThSNaGUC8nAnzrZn6Bk3byMw5jftfMeWRKlHPvA/oxyyV1krcRmyL5sEwvf5UCIai z/F6uy0x7P8Uh9cbbYf0vIsZC6xg7tM= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=J+0u2jKx; spf=pass (imf11.hostedemail.com: domain of jiahao.kernel@gmail.com designates 209.85.214.179 as permitted sender) smtp.mailfrom=jiahao.kernel@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1751435103; a=rsa-sha256; cv=none; b=y/WqPaIqvLRzHVZa8ZrmjZ1krMYq+xA7vcvtr2h+vR8bDuXsmjHbjWEIEKRv8PWVLg/YFZ TLTr5+l+mkFknj/oOdCheMzxzZEuPSNNkE4m+Kdci0VnEMqf8nrzYjktXmF4r1qqXnZp8M D+Q5kqAu8TwEBBGt/PTfX9a4012VYXk= Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-235f9ea8d08so58203015ad.1 for ; Tue, 01 Jul 2025 22:45:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1751435102; x=1752039902; darn=kvack.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=PRMbU9uRH/MlRGEh01copkBiW5W/F/fCF6AC2yx8CfY=; b=J+0u2jKxqhUiP+EaXJUw/M6YrfajlO+gSY57pwHxD+g/tkCfT//7DPixn5y7gHE0VT dxjKxudAjNc5qD+Fzryowz8a7n7WtYSVYEeKX+AN2JAxVzQQuoq7/ybw9Gh0xCmLIuUl X2pDv2iyBXyfloj8AmmTCOOTvPTuco7REM7hOxQw3pcqBiJFBXyvQX+it/B/NPUI6U9/ /sz4krkzBt7GKrfCK9OjQVmowKYMPcH38qjxnwuZghP1VX6GJ5lLiq3CHge6y/anPAtH XmauHT93cagI0EL1RhmvMtrDzOStkQUOzH5eRcTWrM0ro2FN8F1ojOJAH1l/YfBfFhBr RrOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1751435102; x=1752039902; h=content-transfer-encoding:in-reply-to:from:references:cc:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=PRMbU9uRH/MlRGEh01copkBiW5W/F/fCF6AC2yx8CfY=; b=LowKTGOEcJygdW/D4DcVBeAoU3YQ9Qzxy7ChtY2TvFFZM5kfPxW/la58iWPs0cKg7k gxQqrMPzuQRYzcnJqlSl990VUXFfBjA7dnoymIE2DkKoed0BZ1/xo/XWnCXjacC4mdBu GVf8e0dLeD8loaK3BEgID8l2ukzEbg9UbhQgzorOxiLcQyg6zNjpu9FdwYM49Ge9peqO dDDAf4MoTzpYFy74UtWCby9IXTMuCiTfMIV/lyn82XwDsE+Y2BkhsMmawPZSodz95j+G 6VnpNkm23pX260tHGA2bcjLwyzRjDL01ph+Ba2+ATX0sHb9mgyen7os0F/0XRXT54Gzw g+mg== X-Forwarded-Encrypted: i=1; AJvYcCVKTwCrOVyxk28snsZOnpweqPlvZ+YxTrC8FKnyeQeleM+nAROz3vAlpNxTjjxfS0xIxcYkLzJ0Xg==@kvack.org X-Gm-Message-State: AOJu0YyWdM+XF6z15fgGjoAGS+OAa9ybUvBGPRSNXEdTiADKUSfh1Vjs 6KmdshflhZN1jdXf3NsoQZ+NooCc/1yjr/ggX690FY7RKL6gEWEv5qa6 X-Gm-Gg: ASbGnctuyR/PQ1RFROacZW56DJ/WKP3SDZOM991qNEaPxTm4UFbBb4NNXAjulupXIKE EPhQmlUYTQm3nQZB9RIXofVXabTBPwvme9l/O3qnHQtcdh0cc44GGr/WyIrqF6bY3u+vcannpPz S3L1Zwfb8+ZwRyNLtN75AE3cZAltc+SdK8jGicNWNFxMZ776qxsEH58yr94k7koayQPoyIxEEff KT4WN9L+klS9/BImF04/N6c5GfsxdT3+yesFD5plQZjkC9ANKtaSyXlTGzIylFdBKwedE6T089f 5x3EeHKJIv/krMAwTBJYwkknlG80tMDLqn7ULRE58Wb5zpAS/Qpm1oeTsJ1TdgY+o8yOpXN+uyX hL4fFuuU= X-Google-Smtp-Source: AGHT+IFZbI96xEmH/fJb+myVStTu0IbvTbuOCU5QFx6uBVkcjhdA9TM195ZXmmt0s4evkP6zg7cSvg== X-Received: by 2002:a17:903:244f:b0:235:2e0:ab8 with SMTP id d9443c01a7336-23c6e4d681amr23335905ad.6.1751435102130; Tue, 01 Jul 2025 22:45:02 -0700 (PDT) Received: from [10.125.192.71] ([210.184.73.204]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-23acb39f4c0sm119063595ad.103.2025.07.01.22.44.57 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 01 Jul 2025 22:45:01 -0700 (PDT) Message-ID: Date: Wed, 2 Jul 2025 13:44:54 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.15.0 Subject: Re: [PATCH] mm/mglru: Stop try_to_inc_min_seq() if the oldest generation LRU lists are not empty To: Yuanchu Xie Cc: akpm@linux-foundation.org, hannes@cmpxchg.org, yuzhao@google.com, kinseyho@google.com, david@redhat.com, mhocko@kernel.org, zhengqi.arch@bytedance.com, shakeel.butt@linux.dev, lorenzo.stoakes@oracle.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, Hao Jia References: <20250630080603.36171-1-jiahao.kernel@gmail.com> From: Hao Jia In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 8629F40005 X-Stat-Signature: txfyophctp5heuqcfpz93emjx1jnife6 X-HE-Tag: 1751435103-372662 X-HE-Meta: U2FsdGVkX1+ynLgIvwOKozJwkkzPUvs5VrpttZoa7N4T32QSyqT6kRJsAGei8ZDr7ZNSRJS9Jl1p/SNdpiVFmidPT3arlCPKvIgnXxQVzApFhPzm0rVUUSEuYIVfjV+ovsqyF9zl1KdnBr7JqSi73qk2fbTYny1kgmI7CBG+dZD7c+eYUn92FDdVD7bpnXVbaJIgdXBiplCrH4dAByi2T05bUP3ZF0tdWxryeQuZF6ko6Qw9WXOrEwVECOY3awmLfbenu+z38KkLBnYs0aSDL8EIZFEJ9KI9tFN3kRyzP5QsI20QedriPSFNctIa/1i1FSjZJqsbw/IMBV0/1oUxZCSRM4l6NIhdoEJOBvsfVF52Kd8bWjzvVb9ooOZzYgrZSVungcxS6nT/QtitKaOmWGsxU/q0VF2Wm2LgVcFG9kk4z7wR0Rkgfosh5C5QqiZw1GNeDcQ4pOWfg8G0H9ILGQ/Xcot7oiYXTz1cCN4bieo3ckk5x/G1KkkUq2pbDleu22pZkDApm5IbWkVOaDXbBQugTt8wbTlfj/k/Cfa0E/11wlKX9NkLgZOzin1q0hJqaFyOPUDwbnLIiZri8STZ0HdcdU+PH6dxVV6KdFqjE0rw6IkrlerL73w548xWwve87zxEmNeeqXB9hoO4r0LN79fFW2Yva8GFsZlaEuuN9EQKtQFYdz81GR1A2E4d40W14uLH1U1TQ2EgXcFaqIFRUrF871tL5zxjmNmZY+E2w45iSkUjMMwiJeKkiL83o7Gn0PX6jm0JKMQJFaS6G5InVh19WOZs8nT9U0cttS8YO9/C69+wki1+7XhF2IkMP7BMhv2qwFDCHM3iGptFTUgsmF8rjP/M15MkdXkYt5ONZ3SIf252QMGFWO7pIr6SSdwUBcP9MYdFLJ/s5oUrfGK0byQxr4Hvg8vHP8OTdsEYOml7nIaSxvCaibb2Qu8B9J2XEcMH+Lwi7b7erPQ/4Dy wK//M5E0 aLhrneOQ+DnZrO8tOsJeSEraWdcYj5AXl7ozZPSr3CWhrtnuum5ZfIXFMIWtnUbS9yC3vkasR/xwHRbYgctDW5hCbQxdrdA1ivz+7tHFXgl7l/atkj1VFND7JCjUt1O0Ftnvy4ofS7EB1FPIJDT1/IyEW2ceg0HYyNMV4GzRYWBGJuXAAxszGfJ32iQgMcfToR/zJ3kOggKvdKxFmjOdJNfyblQ/P6lAC3DYOh9OCVzd8cEnSMZvMJ3iFEfQb/lDAjbMrEm0cXxK0B7mVEpyqhRSgKxYASIDYsHL2xxt+PfdbIRjOQGQCVPpMNwGmBl4FR6YYwJXaqjwtxYeSZRSdmyYgzXiBmYFw5SAOStUDVGEiIn6xYx0f0FCENMqp9Q6JpzyU944I+jVQCPdwaCg/KHV3e3v/harLCJp14MnTvAoYsJ9scpHFLDao7aaRCs0Qf/+/cgk5BvLdcnEdzvXcCJE9I/CS/MmOXarx/ftAxtVapYCAsynvw3d7j/4XNvcDbKcZkK4oM2NUDG3rYEVEHc9PtdMIHH+Jy2BV1hPyjVAAEE1QnAXgV7DGuDffKjv9qW3N9zpme6vmwmHg6gH888jX3w== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 2025/7/2 08:31, Yuanchu Xie wrote: > On Mon, Jun 30, 2025 at 1:06 AM Hao Jia wrote: >> >> From: Hao Jia >> >> In try_to_inc_min_seq(), if the oldest generation of LRU lists >> (anonymous and file) are not empty. Then we should return directly >> to avoid unnecessary subsequent overhead. >> >> Corollary: If the lrugen->folios[gen][type][zone] lists of both >> anonymous and file are not empty, try_to_inc_min_seq() will fail. >> >> Proof: Taking LRU_GEN_ANON as an example, consider the following two cases: >> >> Case 1: min_seq[LRU_GEN_ANON] <= seq (seq is lrugen->max_seq - MIN_NR_GENS) >> >> Since min_seq[LRU_GEN_ANON] has not increased, >> so min_seq[LRU_GEN_ANON] is still equal to lrugen->min_seq[LRU_GEN_ANON]. >> Therefore, in the following judgment: >> min_seq[LRU_GEN_ANON] <= lrugen->min_seq[LRU_GEN_ANON] is always true. >> So, we will not increase the seq of the oldest generation of anonymous, >> and try_to_inc_min_seq() will return false. >> >> case 2: min_seq[LRU_GEN_ANON] > seq (seq is lrugen->max_seq - MIN_NR_GENS) >> >> If min_seq[LRU_GEN_ANON] > seq, that is, lrugen->min_seq[LRU_GEN_ANON] > seq > This part doesn't make sense to me. > The code is as follows: > > /* find the oldest populated generation */ > for_each_evictable_type(type, swappiness) { > while (min_seq[type] + MIN_NR_GENS <= lrugen->max_seq) { > gen = lru_gen_from_seq(min_seq[type]); > > for (zone = 0; zone < MAX_NR_ZONES; zone++) { > if (!list_empty(&lrugen->folios[gen][type][zone])) > goto next; > } > > min_seq[type]++; > } > > Here, it could be that , min_seq[type] > lrugen->max_seq - MIN_NR_GENS > (what you refer to as seq) > However, this is a result of incrementing a copy of > lrugen->min_seq[type] as this piece of code finds the oldest populated > generation. > > next: > ; > } > >> Then min_seq[LRU_GEN_ANON] is assigned seq. > This is not necessarily true, because swappiness can be 0, and the > assignments happen to prevent one LRU type from going more than 1 gen > past the other. > so if `min_seq[LRU_GEN_ANON] > seq && min_seq[LRU_GEN_FILE] == seq` is > true, then min_seq[LRU_GEN_ANON] is not assigned seq. > > >> Therefore, in the following judgment: >> min_seq[LRU_GEN_ANON] (seq) <= lrugen->min_seq[LRU_GEN_ANON] is always true. >> So, we will not update the oldest generation seq of anonymous, >> and try_to_inc_min_seq() will return false. >> >> It is similar for LRU_GEN_FILE. Therefore, in try_to_inc_min_seq(), >> if the oldest generation LRU lists (anonymous and file) are not empty, >> in other words, min_seq[type] has not increased. >> we can directly return false to avoid unnecessary checking overhead later. > Yeah I don't think this proof holds. If you think it does please > elaborate more and make your assumptions more clear. > Perhaps another way to explain it is clearer. It is known that min_seq[type] has not increased, that is, min_seq[type] is equal to lrugen->min_seq[type], then the following: case 1: min_seq[type] has not been reassigned and changed before judgment min_seq[type] <= lrugen->min_seq[type]. Then the subsequent min_seq[type] <= lrugen->min_seq[type] judgment will always be true. case 2: min_seq[type] is reassigned to seq, before judgment min_seq[type] <= lrugen->min_seq[type]. Then at least the condition of min_seq[type] > seq must be met before min_seq[type] will be reassigned to seq. That is to say, before the reassignment, lrugen->min_seq[type] > seq is met, and then min_seq[type] = seq. Then the following min_seq[type](seq) <= lrugen->min_seq[type] judgment is always true. Thanks, Hao