svn commit: r239645 - stable/9/sys/vm

Dag-Erling Smørgrav des at FreeBSD.org
Fri Aug 24 09:58:15 UTC 2012


Author: des
Date: Fri Aug 24 09:58:14 2012
New Revision: 239645
URL: http://svn.freebsd.org/changeset/base/239645

Log:
  MFH (r239327): warn when too much swap is configured, and avoid flooding
  the console when running out of space for metadata.

Modified:
  stable/9/sys/vm/swap_pager.c
Directory Properties:
  stable/9/sys/   (props changed)

Modified: stable/9/sys/vm/swap_pager.c
==============================================================================
--- stable/9/sys/vm/swap_pager.c	Fri Aug 24 09:28:22 2012	(r239644)
+++ stable/9/sys/vm/swap_pager.c	Fri Aug 24 09:58:14 2012	(r239645)
@@ -1804,6 +1804,7 @@ restart:
 static void
 swp_pager_meta_build(vm_object_t object, vm_pindex_t pindex, daddr_t swapblk)
 {
+	static volatile int exhausted;
 	struct swblock *swap;
 	struct swblock **pswap;
 	int idx;
@@ -1847,7 +1848,9 @@ retry:
 			mtx_unlock(&swhash_mtx);
 			VM_OBJECT_UNLOCK(object);
 			if (uma_zone_exhausted(swap_zone)) {
-				printf("swap zone exhausted, increase kern.maxswzone\n");
+				if (atomic_cmpset_rel_int(&exhausted, 0, 1))
+					printf("swap zone exhausted, "
+					    "increase kern.maxswzone\n");
 				vm_pageout_oom(VM_OOM_SWAPZ);
 				pause("swzonex", 10);
 			} else
@@ -1856,6 +1859,9 @@ retry:
 			goto retry;
 		}
 
+		if (atomic_cmpset_rel_int(&exhausted, 1, 0))
+			printf("swap zone ok\n");
+
 		swap->swb_hnext = NULL;
 		swap->swb_object = object;
 		swap->swb_index = pindex & ~(vm_pindex_t)SWAP_META_MASK;
@@ -2112,6 +2118,31 @@ done:
 	return (error);
 }
 
+/*
+ * Check that the total amount of swap currently configured does not
+ * exceed half the theoretical maximum.  If it does, print a warning
+ * message and return -1; otherwise, return 0.
+ */
+static int
+swapon_check_swzone(unsigned long npages)
+{
+	unsigned long maxpages;
+
+	/* absolute maximum we can handle assuming 100% efficiency */
+	maxpages = uma_zone_get_max(swap_zone) * SWAP_META_PAGES;
+
+	/* recommend using no more than half that amount */
+	if (npages > maxpages / 2) {
+		printf("warning: total configured swap (%lu pages) "
+		    "exceeds maximum recommended amount (%lu pages).\n",
+		    npages, maxpages);
+		printf("warning: increase kern.maxswzone "
+		    "or reduce amount of swap.\n");
+		return (-1);
+	}
+	return (0);
+}
+
 static void
 swaponsomething(struct vnode *vp, void *id, u_long nblks, sw_strategy_t *strategy, sw_close_t *close, dev_t dev)
 {
@@ -2175,6 +2206,7 @@ swaponsomething(struct vnode *vp, void *
 	nswapdev++;
 	swap_pager_avail += nblks;
 	swap_total += (vm_ooffset_t)nblks * PAGE_SIZE;
+	swapon_check_swzone(swap_total / PAGE_SIZE);
 	swp_sizecheck();
 	mtx_unlock(&sw_dev_mtx);
 }


More information about the svn-src-stable-9 mailing list