Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp587358ybl; Wed, 28 Aug 2019 02:22:27 -0700 (PDT) X-Google-Smtp-Source: APXvYqyURNsItOZmlo0gS1tISOIvbTCbgTT4PqLeLK8R7oP+whOWu4HunrUbLCBj19o/hE6vFMJi X-Received: by 2002:a17:90a:a78b:: with SMTP id f11mr3349153pjq.16.1566984147156; Wed, 28 Aug 2019 02:22:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566984147; cv=none; d=google.com; s=arc-20160816; b=gyj2CrWzU6lBybLdkDerBVT8Y3reanD7Rf3dCliOpVdf2VH6DyEsRZx2cf8Mb1CUQS YFvt5yhqoHN9yc56wlNC+WU4k7uoU8EulMY8Oql7qb034cYgdPWG94Z/zMiBO3ZCKlqb kxCNKSl8EfO79vbJsBoHPiPfFzIfcLAtryyKIV6h3fpAiPKVEieKSBjISWJhWQ1jD8sS osZVEoe8yp4jA/E9tYMo+k1YgZMpChklx4SzKBINq71qCu+b1nJpJtPrsGixYtse5X7W 31T8D9+RttmYaCH4Z1TO6Fsnh3YnSpM9+M5iB6QGTTthxvBLzYR9UIxU/QAZfkYcAX4M Hmqg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=8UncF1cgFdg4Sajv84EeBBk0lKmuZVUNqZfyJvm2mEo=; b=eDDcSWwAIXQ+Y9AQCrcwwbmFYsBkERCbHUJBb6ZV2MWQjWzSb4QgjNsAYxmQ+2tpFa sngHO/XUaHs7PWoG450j3Z25DcjVhotJFMk2kVB+gdKa0kvthRuGQiEol9FKLx8CBbxf C9MYn1ZE1yXgbrfafFQvpDLG7wC5EDun6iWLlvSclUivOsGbdQPaMzfis7z+EoLXpVeO XrIhTItv4Z2+K2Li2K7dp/Yv8kPqmzpayJhz+EKDkhNJMujtacMgbzOqGtSbPB/66tbL /ZJyFDQgbjp/IMzs5fzIQhk1TnJvFmbWlB/nDbLb5TnHqFeGVOaUFNcYTyz8M4zvb2kq GuKw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g31si1447545plg.233.2019.08.28.02.22.02; Wed, 28 Aug 2019 02:22:27 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-ext4-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726462AbfH1JVq (ORCPT + 99 others); Wed, 28 Aug 2019 05:21:46 -0400 Received: from szxga05-in.huawei.com ([45.249.212.191]:5230 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726370AbfH1JVq (ORCPT ); Wed, 28 Aug 2019 05:21:46 -0400 Received: from DGGEMS405-HUB.china.huawei.com (unknown [172.30.72.58]) by Forcepoint Email with ESMTP id 3658594782EB051B2335; Wed, 28 Aug 2019 17:21:42 +0800 (CST) Received: from localhost.localdomain (10.67.212.132) by DGGEMS405-HUB.china.huawei.com (10.3.19.205) with Microsoft SMTP Server id 14.3.439.0; Wed, 28 Aug 2019 17:21:32 +0800 From: Shaokun Zhang To: , CC: Yang Guo , Theodore Ts'o , "Andreas Dilger" , Eric Biggers , Shaokun Zhang Subject: [PATCH v2] ext4: use percpu_counters for extent_status cache hits/misses Date: Wed, 28 Aug 2019 17:19:17 +0800 Message-ID: <1566983957-6608-1-git-send-email-zhangshaokun@hisilicon.com> X-Mailer: git-send-email 2.7.4 MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.212.132] X-CFilter-Loop: Reflected Sender: linux-ext4-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-ext4@vger.kernel.org From: Yang Guo @es_stats_cache_hits and @es_stats_cache_misses are accessed frequently in ext4_es_lookup_extent function, it would influence the ext4 read/write performance in NUMA system. Let's optimize it using percpu_counter, it is profitable for the performance. The test command is as below: fio -name=randwrite -numjobs=8 -filename=/mnt/test1 -rw=randwrite -ioengine=libaio -direct=1 -iodepth=64 -sync=0 -norandommap -group_reporting -runtime=120 -time_based -bs=4k -size=5G And the result is better 10% than the initial implement: without the patch,IOPS=197k, BW=770MiB/s (808MB/s)(90.3GiB/120002msec) with the patch, IOPS=218k, BW=852MiB/s (894MB/s)(99.9GiB/120002msec) Cc: "Theodore Ts'o" Cc: Andreas Dilger Cc: Eric Biggers Signed-off-by: Yang Guo Signed-off-by: Shaokun Zhang --- ChangeLog: Fix the issue that there is no percpu_counter_destroy() for the new percpu counters. fs/ext4/extents_status.c | 37 ++++++++++++++++++++++++------------- fs/ext4/extents_status.h | 4 ++-- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/fs/ext4/extents_status.c b/fs/ext4/extents_status.c index 7521de2dcf3a..3c03062a8d6a 100644 --- a/fs/ext4/extents_status.c +++ b/fs/ext4/extents_status.c @@ -947,9 +947,9 @@ int ext4_es_lookup_extent(struct inode *inode, ext4_lblk_t lblk, es->es_pblk = es1->es_pblk; if (!ext4_es_is_referenced(es1)) ext4_es_set_referenced(es1); - stats->es_stats_cache_hits++; + percpu_counter_inc(&stats->es_stats_cache_hits); } else { - stats->es_stats_cache_misses++; + percpu_counter_inc(&stats->es_stats_cache_misses); } read_unlock(&EXT4_I(inode)->i_es_lock); @@ -1235,9 +1235,9 @@ int ext4_seq_es_shrinker_info_show(struct seq_file *seq, void *v) seq_printf(seq, "stats:\n %lld objects\n %lld reclaimable objects\n", percpu_counter_sum_positive(&es_stats->es_stats_all_cnt), percpu_counter_sum_positive(&es_stats->es_stats_shk_cnt)); - seq_printf(seq, " %lu/%lu cache hits/misses\n", - es_stats->es_stats_cache_hits, - es_stats->es_stats_cache_misses); + seq_printf(seq, " %lld/%lld cache hits/misses\n", + percpu_counter_sum_positive(&es_stats->es_stats_cache_hits), + percpu_counter_sum_positive(&es_stats->es_stats_cache_misses)); if (inode_cnt) seq_printf(seq, " %d inodes on list\n", inode_cnt); @@ -1264,35 +1264,46 @@ int ext4_es_register_shrinker(struct ext4_sb_info *sbi) sbi->s_es_nr_inode = 0; spin_lock_init(&sbi->s_es_lock); sbi->s_es_stats.es_stats_shrunk = 0; - sbi->s_es_stats.es_stats_cache_hits = 0; - sbi->s_es_stats.es_stats_cache_misses = 0; + err = percpu_counter_init(&sbi->s_es_stats.es_stats_cache_hits, 0, + GFP_KERNEL); + if (err) + return err; + err = percpu_counter_init(&sbi->s_es_stats.es_stats_cache_misses, 0, + GFP_KERNEL); + if (err) + goto err1; sbi->s_es_stats.es_stats_scan_time = 0; sbi->s_es_stats.es_stats_max_scan_time = 0; err = percpu_counter_init(&sbi->s_es_stats.es_stats_all_cnt, 0, GFP_KERNEL); if (err) - return err; + goto err2; err = percpu_counter_init(&sbi->s_es_stats.es_stats_shk_cnt, 0, GFP_KERNEL); if (err) - goto err1; + 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); if (err) - goto err2; + goto err4; return 0; - -err2: +err4: percpu_counter_destroy(&sbi->s_es_stats.es_stats_shk_cnt); -err1: +err3: percpu_counter_destroy(&sbi->s_es_stats.es_stats_all_cnt); +err2: + percpu_counter_destroy(&sbi->s_es_stats.es_stats_cache_misses); +err1: + percpu_counter_destroy(&sbi->s_es_stats.es_stats_cache_hits); return err; } void ext4_es_unregister_shrinker(struct ext4_sb_info *sbi) { + percpu_counter_destroy(&sbi->s_es_stats.es_stats_cache_hits); + 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); diff --git a/fs/ext4/extents_status.h b/fs/ext4/extents_status.h index 131a8b7df265..e722dd9bd06e 100644 --- a/fs/ext4/extents_status.h +++ b/fs/ext4/extents_status.h @@ -70,8 +70,8 @@ struct ext4_es_tree { struct ext4_es_stats { unsigned long es_stats_shrunk; - unsigned long es_stats_cache_hits; - unsigned long es_stats_cache_misses; + struct percpu_counter es_stats_cache_hits; + struct percpu_counter es_stats_cache_misses; u64 es_stats_scan_time; u64 es_stats_max_scan_time; struct percpu_counter es_stats_all_cnt; -- 2.7.4