Module Name:    src
Committed By:   cherry
Date:           Mon Dec 26 15:47:48 UTC 2016

Modified Files:
        src/sys/arch/i386/i386: machdep.c

Log Message:
Make the msgbuf initialisation track closer to the original
pre-uvm_physseg.h one.

To see the exact changes with the original, line for line, do:

cvs rdiff -u -r1.772 -r1.775 src/sys/arch/i386/i386/machdep.c


To generate a diff of this commit:
cvs rdiff -u -r1.774 -r1.775 src/sys/arch/i386/i386/machdep.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/i386/i386/machdep.c
diff -u src/sys/arch/i386/i386/machdep.c:1.774 src/sys/arch/i386/i386/machdep.c:1.775
--- src/sys/arch/i386/i386/machdep.c:1.774	Fri Dec 23 09:24:57 2016
+++ src/sys/arch/i386/i386/machdep.c	Mon Dec 26 15:47:48 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: machdep.c,v 1.774 2016/12/23 09:24:57 maya Exp $	*/
+/*	$NetBSD: machdep.c,v 1.775 2016/12/26 15:47:48 cherry Exp $	*/
 
 /*-
  * Copyright (c) 1996, 1997, 1998, 2000, 2004, 2006, 2008, 2009
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.774 2016/12/23 09:24:57 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.775 2016/12/26 15:47:48 cherry Exp $");
 
 #include "opt_beep.h"
 #include "opt_compat_ibcs2.h"
@@ -1037,30 +1037,46 @@ initgdt(union descriptor *tgdt)
 static void
 init386_msgbuf(void)
 {
-        /* Message buffer is located at end of core. */
-	psize_t reqsz = round_page(MSGBUFSIZE);
-	psize_t sz = 0;
+	/* Message buffer is located at end of core. */
+	psize_t sz = round_page(MSGBUFSIZE);
+	psize_t reqsz = sz;
+	uvm_physseg_t x;
+		
+search_again:
+        for (x = uvm_physseg_get_first();
+	     uvm_physseg_valid_p(x);
+	     x = uvm_physseg_get_next(x)) {
+		if (ctob(uvm_physseg_get_avail_end(x)) == avail_end) {
+			break;
+		}
+	}
+	if (uvm_physseg_valid_p(x) == false)
+		panic("init386: can't find end of memory");
 
-	for (sz = 0; sz < reqsz; sz += PAGE_SIZE) {
-		paddr_t stolenpa;
+	/* Shrink so it'll fit in the last segment. */
+	if (uvm_physseg_get_avail_end(x) - uvm_physseg_get_avail_start(x) < atop(sz))
+		sz = ctob(uvm_physseg_get_avail_end(x) - uvm_physseg_get_avail_start(x));
 
-		if (!uvm_page_physget(&stolenpa))
-			break;
+	uvm_physseg_unplug(uvm_physseg_get_end(x) - atop(sz), atop(sz));
+	msgbuf_p_seg[msgbuf_p_cnt].sz = sz;
+        msgbuf_p_seg[msgbuf_p_cnt++].paddr = ctob(uvm_physseg_get_avail_end(x));
 
-		if (stolenpa == (msgbuf_p_seg[msgbuf_p_cnt].paddr
-			+ PAGE_SIZE)) {
-			/* contiguous: append it to current buf alloc */
-			msgbuf_p_seg[msgbuf_p_cnt].sz += PAGE_SIZE;
-		} else  {
-			/* non-contiguous: start a new msgbuf seg */
-			msgbuf_p_seg[msgbuf_p_cnt].sz = PAGE_SIZE;
-			msgbuf_p_seg[msgbuf_p_cnt++].paddr = stolenpa;
-		}
+	/* Now find where the new avail_end is. */
+	avail_end = ctob(uvm_physseg_get_avail_end(x));
+
+	if (sz == reqsz)
+		return;
+
+	reqsz -= sz;
+	if (msgbuf_p_cnt == VM_PHYSSEG_MAX) {
+		/* No more segments available, bail out. */
+		printf("WARNING: MSGBUFSIZE (%zu) too large, using %zu.\n",
+		    (size_t)MSGBUFSIZE, (size_t)(MSGBUFSIZE - reqsz));
+		return;
 	}
 
-	if (sz != reqsz)
-		printf("%s: could only allocate %"PRIxPSIZE" bytes of requested"
-		    " %"PRIxPSIZE" bytes\n", __func__, sz, reqsz);
+	sz = reqsz;
+	goto search_again;
 }
 
 #ifndef XEN

Reply via email to