From nobody Wed Nov 27 22:37:10 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=quarantine dis=none) header.from=bytedance.com ARC-Seal: i=1; a=rsa-sha256; t=1690445672; cv=none; d=zohomail.com; s=zohoarc; b=Pte+GUxirTBoKNrW0b8IJCZARRw505HkEtNTwzoI3SJkIrTAcC/0K2WClMdk4tINnyAJArUsYleZ51tusyazETgMCbCPs5nCbqEE1fB9Tzp4FAzr5+oby+CywPzUR7C9wnghzCjqs/01iV65WiL3SHC4ZwXKBp60T0Oayg03240= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1690445672; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=sPvPF+4cfnCSPpn5pwfgQmnhLHHD8eUNQAmayNodhE0=; b=mhDvFV9+F7cpGwE/c4TKalMuaLFuUnMP/wd2bsMm10njq/pV39busE866M9fnsQQZNwdzbywgrPzeV8CXP5DtkY7GdMxl60ap2KrwacODM1jDULSo7aUVmFwNJ6tiIyjXeWMH/W7oXNVWja92gRslGvgNgsAf/swECTbvrWlu5I= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1690445672941828.4815146850414; Thu, 27 Jul 2023 01:14:32 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.570870.893268 (Exim 4.92) (envelope-from ) id 1qOw8U-0004Uc-AS; Thu, 27 Jul 2023 08:14:14 +0000 Received: by outflank-mailman (output) from mailman id 570870.893268; Thu, 27 Jul 2023 08:14:14 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOw8U-0004UT-7p; Thu, 27 Jul 2023 08:14:14 +0000 Received: by outflank-mailman (input) for mailman id 570870; Thu, 27 Jul 2023 08:14:12 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qOw8S-00033O-Hk for xen-devel@lists.xenproject.org; Thu, 27 Jul 2023 08:14:12 +0000 Received: from mail-pf1-x42e.google.com (mail-pf1-x42e.google.com [2607:f8b0:4864:20::42e]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 9042e661-2c55-11ee-8613-37d641c3527e; Thu, 27 Jul 2023 10:14:10 +0200 (CEST) Received: by mail-pf1-x42e.google.com with SMTP id d2e1a72fcca58-6748a616e17so183912b3a.1 for ; Thu, 27 Jul 2023 01:14:10 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.147]) by smtp.gmail.com with ESMTPSA id j8-20020aa78d08000000b006828e49c04csm885872pfe.75.2023.07.27.01.13.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Jul 2023 01:14:08 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 9042e661-2c55-11ee-8613-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1690445649; x=1691050449; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=sPvPF+4cfnCSPpn5pwfgQmnhLHHD8eUNQAmayNodhE0=; b=YUtSHImzHFhUVx7c3A38/9eSWP8Y2UYGj1FAohSpraRjdigKG79oH7xXGVv/st6Oxo VyXpyLT7a2poDQM1BLbe2YZ2f+F4NjGwYTjXKgOmjtdNRT3EltoPRUERX0NGCPGwABx/ guLbSxl8SczSn7UsZFsKIT2jSYiALWPELONV4dGxl+BgYW8LTo4BMAXY89ObnQ5bwB+z TeqwZ6TJLFD7PjgbTEQMgvSuaTCzQbN9MksnEsjGQ7GcxsQYflnPZl/UkK6mnnTiCX+x HfuT7U9+62kKpSnlvuoFhz2dd+gEGZ79L6Z5RTD7Q/dArvGRObCoRNap6LnHLL+kySjl YAWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1690445649; x=1691050449; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=sPvPF+4cfnCSPpn5pwfgQmnhLHHD8eUNQAmayNodhE0=; b=GfHz4XvKeE3MTcuEYCkRMEBmyP0muy2xMd551khM+m9BT6THIKZcyosOQDg5KNnSKp nRCP9HGohj2guoY8o8CSB4cPuPB+Q5pFiAJn4cFesAIvFSLnb4kVSGMf1mGqXwNYU8xK n+OhAkwwvWduEv0v8Yu5IsPcdTFETII+9wagG5NQ0EVPWNpABAl4Mr4eP/r9MgMhqqFF R7SVDFvtl3k8Tiq88h+QH1s452aP2W1p0HeWsZVyaMP0lTUzuAOrGB+Yb7Fp9vDYxu+M QSndin8naEhuZr2Whic7Z32Nu9Sh02EMG+DQkIPVX/LZbNkPEQsfV/saXoXrpaTFCJHE 8Qyg== X-Gm-Message-State: ABy/qLbncW7gy2siJANwwRni9h+/SwmkjOMGZi10XoJVhVHnAxxBCEZS GCYIwQAORUyN2hPuSpSxH3fUCA== X-Google-Smtp-Source: APBJJlHWG/nG8cYGh+bA6ihiUuY1h+OmDGzY+AfGFIW0cwXlJC7qa3aS8ftT4KQ6i8EuYK6gaQtAEg== X-Received: by 2002:a05:6a20:918e:b0:11a:dbb3:703b with SMTP id v14-20020a056a20918e00b0011adbb3703bmr5557054pzd.6.1690445649366; Thu, 27 Jul 2023 01:14:09 -0700 (PDT) From: Qi Zheng To: akpm@linux-foundation.org, david@fromorbit.com, tkhai@ya.ru, vbabka@suse.cz, roman.gushchin@linux.dev, djwong@kernel.org, brauner@kernel.org, paulmck@kernel.org, tytso@mit.edu, steven.price@arm.com, cel@kernel.org, senozhatsky@chromium.org, yujie.liu@intel.com, gregkh@linuxfoundation.org, muchun.song@linux.dev Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org, kvm@vger.kernel.org, xen-devel@lists.xenproject.org, linux-erofs@lists.ozlabs.org, linux-f2fs-devel@lists.sourceforge.net, cluster-devel@redhat.com, linux-nfs@vger.kernel.org, linux-mtd@lists.infradead.org, rcu@vger.kernel.org, netdev@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, dm-devel@redhat.com, linux-raid@vger.kernel.org, linux-bcache@vger.kernel.org, virtualization@lists.linux-foundation.org, linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, Qi Zheng , Muchun Song Subject: [PATCH v3 41/49] zsmalloc: dynamically allocate the mm-zspool shrinker Date: Thu, 27 Jul 2023 16:04:54 +0800 Message-Id: <20230727080502.77895-42-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230727080502.77895-1-zhengqi.arch@bytedance.com> References: <20230727080502.77895-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @bytedance.com) X-ZM-MESSAGEID: 1690445673975100001 Content-Type: text/plain; charset="utf-8" In preparation for implementing lockless slab shrink, use new APIs to dynamically allocate the mm-zspool shrinker, so that it can be freed asynchronously using kfree_rcu(). Then it doesn't need to wait for RCU read-side critical section when releasing the struct zs_pool. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song --- mm/zsmalloc.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index b96230402a8d..e63302e07c97 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -229,7 +229,7 @@ struct zs_pool { struct zs_pool_stats stats; =20 /* Compact classes */ - struct shrinker shrinker; + struct shrinker *shrinker; =20 #ifdef CONFIG_ZSMALLOC_STAT struct dentry *stat_dentry; @@ -2086,8 +2086,7 @@ static unsigned long zs_shrinker_scan(struct shrinker= *shrinker, struct shrink_control *sc) { unsigned long pages_freed; - struct zs_pool *pool =3D container_of(shrinker, struct zs_pool, - shrinker); + struct zs_pool *pool =3D shrinker->private_data; =20 /* * Compact classes and calculate compaction delta. @@ -2105,8 +2104,7 @@ static unsigned long zs_shrinker_count(struct shrinke= r *shrinker, int i; struct size_class *class; unsigned long pages_to_free =3D 0; - struct zs_pool *pool =3D container_of(shrinker, struct zs_pool, - shrinker); + struct zs_pool *pool =3D shrinker->private_data; =20 for (i =3D ZS_SIZE_CLASSES - 1; i >=3D 0; i--) { class =3D pool->size_class[i]; @@ -2121,18 +2119,24 @@ static unsigned long zs_shrinker_count(struct shrin= ker *shrinker, =20 static void zs_unregister_shrinker(struct zs_pool *pool) { - unregister_shrinker(&pool->shrinker); + shrinker_free(pool->shrinker); } =20 static int zs_register_shrinker(struct zs_pool *pool) { - pool->shrinker.scan_objects =3D zs_shrinker_scan; - pool->shrinker.count_objects =3D zs_shrinker_count; - pool->shrinker.batch =3D 0; - pool->shrinker.seeks =3D DEFAULT_SEEKS; + pool->shrinker =3D shrinker_alloc(0, "mm-zspool:%s", pool->name); + if (!pool->shrinker) + return -ENOMEM; + + pool->shrinker->scan_objects =3D zs_shrinker_scan; + pool->shrinker->count_objects =3D zs_shrinker_count; + pool->shrinker->batch =3D 0; + pool->shrinker->seeks =3D DEFAULT_SEEKS; + pool->shrinker->private_data =3D pool; =20 - return register_shrinker(&pool->shrinker, "mm-zspool:%s", - pool->name); + shrinker_register(pool->shrinker); + + return 0; } =20 static int calculate_zspage_chain_size(int class_size) --=20 2.30.2