Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3891961ybb; Tue, 31 Mar 2020 14:15:10 -0700 (PDT) X-Google-Smtp-Source: ADFU+vu0C02/ANbSL/lr/zDLx0hnPKHMQAKD977g6aRtDz9cDLHUmV204oPGeQVAGcjaHxPwDEHx X-Received: by 2002:a05:6830:19e2:: with SMTP id t2mr13522452ott.97.1585689310187; Tue, 31 Mar 2020 14:15:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1585689310; cv=none; d=google.com; s=arc-20160816; b=LYEgw4tjs3HNBWUzxuiqkiX1gxeMQgn/VXZr9jOR40ZVVOkLMIHkBOaBqaa1qqgxkh VGXIdKu7SYcaQbytIo1VzSf0LqBXuIaatFOtHjCTuC6nah7PnXLAHKIKkkwH5IroqKwY S++fYZzpcUQdMA0jbUWoAFxgnCp7mOfHQ0sk18SoswEr5oFRjT9eJx4gPuxVW1ml1RDK VG8RrOH9JHSyPG+G/QEKGBtgvRKdKwa94OornxiC9Qs930FuIdL3q3CApBvmaIqKV+ub zv+ZiNdfRwufQHgoZcixg9gd81rxv6hhduTlAd0hf+kURltR0MsD9N8XX2scaAe5vBWn TqgA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:content-id:mime-version :subject:cc:to:references:in-reply-to:from:organization :dkim-signature; bh=vnd6JOKC9Rxj1l4kNr20jHc2/c0GfJbz4uCFmvz/S54=; b=hKm+0MV9OTiD/4rV0VNsJLbq0dS6dJL/1l5FaHW2CZzHM1qKehYkfwMJX7EfAcjuZm 9R3cOKeTC1lV+Cuty1yq3yxhp0DrDwGM+S7Q4m6sVVPjnP6aR7e0FGj+pqcgmMyMivtN kLO5Y202Ei0OXfihj5D4MZO0O9+xfkZH60wQTwl7fqjrJ3IxCMJl5mUZwhbupqA21ky7 SXoIRFF6h5O8VPPOwdPcLB9WGMKaRHtK6gSZX60O5fOqqeFOpQ03WuGrbOxMBzGXJS1w K7MiIZyscE2jAeupY9J4qOmRMTwR2VxA+IA5e7jtTqY2alPmOoOcLGOyhZn/wwsEU1Jg VyTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GK0R9amp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p21si8833891oth.257.2020.03.31.14.14.57; Tue, 31 Mar 2020 14:15:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=GK0R9amp; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731255AbgCaVO0 (ORCPT + 99 others); Tue, 31 Mar 2020 17:14:26 -0400 Received: from us-smtp-2.mimecast.com ([207.211.31.81]:24618 "EHLO us-smtp-delivery-1.mimecast.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728245AbgCaVO0 (ORCPT ); Tue, 31 Mar 2020 17:14:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1585689264; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=vnd6JOKC9Rxj1l4kNr20jHc2/c0GfJbz4uCFmvz/S54=; b=GK0R9ampD6EWpza9z/LnEmgpOpcxM49PqO0XKdEn5YPYc2y1K1UJvmKk6fgd8hf95iBpMy zX/BapPwY6hhRKHNU/exfSe9REMiO+dQ3Lf98Pr3nWoNKDGh7+BnEjksFJapSIYW6JoBO8 xMUnbnxWpziN/CZmO/Ic1eqercv+3eg= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-71-oN7tCOhCMqaKnNMhCISqjg-1; Tue, 31 Mar 2020 17:14:22 -0400 X-MC-Unique: oN7tCOhCMqaKnNMhCISqjg-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 44BCF108442D; Tue, 31 Mar 2020 21:14:20 +0000 (UTC) Received: from warthog.procyon.org.uk (ovpn-114-243.ams2.redhat.com [10.36.114.243]) by smtp.corp.redhat.com (Postfix) with ESMTP id 34DA61A269; Tue, 31 Mar 2020 21:14:16 +0000 (UTC) Organization: Red Hat UK Ltd. Registered Address: Red Hat UK Ltd, Amberley Place, 107-111 Peascod Street, Windsor, Berkshire, SI4 1TE, United Kingdom. Registered in England and Wales under Company Registration No. 3798903 From: David Howells In-Reply-To: References: <1445647.1585576702@warthog.procyon.org.uk> <2294742.1585675875@warthog.procyon.org.uk> To: Miklos Szeredi Cc: dhowells@redhat.com, Linus Torvalds , Al Viro , dray@redhat.com, Karel Zak , Miklos Szeredi , Steven Whitehouse , Jeff Layton , Ian Kent , andres@anarazel.de, Christian Brauner , Lennart Poettering , keyrings@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: Upcoming: Notifications, FS notifications and fsinfo() MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2415049.1585689255.1@warthog.procyon.org.uk> Date: Tue, 31 Mar 2020 22:14:15 +0100 Message-ID: <2415050.1585689255@warthog.procyon.org.uk> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Miklos Szeredi wrote: > So even the p2 method will give at least 80k queries/s, which is quite > good, considering that the need to rescan the complete mount tree > should be exceedingly rare (and in case it mattered, could be > optimized by priming from /proc/self/mountinfo). One thing to note is that the test is actually a little biased in favour of the "p" test, where the mnt_id is looked up by path from /proc/fdinfo. That's not all that useful, except as an index into mountfs. I'm not sure how much use it as a check on whether the mount is the same mount or not since mount IDs can get reused. If I instead use the parent_id all round as the desired target value, I then see: For 10000 mounts, f=22899us f2=18240us p=101054us p2=117273us <-- prev email For 10000 mounts, f=24853us f2=20453us p=235581us p2= 59798us <-- parent_id Some observations: (1) fsinfo() gets a bit slower, reflecting the extra locking that must be done to access the topology information (it's using a different attribute). (2) Going via /proc/fdinfo now includes further a access into mountfs - and this makes the access ~2.3x slower than it was before. (3) Going via mount ID directly into mountfs (the "p2" test) appears faster than it did (when it shouldn't have changed), though it's still slower than fsinfo. This I ascribe to the caching of the inode and dentry from the "p" test. The attached patch adjusts the test program. David --- commit e9844e27f3061e4ef2d1511786b5ea60338dc610 Author: David Howells Date: Tue Mar 31 21:14:58 2020 +0100 Get parent ID instead diff --git a/samples/vfs/test-fsinfo-perf.c b/samples/vfs/test-fsinfo-perf.c index fba40737f768..2bcde06ee78b 100644 --- a/samples/vfs/test-fsinfo-perf.c +++ b/samples/vfs/test-fsinfo-perf.c @@ -69,27 +69,27 @@ static void do_umount(void) perror("umount"); } -static unsigned long sum_mnt_id; +static unsigned long sum_check, sum_check_2; -static void get_mntid_by_fsinfo(int ix, const char *path) +static void get_id_by_fsinfo(int ix, const char *path) { - struct fsinfo_mount_info r; + struct fsinfo_mount_topology r; struct fsinfo_params params = { .flags = FSINFO_FLAGS_QUERY_PATH, - .request = FSINFO_ATTR_MOUNT_INFO, + .request = FSINFO_ATTR_MOUNT_TOPOLOGY, }; ERR(fsinfo(AT_FDCWD, path, ¶ms, sizeof(params), &r, sizeof(r)), "fsinfo"); - //printf("[%u] %u\n", ix, r.mnt_id); - sum_mnt_id += r.mnt_id; + sum_check += r.parent_id; + sum_check_2 += r.mnt_topology_changes; } -static void get_mntid_by_proc(int ix, const char *path) +static void get_id_by_proc(int ix, const char *path) { - unsigned int mnt_id; + unsigned int mnt_id, x; ssize_t len; - char procfile[100], buffer[4096], *p, *nl; + char procfile[100], buffer[4096], *p, *q, *nl; int fd, fd2; fd = open(path, O_PATH); @@ -130,12 +130,31 @@ static void get_mntid_by_proc(int ix, const char *path) exit(3); } - sum_mnt_id += mnt_id; - //printf("[%u] %u\n", ix, mnt_id); + /* Now look the ID up on mountfs */ + sprintf(procfile, "/mnt/%u/parent", mnt_id); + fd = open(procfile, O_RDONLY); + ERR(fd, procfile); + len = read(fd, buffer, sizeof(buffer) - 1); + ERR(len, "read/parent"); + close(fd); + if (len > 0 && buffer[len - 1] == '\n') + len--; + buffer[len] = 0; + + x = strtoul(buffer, &q, 10); + + if (*q) { + fprintf(stderr, "Bad format in %s '%s'\n", procfile, buffer); + exit(3); + } + + sum_check += x; + //printf("[%u] %u\n", ix, x); } -static void get_mntid_by_fsinfo_2(void) +static void get_id_by_fsinfo_2(void) { + struct fsinfo_mount_topology t; struct fsinfo_mount_child *children, *c, *end; struct fsinfo_mount_info r; struct fsinfo_params params = { @@ -171,15 +190,16 @@ static void get_mntid_by_fsinfo_2(void) for (i = 0; c < end; c++, i++) { //printf("[%u] %u\n", i, c->mnt_id); params.flags = FSINFO_FLAGS_QUERY_MOUNT; - params.request = FSINFO_ATTR_MOUNT_INFO; + params.request = FSINFO_ATTR_MOUNT_TOPOLOGY; sprintf(name, "%u", c->mnt_id); - ERR(fsinfo(AT_FDCWD, name, ¶ms, sizeof(params), &r, sizeof(r)), + ERR(fsinfo(AT_FDCWD, name, ¶ms, sizeof(params), &t, sizeof(t)), "fsinfo/child"); - sum_mnt_id += r.mnt_id; + sum_check += t.parent_id; + sum_check_2 += t.mnt_topology_changes; } } -static void get_mntid_by_mountfs(void) +static void get_id_by_mountfs(void) { unsigned int base_mnt_id, mnt_id, x; ssize_t len, s_children; @@ -260,11 +280,11 @@ static void get_mntid_by_mountfs(void) comma++; } - sprintf(procfile, "%u/id", mnt_id); + sprintf(procfile, "%u/parent", mnt_id); fd = openat(mntfd, procfile, O_RDONLY); ERR(fd, procfile); len = read(fd, buffer, sizeof(buffer) - 1); - ERR(len, "read/id"); + ERR(len, "read/parent"); close(fd); if (len > 0 && buffer[len - 1] == '\n') len--; @@ -278,7 +298,7 @@ static void get_mntid_by_mountfs(void) } if (0) printf("[%u] %u\n", i++, x); - sum_mnt_id += x; + sum_check += x; } while (p = comma, *comma); } @@ -318,32 +338,32 @@ int main(int argc, char **argv) iterate(make_mount); printf("--- test fsinfo by path ---\n"); - sum_mnt_id = 0; + sum_check = 0; ERR(gettimeofday(&f_before, NULL), "gettimeofday"); - iterate(get_mntid_by_fsinfo); + iterate(get_id_by_fsinfo); ERR(gettimeofday(&f_after, NULL), "gettimeofday"); - printf("sum(mnt_id) = %lu\n", sum_mnt_id); + printf("sum(mnt_id) = %lu\n", sum_check); printf("--- test fsinfo by mnt_id ---\n"); - sum_mnt_id = 0; + sum_check = 0; ERR(gettimeofday(&f2_before, NULL), "gettimeofday"); - get_mntid_by_fsinfo_2(); + get_id_by_fsinfo_2(); ERR(gettimeofday(&f2_after, NULL), "gettimeofday"); - printf("sum(mnt_id) = %lu\n", sum_mnt_id); + printf("sum(mnt_id) = %lu\n", sum_check); printf("--- test /proc/fdinfo ---\n"); - sum_mnt_id = 0; + sum_check = 0; ERR(gettimeofday(&p_before, NULL), "gettimeofday"); - iterate(get_mntid_by_proc); + iterate(get_id_by_proc); ERR(gettimeofday(&p_after, NULL), "gettimeofday"); - printf("sum(mnt_id) = %lu\n", sum_mnt_id); + printf("sum(mnt_id) = %lu\n", sum_check); printf("--- test mountfs ---\n"); - sum_mnt_id = 0; + sum_check = 0; ERR(gettimeofday(&p2_before, NULL), "gettimeofday"); - get_mntid_by_mountfs(); + get_id_by_mountfs(); ERR(gettimeofday(&p2_after, NULL), "gettimeofday"); - printf("sum(mnt_id) = %lu\n", sum_mnt_id); + printf("sum(mnt_id) = %lu\n", sum_check); f_dur = duration(&f_before, &f_after); f2_dur = duration(&f2_before, &f2_after);