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 24E07C3DA4A for ; Thu, 15 Aug 2024 00:29:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A6A236B007B; Wed, 14 Aug 2024 20:29:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F2F06B0082; Wed, 14 Aug 2024 20:29:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 893556B0083; Wed, 14 Aug 2024 20:29:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 686EE6B007B for ; Wed, 14 Aug 2024 20:29:50 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C7F45141258 for ; Thu, 15 Aug 2024 00:29:49 +0000 (UTC) X-FDA: 82452596898.02.B8EE0A3 Received: from out-185.mta0.migadu.com (out-185.mta0.migadu.com [91.218.175.185]) by imf24.hostedemail.com (Postfix) with ESMTP id 9546B180012 for ; Thu, 15 Aug 2024 00:29:47 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Z7Mg+sLr; spf=pass (imf24.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.185 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723681715; 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=YkR6+p3tEblVu2HdOj0+q8t6472WPtUOGkMk/DjcCdk=; b=Eag02/L17gUHCgdvZFH9byqdBGl26Q2S7WetEm0suXisJraHiKA8pJExezqwTt+NHJ113X dqejGCyLV9PJJJxRQmfk/0Xob3WC/gEQnwYXMJJbqJ+Wd9wXsTu39vxgyB3Auk05ut1ZIH AogWm4svhPUIBkhM4GpCjLrmeE/8eiM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723681715; a=rsa-sha256; cv=none; b=GfiiKkvGHndI2Cet0HuagbQQl2hGmZljvEYGxrWLOf00unXCBvaAhEmB0XRODxn2u3NNvK dG9rgLLBJLQWXT/DCNWWpjpUoYl2hQKupwU1ioDjsXfNeUFfBZWBREsJOE3Uv7w8+HtJwf dSPdki4b+72KwczkCnbqPYBaKgoDMDA= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=Z7Mg+sLr; spf=pass (imf24.hostedemail.com: domain of shakeel.butt@linux.dev designates 91.218.175.185 as permitted sender) smtp.mailfrom=shakeel.butt@linux.dev; dmarc=pass (policy=none) header.from=linux.dev Date: Wed, 14 Aug 2024 17:29:39 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1723681785; 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=YkR6+p3tEblVu2HdOj0+q8t6472WPtUOGkMk/DjcCdk=; b=Z7Mg+sLr2hIxf+kue6IUr+8WClBd01MOVSZ2Slyk9GrUKax7LOgLiynYcwOMBb7pfvy4Gu AROQ9PCRqNXXLJrqD+7YOHfDJlpl7ISauQcMOQSVPkKW4abkSOfjcd9ASpyCp8eIjdEtCS P70o6Jlbs+xpoCxNbhwoNW+h2ZI4Fe0= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Yosry Ahmed Cc: Nhat Pham , Jesper Dangaard Brouer , Andrew Morton , Johannes Weiner , Michal Hocko , Roman Gushchin , Muchun Song , Yu Zhao , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Meta kernel team , cgroups@vger.kernel.org Subject: Re: [PATCH v2] memcg: use ratelimited stats flush in the reclaim Message-ID: References: <20240813215358.2259750-1-shakeel.butt@linux.dev> <5psrsuvzabh2gwj7lmf6p2swgw4d4svi2zqr4p6bmmfjodspcw@fexbskbtchs7> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Migadu-Flow: FLOW_OUT X-Stat-Signature: 7mui3mxq5b7m6hy9td3h7n5esacibt9t X-Rspamd-Queue-Id: 9546B180012 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1723681787-743786 X-HE-Meta: U2FsdGVkX18v4XK0NJdJlKOarPAQbrNpKMPunxCQ8PaSGB7/IWdUw0yYEhomS5UoI7alKrUHDUNd23awkpN1QQGVS1kJD4s5XHfYMoqyUPM9VarXZUZBEnPNO3HWli2j47GT0OyPdP+qidsU+RqXenr5oBdfKWNiE8e+m9JTwR5J8ZGBs1GiibGlCChUxLevTE37rLr2ftq13dpywJ+yzMCGKZRgtIxYAel4L3VNieUQj0DKrtr3n117KddCii1mXUp6uNSK40IzkqrGm/A2cArqe3ZSVANbvJOVdYz/jBcqJ2zaxpUfkcLpw0VTjC4yF2TJLkfyAF1ElM+KImOcdO3wRhjWDs08HnfiOzwYN3/gWrUF9fGqPEKO0O1/28EIQ6rqU1/glgCcCU9cDoKp6ACHdSZM6Xk3KkNxroAFMmCn7MEdX9UrmMpT7GFRYEh1Lf9WUTtSrh8r1AMpwhcfGJ+LWMphdFjuVKayeKmq6EqG53AWkY+UQ0sg7LOYKJ8827lONUgXLXBeb3PXtyM0wiZFq5YBP7DUuK9efk/hMZWuWgUinUwsTW2E3gcnPKCHSxXJ1B103pZUoSHYlCtfiLp2D5wqCJjB+xwKiLJPtv942ipGdlRUaequW2Sq3KDYCjEEuDfZuOpE/xiitxsDzw3TxpHx+vRkGBhGeXi5wAtgmC8UR4i4PMY6unE3iRgWYnqEyiiV+zsjkhXoD+wIBHrPPH8WN1kRpFWi15LU3i22i31+3oOG2jaZNnUr+o0+wqtF0h88jORLcKxYjP6iC/78O7BOXBvfLC+BfPX+Kf3pTcdz7DyNHuLr1kjEE2M4qSGa3GkynnPB4Y5npk35+SivvwHVVl3soLHFFNK1G+iZmJH/+PtlOZaOau4/8HyzgoUAEacm9xAuLzPyY17KdBbej/9sodz2jmsaoZEQ4h2pKkH+kFbNrWf4u5MbIcMD4vuwAma0ub5CaanccxI 3dzMBdOF Qh4/R8M02lQhr1bYuHWLLCpm4t18BJLBNFy1FhTkqPsXRHHHo2XP6F2DG0elOcDrEMkfXWrRzSn+pORqn/DqenwsqAE7rakUC6IiJfP2oiPL/5RylQIC038+8BZjmQc5kjcWgLShuZyhjU1bpjp1dpMTVIw== 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 Wed, Aug 14, 2024 at 04:48:42PM GMT, Yosry Ahmed wrote: > On Wed, Aug 14, 2024 at 4:42 PM Shakeel Butt wrote: > > > > On Wed, Aug 14, 2024 at 04:03:13PM GMT, Nhat Pham wrote: > > > On Wed, Aug 14, 2024 at 9:32 AM Shakeel Butt wrote: > > > > > > > > > > > > Ccing Nhat > > > > > > > > On Wed, Aug 14, 2024 at 02:57:38PM GMT, Jesper Dangaard Brouer wrote: > > > > > I suspect the next whac-a-mole will be the rstat flush for the slab code > > > > > that kswapd also activates via shrink_slab, that via > > > > > shrinker->count_objects() invoke count_shadow_nodes(). > > > > > > > > > > > > > Actually count_shadow_nodes() is already using ratelimited version. > > > > However zswap_shrinker_count() is still using the sync version. Nhat is > > > > modifying this code at the moment and we can ask if we really need most > > > > accurate values for MEMCG_ZSWAP_B and MEMCG_ZSWAPPED for the zswap > > > > writeback heuristic. > > > > > > You are referring to this, correct: > > > > > > mem_cgroup_flush_stats(memcg); > > > nr_backing = memcg_page_state(memcg, MEMCG_ZSWAP_B) >> PAGE_SHIFT; > > > nr_stored = memcg_page_state(memcg, MEMCG_ZSWAPPED); > > > > > > It's already a bit less-than-accurate - as you pointed out in another > > > discussion, it takes into account the objects and sizes of the entire > > > subtree, rather than just the ones charged to the current (memcg, > > > node) combo. Feel free to optimize this away! > > > > > > In fact, I should probably replace this with another (atomic?) counter > > > in zswap_lruvec_state struct, which tracks the post-compression size. > > > That way, we'll have a better estimate of the compression factor - > > > total post-compression size / (length of LRU * page size), and > > > perhaps avoid the whole stat flushing path altogether... > > > > > > > That sounds like much better solution than relying on rstat for accurate > > stats. > > We can also use such atomic counters in obj_cgroup_may_zswap() and > eliminate the rstat flush there as well. Same for zswap_current_read() > probably. > > Most in-kernel flushers really only need a few stats, so I am > wondering if it's better to incrementally move these ones outside of > the rstat framework and completely eliminate in-kernel flushers. For > instance, MGLRU does not require the flush that reclaim does as > Shakeel pointed out. > > This will solve so many scalability problems that all of us have > observed at some point or another and tried to optimize. I believe > using rstat for userspace reads was the original intention anyway. I like this direction and I think zswap would be a good first target.