From patchwork Thu Aug 24 03:42:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qi Zheng X-Patchwork-Id: 13363493 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 B62FBC71145 for ; Thu, 24 Aug 2023 03:48:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 539742800A4; Wed, 23 Aug 2023 23:48:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4C2548E0011; Wed, 23 Aug 2023 23:48:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 33C5B2800A4; Wed, 23 Aug 2023 23:48:18 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 1EE188E0011 for ; Wed, 23 Aug 2023 23:48:18 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 037B41401B1 for ; Thu, 24 Aug 2023 03:48:18 +0000 (UTC) X-FDA: 81157615476.01.1BABA8C Received: from mail-oi1-f182.google.com (mail-oi1-f182.google.com [209.85.167.182]) by imf08.hostedemail.com (Postfix) with ESMTP id 0A36D160013 for ; Thu, 24 Aug 2023 03:48:15 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=kvKgrGQv; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.182 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1692848896; 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=cCUdhxTNgYopmfrUvm5tWP9/UPIt4enx1ZSflKLoeW0=; b=dSgnjzKT3TPP+drQRMO1yOhE92VfuZmdKaodIJo/RV89FFp3WZnE28XOeTk3rkv84SjfsR 5SSF8+fSc3ZAxzqmW0v7h/5d7JcEli2Exvf0SdiLLtQsSKe2vLjE7HgRnmVvuvnPUNcjou f8OqxqykcJDXWa6EkNOKMgQ4G9jfRV0= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=kvKgrGQv; dmarc=pass (policy=quarantine) header.from=bytedance.com; spf=pass (imf08.hostedemail.com: domain of zhengqi.arch@bytedance.com designates 209.85.167.182 as permitted sender) smtp.mailfrom=zhengqi.arch@bytedance.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1692848896; a=rsa-sha256; cv=none; b=6ekrDvTzAYtqqgcPrXR85TDcz6Bxi2htTPHTasvfEVxTUg2pznkMAZthI0if39zBOjQEfI xL92EeZsMRQH9SuZvGmX87HKIB27ShzqlBBDjaQuSnrRw34/ClbWBg9tpvgqJe+UJTXrlT 7PbA6zA553rJGmbnRUd3Hqnl72CDpvw= Received: by mail-oi1-f182.google.com with SMTP id 5614622812f47-3a86b1114ceso349537b6e.1 for ; Wed, 23 Aug 2023 20:48:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1692848895; x=1693453695; 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=cCUdhxTNgYopmfrUvm5tWP9/UPIt4enx1ZSflKLoeW0=; b=kvKgrGQv1mYZZS4wF3iCkRztwK2mmzphcIiXW0hKBcBmpcBvr4ErwgCDxT0L2eW0Zv DJtsfJPfQXVQjgbnZU8cUPbTUerpeh1mFrxeeqphvRnfm0XvYoY6wkXj976IEu2KPv8M UY81aGvh1S2CZkAubHr77TRlgVTQj3S+O6bIip73XKRxSzJ3mZvjOtnJ5IA9wdPa4ZiS bWHD8dtc86fBmv8R6Lmll8JjHXVoefuawXEuLIf69c5aeNKZ5HFce3zJFQbqcfZDtHTW 00qh3ZW5H0/jsYXIB/RBrVJBng/341ReHz9UooUbIAK8ltPn7oPpr+d+F95I3H7EoQOD 4xOA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692848895; x=1693453695; 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=cCUdhxTNgYopmfrUvm5tWP9/UPIt4enx1ZSflKLoeW0=; b=JPzL2r2jxTpuT5KKAwKHb03JOc2oJPLa6SOVKI61m6a9hFJ1MRG8KeqjRTsxufazuy o18vMqrPGfG+P+bo1tivbT4EqJWYmPCoo81Iv6OqXGPvqN77woMRJDeVJCL2d2Py17tA RIqtebjIMT5PWEISSQDjXr27RhXCKdvPzTRZVWL7x3vygdf1JdoOr4E1JkMKAnzrElZ4 7fXydDc8SvTfhOjd2ofxxroVhjbTDynvVvkkbM3qQonCuOWmxjOhIfoIpBxX/PAqbYSl RuC2q+EEnvFu3oqJo9OKefw+Ye1Z5ivG0KwATrcheeZPxdX1wsQ6NZPvEuJPtM2HChpD JK5w== X-Gm-Message-State: AOJu0Yy4KMvhoA8CQS4Fhbm8UB/Q4SYfOtIcRY8XSMQdnEZa9/052R5d hiEIM1tIUJJHBZevsni5Mv/4CA== X-Google-Smtp-Source: AGHT+IH2JbF6bibig8NYJYSBcTW5xuf5z4s3TwsXtyBJWRygTdPzsu3RVfUJVPK/hAkIo2xRy+AgMQ== X-Received: by 2002:a05:6808:180a:b0:3a7:8e1b:9d4f with SMTP id bh10-20020a056808180a00b003a78e1b9d4fmr16979066oib.3.1692848895236; Wed, 23 Aug 2023 20:48:15 -0700 (PDT) Received: from C02DW0BEMD6R.bytedance.net ([203.208.167.146]) by smtp.gmail.com with ESMTPSA id t6-20020a63b246000000b005579f12a238sm10533157pgo.86.2023.08.23.20.48.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 23 Aug 2023 20:48:14 -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, linux-fsdevel@vger.kernel.org, Qi Zheng , Muchun Song , Andreas Dilger , linux-ext4@vger.kernel.org Subject: [PATCH v5 30/45] ext4: dynamically allocate the ext4-es shrinker Date: Thu, 24 Aug 2023 11:42:49 +0800 Message-Id: <20230824034304.37411-31-zhengqi.arch@bytedance.com> X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: <20230824034304.37411-1-zhengqi.arch@bytedance.com> References: <20230824034304.37411-1-zhengqi.arch@bytedance.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 0A36D160013 X-Rspam-User: X-Rspamd-Server: rspam02 X-Stat-Signature: c6c73fu4wcokioh4swz8rrb49qco5b55 X-HE-Tag: 1692848895-724673 X-HE-Meta: U2FsdGVkX183nK757ZNyGV1/JUZ240TlOZd11xupHfrQi2AgHNAzYbA9oiSuYNzo6NAlWXfHbcEydMkkRknxfVdwrrUG+ltksK36SQDVTj1xL0jLKUZ65ddObGJMmAmu2ZJ8YwL7rs1TrR0mqa7G12tpj+iYGO7+oAufD9c9fJpHsKaeR40sQ7s1N5Ovqg1j9VdHveCitC+wlLztaXl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1FFnGydxiTwokP4N5NZ9H56pRRJ+l4nqXRalcYJAsIAcEaK74AeJKHywRNk2TXLVXGnRGPGLcTTv8QrM86eNlTT9tjHsNSzs+9w1rCcSXG7+ByTVeUiqpJuCAkaw22M8FyGuF1hWHNoxIJ/hcxhn7vq9ra5CP2mCmtJmKr5YjclBN7CjrQqbE0HswHTx9hEY3DjhCFPmyAPPK/5klUDLooNhaOW3SIH+a+OUQA== 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, use new APIs to dynamically allocate the ext4-es shrinker, so that it can be freed asynchronously via RCU. Then it doesn't need to wait for RCU read-side critical section when releasing the struct ext4_sb_info. Signed-off-by: Qi Zheng Reviewed-by: Muchun Song CC: "Theodore Ts'o" CC: Andreas Dilger CC: linux-ext4@vger.kernel.org --- fs/ext4/ext4.h | 2 +- fs/ext4/extents_status.c | 24 ++++++++++++++---------- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h index e5055eac42f6..353a7fcd609a 100644 --- a/fs/ext4/ext4.h +++ b/fs/ext4/ext4.h @@ -1653,7 +1653,7 @@ struct ext4_sb_info { __u32 s_csum_seed; /* Reclaim extents from extent status tree */ - struct shrinker s_es_shrinker; + struct shrinker *s_es_shrinker; struct list_head s_es_list; /* List of inodes with reclaimable extents */ long s_es_nr_inode; struct ext4_es_stats s_es_stats; diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 9b5b8951afb4..0532a81a7669 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -1596,7 +1596,7 @@ static unsigned long ext4_es_count(struct shrinker *shrink, unsigned long nr; struct ext4_sb_info *sbi; - sbi = container_of(shrink, struct ext4_sb_info, s_es_shrinker); + sbi = shrink->private_data; nr = percpu_counter_read_positive(&sbi->s_es_stats.es_stats_shk_cnt); trace_ext4_es_shrink_count(sbi->s_sb, sc->nr_to_scan, nr); return nr; @@ -1605,8 +1605,7 @@ static unsigned long ext4_es_count(struct shrinker *shrink, static unsigned long ext4_es_scan(struct shrinker *shrink, struct shrink_control *sc) { - struct ext4_sb_info *sbi = container_of(shrink, - struct ext4_sb_info, s_es_shrinker); + struct ext4_sb_info *sbi = shrink->private_data; int nr_to_scan = sc->nr_to_scan; int ret, nr_shrunk; @@ -1690,13 +1689,18 @@ int ext4_es_register_shrinker(struct ext4_sb_info *sbi) if (err) goto err3; - sbi->s_es_shrinker.scan_objects = ext4_es_scan; - sbi->s_es_shrinker.count_objects = ext4_es_count; - sbi->s_es_shrinker.seeks = DEFAULT_SEEKS; - err = register_shrinker(&sbi->s_es_shrinker, "ext4-es:%s", - sbi->s_sb->s_id); - if (err) + sbi->s_es_shrinker = shrinker_alloc(0, "ext4-es:%s", sbi->s_sb->s_id); + if (!sbi->s_es_shrinker) { + err = -ENOMEM; goto err4; + } + + sbi->s_es_shrinker->scan_objects = ext4_es_scan; + sbi->s_es_shrinker->count_objects = ext4_es_count; + sbi->s_es_shrinker->seeks = DEFAULT_SEEKS; + sbi->s_es_shrinker->private_data = sbi; + + shrinker_register(sbi->s_es_shrinker); return 0; err4: @@ -1716,7 +1720,7 @@ void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi) percpu_counter_destroy(&sbi->s_es_stats.es_stats_cache_misses); percpu_counter_destroy(&sbi->s_es_stats.es_stats_all_cnt); percpu_counter_destroy(&sbi->s_es_stats.es_stats_shk_cnt); - unregister_shrinker(&sbi->s_es_shrinker); + shrinker_free(sbi->s_es_shrinker); } /*