From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f173.google.com (mail-qk1-f173.google.com [209.85.222.173]) (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 09B4945D1AD for ; Thu, 23 Jul 2026 17:11:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.173 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784826709; cv=none; b=alfGJt/SA8lidHk5BE1aqG1bhXUqnhbM3bg4qWrTvB6a4gLwL57RrLjdfTygx58p8gAOme1Hq73FRB7yEOGAOz8q2MMTpajr/c4k4x9752pP7IqNtnlIch3ROM6dUWcVKEZM/l6FZIoXibobL6q1vnMh3SOFeI2ksPNfUjWA8qo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784826709; c=relaxed/simple; bh=tUTBnTpIFePxO3CeYW+TX9+SIeQSbzlag/dkm7OOyH0=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=l23k3hPUqLV7MM0ei/OpWu/EqN01afigF5Hk8IiYID+Xakm7YmRMqs5ocwS8tv1u79e4/OEZXmyjzG4bIwOJJCU4FCrWLQxQovvVEq6rDVwybyfe0KOovp4ovLdeRzMghPesIz/SJgwuTbZOIuMmrDBOflIry/Ghjld0m+F5MNk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org; spf=pass smtp.mailfrom=cmpxchg.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b=nSezCHZg; arc=none smtp.client-ip=209.85.222.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=cmpxchg.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=cmpxchg.org header.i=@cmpxchg.org header.b="nSezCHZg" Received: by mail-qk1-f173.google.com with SMTP id af79cd13be357-92e50979c71so117116685a.3 for ; Thu, 23 Jul 2026 10:11:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg.org; s=google; t=1784826702; x=1785431502; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to:content-type; bh=oKoEFKHAauD9ChUUVwq+5WmbWXEzRCLgc2RAxWNhYLo=; b=nSezCHZgvzUe4adwbOp3wXMp4Fnpo8guQmvCrsFBs0ZJVStaV9fveF+ysC8xNvMGvX lzsZeNnhvGM5gjkiUmyPgzEe2beqhVh84vemlD/4f8/wlxA6h/Vhy+GLNKPOYbvMpu+H MyZeln0CwvDPUnaZ+L/7KBvqnE++YMyq2rV8N3n7B9kswZQECgfsa0bZfjnn4NXfh7UF +vkPl9tKX7TnlhUQlmLT1xYdLWlOslxpZ+QGnK6thSaDXz8+khyijP/KDmLJFWnn0tAA uO+ikJAo4/KYqJlC2TX8kctS07e8sJk9/r7fqdJiKa4TeJqtz2IEI6Sj7379tXk3Oo5O hl6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784826702; x=1785431502; h=in-reply-to:content-transfer-encoding:content-disposition :content-type:mime-version:references:message-id:subject:cc:to:from :date:x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=oKoEFKHAauD9ChUUVwq+5WmbWXEzRCLgc2RAxWNhYLo=; b=BY6yTRh79W8CecOcTIIqtNc+Pt2785BXPTBfbNn0oYby+SVZNtK7nYauaGxDgM96KA CwlMsiNW0vfoC2V+YEWormM75s06gBQG6dcpdVAh2Sx+IgwmoLawYez+LltiFVYxXWTo Iu0X/rl18zWGavZJY0h97SPZO1bR4tn048EQCahMkii4cgZJpI5wyN8cYwy4N1kph29i P/BHqi3Dqi2z7fltBcB/Vhqt4Q5lEtfgPrO2k3hqX5txYxEFuuUkGZu1vjouDMLtn+SL 9uVDRzfZcbogrFsQ0Hgd9IZCG6yg1cVa0yqhuFYuv/qLHUneAv/5CwnL9IL+oATs12fO Y4uQ== X-Forwarded-Encrypted: i=1; AHgh+RqP5lxd/w1RIAmXcJi9gkNt82SJgT3t8ZrBlMOcp/Po5Kcg/M7GJZPlHudEvw010jgNTYSYdqoFkUZA1TY=@vger.kernel.org X-Gm-Message-State: AOJu0YzCKDIeyhwI2p80MKd9Y11Zm+XG06p0A5duSWjgu1uF+XX4x4Fj euuLhyBFi/53rCknWxqLicRiURFoN+9gCXMDp7n6gL/3OnNbvv5PF+C6mu7B0951YSQ= X-Gm-Gg: AR+sD13u9ACIXK0eqEyBZt1gvQ8zTL7MnlUysBPYEFKGjQ0b+M7JkKfed48GwURrqKp R771GAqHeMJf7LmqP2wvMicK8nq9nHdev2qe9OGhDaNFhKmPl4k24SaepN0uPLgWt6s8AbTzS8T 5j4kHz/vrT9x1OeFKsmtySsL9p7FilEgU1XydCNoOTNOceUtRSYFWpKOUpnTOXFNzX5hUBaI6pO +OMZuhFOyoYheoXXl+1/91BJWiROQpo9GvWanUMC8WxkdJjzlOQ1NNukkH9p21hTS+xa4Gl23x9 VlyR3brYo/5LOiG1rXV7/Tnth58ZSCgjSfaBookdX0+Sz2UeSvmlceu8z8ocp61xyM5FKGfLn7r cPn7x01EbZBV5yY1iQdCeSg6QLg8+HpJJQf+kNJyAx/2TYZB4fRV/AoLXo21yTYy5mbpOT2xdnF Mo X-Received: by 2002:a05:620a:1728:b0:92e:f3ca:2eaf with SMTP id af79cd13be357-93103907cd9mr404452485a.11.1784826702204; Thu, 23 Jul 2026 10:11:42 -0700 (PDT) Received: from localhost ([2603:7001:f100:500:365a:60ff:fe62:ff29]) by smtp.gmail.com with ESMTPSA id af79cd13be357-930f68743c8sm466141585a.7.2026.07.23.10.11.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Jul 2026 10:11:41 -0700 (PDT) Date: Thu, 23 Jul 2026 13:11:40 -0400 From: Johannes Weiner To: Yosry Ahmed Cc: Hao Jia , akpm@linux-foundation.org, tj@kernel.org, shakeel.butt@linux.dev, mhocko@kernel.org, mkoutny@suse.com, nphamcs@gmail.com, chengming.zhou@linux.dev, muchun.song@linux.dev, roman.gushchin@linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, Hao Jia Subject: Re: [PATCH v2 2/2] mm/zswap: Support batch writeback in shrink_memcg() Message-ID: References: <20260717085151.22822-1-jiahao.kernel@gmail.com> <20260717085151.22822-3-jiahao.kernel@gmail.com> 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-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Thu, Jul 23, 2026 at 09:39:35AM -0700, Yosry Ahmed wrote: > On Thu, Jul 23, 2026 at 6:55 AM Johannes Weiner wrote: > > > > On Wed, Jul 22, 2026 at 09:52:18PM -0700, Yosry Ahmed wrote: > > > On Wed, Jul 22, 2026 at 7:27 PM Johannes Weiner wrote: > > > > > > > > On Fri, Jul 17, 2026 at 04:51:51PM +0800, Hao Jia wrote: > > > > > @@ -1369,7 +1402,7 @@ static void shrink_worker(struct work_struct *w) > > > > > goto resched; > > > > > } > > > > > > > > > > - ret = shrink_memcg(memcg); > > > > > + ret = shrink_memcg(memcg, NR_ZSWAP_WB_BATCH); > > > > > /* drop the extra reference */ > > > > > mem_cgroup_put(memcg); > > > > > > > > > > @@ -1493,7 +1526,7 @@ bool zswap_store(struct folio *folio) > > > > > objcg = get_obj_cgroup_from_folio(folio); > > > > > if (objcg && !obj_cgroup_may_zswap(objcg)) { > > > > > memcg = get_mem_cgroup_from_objcg(objcg); > > > > > - if (shrink_memcg(memcg)) { > > > > > + if (shrink_memcg(memcg, 1)) { > > > > > > > > Why 64 for the global limit but only 1 for the cgroup limit? That > > > > seems arbitrary in multiple ways. > > > > > > I suggested that we keep the writeback here without batching and do > > > that change separately, mainly out of abundance of caution as > > > writeback is done synchronously here so the extra latency could be > > > problematic. I think we probably want to measure the performance > > > impact of that separately. > > > > > > That being said, this path is potentially too expensive anyway due to > > > the flush, but I would rather we do some basic measurements before > > > batching here. > > > > > > What do you think? > > > > It's not an unknown, right? We know this works for direct reclaimers, > > cgroup limit reclaim e.g., and what the latency implications are. > > > > Because of how reclaim works, we also know it'll call zswap_store() in > > batches of SWAP_CLUSTER_MAX. If we don't batch here, they're likely to > > each call shrink_memcg() once we're at the limit - while still risking > > rejections due to compressibility differences. > > > > My worry is that if we start with an inconsistency, we'll be stuck > > with it for a long time. > > > > I'd rather start with the clean, consistent version. Dial it back only > > if we have data to justfiy the complication that we can put into a > > comment and the changelog that outlines why exactly it's different. > > I am fine with doing that and basically always using NR_ZSWAP_WB_BATCH > as the batch size in shrink_memcg(), but I would be more comfortable > if we did some sanity testing. > > Hao, would you be able to do some smoke testing with NR_ZSWAP_WB_BATCH > used for all paths, and memory.zswap.max set in a way that induces > writeback? You can probably set memory.zswap.max to 1% of total memory > instead of the global pool limit and rerun the same test. Please just use SWAP_CLUSTER_MAX. That's what the reclaim side which issues the stores is also using for batching.