From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 9CA22369D60 for ; Fri, 24 Jul 2026 10:21:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784888462; cv=none; b=qbiccyr+lBiEzEVM21qzMvJXmwIyA0T4U+Y74O7mRtuEhymoXPkidcDk+qrONCf85N5JtVDG8IlnQGZ+RD72rS4WBGqcrI6YKrY+XXQ1SRyntJ/fLmYg4NuXuv/nMN0aqLG1h/XiW4pwFB84LPvEmH+yd709Emr9ULZ/aSERJYk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784888462; c=relaxed/simple; bh=A1tjyn8+UTrbbvmvprs57qwDcN/f/0G+E1vNReNaUFc=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=DIeY5jnlmn5JmS3TFMiutq9+amcChdb0daki7PFyRpLAx5uzXrj4wWo3FYwwjQXvc3t9xeVYVZ0AiA1yWbSSZKUgM8Vl0orIlLF4iLIsoFUTAgKFxD1CBatkcutF4GUDKtrrjxLqxI14+vq6Ht5fe0G8BF64YwoWAN5QEjjT8qc= 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=sXksBIxQ; arc=none smtp.client-ip=209.85.214.181 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="sXksBIxQ" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2ceed7018c8so1877935ad.1 for ; Fri, 24 Jul 2026 03:21:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784888461; x=1785493261; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:from:references :cc:to:subject:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to:content-type; bh=OHv4nBZUAA4QHT3/Nk9dUVsgZ03YSj5oD2kL/0soAWU=; b=sXksBIxQwaosZqAtvueCaqkvIckrU8lpTWKG7tmrerNG9BDKD9YFNlvOAaq+iYMIS0 bcdaBY6LhU+t+cYtEncexxVGNbdE2YpT/czR7dx3gC2+rj29juQTT0doGEat+Wh4Gp6L B8xEwBCanvlwi4Wt3XibwDJul6t6RGjM4HvCiTYw/QcK1wAcWkcjzlkwTUhwc+wnoSLp icRqXxNLVnUty8qCCCNFW696fztYxOc3Kyu6xnUMdcP/xlvmQxdYBn3Qn3zVeoIHxbKN PFAjLv0fkUeOkCJ2SWHjA0zNtXrttolIA7uyf1hEP4Krb4JqgOb9t3tXG8e2nHL8TYRE ahZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784888461; x=1785493261; h=content-transfer-encoding:content-type:in-reply-to:from:references :cc:to:subject:user-agent:mime-version:date:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=OHv4nBZUAA4QHT3/Nk9dUVsgZ03YSj5oD2kL/0soAWU=; b=pfI8v+DWfCKooqWZtFIfoI189pNuhpToFnb8KpW5Lx9eqBDr4y6eUP/86+9haZ3xpq VkmBOa1SA72ETPbd6VucXB9KYu3+t/YWGHoDPKuz9GTcWVno+N/qSTL7aHEy1G6UBSXt BnartfCCfK10TeFEZWDPVa07xcFvJz0Pud5Jfq6+GSiGesTxGBkv0QTCbVbIKn4zbUfX 7kngE6Y8WibTlYpfn9mp1BFXoOjRJuaKbnISR5Fqx59BeUSmiB/BLtdLJZrQNiJBQ1eu DZO31xeoSt7tf84XsQvc+XMmQGdjGL70Hq2bK30AxMArvR/2Tn1F+wlN6P5iGsn7lmDN q5eg== X-Forwarded-Encrypted: i=1; AHgh+RrZjLo2onPB7doAjOEOEoucM9fAwQYr7OMcgALKxGXDsnTiJsF6f+eke35tu5Gzi4rEOUnjQ4klzDHscqg=@vger.kernel.org X-Gm-Message-State: AOJu0YwWa15cFnEdF63h7Knb7TbHTZ0v2YKwMdO+DosoErfwr8ArFU5N niWmXx1JkT7oxzBTn3juuIs5WS6KbEImvwn2gMDJ6ZUxKLBEMtQmvYio X-Gm-Gg: AR+sD12wT/pWfgAJZv2O4/prBvVXG82+Zj4MhTkx3b91r8pnRcQFp6pKV2mybrde+cV eotAtsNya4UZdRv5E9SnAcYJI709oWiOS46f93UPnODGbZraq/AbDER8V9SEK9B7HqrcyYLWPLI QdES5GGH79vlRqvesd7HREEYLB34AkJjU3Nj5lnReFAj4EXGcx5nzooqaH2rCT2+SQtf4aQ7b12 ZwXMlNKQYPjRM9LhTPx6RXcJb+fgPvXFlkAoVvmH7RN5ApimRwtI2DScqG32vuLt9HM3FtyhvgI 9lnt6v1f1Ar2uPG+mMxRJXN3pwsjhP6kf6G22IF4kfRLbxNiy/ADD1XyK3uOw2cPNjH0FdqFDDg wRlOk0ZDotar9q0Y6rHSmU6O6eImWfYJS/2qaMLiF0xIMlwiqKQJr3nQpS0ZA2f2VbT69Rgf8Ua ASToq72CdbxQgqBy5xktmVjg== X-Received: by 2002:a17:903:2f88:b0:2cf:bf32:b754 with SMTP id d9443c01a7336-2cfbf32bf7amr33103845ad.8.1784888460802; Fri, 24 Jul 2026 03:21:00 -0700 (PDT) Received: from [10.125.192.96] ([210.184.73.204]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2cf8efa2cd0sm48812475ad.4.2026.07.24.03.20.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 24 Jul 2026 03:21:00 -0700 (PDT) Message-ID: Date: Fri, 24 Jul 2026 18:20:50 +0800 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: 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 v2 2/2] mm/zswap: Support batch writeback in shrink_memcg() To: Yosry Ahmed , Johannes Weiner Cc: 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 References: <20260717085151.22822-1-jiahao.kernel@gmail.com> <20260717085151.22822-3-jiahao.kernel@gmail.com> From: Hao Jia In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2026/7/24 00:39, 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. Building on Test Case 2, I set zswap.max=320M (~1% of total system memory) and updated both invocation paths of shrink_memcg() to process batches of 32 or 64. The resulting benchmark data is shown below. (Note: Test Case 2 also sets max_pool_percent=1.) baseline-cgroup batch-all-32-cgroup batch-all-64-cgroup shrink_worker wakeups 7,238 766 367 shrink_memcg calls 12,059,142 1,961,194 983,878 written_back 28,277 301,157 327,997 zswap_store calls 1,349,572 1,168,190 1,114,549 store succeeded 492,861 521,315 459,246 store rejected 856,712 646,875 655,303 store reject rate ~63% ~55% ~58% pool_limit_hit 510,130 50,096 57,715 pswpout 884,989 948,032 983,300 pswpin 1,251,268 1,638,668 1,878,453 Thanks, Hao