Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 22 Mar 2018 19:11:44 +0000 (UTC)
From:      Jeff Roberson <jeff@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r331368 - in head/sys: kern sys vm
Message-ID:  <201803221911.w2MJBirP056724@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jeff
Date: Thu Mar 22 19:11:43 2018
New Revision: 331368
URL: https://svnweb.freebsd.org/changeset/base/331368

Log:
  Start witness much earlier in boot so that we can shrink the pend list and
  make it more immune to further change.
  
  Reviewed by:	markj, imp (Part of D14707)
  Sponsored by:	Netflix, Dell/EMC Isilon

Modified:
  head/sys/kern/subr_witness.c
  head/sys/sys/lock.h
  head/sys/vm/vm_page.c

Modified: head/sys/kern/subr_witness.c
==============================================================================
--- head/sys/kern/subr_witness.c	Thu Mar 22 19:06:50 2018	(r331367)
+++ head/sys/kern/subr_witness.c	Thu Mar 22 19:11:43 2018	(r331368)
@@ -139,7 +139,7 @@ __FBSDID("$FreeBSD$");
 #define	WITNESS_COUNT 		1536
 #endif
 #define	WITNESS_HASH_SIZE	251	/* Prime, gives load factor < 2 */
-#define	WITNESS_PENDLIST	(2048 + (MAXCPU * 4))
+#define	WITNESS_PENDLIST	(512 + (MAXCPU * 4))
 
 /* Allocate 256 KB of stack data space */
 #define	WITNESS_LO_DATA_COUNT	2048
@@ -752,27 +752,45 @@ fixup_filename(const char *file)
 }
 
 /*
+ * Calculate the size of early witness structures.
+ */
+int
+witness_startup_count(void)
+{
+	int sz;
+
+	sz = sizeof(struct witness) * witness_count;
+	sz += sizeof(*w_rmatrix) * (witness_count + 1);
+	sz += sizeof(*w_rmatrix[0]) * (witness_count + 1) *
+	    (witness_count + 1);
+
+	return (sz);
+}
+
+/*
  * The WITNESS-enabled diagnostic code.  Note that the witness code does
  * assume that the early boot is single-threaded at least until after this
  * routine is completed.
  */
-static void
-witness_initialize(void *dummy __unused)
+void
+witness_startup(void *mem)
 {
 	struct lock_object *lock;
 	struct witness_order_list_entry *order;
 	struct witness *w, *w1;
+	uintptr_t p;
 	int i;
 
-	w_data = malloc(sizeof (struct witness) * witness_count, M_WITNESS,
-	    M_WAITOK | M_ZERO);
+	p = (uintptr_t)mem;
+	w_data = (void *)p;
+	p += sizeof(struct witness) * witness_count;
 
-	w_rmatrix = malloc(sizeof(*w_rmatrix) * (witness_count + 1),
-	    M_WITNESS, M_WAITOK | M_ZERO);
+	w_rmatrix = (void *)p;
+	p += sizeof(*w_rmatrix) * (witness_count + 1);
 
 	for (i = 0; i < witness_count + 1; i++) {
-		w_rmatrix[i] = malloc(sizeof(*w_rmatrix[i]) *
-		    (witness_count + 1), M_WITNESS, M_WAITOK | M_ZERO);
+		w_rmatrix[i] = (void *)p;
+		p += sizeof(*w_rmatrix[i]) * (witness_count + 1);
 	}
 	badstack_sbuf_size = witness_count * 256;
 
@@ -840,8 +858,6 @@ witness_initialize(void *dummy __unused)
 
 	mtx_lock(&Giant);
 }
-SYSINIT(witness_init, SI_SUB_WITNESS, SI_ORDER_FIRST, witness_initialize,
-    NULL);
 
 void
 witness_init(struct lock_object *lock, const char *type)

Modified: head/sys/sys/lock.h
==============================================================================
--- head/sys/sys/lock.h	Thu Mar 22 19:06:50 2018	(r331367)
+++ head/sys/sys/lock.h	Thu Mar 22 19:11:43 2018	(r331368)
@@ -277,6 +277,8 @@ const char *witness_file(struct lock_object *);
 void	witness_thread_exit(struct thread *);
 
 #ifdef	WITNESS
+int	witness_startup_count(void);
+void	witness_startup(void *);
 
 /* Flags for witness_warn(). */
 #define	WARN_GIANTOK	0x01	/* Giant is exempt from this check. */

Modified: head/sys/vm/vm_page.c
==============================================================================
--- head/sys/vm/vm_page.c	Thu Mar 22 19:06:50 2018	(r331367)
+++ head/sys/vm/vm_page.c	Thu Mar 22 19:11:43 2018	(r331368)
@@ -539,6 +539,15 @@ vm_page_startup(vm_offset_t vaddr)
 	bzero((void *)mapped, end - new_end);
 	uma_startup((void *)mapped, boot_pages);
 
+#ifdef WITNESS
+	end = new_end;
+	new_end = end - round_page(witness_startup_count());
+	mapped = pmap_map(&vaddr, new_end, end,
+	    VM_PROT_READ | VM_PROT_WRITE);
+	bzero((void *)mapped, end - new_end);
+	witness_startup((void *)mapped);
+#endif
+
 #if defined(__aarch64__) || defined(__amd64__) || defined(__arm__) || \
     defined(__i386__) || defined(__mips__)
 	/*



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