From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 54679C38A2A for ; Fri, 8 May 2020 12:23:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 30D6621582 for ; Fri, 8 May 2020 12:23:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=yandex-team.ru header.i=@yandex-team.ru header.b="Ph/BhQVD" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727108AbgEHMXZ (ORCPT ); Fri, 8 May 2020 08:23:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1727094AbgEHMXX (ORCPT ); Fri, 8 May 2020 08:23:23 -0400 Received: from forwardcorp1j.mail.yandex.net (forwardcorp1j.mail.yandex.net [IPv6:2a02:6b8:0:1619::183]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 880FEC05BD43 for ; Fri, 8 May 2020 05:23:22 -0700 (PDT) Received: from mxbackcorp1o.mail.yandex.net (mxbackcorp1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::301]) by forwardcorp1j.mail.yandex.net (Yandex) with ESMTP id ED8512E151F; Fri, 8 May 2020 15:23:18 +0300 (MSK) Received: from myt4-18a966dbd9be.qloud-c.yandex.net (myt4-18a966dbd9be.qloud-c.yandex.net [2a02:6b8:c00:12ad:0:640:18a9:66db]) by mxbackcorp1o.mail.yandex.net (mxbackcorp/Yandex) with ESMTP id 7NK2742NLq-NHb8lZG3; Fri, 08 May 2020 15:23:18 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex-team.ru; s=default; t=1588940598; bh=KU2g+Q0yPMTYZlBSSwWKdYtFznVsnPkB2sauyejITt4=; h=In-Reply-To:Message-ID:References:Date:To:From:Subject:Cc; b=Ph/BhQVD66wYtc1XAoeAQ8rPXfDRFEjS5ND7g8MKREO1d+1S3FOOlB09mrxBbycic ilB0e9MG7CuVf+MUwol8NI2wO8wjpSzQwLsV75E8K39ZyTg+gAnxFL0e2MCEm06cOD b0CaYwDrDTyPOgd42IzPNlN4Du43O30PJAgj/Vps= Authentication-Results: mxbackcorp1o.mail.yandex.net; dkim=pass header.i=@yandex-team.ru Received: from dynamic-vpn.dhcp.yndx.net (dynamic-vpn.dhcp.yndx.net [2a02:6b8:b080:7008::1:4]) by myt4-18a966dbd9be.qloud-c.yandex.net (smtpcorp/Yandex) with ESMTPSA id ZuTxA7ymDv-NHWCQXMj; Fri, 08 May 2020 15:23:17 +0300 (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (Client certificate not present) Subject: [PATCH RFC 2/8] selftests: add stress testing tool for dcache From: Konstantin Khlebnikov To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, Alexander Viro Cc: Waiman Long Date: Fri, 08 May 2020 15:23:17 +0300 Message-ID: <158894059714.200862.11121403612367981747.stgit@buzz> In-Reply-To: <158893941613.200862.4094521350329937435.stgit@buzz> References: <158893941613.200862.4094521350329937435.stgit@buzz> User-Agent: StGit/0.22-32-g6a05 MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This tool fills dcache with negative dentries. Between iterations it prints statistics and measures time of inotify operation which might degrade. Signed-off-by: Konstantin Khlebnikov --- tools/testing/selftests/filesystems/Makefile | 1 .../testing/selftests/filesystems/dcache_stress.c | 210 ++++++++++++++++++++ 2 files changed, 211 insertions(+) create mode 100644 tools/testing/selftests/filesystems/dcache_stress.c diff --git a/tools/testing/selftests/filesystems/Makefile b/tools/testing/selftests/filesystems/Makefile index 129880fb42d3..6b5e08617d11 100644 --- a/tools/testing/selftests/filesystems/Makefile +++ b/tools/testing/selftests/filesystems/Makefile @@ -3,5 +3,6 @@ CFLAGS += -I../../../../usr/include/ TEST_GEN_PROGS := devpts_pts TEST_GEN_PROGS_EXTENDED := dnotify_test +TEST_GEN_FILES += dcache_stress include ../lib.mk diff --git a/tools/testing/selftests/filesystems/dcache_stress.c b/tools/testing/selftests/filesystems/dcache_stress.c new file mode 100644 index 000000000000..770e8876629e --- /dev/null +++ b/tools/testing/selftests/filesystems/dcache_stress.c @@ -0,0 +1,210 @@ +// SPDX-License-Identifier: GPL-2.0 +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +double now(void) +{ + struct timespec ts; + + clock_gettime(CLOCK_MONOTONIC, &ts); + return ts.tv_sec + ts.tv_nsec * 1e-9; +} + +struct dentry_stat { + long nr_dentry; + long nr_unused; + long age_limit; /* age in seconds */ + long want_pages; /* pages requested by system */ + long nr_negative; /* # of unused negative dentries */ + long nr_buckets; /* count of dcache hash buckets */ +}; + +void show_dentry_state(void) +{ + struct dentry_stat stat; + ssize_t len; + FILE *f; + + f = fopen("/proc/sys/fs/dentry-state", "r"); + if (!f) + err(2, "open fs.dentry-state"); + + if (fscanf(f, "%ld %ld %ld %ld %ld %ld", + &stat.nr_dentry, + &stat.nr_unused, + &stat.age_limit, + &stat.want_pages, + &stat.nr_negative, + &stat.nr_buckets) != 6) + err(2, "read fs.dentry-state"); + fclose(f); + + if (!stat.nr_buckets) + stat.nr_buckets = 1 << 20; // for 8Gb ram + + printf("nr_dentry = %ld\t%.1fM\n", stat.nr_dentry, stat.nr_dentry / 1e6); + printf("nr_buckets = %ld\t%.1f avg\n", stat.nr_buckets, (double)stat.nr_dentry / stat.nr_buckets); + printf("nr_unused = %ld\t%.1f%%\n", stat.nr_unused, stat.nr_unused * 100. / stat.nr_dentry); + printf("nr_negative = %ld\t%.1f%%\n\n", stat.nr_negative, stat.nr_negative * 100. / stat.nr_dentry); +} + +void test_inotify(const char *path) +{ + double tm; + int fd; + + fd = inotify_init1(0); + + tm = now(); + inotify_add_watch(fd, path, IN_OPEN); + tm = now() - tm; + + printf("inotify time: %f seconds\n\n", tm); + + close(fd); +} + +int main(int argc, char **argv) +{ + char dir_name[] = "dcache_stress.XXXXXX"; + char name[4096]; + char *suffix = name; + int nr_iterations = 10; + int nr_names = 1 << 20; + int iteration, index; + int other_dir = -1; + int mknod_unlink = 0; + int mkdir_chdir = 0; + int second_access = 0; + long long total_names = 0; + double tm; + int opt; + + while ((opt = getopt(argc, argv, "i:n:p:o:usdh")) != -1) { + switch (opt) { + case 'i': + nr_iterations = atoi(optarg); + break; + case 'n': + nr_names = atoi(optarg); + break; + case 'p': + strcpy(suffix, optarg); + suffix += strlen(suffix); + break; + case 'o': + other_dir = open(optarg, O_RDONLY | O_DIRECTORY); + if (other_dir < 0) + err(2, "open %s", optarg); + break; + case 'u': + mknod_unlink = 1; + break; + case 'd': + mkdir_chdir = 1; + break; + case 's': + second_access = 1; + break; + case '?': + case 'h': + printf("usage: %s [-i ] [-n ] [-p ] [-o ] [-u] [-s]\n" + " -i test iterations, default %d\n" + " -n names at each iterations, default %d\n" + " -p prefix for names\n" + " -o interlave with other dir\n" + " -s touch twice\n" + " -u mknod-unlink sequence\n" + " -d mkdir-chdir sequence (leaves garbage)\n", + argv[0], nr_iterations, nr_names); + return 1; + } + } + + + if (!mkdtemp(dir_name)) + err(2, "mkdtemp"); + + if (chdir(dir_name)) + err(2, "chdir"); + + show_dentry_state(); + + if (!mkdir_chdir) + test_inotify("."); + + printf("working in temporary directory %s\n\n", dir_name); + + for (iteration = 1; iteration <= nr_iterations; iteration++) { + + printf("start iteration %d, %d names\n", iteration, nr_names); + + tm = now(); + + sprintf(suffix, "%08x", iteration); + + for (index = 0; index < nr_names; index++) { + sprintf(suffix + 8, "%08x", index); + + if (mknod_unlink) { + if (mknod(name, S_IFREG, 0)) + err(2, "mknod %s", name); + if (unlink(name)) + err(2, "unlink %s", name); + } else if (mkdir_chdir) { + if (mkdir(name, 0775)) + err(2, "mkdir %s", name); + if (chdir(name)) + err(2, "chdir %s", name); + } else + access(name, 0); + + if (second_access) + access(name, 0); + + if (other_dir >= 0) { + faccessat(other_dir, name, 0, 0); + if (second_access) + faccessat(other_dir, name, 0, 0); + } + } + + total_names += nr_names; + + tm = now() - tm; + printf("iteration %d complete in %f seconds, total names %lld\n\n", iteration, tm, total_names); + + show_dentry_state(); + + if (!mkdir_chdir) + test_inotify("."); + } + + if (chdir("..")) + err(2, "chdir"); + + if (mkdir_chdir) { + printf("leave temporary directory %s\n", dir_name); + return 0; + } + + printf("removing temporary directory %s\n", dir_name); + tm = now(); + if (rmdir(dir_name)) + err(2, "rmdir"); + tm = now() - tm; + printf("remove complete in %f seconds\n\n", tm); + + show_dentry_state(); + + return 0; +}