FreeBSD Bugzilla – Attachment 224366 Details for
Bug 255261
Slow unmount of (ZFS) filesystem at reboot time
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
Improved FreeBSD 12.2 version of "verbose shutdown" patch
verbose_shutdown-12.2.patch (text/plain), 12.14 KB, created by
Peter Eriksson
on 2021-04-22 21:49:57 UTC
(
hide
)
Description:
Improved FreeBSD 12.2 version of "verbose shutdown" patch
Filename:
MIME Type:
Creator:
Peter Eriksson
Created:
2021-04-22 21:49:57 UTC
Size:
12.14 KB
patch
obsolete
>Index: sys/kern/kern_shutdown.c >=================================================================== >--- sys/kern/kern_shutdown.c (revision 369637) >+++ sys/kern/kern_shutdown.c (working copy) >@@ -74,6 +74,7 @@ > #include <sys/sysctl.h> > #include <sys/sysproto.h> > #include <sys/taskqueue.h> >+#include <sys/time.h> > #include <sys/vnode.h> > #include <sys/watchdog.h> > >@@ -107,6 +108,7 @@ > &panic_reboot_wait_time, 0, > "Seconds to wait before rebooting after a panic"); > >+ > /* > * Note that stdarg.h and the ANSI style va_start macro is used for both > * ANSI and traditional C compilers. >@@ -169,6 +171,10 @@ > SYSCTL_INT(_kern, OID_AUTO, suspend_blocked, CTLFLAG_RW, > &suspend_blocked, 0, "Block suspend due to a pending shutdown"); > >+int verbose_shutdown = 1; >+SYSCTL_INT(_kern_shutdown, OID_AUTO, verbose, CTLFLAG_RW, >+ &verbose_shutdown, 0, "Be more verbose at shutdown/reboot"); >+ > #ifdef EKCD > FEATURE(ekcd, "Encrypted kernel crash dumps support"); > >@@ -393,6 +399,9 @@ > { > static int once = 0; > >+ if (verbose_shutdown) >+ printf("System is going down.\n"); >+ > /* > * Normal paths here don't hold Giant, but we can wind up here > * unexpectedly with it held. Drop it now so we don't have to >@@ -424,6 +433,8 @@ > /* We are out of the debugger now. */ > kdb_active = 0; > >+ if (verbose_shutdown > 1) >+ printf("Before shutdown_pre_sync.\n"); > /* > * Do any callouts that should be done BEFORE syncing the filesystems. > */ >@@ -433,6 +444,8 @@ > * Now sync filesystems > */ > if (!cold && (howto & RB_NOSYNC) == 0 && once == 0) { >+ if (verbose_shutdown > 1) >+ printf("Before bufshutdown.\n"); > once = 1; > bufshutdown(show_busybufs); > } >@@ -445,11 +458,23 @@ > * Ok, now do things that assume all filesystem activity has > * been completed. > */ >+ if (verbose_shutdown > 1) >+ printf("Before shutdown_post_sync.\n"); >+ > EVENTHANDLER_INVOKE(shutdown_post_sync, howto); > > if ((howto & (RB_HALT|RB_DUMP)) == RB_DUMP && !cold && !dumping) > doadump(TRUE); > >+ if (verbose_shutdown) { >+ printf("\nI've seen things you people wouldn't believe.\n"); >+ printf("Attack ships on fire off the shoulder of Orion.\n"); >+ printf("I watched C-beams glitter in the dark near the\n"); >+ printf("Tannhäuser Gate. All those moments will be lost\n"); >+ printf("in time, like tears in rain.\n"); >+ printf("\nTime to die.\n"); >+ } >+ > /* Now that we're going to really halt the system... */ > EVENTHANDLER_INVOKE(shutdown_final, howto); > >Index: sys/kern/vfs_subr.c >=================================================================== >--- sys/kern/vfs_subr.c (revision 369637) >+++ sys/kern/vfs_subr.c (working copy) >@@ -79,6 +79,7 @@ > #include <sys/stat.h> > #include <sys/sysctl.h> > #include <sys/syslog.h> >+#include <sys/time.h> > #include <sys/vmmeter.h> > #include <sys/vnode.h> > #include <sys/watchdog.h> >@@ -4162,12 +4163,27 @@ > vfs_unmountall(void) > { > struct mount *mp, *tmp; >+ unsigned int n, ns, n_fs; >+ time_t t0, t1, ts, dt; > > CTR1(KTR_VFS, "%s: unmounting all filesystems", __func__); > > /* >+ * Count the number of filesystems to unmount >+ */ >+ n_fs = 0; >+ TAILQ_FOREACH_REVERSE_SAFE(mp, &mountlist, mntlist, mnt_list, tmp) { >+ ++n_fs; >+ } >+ if (verbose_shutdown) { >+ printf("Unmounting %u filesystems:\n", n_fs); >+ t0 = ts = time_second; >+ } >+ >+ /* > * Since this only runs when rebooting, it is not interlocked. > */ >+ ns = n = 0; > TAILQ_FOREACH_REVERSE_SAFE(mp, &mountlist, mntlist, mnt_list, tmp) { > vfs_ref(mp); > >@@ -4178,11 +4194,47 @@ > if (mp == rootdevmp) > continue; > >+ ++n; >+ if ((verbose_shutdown && n_fs < 100) || verbose_shutdown > 2) { >+ printf(" %2u. %s\n", n, mp->mnt_stat.f_mntonname); >+ } > unmount_or_warn(mp); >+ >+ /* >+ * If more than 99 filesystems to unmount, print a running count >+ * every second, else print the filesystem names (with thousands >+ * of filesystems this becomes too tedious (and slows down the >+ * reboot process even more...) >+ */ >+ if (verbose_shutdown == 1 && n_fs > 99) { >+ t1 = time_second; >+ dt = t1-ts; >+ if (dt > 0) { >+ printf(" %6u of %u [%u%% done, %ld fs/s (cur), %ld fs/s (avg)] \r", >+ n, n_fs, n*100/n_fs, (n-ns)/dt, n/(t1-t0)); >+ ts = t1; >+ ns = n; >+ } >+ } > } > >- if (rootdevmp != NULL) >+ if (rootdevmp != NULL) { >+ ++n; >+ if ((verbose_shutdown && n_fs < 100) || verbose_shutdown > 2) { >+ printf(" %2u. %s\n", n, rootdevmp->mnt_stat.f_mntonname); >+ } > unmount_or_warn(rootdevmp); >+ } >+ >+ if (verbose_shutdown) { >+ dt = time_second - t0; >+ if (dt > 0) >+ printf("All %u filesystem%s unmounted in %lds (%ld fs/s). \n", >+ n, n == 1 ? "" : "s", dt, n/dt); >+ else >+ printf("All %u filesystem%s unmounted.\n", >+ n, n == 1 ? "" : "s"); >+ } > } > > /* >Index: sys/sys/systm.h >=================================================================== >--- sys/sys/systm.h (revision 369637) >+++ sys/sys/systm.h (working copy) >@@ -53,6 +53,7 @@ > extern int suspend_blocked; /* block suspend due to pending shutdown */ > extern int rebooting; /* kern_reboot() has been called. */ > extern const char *panicstr; /* panic message */ >+extern int verbose_shutdown; /* Be more verbose at shutdown */ > extern char version[]; /* system version */ > extern char compiler_version[]; /* compiler version */ > extern char copyright[]; /* system copyright */ >Index: sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c >=================================================================== >--- sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c (revision 369637) >+++ sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ioctl.c (working copy) >@@ -7276,15 +7276,56 @@ > int > zfs__fini(void) > { >+ time_t t0, t1; >+ long int dt; >+ > if (spa_busy() || zfs_busy() || zvol_busy() || > zio_injection_enabled) { > return (EBUSY); > } > >+ if (verbose_shutdown) >+ printf("ZFS is shutting down.\n"); >+ >+ if (verbose_shutdown) >+ t0 = time_second; > zfsdev_fini(); >+ if (verbose_shutdown) { >+ t1 = time_second; >+ dt = t1-t0; >+ if (dt > 1 || verbose_shutdown > 1) >+ printf(" zfsdev_fini() took %lds\n", dt); >+ } >+ >+ if (verbose_shutdown) >+ t0 = time_second; > zvol_fini(); >+ if (verbose_shutdown) { >+ t1 = time_second; >+ dt = t1-t0; >+ if (dt > 1 || verbose_shutdown > 1) >+ printf(" zvol_fini() took %lds\n", dt); >+ } >+ >+ if (verbose_shutdown) >+ t0 = time_second; > zfs_fini(); >+ if (verbose_shutdown) { >+ t1 = time_second; >+ dt = t1-t0; >+ if (dt > 1 || verbose_shutdown > 1) >+ printf(" zfs_fini() took %lds\n", dt); >+ } >+ >+ if (verbose_shutdown) >+ t0 = time_second; > spa_fini(); >+ if (verbose_shutdown) { >+ t1 = time_second; >+ dt = t1-t0; >+ if (dt > 1 || verbose_shutdown > 1) >+ printf(" spa_fini() took %lds\n", dt); >+ } > > tsd_destroy(&zfs_fsyncer_key); > tsd_destroy(&rrw_tsd_key); >@@ -7291,7 +7332,6 @@ > tsd_destroy(&zfs_allow_log_key); > > mutex_destroy(&zfs_share_lock); >- > return (0); > } > >Index: sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_misc.c >=================================================================== >--- sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_misc.c (revision 369637) >+++ sys/cddl/contrib/opensolaris/uts/common/fs/zfs/spa_misc.c (working copy) >@@ -2209,22 +2209,117 @@ > void > spa_fini(void) > { >+ time_t t0, t1; >+ long int dt; >+ >+ if (verbose_shutdown > 1) >+ printf(" spa_fini() starting.\n"); >+ >+ if (verbose_shutdown) >+ t0 = t1 = time_second; > l2arc_stop(); >- >+ if (verbose_shutdown) { >+ dt = time_second - t1; >+ if (dt > 1 || verbose_shutdown > 1) >+ printf(" l2arc_stop() took %lds\n", dt); >+ t1 = time_second; >+ } >+ > spa_evict_all(); >+ if (verbose_shutdown) { >+ dt = time_second - t1; >+ if (dt > 1 || verbose_shutdown > 1) >+ printf(" spa_evict_all() took %lds\n", dt); >+ t1 = time_second; >+ } > > vdev_file_fini(); >+ if (verbose_shutdown) { >+ dt = time_second - t1; >+ if (dt > 1 || verbose_shutdown > 1) >+ printf(" vdev_file_fini() took %lds\n", dt); >+ t1 = time_second; >+ } >+ > vdev_cache_stat_fini(); >+ if (verbose_shutdown) { >+ dt = time_second - t1; >+ if (dt > 1 || verbose_shutdown > 1) >+ printf(" vdev_cache_stat_fini() took %lds\n", dt); >+ t1 = time_second; >+ } >+ > zil_fini(); >+ if (verbose_shutdown) { >+ dt = time_second - t1; >+ if (dt > 1 || verbose_shutdown > 1) >+ printf(" zil_fini() took %lds\n", dt); >+ t1 = time_second; >+ } >+ > dmu_fini(); >+ if (verbose_shutdown) { >+ dt = time_second - t1; >+ if (dt > 1 || verbose_shutdown > 1) >+ printf(" dmu_fini() took %lds\n", dt); >+ t1 = time_second; >+ } >+ > lz4_fini(); >+ if (verbose_shutdown) { >+ dt = time_second - t1; >+ if (dt > 1 || verbose_shutdown > 1) >+ printf(" lz4_fini() took %lds\n", dt); >+ t1 = time_second; >+ } >+ > zio_fini(); >+ if (verbose_shutdown) { >+ dt = time_second - t1; >+ if (dt > 1 || verbose_shutdown > 1) >+ printf(" zio_fini() took %lds\n", dt); >+ t1 = time_second; >+ } >+ > metaslab_alloc_trace_fini(); >+ if (verbose_shutdown) { >+ dt = time_second - t1; >+ if (dt > 1 || verbose_shutdown > 1) >+ printf(" metaslab_alloc_trace_fini() took %lds\n", dt); >+ t1 = time_second; >+ } >+ > range_tree_fini(); >+ if (verbose_shutdown) { >+ dt = time_second - t1; >+ if (dt > 1 || verbose_shutdown > 1) >+ printf(" range_tree_fini) took %lds\n", dt); >+ t1 = time_second; >+ } >+ > unique_fini(); >+ if (verbose_shutdown) { >+ dt = time_second - t1; >+ if (dt > 1 || verbose_shutdown > 1) >+ printf(" unique_fini() took %lds\n", dt); >+ t1 = time_second; >+ } >+ > zfs_refcount_fini(); >+ if (verbose_shutdown) { >+ dt = time_second - t1; >+ if (dt > 1 || verbose_shutdown > 1) >+ printf(" zfs_refcount_fini() took %lds\n", dt); >+ t1 = time_second; >+ } >+ > scan_fini(); >- >+ if (verbose_shutdown) { >+ dt = time_second - t1; >+ if (dt > 1 || verbose_shutdown > 1) >+ printf(" scan_fini() took %lds\n", dt); >+ } >+ > avl_destroy(&spa_namespace_avl); > avl_destroy(&spa_spare_avl); > avl_destroy(&spa_l2cache_avl); >Index: sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio.c >=================================================================== >--- sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio.c (revision 369637) >+++ sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zio.c (working copy) >@@ -31,6 +31,7 @@ > #include <sys/fm/fs/zfs.h> > #include <sys/spa.h> > #include <sys/txg.h> >+#include <sys/time.h> > #include <sys/spa_impl.h> > #include <sys/vdev_impl.h> > #include <sys/zio_impl.h> >@@ -60,6 +61,7 @@ > SYSCTL_INT(_vfs_zfs_zio, OID_AUTO, exclude_metadata, CTLFLAG_RDTUN, &zio_exclude_metadata, 0, > "Exclude metadata buffers from dumps as well"); > >+ > zio_trim_stats_t zio_trim_stats = { > { "bytes", KSTAT_DATA_UINT64, > "Number of bytes successfully TRIMmed" }, >@@ -235,23 +237,67 @@ > size_t c; > kmem_cache_t *last_cache = NULL; > kmem_cache_t *last_data_cache = NULL; >+ time_t t0, t1, t2; >+ long int dt; > >+ >+ if (verbose_shutdown > 1) { >+ printf(" zio_fini() starting.\n"); >+ t0 = time_second; >+ } >+ > for (c = 0; c < SPA_MAXBLOCKSIZE >> SPA_MINBLOCKSHIFT; c++) { > if (zio_buf_cache[c] != last_cache) { > last_cache = zio_buf_cache[c]; >+ if (verbose_shutdown) >+ t1 = time_second; > kmem_cache_destroy(zio_buf_cache[c]); >+ if (verbose_shutdown) { >+ t2 = time_second; >+ dt = t2-t1; >+ if (dt > 1 || verbose_shutdown > 1) >+ printf(" kmem_cache_destroy(zio_buf_cache[%llu]) took %lds\n", >+ (long long unsigned) c, dt); >+ } > } > zio_buf_cache[c] = NULL; > >+ > if (zio_data_buf_cache[c] != last_data_cache) { > last_data_cache = zio_data_buf_cache[c]; >+ if (verbose_shutdown) >+ t1 = time_second; > kmem_cache_destroy(zio_data_buf_cache[c]); >+ if (verbose_shutdown) { >+ t2 = time_second; >+ dt = t2-t1; >+ if (dt > 1 || verbose_shutdown > 1) >+ printf(" kmem_cache_destroy(zio_data_buf_cache[%llu]) took %lds\n", >+ (long long unsigned) c, dt); >+ } > } > zio_data_buf_cache[c] = NULL; > } > >+ if (verbose_shutdown) >+ t1 = time_second; > kmem_cache_destroy(zio_link_cache); >+ if (verbose_shutdown) { >+ t2 = time_second; >+ dt = t2-t1; >+ if (dt > 1 || verbose_shutdown > 1) >+ printf(" kmem_cache_destroy(zio_link_cache) took %lds\n", dt); >+ } >+ >+ if (verbose_shutdown) >+ t1 = time_second; > kmem_cache_destroy(zio_cache); >+ if (verbose_shutdown) { >+ t2 = time_second; >+ dt = t2-t1; >+ if (dt > 1 || verbose_shutdown > 1) >+ printf(" kmem_cache_destroy(zio_cache) took %lds\n", dt); >+ } > > zio_inject_fini(); >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 255261
:
224295
|
224325
|
224326
|
224327
| 224366 |
224367