Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp10590465rwd; Thu, 22 Jun 2023 01:58:02 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6rvNhMC5lSxfytDwEZM3QdOk0onQd0xdMYYqRkGJq8JeewUKGA0AhFX5CuXzVFAou87qEY X-Received: by 2002:ad4:5deb:0:b0:62f:e488:a458 with SMTP id jn11-20020ad45deb000000b0062fe488a458mr22394481qvb.0.1687424282465; Thu, 22 Jun 2023 01:58:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687424282; cv=none; d=google.com; s=arc-20160816; b=ayu65K+TmhokFAL+MLOjKZn63047nB1d9fH40DoWM2c/lVCbz2PZtr0p0O1uJTyKsa PXwYhGpQLwDpSLJIP84+wbYtBcQL9WL1snHtfjjeZN0kNWUlui36KiJWw8K2oQOwEeJ1 YkVcPESSe2feDx64xkQumIo2wdhBAg81slG9GZ61DRZ9rI+MdyXxawwN9voDPFKyp6F4 92T775qdMwANm6ilj/vmOBw4HJLTe+xJH2SJ1jVXgu89bwpwBTpEqn45nrguYEUmALPM AlnDSc7QHfV05Ghu53M99fAjj8tKS22NzfSzUEO1UqrQ+Ir7Xraa0oVzsfxzB6LZeVrM Ivpg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=161EjO+w9TmzA/a8qJytM8fXp/e7+Gx/R5PIlDH2uAk=; b=a4eM9/SSCmm16Yi11SUD08b+Pkb4eLsnDJ7R4MQbYP3qx2b88UrYiuiqlm9GZ6ssCb xf0NQ4DE3JST36a9lZoBL9N3od9tHvJtp1FdDxB1wNClVbL+D32whFN+csTPDciEQQ9S wBSLOqeh0d8cQM+H9d3nMB0TSLjgK5KYU6DpmJjUGfMBG43wxRheEA4BiI/0vA4Um6rf cD5mDjEuUEjz09+yyv42ZHTTwloSbuNprDACQ2qYUizQCKs4aaOK00qK6xr2VfLDHN2w J/ho7LO8CiQwzqhoHAsD9WTfkJacLqBcbNYhGGSK6vgeutS9CzosX2wKSXpGvGcy0eV8 S1mQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=VsUY2aig; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y196-20020a6264cd000000b00668718e54c6si5888946pfb.202.2023.06.22.01.57.50; Thu, 22 Jun 2023 01:58:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance.com header.s=google header.b=VsUY2aig; spf=pass (google.com: domain of linux-nfs-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-nfs-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231473AbjFVI5K (ORCPT + 99 others); Thu, 22 Jun 2023 04:57:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37490 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231512AbjFVIzX (ORCPT ); Thu, 22 Jun 2023 04:55:23 -0400 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B469A2137 for ; Thu, 22 Jun 2023 01:54:51 -0700 (PDT) Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-6664ac3be47so1328441b3a.0 for ; Thu, 22 Jun 2023 01:54:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1687424091; x=1690016091; 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=161EjO+w9TmzA/a8qJytM8fXp/e7+Gx/R5PIlDH2uAk=; b=VsUY2aigV4ZcD/zqH6R6qf5YjeDjgcBdr5DWNiFL+xj8FWQJXfxqjN+JjtQQqPUTZU y/hvwjl2otPmZYcL1mDMWeSCzXx77cZKx3CoOlix2I89OTP/XqbmazxkdkRcxT8IoFUn 2QEonOktxP7xKSbe3Xt0JkWeJ0vXY7bYmU0ntULjSwRJaXbaN1TAoEufMFnqYH3EWbZ2 epggxRJm4wrl127Vz5WoCbm7/HM2e7h8o7U+VP/mEnC0Icgf0KIm3PI/NPbIYz3ozq3C dpiJUcJ4yXe7UOxEIQJgQOohxTSbyOV1lnJIMgAbmswsZtfNIYimqUElkeBCjB3tvm0/ 8Aig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687424091; x=1690016091; 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=161EjO+w9TmzA/a8qJytM8fXp/e7+Gx/R5PIlDH2uAk=; b=bORhH/moZjGgx4d0YZddaqAx9xnbECk0SjlSUSlJS2FgWnarJw5LE8vXD2Be/dILy0 evimNkXrJDxCmXxdierakd8m+EPksQLlBc0ln5Bb1WydLlbK5jBr4qaDdJM2bBh9zP8R 9PuYzouNq1pjA1oKutEuZ8wqtdIplEuMyQjgzCNapXEQaCe340E5VkGdqu3xzYi2ghDf Zs63oG4jXLZh4IAQ2vpldxNOnBl9d5rmgdM7j7mK/xsuVOxzHQ/3zPg9EUT3OafCYGCv WjNhnHKBC9u1ROa4mQzrIB0T3jrv1/zz8go1I5EzGyeLxG/tAZz2vqmvWR+Lg3lQkEDS xtlw== X-Gm-Message-State: AC+VfDwa6UseEovLMxFhZsxA60HkZdV7MbrLCTtztBf93yizBqnRaQzA n5PyNMlvDDB2L9CvTXcMr2jwyg== X-Received: by 2002:a17:902:ea01:b0:1b3:e842:40a7 with SMTP id s1-20020a170902ea0100b001b3e84240a7mr20959635plg.1.1687424091188; Thu, 22 Jun 2023 01:54:51 -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.54.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jun 2023 01:54:50 -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 06/29] dm: dynamically allocate the dm-bufio shrinker Date: Thu, 22 Jun 2023 16:53:12 +0800 Message-Id: <20230622085335.77010-7-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 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-nfs@vger.kernel.org In preparation for implementing lockless slab shrink, we need to dynamically allocate the dm-bufio 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 dm_bufio_client. Signed-off-by: Qi Zheng --- drivers/md/dm-bufio.c | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/drivers/md/dm-bufio.c b/drivers/md/dm-bufio.c index eea977662e81..9472470d456d 100644 --- a/drivers/md/dm-bufio.c +++ b/drivers/md/dm-bufio.c @@ -963,7 +963,7 @@ struct dm_bufio_client { sector_t start; - struct shrinker shrinker; + struct shrinker *shrinker; struct work_struct shrink_work; atomic_long_t need_shrink; @@ -2385,7 +2385,7 @@ static unsigned long dm_bufio_shrink_scan(struct shrinker *shrink, struct shrink { struct dm_bufio_client *c; - c = container_of(shrink, struct dm_bufio_client, shrinker); + c = shrink->private_data; atomic_long_add(sc->nr_to_scan, &c->need_shrink); queue_work(dm_bufio_wq, &c->shrink_work); @@ -2394,7 +2394,7 @@ static unsigned long dm_bufio_shrink_scan(struct shrinker *shrink, struct shrink static unsigned long dm_bufio_shrink_count(struct shrinker *shrink, struct shrink_control *sc) { - struct dm_bufio_client *c = container_of(shrink, struct dm_bufio_client, shrinker); + struct dm_bufio_client *c = shrink->private_data; unsigned long count = cache_total(&c->cache); unsigned long retain_target = get_retain_buffers(c); unsigned long queued_for_cleanup = atomic_long_read(&c->need_shrink); @@ -2507,14 +2507,15 @@ struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsign INIT_WORK(&c->shrink_work, shrink_work); atomic_long_set(&c->need_shrink, 0); - c->shrinker.count_objects = dm_bufio_shrink_count; - c->shrinker.scan_objects = dm_bufio_shrink_scan; - c->shrinker.seeks = 1; - c->shrinker.batch = 0; - r = register_shrinker(&c->shrinker, "dm-bufio:(%u:%u)", + c->shrinker = shrinker_alloc_and_init(dm_bufio_shrink_count, + dm_bufio_shrink_scan, 0, 1, 0, c); + if (!c->shrinker) + goto bad; + + r = register_shrinker(c->shrinker, "dm-bufio:(%u:%u)", MAJOR(bdev->bd_dev), MINOR(bdev->bd_dev)); if (r) - goto bad; + goto bad_shrinker; mutex_lock(&dm_bufio_clients_lock); dm_bufio_client_count++; @@ -2524,6 +2525,8 @@ struct dm_bufio_client *dm_bufio_client_create(struct block_device *bdev, unsign return c; +bad_shrinker: + shrinker_free(c->shrinker); bad: while (!list_empty(&c->reserved_buffers)) { struct dm_buffer *b = list_to_buffer(c->reserved_buffers.next); @@ -2554,7 +2557,7 @@ void dm_bufio_client_destroy(struct dm_bufio_client *c) drop_buffers(c); - unregister_shrinker(&c->shrinker); + unregister_and_free_shrinker(c->shrinker); flush_work(&c->shrink_work); mutex_lock(&dm_bufio_clients_lock); -- 2.30.2