Received: by 2002:a89:413:0:b0:1fd:dba5:e537 with SMTP id m19csp280968lqs; Thu, 13 Jun 2024 09:49:38 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVsvNUVSvzPJ16QpbcXGSRFCVaM65p7Q5tGEoczZ3plMq1l2Dh1lh7FTK8GZbBb4ZGXI1zp0grTL4l+CSYKf7dpaY4GMWfKVyT7Aryplg== X-Google-Smtp-Source: AGHT+IHtfkmPcKAEblqvyIAlXmiDpqvHrQbkSzYiQQ1LOeBu3Ob+bW8uzbU6blVfgH85g/69bb5a X-Received: by 2002:a05:6a20:3218:b0:1b5:cf6a:1883 with SMTP id adf61e73a8af0-1bae830020dmr338711637.62.1718297377860; Thu, 13 Jun 2024 09:49:37 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718297377; cv=pass; d=google.com; s=arc-20160816; b=H9U0FiwfjSTY/voTLNnL65PdKo8/s87vHFpw9R7Jd3xKHjDa1xl4VyDF6SasXtS0Xt B19H3LlWAYzD6lY9F/SW9uuiEDi9CkLKWIl4L8qWvAcz/pGQecTazHqTFnp1PgzsSxU7 vyDRNj9iC1J3HQKfLOkcvp53h9R4swbeI/u7Kid90NEBm+72iiQgTw2qPRXigYFPKLyZ md8ukfc+wnMjucPsWiMTFmaV7flPW40QqI70r0am0HSLr2yMOIbYf0b6b4KQJ3D8aZ8x JtqilfkJ8zK0r8PueFKMsX+QKZZv2Vv3whr/FiUosICPaunsHrCQCukh8OE2IYefk8KL CCOQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=wYZqS3WmpZ1OvyFzFMKzzNWnX5VrFLB0li+OWnNc9tk=; fh=/vv6gtrO94cCO6J72dqJM6fgUWS58RnN/k67sZP9mME=; b=n0nMsciYv/HJmJDgy9hVw51zFuBBpr+FLL2Bh+gvUX7Aosfsw0SGelzVQU9jnFLakM 69hGAvTmcdQHN6pyAw2lsCMWdo5RRpnNiq68bOWHP+6s3c8Q4HelQTTG6psvA2ny/zvD gpc8+G2w8Ld6on1tahURcw5kjHOYEnFc287Xx7rByDmXFic7NN9E1Q8qh1s7zDZ+bR8B XZ1CdVvJiV1OcQP7rJGFJopisYoJgmn2X+dHKSurZHgM1h5cnVCkjHGI0kr67bBTUX1L YxQzUFcqCOsxuNBToNF0gbq+BSW+Kh97lfjFziFMwBr42e5Y59t7B1jj+AEwVhAv0+u5 Q4kw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=lTDAk4co; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-213679-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213679-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id 41be03b00d2f7-6fee453c418si1654525a12.580.2024.06.13.09.49.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 09:49:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-213679-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=lTDAk4co; arc=pass (i=1 spf=pass spfdomain=linux.dev dkim=pass dkdomain=linux.dev dmarc=pass fromdomain=linux.dev); spf=pass (google.com: domain of linux-kernel+bounces-213679-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-213679-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 786AB28315E for ; Thu, 13 Jun 2024 16:49:37 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0FAF61339A4; Thu, 13 Jun 2024 16:49:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="lTDAk4co" Received: from out-183.mta1.migadu.com (out-183.mta1.migadu.com [95.215.58.183]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6B88E12EBE6 for ; Thu, 13 Jun 2024 16:49:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.183 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718297357; cv=none; b=okswqLD9JZJbeM+btyJ8fRF89nnN40nOwAGlVZ/9KZ3+PIGiOkCG2+wbwcYeAdrc/iAU2mZvOuYyS0ub0zsdTmX4Jdo5CP7rYTWtvlnJaAgZyNluyg/io5ZzHh8Hss5j5hhDK4opChiO5cayYiaVDnAFYKUbcFGsyjP47e3Hx/c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718297357; c=relaxed/simple; bh=DICBEk8onTRIhXycuenMRZ2If1US8PChQMniiIGYzF8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=s8QiMFAzrQaZdEmR6Rn5g/w3/MCNs1kj3531awBqKGyfO6pgspMCzJQvfRMj6o2p4ECHn4+wpDxUK6my8OTRbDzNcom6FuLiXG2x/tnh65o6MoHfmsP4VLmnxINDVHvs4AOJ2FLpa3SuPdxjIELUvkP5unAbczjURLfSmszIDa8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=lTDAk4co; arc=none smtp.client-ip=95.215.58.183 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev X-Envelope-To: nphamcs@gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1718297352; 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: in-reply-to:in-reply-to:references:references; bh=wYZqS3WmpZ1OvyFzFMKzzNWnX5VrFLB0li+OWnNc9tk=; b=lTDAk4coW1qoEqSDcrGUh77VX9j2ToBzIDmRD01DGlpZ2pVHQOSkG9HMrZUWcbzW7hp1ia ubqHXDB4O45iH/naEAOAuHIR1o6brS/DizNg2D09vDop/YnP1binzlzb0CGPMvXO1oDW7q t3sjoCaZwpP/bn3Iv10dVkKj4mCo+ik= X-Envelope-To: yosryahmed@google.com X-Envelope-To: flintglass@gmail.com X-Envelope-To: hannes@cmpxchg.org X-Envelope-To: chengming.zhou@linux.dev X-Envelope-To: corbet@lwn.net X-Envelope-To: akpm@linux-foundation.org X-Envelope-To: cerasuolodomenico@gmail.com X-Envelope-To: linux-mm@kvack.org X-Envelope-To: linux-doc@vger.kernel.org X-Envelope-To: linux-kernel@vger.kernel.org Date: Thu, 13 Jun 2024 09:49:06 -0700 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Shakeel Butt To: Nhat Pham Cc: Yosry Ahmed , Takero Funaki , Johannes Weiner , Chengming Zhou , Jonathan Corbet , Andrew Morton , Domenico Cerasuolo , linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v1 1/3] mm: zswap: fix global shrinker memcg iteration Message-ID: References: <20240608155316.451600-1-flintglass@gmail.com> <20240608155316.451600-2-flintglass@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=us-ascii Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT On Thu, Jun 13, 2024 at 08:04:39AM GMT, Nhat Pham wrote: [...] > > > > > > > > Is the idea here to avoid moving the iterator to another offline memcg > > > > that zswap_memcg_offline_cleanup() was already called for, to avoid > > > > holding a ref on that memcg until the next run of zswap shrinking? > > > > > > > > If yes, I think it's probably worth doing. But why do we need to > > > > release and reacquire the lock in the loop above? > > > > > > Yes, the existing cleaner might leave the offline, already-cleaned memcg. > > > > > > The reacquiring lock is to not loop inside the critical section. > > > In shrink_worker of v0 patch, the loop was restarted on offline memcg > > > without releasing the lock. Nhat pointed out that we should drop the > > > lock after every mem_cgroup_iter() call. v1 was changed to reacquire > > > once per iteration like the cleaner code above. > > > > I am not sure how often we'll run into a situation where we'll be > > holding the lock for too long tbh. It should be unlikely to keep > > encountering offline memcgs for a long time. > > > > Nhat, do you think this could cause a problem in practice? > > I don't remember prescribing anything to be honest :) I think I was > just asking why can't we just drop the lock, then "continue;". This is > mostly for simplicity's sake. > > https://lore.kernel.org/linux-mm/CAKEwX=MwrRc43iM2050v5u-TPUK4Yn+a4G7+h6ieKhpQ7WtQ=A@mail.gmail.com/ > > But I think as Takero pointed out, it would still skip over the memcg > that was (concurrently) updated to zswap_next_shrink by the memcg > offline callback. What's the issue with keep traversing until an online memcg is found? Something like the following: spin_lock(&zswap_shrink_lock); do { zswap_next_shrink = mem_cgroup_iter(NULL, zswap_next_shrink, NULL); } while (zswap_next_shrink && !mem_cgroup_online(zswap_next_shrink)); if (!zswap_next_shrink) zswap_next_shrink = mem_cgroup_iter(NULL, NULL, NULL); .... Is the concern that there can a lot of offlined memcgs which may cause need resched warnings?