Received: by 2002:ab2:6f44:0:b0:1fd:c486:4f03 with SMTP id l4csp120372lqq; Wed, 12 Jun 2024 19:36:15 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCV3k/mVw3X+6RiL3eGMruEw8zgUAUoZ3i4hbZ6dNKAUYZ/Bq78iITx1p5Uthfv7CZiu6GSXe1CPM9/cGSVjOTj0Skdv/0s43BKMHA1jEg== X-Google-Smtp-Source: AGHT+IGZ/D9PKKp2wgMDST80kK6W68vmDfLJ95rGUn3kB9EloUH3DkcZN8/8vTrDE8197Pig87z4 X-Received: by 2002:a17:906:4685:b0:a6f:132a:2f9b with SMTP id a640c23a62f3a-a6f4800a162mr199584666b.65.1718246174971; Wed, 12 Jun 2024 19:36:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718246174; cv=pass; d=google.com; s=arc-20160816; b=SJCBzFIOCT/P+J5/wCCxhDOvYtsl/ebF8/L7heLCg8YoggIWS+W0L7Y1cKcPfBMHvd n0eNLZjSJh2wEPxA5s88EaVQs43I7ErWWhSGi62b+f6JFWefqaUvXZ8LevugdBu4/qgR AJVXajRAXiDzZqVACBbO0H/JKoZbrYQtyVC3Lt5p3bCEkCYEeeeqPIHsYg3xJKMHa/kp LcpQZS3LoK//UTuUDdesy7SmSWc2Lx0alpKDS1h3IfXVXDj+DpirEM+zeEGEa6YHa+w1 XPSLSm6bde9BkEegqUxCd6u2eNXgYXlOKw0UVfdahjl1X/FUBuh24jzf/RFf+YcZN5ka cIuw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=82RdtfxYrWWcM3I6B6y84KEkzZzezIo37YsjuYxzk9s=; fh=f0fmIZpb0ctfg6my84OY3/FXkGrYXzTf04FoVrcBd9c=; b=cKZfeb4qjuzNpZEEEXu34nB23B6CAdK7R14hAMtWYyBaOfrOAnXQOEBvFvdLmlFvge mDfL3onUcqZMo38oYPUflf/jnELhcABTQ2dbNawXmvxlbkDMGruTwoP+WOF6LnB4qxm0 M+dmJivJ3oUYAzSxdxCc0iBwc3wEG8NFL1kBcuIXKkROvt+uwsbthS8jv6Gvr5mGHffJ zLNm18HaKJOXVAOMhlZAW0cuesebJJ4Q3oR5Y953NxmGsW40//t9tKMIYAboP4svdpbT HHbB3pBSjwI5xOdevwJNTpeHb7z4XilLBmm3hZ63+1FsYZQzsRpm1HUFOc87FTaMvmlg 9r5A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=A0KGvJec; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-212498-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212498-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id a640c23a62f3a-a6f56d4d19fsi17944966b.246.2024.06.12.19.36.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 19:36:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-212498-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=A0KGvJec; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-212498-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212498-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com 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 am.mirrors.kernel.org (Postfix) with ESMTPS id AB1971F2218C for ; Thu, 13 Jun 2024 02:36:14 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 8AC1712B16E; Thu, 13 Jun 2024 02:36:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="A0KGvJec" Received: from mail-yb1-f182.google.com (mail-yb1-f182.google.com [209.85.219.182]) (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 5EEEB1756A; Thu, 13 Jun 2024 02:36:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718246169; cv=none; b=nXKBk1R7YWH0Nky3LpLMHyIjYJOFmmdaKByRxxJOC4umzqs/uH1OOkYaLqwUrmLUbBU5fdAlrRg6SSiNucEkaIbFtKGR1jQ1HEb+llfCpqZzhYkWOR/ZlwAQ7H0PiPs2ugBcY99TWCn2zBE737jOYQK6/q7bHhZL/oCqVDoOPqA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718246169; c=relaxed/simple; bh=Y6hdmKk2/Vk2ule0qdcuvwWu0NHntXbzPfcjRAUsj0w=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=jardV2CvAUNKhXMX88KVYrIo467a7yycANNCkPOYCrNkK50QG/gVA7OXZpsZZI+cU1kNogDgw7mR2THWZlgr/3Pcrk2Q3J5jukloWNud2wGjQlzUf7IUFLhfzHxjIRCw386nuC7HRbZ+gFYHep94DFUy1iYJrJ5QUErmPUtk+Ow= 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=A0KGvJec; arc=none smtp.client-ip=209.85.219.182 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 Received: by mail-yb1-f182.google.com with SMTP id 3f1490d57ef6-dfef7b13c98so636590276.0; Wed, 12 Jun 2024 19:36:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1718246167; x=1718850967; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=82RdtfxYrWWcM3I6B6y84KEkzZzezIo37YsjuYxzk9s=; b=A0KGvJecJWsmqk5qJOtlP/zTiZSscl2Xzo+o6v4yBWu4GfEtCDzXXLNHEB92GJOc7f w5eW+ZirlGw5H7+V5D/h8ZY9719/tJq2DLYY8PBlH5Gd/CumgLZYmq0jiRAq1jOZF0am jHKMKOJPAoKSyzDAZg/IG721Ndec/H7KYo5ot2LrVV3VOBwLCONU9hqBXZovdklYqFIz G6KZJ+yVN0Gz0Apym1CQzTp/ZBfYnzj+eWkNBpz1p7uAuLaDQvDGCluFGwcYaos8Zmlr XJ+nAZWNltA/iKYs2k230vFgh1FdK9GVuQvOxM3F06GwPhNN6uEXMxIycOTSIFVtRy84 yFZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718246167; x=1718850967; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=82RdtfxYrWWcM3I6B6y84KEkzZzezIo37YsjuYxzk9s=; b=dU5G9d90pZ8YTJkpymJFS2V/G8ieVXJf19I1MjJEKhkNrS6CFTT+biMq3vyjRBt0cV GJGauZDbGDjSMyqYNler6llcWC/OKbaYSaAIKTvvEmYiAsQAtgpvETTVY7lmZOM/R17N vv4bGoLDlDUTIVpataOO2kNGGS1RMae7K9/m8YgQNtgjZRS39SyEuUmSczwoO4EGAw6i 0zZzkR17lLGzzpK3EL2LZLUo6in4ad+TFDnDWGQZKS7t9DeEIza17GmcZdWeLW0xnTBU giUuOfCi+woFE6d93ei0f2AVOMeUPiNl105o3Agmjga4+zduANVe1sT6zEALl97NO3h2 dVVg== X-Forwarded-Encrypted: i=1; AJvYcCXKN+NPB2qCuBbfZhdj7SrdCW8eLGGLdFz8yQT1way+xNWWyMRXyTDiFHtCtK8ZaRmN290LinRL9ivRhlQg29jaX3hlitlmPy0jwYgo39aMU564VjPZuwC9x/gt7lrMlcyMGMpvI2uq X-Gm-Message-State: AOJu0Yxq4UaIBYoxhWMGFvHKy/txLx4w0mGkw+9KYb0J90SGSMa3rAcO Vasax7w1Q9ieTaaBz5rGI2Sl9AepUAy8cf55dYwA8NKgMZIDnGQKBScdCzrywhlW28XkyJDBaj/ U528OpUAM6CgEQWUKs7P2td55l5csAnksHD13AA== X-Received: by 2002:a25:d688:0:b0:dfa:5a37:41d0 with SMTP id 3f1490d57ef6-dfe65e7ec75mr3578791276.7.1718246167344; Wed, 12 Jun 2024 19:36:07 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240608155316.451600-1-flintglass@gmail.com> <20240608155316.451600-2-flintglass@gmail.com> In-Reply-To: From: Takero Funaki Date: Thu, 13 Jun 2024 11:35:56 +0900 Message-ID: Subject: Re: [PATCH v1 1/3] mm: zswap: fix global shrinker memcg iteration To: Yosry Ahmed Cc: Nhat Pham , Johannes Weiner , Chengming Zhou , Jonathan Corbet , Andrew Morton , Domenico Cerasuolo , linux-mm@kvack.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Shakeel Butt Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable 2024=E5=B9=B46=E6=9C=8813=E6=97=A5(=E6=9C=A8) 11:18 Yosry Ahmed : > > The corrected version of the cleaner should be: > > ```c > > void zswap_memcg_offline_cleanup(struct mem_cgroup *memcg) > > { > > /* lock out zswap shrinker walking memcg tree */ > > spin_lock(&zswap_shrink_lock); > > if (zswap_next_shrink =3D=3D memcg) { > > do { > > zswap_next_shrink =3D mem_cgroup_iter(NULL, > > zswap_next_shrink, NULL); > > spin_unlock(&zswap_shrink_lock); > > spin_lock(&zswap_shrink_lock); > > if (!zswap_next_shrink) > > break; > > } while (!mem_cgroup_online(zswap_next_shrink)); > > } > > spin_unlock(&zswap_shrink_lock); > > } > > ``` > > 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.