Author: markj
Date: Thu Jan 23 14:01:03 2020
New Revision: 357044
URL: https://svnweb.freebsd.org/changeset/base/357044

Log:
  MFC r356563:
  UMA: Don't destroy zones after the system shutdown process starts.
  
  PR:   242427

Modified:
  stable/12/sys/vm/uma_core.c
Directory Properties:
  stable/12/   (props changed)

Modified: stable/12/sys/vm/uma_core.c
==============================================================================
--- stable/12/sys/vm/uma_core.c Thu Jan 23 13:56:12 2020        (r357043)
+++ stable/12/sys/vm/uma_core.c Thu Jan 23 14:01:03 2020        (r357044)
@@ -156,8 +156,14 @@ SYSCTL_ULONG(_vm, OID_AUTO, uma_kmem_total, CTLFLAG_RD
     "UMA kernel memory usage");
 
 /* Is the VM done starting up? */
-static enum { BOOT_COLD = 0, BOOT_STRAPPED, BOOT_PAGEALLOC, BOOT_BUCKETS,
-    BOOT_RUNNING } booted = BOOT_COLD;
+static enum {
+       BOOT_COLD,
+       BOOT_STRAPPED,
+       BOOT_PAGEALLOC,
+       BOOT_BUCKETS,
+       BOOT_RUNNING,
+       BOOT_SHUTDOWN,
+} booted = BOOT_COLD;
 
 /*
  * This is the handle used to schedule events that need to happen
@@ -261,6 +267,7 @@ static int hash_expand(struct uma_hash *, struct uma_h
 static void hash_free(struct uma_hash *hash);
 static void uma_timeout(void *);
 static void uma_startup3(void);
+static void uma_shutdown(void);
 static void *zone_alloc_item(uma_zone_t, void *, int, int);
 static void zone_free_item(uma_zone_t, void *, void *, enum zfreeskip);
 static void bucket_enable(void);
@@ -1184,8 +1191,7 @@ startup_alloc(uma_zone_t zone, vm_size_t bytes, int do
                case BOOT_PAGEALLOC:
                        if (keg->uk_ppera > 1)
                                break;
-               case BOOT_BUCKETS:
-               case BOOT_RUNNING:
+               default:
 #ifdef UMA_MD_SMALL_ALLOC
                        keg->uk_allocf = (keg->uk_ppera > 1) ?
                            page_alloc : uma_small_alloc;
@@ -2134,10 +2140,6 @@ uma_startup2(void)
        bucket_enable();
 }
 
-/*
- * Initialize our callout handle
- *
- */
 static void
 uma_startup3(void)
 {
@@ -2150,8 +2152,18 @@ uma_startup3(void)
        callout_init(&uma_callout, 1);
        callout_reset(&uma_callout, UMA_TIMEOUT * hz, uma_timeout, NULL);
        booted = BOOT_RUNNING;
+
+       EVENTHANDLER_REGISTER(shutdown_post_sync, uma_shutdown, NULL,
+           EVENTHANDLER_PRI_FIRST);
 }
 
+static void
+uma_shutdown(void)
+{
+
+       booted = BOOT_SHUTDOWN;
+}
+
 static uma_keg_t
 uma_kcreate(uma_zone_t zone, size_t size, uma_init uminit, uma_fini fini,
                int align, uint32_t flags)
@@ -2371,6 +2383,14 @@ void
 uma_zdestroy(uma_zone_t zone)
 {
 
+       /*
+        * Large slabs are expensive to reclaim, so don't bother doing
+        * unnecessary work if we're shutting down.
+        */
+       if (booted == BOOT_SHUTDOWN &&
+           zone->uz_fini == NULL &&
+           zone->uz_release == (uma_release)zone_release)
+               return;
        sx_slock(&uma_drain_lock);
        zone_free_item(zones, zone, NULL, SKIP_NONE);
        sx_sunlock(&uma_drain_lock);
_______________________________________________
[email protected] mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "[email protected]"

Reply via email to