summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormlarkin <mlarkin@openbsd.org>2014-07-11 03:06:08 +0000
committermlarkin <mlarkin@openbsd.org>2014-07-11 03:06:08 +0000
commit22433bb623a7904d32a0d85497158f6a3f6bc2bb (patch)
tree09471f1e7e23a214635006c7eb8879b6736006d2
parentFix dumb copy/paste mistake. (diff)
downloadwireguard-openbsd-22433bb623a7904d32a0d85497158f6a3f6bc2bb.tar.xz
wireguard-openbsd-22433bb623a7904d32a0d85497158f6a3f6bc2bb.zip
Flush the buffercache to 16MB on hibernate and restore its previous max
size (kern.bufcachepercent) on resume, for better hibernate performance. ok beck@
-rw-r--r--sys/dev/acpi/acpi.c8
-rw-r--r--sys/kern/vfs_bio.c34
-rw-r--r--sys/sys/hibernate.h4
3 files changed, 43 insertions, 3 deletions
diff --git a/sys/dev/acpi/acpi.c b/sys/dev/acpi/acpi.c
index b74cb27c529..a561faaadee 100644
--- a/sys/dev/acpi/acpi.c
+++ b/sys/dev/acpi/acpi.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: acpi.c,v 1.261 2014/07/10 13:52:15 blambert Exp $ */
+/* $OpenBSD: acpi.c,v 1.262 2014/07/11 03:06:08 mlarkin Exp $ */
/*
* Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com>
* Copyright (c) 2005 Jordan Hargrave <jordan@openbsd.org>
@@ -2116,6 +2116,11 @@ acpi_sleep_state(struct acpi_softc *sc, int state)
if (config_suspend(mainbus, DVACT_QUIESCE))
goto fail_quiesce;
+#ifdef HIBERNATE
+ if (state == ACPI_STATE_S4)
+ hibernate_suspend_bufcache();
+#endif /* HIBERNATE */
+
bufq_quiesce();
#ifdef MULTIPROCESSOR
@@ -2193,6 +2198,7 @@ fail_quiesce:
if (state == ACPI_STATE_S4) {
hibernate_free();
uvm_pmr_dirty_everything();
+ hibernate_resume_bufcache();
}
#endif /* HIBERNATE */
diff --git a/sys/kern/vfs_bio.c b/sys/kern/vfs_bio.c
index 936777e4709..bab53313460 100644
--- a/sys/kern/vfs_bio.c
+++ b/sys/kern/vfs_bio.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: vfs_bio.c,v 1.156 2014/07/08 17:19:25 deraadt Exp $ */
+/* $OpenBSD: vfs_bio.c,v 1.157 2014/07/11 03:06:08 mlarkin Exp $ */
/* $NetBSD: vfs_bio.c,v 1.44 1996/06/11 11:15:36 pk Exp $ */
/*
@@ -58,6 +58,10 @@
#include <sys/kernel.h>
#include <sys/specdev.h>
+#ifdef HIBERNATE
+#include <sys/hibernate.h>
+#endif /* HIBERNATE */
+
int nobuffers;
int needbuffer;
struct bio_ops bioops;
@@ -1228,3 +1232,31 @@ bufcache_release(struct buf *bp)
}
TAILQ_INSERT_TAIL(queue, bp, b_freelist);
}
+
+#ifdef HIBERNATE
+/*
+ * Flush buffercache to lowest value on hibernate suspend
+ */
+void
+hibernate_suspend_bufcache(void)
+{
+ long save_buflowpages = buflowpages;
+
+ /* Shrink buffercache to 16MB (4096 pages) */
+ buflowpages = 4096;
+ bufadjust(buflowpages);
+ buflowpages = save_buflowpages;
+ bufhighpages = bufpages;
+}
+
+void
+hibernate_resume_bufcache(void)
+{
+ uint64_t dmapages, pgs;
+
+ dmapages = uvm_pagecount(&dma_constraint);
+ pgs = bufcachepercent * dmapages / 100;
+ bufadjust(pgs);
+ bufhighpages = bufpages;
+}
+#endif /* HIBERNATE */
diff --git a/sys/sys/hibernate.h b/sys/sys/hibernate.h
index c3612fc20bd..b1f546980fe 100644
--- a/sys/sys/hibernate.h
+++ b/sys/sys/hibernate.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: hibernate.h,v 1.32 2014/07/09 14:10:25 mlarkin Exp $ */
+/* $OpenBSD: hibernate.h,v 1.33 2014/07/11 03:06:08 mlarkin Exp $ */
/*
* Copyright (c) 2011 Ariane van der Steldt <ariane@stack.nl>
@@ -145,5 +145,7 @@ void hibernate_free(void);
int hibernate_check_overlap(paddr_t, paddr_t, paddr_t, paddr_t);
void hibernate_sort_ranges(union hibernate_info *);
+void hibernate_suspend_bufcache(void);
+void hibernate_resume_bufcache(void);
#endif /* _SYS_HIBERNATE_H_ */