From patchwork Thu Jun 22 08:53:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13288652 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 44E6AEB64D8 for ; Thu, 22 Jun 2023 08:56:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D89548D000D; Thu, 22 Jun 2023 04:56:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D38DC8D0001; Thu, 22 Jun 2023 04:56:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C022E8D000D; Thu, 22 Jun 2023 04:56:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id ADE238D0001 for ; Thu, 22 Jun 2023 04:56:46 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8F2C512010E for ; Thu, 22 Jun 2023 08:56:46 +0000 (UTC) X-FDA: 80929778412.06.B9BB00B Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) by imf19.hostedemail.com (Postfix) with ESMTP id AC2C21A0007 for ; Thu, 22 Jun 2023 08:56:44 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=E8DR3f2H; spf=pass (imf19.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687424204; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=uYJ0Isr1XZATX6JGPvTVuhl3oDZVpp/hY4/4gwVGW9E=; b=qzWs3RE+d52HXKZUY0bqwsx35FJ7b6NamigfiJH6THp90KFPMgGhD1mRVZJUgtGsm+wjBa FqSj5dS1o5muifOPTtJIflAPxCHzh7Be5WACxmx8yiHgrl8FnaSgHDzmChry/QmGNAW08x SotPz9THcu90EAIl9Sjfw8cH81+VxQI= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687424204; a=rsa-sha256; cv=none; b=1pqIGAp2SeqhYapYqgJMI68vt4MVuQ8o97vlZYl3rUdXEs2ibGnd4BcR+s+NyAp7k4a2Jk HlfM1w0t6w7onYpVmt05Nb8DmT5dv0RD6PvnhyU6Q5n1JRX1xQ2G8AbgoQeNwOGiejK6bv gfxDRkyWQCNr85qdOsnN4PtHZeYqSbo= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=E8DR3f2H; spf=pass (imf19.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.214.182 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1b693afe799so2466145ad.1 for ; Thu, 22 Jun 2023 01:56:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1687424203; x=1690016203; 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=uYJ0Isr1XZATX6JGPvTVuhl3oDZVpp/hY4/4gwVGW9E=; b=E8DR3f2Hoat1dr+eWUDbHZgFwAog/Y14Fyr901nadnjVcnG4wi/dzsYXue5lsR1fMf J4lGKXcngL6tZ98mDRA+meQDFEQqI8M8C2U7Jzsh+P5pb02lqX9x9oPIGG3MqGtcEQBd gtcaY6d5Wvcszm2wAYU1/GbNiI4/W6jf6+osdVtp14uPtbwdSj3xBB3cuLupxVd/0Bva 3aNVjboq1g3R8QF56ponf3Z0k9HzBLbK6msqxIkke8ZOuuk+1QHFYDcPM2BRj2r4DT2+ yfbsCvnlQ4hLgF8msig/7Mg+peyLnaUmJHbCBGncbsN2mdvtqIXKdXSMs3btfn7dPCo7 J6Zg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687424203; x=1690016203; 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=uYJ0Isr1XZATX6JGPvTVuhl3oDZVpp/hY4/4gwVGW9E=; b=K6rnnGK6eJw7GYG/jg42D76bMQKnZ+3jQFKMGO9BKqx7RugzMSzr5/HM3WEUmIlLpE 5CmeHP1BaeuQ5CGCnyD/qxG/6GWUwnig8pPCKVjoXeS1uqitVpF0gdNER1BUvm6EYtgd +bocJZHrqPpd2fdc1Rl255ceYHPMXjxJr/4zG2JCcyQis34XV4BSZgBWnPlGbQE3e5TI rOn8emnnIz/pEfNVctpfQW+k2VLJs/ic/YkdkuoXLd/EvlpaaQ+cL+GcwqVaevARe1F0 1S0V+7O8shp3uK0rxq62KWWUGMXz6cTmJqp30TF2slxOzGEJ+LreGRmm1pp0yv26Cfrq OXyQ== X-Gm-Message-State: AC+VfDxHeMxC0mznaqu83Y4V5reKOYNkTpQM2W/lyXBhEmyXI8JJfDJ6 FgJMFT2CTwXwU9FIympKnie1Lw== X-Google-Smtp-Source: ACHHUZ4t5WHqyo4ZYahXOm5IhQBts9kOj8de1dBmPyGeGIdQ3YL7Www59M51QQRN7AwqoJV6XrQ1Ww== X-Received: by 2002:a17:902:ea01:b0:1a9:6467:aa8d with SMTP id s1-20020a170902ea0100b001a96467aa8dmr21674286plg.1.1687424203648; Thu, 22 Jun 2023 01:56:43 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([139.177.225.254]) by smtp.gmail.com with ESMTPSA id h2-20020a170902f7c200b001b549fce345sm4806971plw.230.2023.06.22.01.56.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jun 2023 01:56:43 -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 Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, intel-gfx@lists.freedesktop.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-nfs@vger.kernel.org, linux-xfs@vger.kernel.org, linux-btrfs@vger.kernel.org, Qi Zheng Subject: [PATCH 20/29] zsmalloc: dynamically allocate the mm-zspool shrinker Date: Thu, 22 Jun 2023 16:53:26 +0800 Message-Id: <20230622085335.77010-21-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230622085335.77010-1-zhengqi.arch@bytedance.com> References: <20230622085335.77010-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: AC2C21A0007 X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: kka3hrcegmd7qg7fiw5xch3twybb7rb6 X-HE-Tag: 1687424204-610768 X-HE-Meta: U2FsdGVkX186CTqUwPbLyRKasEslYSWnTBeyMXhf3+qr1urEjNBaSyIUfYtCWADPp4y1Z3B4hpcdfssbtU9b6GKB27ih4IlRMchAjAFeMZU+183vFXx3nSXV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xXE/vCN/MtmI5K4PCjwMOBzBz5uHw1/90xScFqtMtkj6XVXsjMh8B7IIHI3HrZM4h0V0ew1t6V9BrXZPSsvkT/PNO2Y86g8t/c2pyQUZVmPcI9QTFM3xd0itAHn9xiQeJE8/nWJmeabGy84Z+eJgp468BSyTR0xNPvn9DryTCESLKPmDsiJZRJSZ3n1rWBlcZ/oT6B6mAJfRgpxlF454/a9p69/KCsRTHEzaHmGKi5ewIUqYulkOhyTX2ggwbnM= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: In preparation for implementing lockless slab shrink, we need 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 --- mm/zsmalloc.c | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 3f057970504e..c03b34ae637e 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -229,7 +229,7 @@ struct zs_pool { struct zs_pool_stats stats; /* Compact classes */ - struct shrinker shrinker; + struct shrinker *shrinker; #ifdef CONFIG_ZSMALLOC_STAT struct dentry *stat_dentry; @@ -2107,8 +2107,7 @@ static unsigned long zs_shrinker_scan(struct shrinker *shrinker, struct shrink_control *sc) { unsigned long pages_freed; - struct zs_pool *pool = container_of(shrinker, struct zs_pool, - shrinker); + struct zs_pool *pool = shrinker->private_data; /* * Compact classes and calculate compaction delta. @@ -2126,8 +2125,7 @@ static unsigned long zs_shrinker_count(struct shrinker *shrinker, int i; struct size_class *class; unsigned long pages_to_free = 0; - struct zs_pool *pool = container_of(shrinker, struct zs_pool, - shrinker); + struct zs_pool *pool = shrinker->private_data; for (i = ZS_SIZE_CLASSES - 1; i >= 0; i--) { class = pool->size_class[i]; @@ -2142,18 +2140,24 @@ static unsigned long zs_shrinker_count(struct shrinker *shrinker, static void zs_unregister_shrinker(struct zs_pool *pool) { - unregister_shrinker(&pool->shrinker); + unregister_and_free_shrinker(pool->shrinker); } static int zs_register_shrinker(struct zs_pool *pool) { - pool->shrinker.scan_objects = zs_shrinker_scan; - pool->shrinker.count_objects = zs_shrinker_count; - pool->shrinker.batch = 0; - pool->shrinker.seeks = DEFAULT_SEEKS; + int ret; + + pool->shrinker = shrinker_alloc_and_init(zs_shrinker_count, + zs_shrinker_scan, 0, + DEFAULT_SEEKS, 0, pool); + if (!pool->shrinker) + return -ENOMEM; - return register_shrinker(&pool->shrinker, "mm-zspool:%s", - pool->name); + ret = register_shrinker(pool->shrinker, "mm-zspool:%s", pool->name); + if (ret) + shrinker_free(pool->shrinker); + + return ret; } static int calculate_zspage_chain_size(int class_size)