diff options
author | pjd <pjd@FreeBSD.org> | 2012-01-21 21:12:53 +0000 |
---|---|---|
committer | pjd <pjd@FreeBSD.org> | 2012-01-21 21:12:53 +0000 |
commit | 8e3e986346a1f6262fbbfa8b01def0b147b5084b (patch) | |
tree | 841c512688ceb07838f82957e5d5844134e5f572 /cddl/contrib/opensolaris/cmd/zfs/zfs_main.c | |
parent | 5ee1538f37aa8b2c679b8752982620362e459ab0 (diff) | |
download | FreeBSD-src-8e3e986346a1f6262fbbfa8b01def0b147b5084b.zip FreeBSD-src-8e3e986346a1f6262fbbfa8b01def0b147b5084b.tar.gz |
Dramatically optimize listing snapshots when user requests only snapshot
names and wants to sort them by name, ie. when executes:
# zfs list -t snapshot -o name -s name
Because only name is needed we don't have to read all snapshot properties.
Below you can find how long does it take to list 34509 snapshots from a single
disk pool before and after this change with cold and warm cache:
before:
# time zfs list -t snapshot -o name -s name > /dev/null
cold cache: 525s
warm cache: 218s
after:
# time zfs list -t snapshot -o name -s name > /dev/null
cold cache: 1.7s
warm cache: 1.1s
MFC after: 1 week
Diffstat (limited to 'cddl/contrib/opensolaris/cmd/zfs/zfs_main.c')
-rw-r--r-- | cddl/contrib/opensolaris/cmd/zfs/zfs_main.c | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c b/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c index 4282f0b..8c96379 100644 --- a/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c +++ b/cddl/contrib/opensolaris/cmd/zfs/zfs_main.c @@ -23,7 +23,7 @@ * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. * Copyright 2011 Nexenta Systems, Inc. All rights reserved. * Copyright (c) 2011 by Delphix. All rights reserved. - * Copyright (c) 2011 Pawel Jakub Dawidek <pawel@dawidek.net>. + * Copyright (c) 2011-2012 Pawel Jakub Dawidek <pawel@dawidek.net>. * All rights reserved. * Copyright (c) 2011 Martin Matuska <mm@FreeBSD.org>. All rights reserved. */ @@ -2838,7 +2838,12 @@ print_dataset(zfs_handle_t *zhp, zprop_list_t *pl, boolean_t scripted) first = B_FALSE; } - if (pl->pl_prop != ZPROP_INVAL) { + if (pl->pl_prop == ZFS_PROP_NAME) { + (void) strlcpy(property, zfs_get_name(zhp), + sizeof(property)); + propstr = property; + right_justify = zfs_prop_align_right(pl->pl_prop); + } else if (pl->pl_prop != ZPROP_INVAL) { if (zfs_prop_get(zhp, pl->pl_prop, property, sizeof (property), NULL, NULL, 0, B_FALSE) != 0) propstr = "-"; @@ -3005,6 +3010,13 @@ zfs_do_list(int argc, char **argv) fields = default_fields; /* + * If we are only going to list snapshot names and sort by name, + * then we can use faster version. + */ + if (strcmp(fields, "name") == 0 && zfs_sort_only_by_name(sortcol)) + flags |= ZFS_ITER_SIMPLE; + + /* * If "-o space" and no types were specified, don't display snapshots. */ if (strcmp(fields, "space") == 0 && types_specified == B_FALSE) |