From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f180.google.com (mail-oi1-f180.google.com [209.85.167.180]) (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 37AF53812F7 for ; Mon, 24 Aug 2026 21:31:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.180 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787607092; cv=none; b=RK1hqhCdiRSOD2MRhhkCqNEVktzlr2DbUZmo5vlcpH+bYgpMbGC5gysmyW39A9aIOwVoCVylCTpcWZR/ftvD0JUvHQShGJ0fq5uA8RWg5iFBFD9NAHEjp5j6L8J0bNWq1PdBzP4XwZ5+qwyuyIV9ZZz1oSzsFJbi1xjuu8AX8EM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787607092; c=relaxed/simple; bh=wZY3CZQXf2ac8DYGwJxJJwhkYcTevE4ky5EalI+ry2o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oYJbaTs8PfKtUob5RVXAAbf2bli7gUXCI4h+80cL9hBrFhMPHoR1E6otn0dMxlecXqd25lHwRa+jyQdAasSuL47CaUjHJKZYZKEX4+KEiyfvi3WkZarL1hnJoNsvzTicZBjnWenHVAAGbYOaelKvPIJbu10fz+KrGf/ygzCLKfA= 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=lFHGvc1B; arc=none smtp.client-ip=209.85.167.180 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="lFHGvc1B" Received: by mail-oi1-f180.google.com with SMTP id 5614622812f47-4a43c2a126fso1775391b6e.3 for ; Mon, 24 Aug 2026 14:31:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787607090; x=1788211890; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=FwuBEBnZB8YTVmGcPOdxFw7ZwLMAxP26w8gq8guPh/o=; b=lFHGvc1BnYhs5er9RJ8gfNpRUTrso7wRH2CilyO5IEZcKQp3qKsL/twDY2hfwE4oTw Hl11izCopIR07U33KvW8vA7iJq06y1pcMrxrCLfYOZfwd3KsbszCV3eBRFUuWXw0XbFz HcrUORn+Y7GRl5so/TQbwG3/kYsOXhlg0eKDcxuoL6cJmXNpMmw8WuKzN+wf+z9gFnxV PqXJawMWhGROWOZO+RPfQktHNvm5iQneVnJGYZmoHT6RMk6rfsU9GklQ3YtlfbpyR4Y8 kCxp+1p6t68Xcv41xr9C5byZ2202/kl9x5DImoD04XnshuMxiqyeDUzbNO4b5uON7G+1 oiaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787607090; x=1788211890; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=FwuBEBnZB8YTVmGcPOdxFw7ZwLMAxP26w8gq8guPh/o=; b=Fd/Zs03KvYRr8lyarY/4AxcvAkSHgBLrcq2x+4bPZhjUyoyP+UPmXyXY00yUcFhUEr y2Ko+8IX5sPMFCSShQhZRM+c2QDb9I49UhQ/rlIC9IcIlIY+1benAoSwsfX4wTH7Q2bB kA4hFFJNv3eGTWky6/PuZ7jkgBw8FWG1wDfn1fCI7VBR7d/wRy9IjW63fBu0FIK5zBDL 5AfB0JNUd9gSa5ECTTTlmo8s0Hj3rTQgQnnjpNL5tPuALFDs0XS5U0to4yyGhhWiFi3o Zz5KbJ8seftZipNrow9+tRxSJe2DyM8GK1xoJhyCb01zzsDYFyJZD2T8vrMMDjWm7z9I FC/g== X-Forwarded-Encrypted: i=1; AHgh+RrY1CWJENv+ikXeOE0QD7jPw1kAo1oSRWrnfhwevgTdMWA9aT804AcGrRkNEjxzJ2iJJ1mbLWsSSqseEQc=@vger.kernel.org X-Gm-Message-State: AFuF++nW77Wwm1pgnLuYi6NvFiPTOgioyUDq5ZrG2yBhAv0rNjhQ+pT+ JO+tcGs+L8hzSi2TfQIJbaWsQHXSxJivIdzI2dBq2yF9gS8ollA6Kody X-Gm-Gg: AR+sD11MQ5ZO6ZwcTpGTpfyKfHd3nGIToClEr8KH2snX0++CkipEgL7g3RboPb3ioIU 1p7UWkDaNMp2UciipZjmiNwtiRpTYXqZwJHihqwQ4VNxuyz4FrJjxxo+EQCZ2YDywzcQMc9DSOz gpQq5nBl+OlNMZwhmblpRtzBQKG57vbhPMn95jw0AQL9y+apaDh3C/jcwg7HB7Hn/EMTMWoMuVe IDoWvLLtux7HDOd+C+nZM3TBimE3hz6nuGZKL6SPSh2LyPJYI+pgeAv/cGkcNh7un+h6HElUvD/ m/iq1QuYbIG1jK7eku+bW5O7WcyyISixPgopDEO0ay4dIMz/4OCuaLkh8yZC1waA7fsaW/9KV/r EIy7h2wTiH0KgKQ2JDZMLdTp/Qzkix7TF9FB98q7fAQCxVAlyuV8Cf3UVbCSKiKnepUZtmF7Cbr QoIl1vs6F/6s+zm5faj8SpRvEwkMcKEvFE4y8I6Z/hW4TV0SCrVjE1AbxUwsULTmpHuHQALrEgv 50TFj5u+mHJVQloM9M= X-Received: by 2002:a05:6808:1b0c:b0:4a4:744:a4ff with SMTP id 5614622812f47-4b30998976bmr18801430b6e.4.1787607089949; Mon, 24 Aug 2026 14:31:29 -0700 (PDT) Received: from localhost ([2a03:2880:10ff:23::]) by smtp.gmail.com with ESMTPSA id 5614622812f47-4b32c64a07bsm3949888b6e.4.2026.08.24.14.31.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Aug 2026 14:31:29 -0700 (PDT) From: Joshua Hahn To: Joanne Koong Cc: Yosry Ahmed , Song Hu , Shakeel Butt , akpm@linux-foundation.org, linux-mm@kvack.org, cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, hannes@cmpxchg.org, nphamcs@gmail.com, chengming.zhou@linux.dev, yunzhao@cloudflare.com Subject: Re: [PATCH] mm: memcg: use ratelimited stats flush in obj_cgroup_may_zswap() Date: Mon, 24 Aug 2026 14:31:25 -0700 Message-ID: <20260824213127.2783019-1-joshua.hahnjy@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On Thu, 20 Aug 2026 15:18:39 -0700 Joanne Koong wrote: > On Tue, Aug 18, 2026 at 11:35 AM Yosry Ahmed wrote: > > > > On Mon, Aug 17, 2026 at 6:53 PM Song Hu wrote: > > > > > > > > > > > > 在 2026/8/18 00:04, Shakeel Butt 写道: > > > > On Mon, Aug 17, 2026 at 09:18:43PM +0800, Song Hu wrote: > > > >> obj_cgroup_may_zswap() runs on every folio swapped out through > > > >> zswap. For each ancestor with a non-max zswap.max, it flushes the > > > >> cgroup rstat hierarchy synchronously with force=true, which skips > > > >> the ratelimit inside __mem_cgroup_flush_stats(). In a swap storm > > > >> with zswap.max configured, a container takes the global rstat lock > > > >> on every swapped-out folio. > > > > > > > > Any reason you are limiting zswap through zswap.max? > > > > > > > > > > Mostly fairness on a shared pool: zswap.max_pool_percent is global > > > only, so on a multi-tenant host one cgroup's cold anonymous memory > > > can soak the pool and crowd out the others. zswap.max is the only > > > per-cgroup control over that share; memory.max bounds the total > > > footprint, not the share of the pool. > > > > > > >> > > > >> zswap_shrinker_count() had the same pattern and switched to > > > >> mem_cgroup_flush_stats_ratelimited() in commit ea80da363a1f > > > >> ("mm/zswap: use ratelimited stats flush in zswap_shrinker_count()"), > > > >> where the same flush on the shrinker side showed up at 2.88% of > > > >> kernel cycles under osq_lock on a 96-core machine. > > > >> > > > >> Measured on a KVM guest with a swap storm under a cgroup with > > > >> zswap.max set: obj_cgroup_may_zswap() was entered 198,977 times > > > >> before the patch and 198,968 times after, while > > > >> __mem_cgroup_flush_stats() was entered 281,017 times before and > > > >> 80,445 times after. The removed 200,572 flushes match the store > > > >> attempt count almost exactly; the remainder comes from other stats > > > >> readers in the swap path. > > > > > > > > This is a known issue. Using ratelimited interface also comes with a drawback > > > > that the kernel may react on stale information and the consequences might be > > > > unneeded oom-kills. > > > > > > > > There was orthogonal discussion on moving zswap limit enforcement away from > > > > rstat. Yosry, any updates on that? > > > > I am not actively looking into that, but Joanne was looking into > > AFAICT. I will respond to the thread there and CC Song as well. > > > > For this zswap stat, I ran some benchmarks comparing 4 approaches > (switchable behind a runtime knob [1]): > a) rstat + forced flush (baseline aka what the tree does today) > b) rstat + ratelimited (Song's proposal) > c) hierarchical per-CPU (Yosry's idea from [2]) > d) page counters (following what all the other memcg limits do) Hi Joanne, I hope you are doing well! Thank you for running all these experiments. I'm not biased in any direction but I was curious what you did for the page counter implementation. The reason I am asking is because I am working on making page counters more scalable / performant by pushing the memcg stock down to the page counter level [3]. I wonder if the caching that stock provides can give (d) an upper hand over (c). This is just an idea though, and I think this would depend on how your (d) implementation looks like. Sorry that I joined in this conversation late : -( Thanks again, Joanne! Joshua [3] https://lore.kernel.org/all/20260623180124.868655-1-joshua.hahnjy@gmail.com/ (It's been a while since v4, I got a little sidetracked working on the tiered memcg series. I have a v5 ready to go, just waiting on some running some tests before sending it out.)