From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 917E2C48BC4 for ; Tue, 20 Feb 2024 03:24:14 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1DC636B007B; Mon, 19 Feb 2024 22:24:14 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 18D5F6B007E; Mon, 19 Feb 2024 22:24:14 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 054CC6B0081; Mon, 19 Feb 2024 22:24:14 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id EA8596B007B for ; Mon, 19 Feb 2024 22:24:13 -0500 (EST) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 92179C04B0 for ; Tue, 20 Feb 2024 03:24:13 +0000 (UTC) X-FDA: 81810738786.08.32DE46D Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by imf09.hostedemail.com (Postfix) with ESMTP id DC47B140005 for ; Tue, 20 Feb 2024 03:24:09 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=aod6GteC; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf09.hostedemail.com: domain of zhouchengming@bytedance.com designates 209.85.210.181 as permitted sender) smtp.mailfrom=zhouchengming@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708399451; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=7hf1JftyPCJ/e/S2Ajsn23dPixx108Nels4BBRFt3s8=; b=L4f0H9svcfI5nDmqBT2pHapAX+Inh6PTDXtn5kfSqhDj2UbHDd7+dNm2Tp+gb8FyECsET3 KrP00cAGIpo4l7xqWaL8M1N0kgGyLCLIuMhOVFJbt4S+l3SXpDr7oNuGs3aEyIhZA6d2VO B1hfLpsEjmBasdYvLeS4mlqK1uAAFiI= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=aod6GteC; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf09.hostedemail.com: domain of zhouchengming@bytedance.com designates 209.85.210.181 as permitted sender) smtp.mailfrom=zhouchengming@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708399451; a=rsa-sha256; cv=none; b=5l+Yy3qfracKkFBhmzh1mWPsHZsch7SLUYNFinoBadYDKeLvfQIKKq+lJdB5Ie/IXYd5zV vcpaiaH0y5cCJbb8q7I4TMQ2KxIxRb8RAWEaWKLvjTQ2SAqICMAcVDYkaV+pdG/QiWmbjn mlQvzJ1CJ2FDdBzqcfT1pV1oWluCWpo= Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-6e471f5f1a5so672883b3a.1 for ; Mon, 19 Feb 2024 19:24:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1708399448; x=1709004248; darn=kvack.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=7hf1JftyPCJ/e/S2Ajsn23dPixx108Nels4BBRFt3s8=; b=aod6GteC6JG1gfPflcBdVmsg0eEIZ4nzztXIxZaJ1nzQbtH5sf6Pf0HnN5dAmYc80c /aurmuUgqpDW4pMktQNI+CkR4a84Kk4g8kkNDIqmD5xKT9WDCbA1Pu/XWznJtmMqtWFN X6WpwMvKJhCrXb+acfrc/8rwvnHoCS5mtB3opzzbQYDYnBHdhFajvvWkaVg+hqB2qVQ0 umveGfqsXv74hz1cK6qREcWbo4x4CMhJWi78+tskBz/PNClQBsnPvsyBga6ifXHe7Tw6 o+yEhacyltObXa501TqIwPreUfk+OP6OjfDQWRZSfp+tkeHIKzN5S5wturzKUy0pWCu2 egEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708399448; x=1709004248; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=7hf1JftyPCJ/e/S2Ajsn23dPixx108Nels4BBRFt3s8=; b=mD1wuj+qcErNvMOFITYicGB+6m2HE4916i1WVRbADP0YXD/3IplHO7uS5M/Sj+uhVg +K2syP7ptQjwBzTxWX7IT21A1TnD2fhagKFZMm60ST4/sLi8bW39JdouwTQQhAjX4vC5 jtWibN1/QJG3+2k0bXmucL7TbVa5o+owYAMLvy+VZk0Od1XaQbbVmEWcrzCSSmtV4Nbc a8mQQALrBWD6ERzoYlUXOfMOYloPltRyN74a8/DrYk/13gqWakyOBMQTUTOXt50EqXTO PBu/UUW38qHHa7SXPpMxvtCpPo/d2dHsvp62oADHE/nHYlEjEZoZNTg8kTI9ZbAWefpq 0wow== X-Forwarded-Encrypted: i=1; AJvYcCVif1Sag9rT4ge+aL6YHzLQmCXhsNfNAuwDykG0h/amEM+Qx0FUoIj5js/j7eIXIOob2z912rPok423o3LHbJj6PHg= X-Gm-Message-State: AOJu0YwaeBdeQskMmzh6bpWrqBdBFa9ZhS3HQr5PFMqCvT0uGiMr5/Eg DotsBQ4Pw0OhUsz8KGTVTTscs+0q1kPWQIxh8IvXzA5L6t/seF8w9/xZCzcPpBI= X-Google-Smtp-Source: AGHT+IEJ0H3EvdJYSoSpOLcIAdWmBhK4wZEzXFXYvaGjt3+9rPnc32Q0j1sI1CuxMkQoznN7vItrSA== X-Received: by 2002:a62:cd82:0:b0:6e4:3ea4:a7e1 with SMTP id o124-20020a62cd82000000b006e43ea4a7e1mr3625483pfg.27.1708399448424; Mon, 19 Feb 2024 19:24:08 -0800 (PST) Received: from [10.254.117.3] ([139.177.225.234]) by smtp.gmail.com with ESMTPSA id n3-20020aa79843000000b006e319d8c752sm5143715pfq.150.2024.02.19.19.24.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 19 Feb 2024 19:24:08 -0800 (PST) Message-ID: <03b83a30-742e-4885-a478-d3dadf444de2@bytedance.com> Date: Tue, 20 Feb 2024 11:24:03 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3 1/2] mm/zswap: global lru and shrinker shared by all zswap_pools Content-Language: en-US To: Nhat Pham Cc: Johannes Weiner , Yosry Ahmed , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20240210-zswap-global-lru-v3-0-200495333595@bytedance.com> <20240210-zswap-global-lru-v3-1-200495333595@bytedance.com> From: Chengming Zhou In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: DC47B140005 X-Stat-Signature: p979ysxn8jjqebt7z5jz7o1ooh5pecuw X-HE-Tag: 1708399449-20368 X-HE-Meta: U2FsdGVkX18g45tUNMrotR5oqPdOpR4uw2rpykHrlN9huoX8ybKhn9v6C/o9Qbvx61AdXKmtsQvrCgCLKAqhLdzceUOEzxa5L475QaiD5TRt/rQ6raASbI9kIKmILctQPzY0uC5cjlEcBttiL7S+sWvveAkksI7rz9zuyBR566piNSLfLOK3r0kYJgOsFVAZ9gRsPjPhNK0SuDON2pcoYQStxsQv/OCv4qaRSPn+m5Rtabe6xy4Xy4d3ucyk1QEtaLHy99dvbdV34nXpN4uDywTPvd0L2DebkoJ9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K+J+kgZRWqQBtMTAINFmCHPYpWgwQIB9zBlC0VP4Jx4Xg1OHN5X/YHZbSCXsAMlSSvoNtO8MrFCJWGlnNpPO6a/VpnOiqq17T66ouXvuM4ALimEna2TbmYWhLHALk4+eN4o1ITpX3tqgoV3LLEDxcawWmX4b641lhNnDJN2BXvm6O4Eg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000007, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On 2024/2/20 09:28, Nhat Pham wrote: > On Fri, Feb 16, 2024 at 12:55 AM Chengming Zhou > wrote: >> >> Dynamic zswap_pool creation may create/reuse to have multiple >> zswap_pools in a list, only the first will be current used. >> >> Each zswap_pool has its own lru and shrinker, which is not >> necessary and has its problem: >> >> 1. When memory has pressure, all shrinker of zswap_pools will >> try to shrink its own lru, there is no order between them. >> >> 2. When zswap limit hit, only the last zswap_pool's shrink_work >> will try to shrink its lru list. The rationale here was to >> try and empty the old pool first so that we can completely >> drop it. However, since we only support exclusive loads now, >> the LRU ordering should be entirely decided by the order of >> stores, so the oldest entries on the LRU will naturally be >> from the oldest pool. >> >> Anyway, having a global lru and shrinker shared by all zswap_pools >> is better and efficient. >> >> Acked-by: Yosry Ahmed >> Signed-off-by: Chengming Zhou >> --- >> mm/zswap.c | 171 ++++++++++++++++++++++++------------------------------------- >> 1 file changed, 66 insertions(+), 105 deletions(-) >> >> diff --git a/mm/zswap.c b/mm/zswap.c >> index 62fe307521c9..d275eb523fc4 100644 >> --- a/mm/zswap.c >> +++ b/mm/zswap.c >> @@ -176,14 +176,19 @@ struct zswap_pool { >> struct kref kref; >> struct list_head list; >> struct work_struct release_work; >> - struct work_struct shrink_work; >> struct hlist_node node; >> char tfm_name[CRYPTO_MAX_ALG_NAME]; >> +}; >> + >> +static struct { >> struct list_lru list_lru; >> - struct mem_cgroup *next_shrink; >> - struct shrinker *shrinker; >> atomic_t nr_stored; >> -}; >> + struct shrinker *shrinker; >> + struct work_struct shrink_work; >> + struct mem_cgroup *next_shrink; >> + /* The lock protects next_shrink. */ >> + spinlock_t shrink_lock; >> +} zswap; > > nit: Is there a reason why we're putting these in a struct instead of > just a bunch of static variables (perhaps prefixed with zswap?) No reason, both is ok for me. I thought there should be no difference. But I can change to static variables if it's preferred in kernel. :)