Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 10 May 2017 16:32:13 +0000 (UTC)
From:      John Baldwin <jhb@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r318145 - in stable: 10/sys/geom/journal 11/sys/geom/journal
Message-ID:  <201705101632.v4AGWDhx031491@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jhb
Date: Wed May 10 16:32:12 2017
New Revision: 318145
URL: https://svnweb.freebsd.org/changeset/base/318145

Log:
  MFC 313409: Defer startup of gjournal switcher kproc.
  
  Don't start switcher kproc until the first GEOM is created.

Modified:
  stable/10/sys/geom/journal/g_journal.c
Directory Properties:
  stable/10/   (props changed)

Changes in other areas also in this revision:
Modified:
  stable/11/sys/geom/journal/g_journal.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/10/sys/geom/journal/g_journal.c
==============================================================================
--- stable/10/sys/geom/journal/g_journal.c	Wed May 10 16:06:22 2017	(r318144)
+++ stable/10/sys/geom/journal/g_journal.c	Wed May 10 16:32:12 2017	(r318145)
@@ -230,11 +230,14 @@ struct g_class g_journal_class = {
 
 static int g_journal_destroy(struct g_journal_softc *sc);
 static void g_journal_metadata_update(struct g_journal_softc *sc);
+static void g_journal_start_switcher(struct g_class *mp);
+static void g_journal_stop_switcher(void);
 static void g_journal_switch_wait(struct g_journal_softc *sc);
 
 #define	GJ_SWITCHER_WORKING	0
 #define	GJ_SWITCHER_DIE		1
 #define	GJ_SWITCHER_DIED	2
+static struct proc *g_journal_switcher_proc = NULL;
 static int g_journal_switcher_state = GJ_SWITCHER_WORKING;
 static int g_journal_switcher_wokenup = 0;
 static int g_journal_sync_requested = 0;
@@ -2386,6 +2389,10 @@ g_journal_create(struct g_class *mp, str
 		sc->sc_jconsumer = cp;
 	}
 
+	/* Start switcher kproc if needed. */
+	if (g_journal_switcher_proc == NULL)
+		g_journal_start_switcher(mp);
+
 	if ((sc->sc_type & GJ_TYPE_COMPLETE) != GJ_TYPE_COMPLETE) {
 		/* Journal is not complete yet. */
 		return (gp);
@@ -2766,7 +2773,6 @@ static void g_journal_switcher(void *arg
 static void
 g_journal_init(struct g_class *mp)
 {
-	int error;
 
 	/* Pick a conservative value if provided value sucks. */
 	if (g_journal_cache_divisor <= 0 ||
@@ -2786,9 +2792,6 @@ g_journal_init(struct g_class *mp)
 	    g_journal_lowmem, mp, EVENTHANDLER_PRI_FIRST);
 	if (g_journal_event_lowmem == NULL)
 		GJ_DEBUG(0, "Warning! Cannot register lowmem event.");
-	error = kproc_create(g_journal_switcher, mp, NULL, 0, 0,
-	    "g_journal switcher");
-	KASSERT(error == 0, ("Cannot create switcher thread."));
 }
 
 static void
@@ -2801,11 +2804,7 @@ g_journal_fini(struct g_class *mp)
 	}
 	if (g_journal_event_lowmem != NULL)
 		EVENTHANDLER_DEREGISTER(vm_lowmem, g_journal_event_lowmem);
-	g_journal_switcher_state = GJ_SWITCHER_DIE;
-	wakeup(&g_journal_switcher_state);
-	while (g_journal_switcher_state != GJ_SWITCHER_DIED)
-		tsleep(&g_journal_switcher_state, PRIBIO, "jfini:wait", hz / 5);
-	GJ_DEBUG(1, "Switcher died.");
+	g_journal_stop_switcher();
 }
 
 DECLARE_GEOM_CLASS(g_journal_class, g_journal);
@@ -3011,9 +3010,34 @@ next:
 	}
 }
 
+static void
+g_journal_start_switcher(struct g_class *mp)
+{
+	int error;
+
+	g_topology_assert();
+	MPASS(g_journal_switcher_proc == NULL);
+	g_journal_switcher_state = GJ_SWITCHER_WORKING;
+	error = kproc_create(g_journal_switcher, mp, &g_journal_switcher_proc,
+	    0, 0, "g_journal switcher");
+	KASSERT(error == 0, ("Cannot create switcher thread."));
+}
+
+static void
+g_journal_stop_switcher(void)
+{
+	g_topology_assert();
+	MPASS(g_journal_switcher_proc != NULL);
+	g_journal_switcher_state = GJ_SWITCHER_DIE;
+	wakeup(&g_journal_switcher_state);
+	while (g_journal_switcher_state != GJ_SWITCHER_DIED)
+		tsleep(&g_journal_switcher_state, PRIBIO, "jfini:wait", hz / 5);
+	GJ_DEBUG(1, "Switcher died.");
+	g_journal_switcher_proc = NULL;
+}
+
 /*
- * TODO: Switcher thread should be started on first geom creation and killed on
- * last geom destruction.
+ * TODO: Kill switcher thread on last geom destruction?
  */
 static void
 g_journal_switcher(void *arg)



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201705101632.v4AGWDhx031491>