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 1CD3EC83F1A for ; Fri, 11 Jul 2025 17:20:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 6C1E06B009C; Fri, 11 Jul 2025 13:20:37 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 699E66B009F; Fri, 11 Jul 2025 13:20:37 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5D6C86B00A1; Fri, 11 Jul 2025 13:20:37 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 4DCFD6B009C for ; Fri, 11 Jul 2025 13:20:37 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C356B16118A for ; Fri, 11 Jul 2025 17:20:36 +0000 (UTC) X-FDA: 83652648072.10.79381B3 Received: from mail-qt1-f181.google.com (mail-qt1-f181.google.com [209.85.160.181]) by imf16.hostedemail.com (Postfix) with ESMTP id B8504180009 for ; Fri, 11 Jul 2025 17:20:34 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=tW7JG3HW; spf=pass (imf16.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.160.181 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1752254434; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=al399wbnt8pSRezGjRpPW7y1b0c1HdMARHLUQW6DYpM=; b=POFQnIk7oINyIWxqPGdDaRmurQUdBvZGtWcGySRD6xZoh55C7nu0LX8eBi+5/mmW/uVRqQ CRQmnJdersM7RwvW0stKsnrAVBtXZIoX2uKwqMK30KiHXglmKecZQP2no28opdH1YTxRV9 NKpfC+xJ/Hqc0xPyt+UTcRuBI90lG4U= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=cmpxchg-org.20230601.gappssmtp.com header.s=20230601 header.b=tW7JG3HW; spf=pass (imf16.hostedemail.com: domain of hannes@cmpxchg.org designates 209.85.160.181 as permitted sender) smtp.mailfrom=hannes@cmpxchg.org; dmarc=pass (policy=none) header.from=cmpxchg.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1752254434; a=rsa-sha256; cv=none; b=WzVA4R2O5cBlPxLB97+fyi8NCv2rN8f4/LBaKqeoQijBrdHgTRzkTsbFUXMOqMtMClsg91 oZLNJYBO4vHbM3tfs17Pg/tqtXRuDQv0kvlqidjgy7dCbWXBAuuUCHuz9vprTuwauhmuF/ wygCLgEPqseEzNK8J2zY1kZPBNv6Pqk= Received: by mail-qt1-f181.google.com with SMTP id d75a77b69052e-4a7a8c2b7b9so31777711cf.1 for ; Fri, 11 Jul 2025 10:20:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20230601.gappssmtp.com; s=20230601; t=1752254434; x=1752859234; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=al399wbnt8pSRezGjRpPW7y1b0c1HdMARHLUQW6DYpM=; b=tW7JG3HWdDVRxI1HD3mOxGYc2FASbHUsPyWLWn3xq2/eIni5WOpfqLg7zh2kRLDb7Y drzZDqgpax23x06mXNt0ld6ymyeEOHTvFhoP9cuU/WNBtSJmKwVF1bboa7E54CMTF+jc duSdtoPFZ8NEEpgCe79qMvdXKXxHk9DYOZEgruTH8VP1CavyFvELNovpuU1lJH1ENhAF BD5oYl0NZUnwjTbybiItCpaKoKA+mmQzziGSjzjYtG6EJo/tzY9u24i/qM++nA0rXc+h Rtlw1RJkdsvM+OwL+S1FH/FAyvlTTmjH9dBcT8hr7xuNbMuo2xYSwNVesJt5RKkULiOy mgPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752254434; x=1752859234; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=al399wbnt8pSRezGjRpPW7y1b0c1HdMARHLUQW6DYpM=; b=UPk7GmEL/+r703TI5PIDpl5DrMkD4lTiyaOx1q6dIxubuNmStB+DOvbhox6sFxoo5U RY4GoaevcJTW7l1WnxcSvDpsEWBz0sme3ev8z7UuNgV3bYtdij4guRq4bbO4ppCDhuUx oA1W+snfUSw1B6A+7eVgKFfn9d7o4d9PJGGYM0SJikWwXf5g4BjeXjX8Nzdn4Lk3IreQ zpCShpKPj8SUWgJBu2IDASdP8n+vhoJnirXEB7Q6k/lvNfCCFNtTNOuXRNo4hB+NkzG4 SauEBoLE1rvxaMOBL5a34LC3p5/XwiHuKKU4FybKxdllNPyloTAGh0YUAeM/D5AESyAM fhvA== X-Forwarded-Encrypted: i=1; AJvYcCVG8O1WaUz7NvPK69jMDs4OLjtJ/8Y9SWd8JTb3Nq9dP+b5Rc5Sf79kgMuRmX7dZLrQT0gWn2YR7w==@kvack.org X-Gm-Message-State: AOJu0Yy6vfWERXbkcetjoCJlOo3Amhm5cJVhfwLwsrhRbx5KlMNi6+FW BfP8W9wAYusn/+vvFuWOOnWKkk7Y9HULexJ4LsVYSL1/2SZuXDBSI5YMWqNt7K1tgvo= X-Gm-Gg: ASbGncuCAufM4xa9ND/C+s5q9x5J7WB/bnzpB29A9vPTww7vexyiZut6DGP/l3Cq1wg Eu02lYQv32NMjaliHPysfYC/6atpXJNt/OlnVzyZAddZGBYwNTEICFugfPzUvebz1BZuwoskFi1 hRRfYNhkQp4RLYBTlI+LGkcyu45kT8U960k3iVN9drRPg0yw9wbj7kiOnRi8IUu9M4TLEUuH0gv Iobblnw/WVsWuBZhcjIEDRsCQmrVPt8SjSGP1CnVtHIaP3SBUkPbwcdnPwHIVqkqkVxxFrwU+5c fT6MWC4tIHzDIb1DF7iE8J/iDH/NATagHn3xXBIJ7inta3CyTpxUXLWUnyYUC89YCUc2AdV14+Y UdotqO9urleHkFv0D0/OH0Q== X-Google-Smtp-Source: AGHT+IET6OIRRs4zSSDeQf4/2ObcvV/kaNXKSCKy47s89cQfeakGKCZrUmNNGPFtv4q3Vww40VmuDw== X-Received: by 2002:a05:622a:250:b0:4a9:b1ca:9fe1 with SMTP id d75a77b69052e-4aa35dc7a45mr49969421cf.12.1752254433464; Fri, 11 Jul 2025 10:20:33 -0700 (PDT) Received: from localhost ([2603:7000:c01:2716:365a:60ff:fe62:ff29]) by smtp.gmail.com with UTF8SMTPSA id d75a77b69052e-4a9ededcd5fsm23014531cf.68.2025.07.11.10.20.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Jul 2025 10:20:32 -0700 (PDT) Date: Fri, 11 Jul 2025 13:20:28 -0400 From: Johannes Weiner To: Roman Gushchin Cc: Andrew Morton , Shakeel Butt , Lorenzo Stoakes , Michal Hocko , David Hildenbrand , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] mm: skip lru_note_cost() when scanning only file or anon Message-ID: <20250711172028.GA991@cmpxchg.org> References: <20250711155044.137652-1-roman.gushchin@linux.dev> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20250711155044.137652-1-roman.gushchin@linux.dev> X-Rspamd-Server: rspam08 X-Rspamd-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HGi0v8DOCu5TMILfkWBPEfPmNGoqSudTUNxQgGYlCaWfopcLAmeonnu/gdEleb5yB+vUo5PKGyQUOcC2d771hUTk0LlPiH0Q3AXdSmUzutPWrbPFjlZMK11FnHG8kK/DXko4TQmuwUOlJdAvYaw/OoGVz7BfQHyUqTD16OzrPZRQNeZOB6Iw6T7zrupNPFl3Vs8KvBUYdjrWrMYAvywZEZ+4I0lpAKDpV99Z9Rpep12nH9uSYnGKtPbOo5EKJCiN9fUQUDY2zU/3Ny4Q8VoA7ZT5FhQIwgTQC3gZT0U1a919TDCK7swRlno00l0BpWK+NyWv6ILO8rrKz5BFA2GCxB238FghzSYZ1jAo2SULY2w8KIyccGpM86eik2W5Y14m54wo/5kkDpLfMXfxtZTBhZuEQ3IcCOcB0mOgoWhM31OIr1xL7QVUPAze7yy3evFDTf5s2H1emLHlEkatjueAYRXxg8b85y24Pr6d5Fpl7Q36APTDFJuxAA7QqCfiXHru+B 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 Fri, Jul 11, 2025 at 08:50:44AM -0700, Roman Gushchin wrote: > lru_note_cost() records relative cost of incurring io and cpu spent > on lru rotations, which is used to balance the pressure on file and > anon memory. The applied pressure is inversely proportional to the > recorded cost of reclaiming, but only within 2/3 of the range > (swappiness aside). > > This is useful when both anon and file memory is reclaimable, however > in many cases it's not the case: e.g. there might be no swap, > proactive reclaim can target anon memory specifically, > the memory pressure can come from cgroup v1's memsw limit, etc. > In all these cases recording the cost will only bias all following > reclaim, also potentially outside of the scope of the original memcg. > > So it's better to not record the cost if it comes from the initially > biased reclaim. > > lru_note_cost() is a relatively expensive function, which traverses > the memcg tree up to the root and takes the lruvec lock on each level. > Overall it's responsible for about 50% of cycles spent on lruvec lock, > which might be a non-trivial number overall under heavy memory > pressure. So optimizing out a large number of lru_note_cost() calls > is also beneficial from the performance perspective. Does it actually help? It's under elevated pressure, when lru locks are the most contended, that we also usually scan both lists. The caveat with this patch is that, aside from the static noswap scenario, modes can switch back and forth abruptly or even overlap. So if you leave a pressure scenario and go back to cache trimming, you will no longer age the cost information anymore. The next spike could be starting out with potentially quite stale information. Or say proactive reclaim recently already targeted anon, and there were rotations and pageouts; that would be useful data for a reactive reclaimer doing work at around the same time, or shortly thereafter. So for everything but the static noswap case, the patch makes me nervous. And I'm not sure it actually helps in the cases where it would matter the most. It might make more sense to look into the cost (ha) of the cost recording itself. Can we turn it into a vmstat item? That would make it lockless, would get rstat batching up the cgroup tree etc. This doesn't need to be 100% precise and race free after all.