Mon Mar 3 16:50:28 2014 UTC ()
Fix the memory limiter to work for non-pagedaemon threads again

reported by njoly


(pooka)
diff -r1.149 -r1.150 src/sys/rump/librump/rumpkern/vm.c

cvs diff -r1.149 -r1.150 src/sys/rump/librump/rumpkern/vm.c (expand / switch to unified diff)

--- src/sys/rump/librump/rumpkern/vm.c 2014/02/18 06:18:13 1.149
+++ src/sys/rump/librump/rumpkern/vm.c 2014/03/03 16:50:28 1.150
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: vm.c,v 1.149 2014/02/18 06:18:13 pooka Exp $ */ 1/* $NetBSD: vm.c,v 1.150 2014/03/03 16:50:28 pooka Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2007-2011 Antti Kantee. All Rights Reserved. 4 * Copyright (c) 2007-2011 Antti Kantee. All Rights Reserved.
5 * 5 *
6 * Development of this software was supported by 6 * Development of this software was supported by
7 * The Finnish Cultural Foundation and the Research Foundation of 7 * The Finnish Cultural Foundation and the Research Foundation of
8 * The Helsinki University of Technology. 8 * The Helsinki University of Technology.
9 * 9 *
10 * Redistribution and use in source and binary forms, with or without 10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions 11 * modification, are permitted provided that the following conditions
12 * are met: 12 * are met:
13 * 1. Redistributions of source code must retain the above copyright 13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer. 14 * notice, this list of conditions and the following disclaimer.
@@ -31,27 +31,27 @@ @@ -31,27 +31,27 @@
31 31
32/* 32/*
33 * Virtual memory emulation routines. 33 * Virtual memory emulation routines.
34 */ 34 */
35 35
36/* 36/*
37 * XXX: we abuse pg->uanon for the virtual address of the storage 37 * XXX: we abuse pg->uanon for the virtual address of the storage
38 * for each page. phys_addr would fit the job description better, 38 * for each page. phys_addr would fit the job description better,
39 * except that it will create unnecessary lossage on some platforms 39 * except that it will create unnecessary lossage on some platforms
40 * due to not being a pointer type. 40 * due to not being a pointer type.
41 */ 41 */
42 42
43#include <sys/cdefs.h> 43#include <sys/cdefs.h>
44__KERNEL_RCSID(0, "$NetBSD: vm.c,v 1.149 2014/02/18 06:18:13 pooka Exp $"); 44__KERNEL_RCSID(0, "$NetBSD: vm.c,v 1.150 2014/03/03 16:50:28 pooka Exp $");
45 45
46#include <sys/param.h> 46#include <sys/param.h>
47#include <sys/atomic.h> 47#include <sys/atomic.h>
48#include <sys/buf.h> 48#include <sys/buf.h>
49#include <sys/kernel.h> 49#include <sys/kernel.h>
50#include <sys/kmem.h> 50#include <sys/kmem.h>
51#include <sys/vmem.h> 51#include <sys/vmem.h>
52#include <sys/mman.h> 52#include <sys/mman.h>
53#include <sys/null.h> 53#include <sys/null.h>
54#include <sys/vnode.h> 54#include <sys/vnode.h>
55 55
56#include <machine/pmap.h> 56#include <machine/pmap.h>
57 57
@@ -1148,38 +1148,39 @@ uvm_kick_pdaemon() @@ -1148,38 +1148,39 @@ uvm_kick_pdaemon()
1148 * 90% of the memory limit. This is a complete and utter 1148 * 90% of the memory limit. This is a complete and utter
1149 * stetson-harrison decision which you are allowed to finetune. 1149 * stetson-harrison decision which you are allowed to finetune.
1150 * Don't bother locking. If we have some unflushed caches, 1150 * Don't bother locking. If we have some unflushed caches,
1151 * other waker-uppers will deal with the issue. 1151 * other waker-uppers will deal with the issue.
1152 */ 1152 */
1153 if (NEED_PAGEDAEMON()) { 1153 if (NEED_PAGEDAEMON()) {
1154 cv_signal(&pdaemoncv); 1154 cv_signal(&pdaemoncv);
1155 } 1155 }
1156} 1156}
1157 1157
1158void * 1158void *
1159rump_hypermalloc(size_t howmuch, int alignment, bool waitok, const char *wmsg) 1159rump_hypermalloc(size_t howmuch, int alignment, bool waitok, const char *wmsg)
1160{ 1160{
 1161 const unsigned long thelimit =
 1162 curlwp == uvm.pagedaemon_lwp ? pdlimit : rump_physmemlimit;
1161 unsigned long newmem; 1163 unsigned long newmem;
1162 void *rv; 1164 void *rv;
1163 int error; 1165 int error;
1164 1166
1165 uvm_kick_pdaemon(); /* ouch */ 1167 uvm_kick_pdaemon(); /* ouch */
1166 1168
1167 /* first we must be within the limit */ 1169 /* first we must be within the limit */
1168 limitagain: 1170 limitagain:
1169 if (rump_physmemlimit != RUMPMEM_UNLIMITED) { 1171 if (thelimit != RUMPMEM_UNLIMITED) {
1170 newmem = atomic_add_long_nv(&curphysmem, howmuch); 1172 newmem = atomic_add_long_nv(&curphysmem, howmuch);
1171 if ((newmem > rump_physmemlimit) && 1173 if (newmem > thelimit) {
1172 !(curlwp == uvm.pagedaemon_lwp || newmem > pdlimit)) { 
1173 newmem = atomic_add_long_nv(&curphysmem, -howmuch); 1174 newmem = atomic_add_long_nv(&curphysmem, -howmuch);
1174 if (!waitok) { 1175 if (!waitok) {
1175 return NULL; 1176 return NULL;
1176 } 1177 }
1177 uvm_wait(wmsg); 1178 uvm_wait(wmsg);
1178 goto limitagain; 1179 goto limitagain;
1179 } 1180 }
1180 } 1181 }
1181 1182
1182 /* second, we must get something from the backend */ 1183 /* second, we must get something from the backend */
1183 again: 1184 again:
1184 error = rumpuser_malloc(howmuch, alignment, &rv); 1185 error = rumpuser_malloc(howmuch, alignment, &rv);
1185 if (__predict_false(error && waitok)) { 1186 if (__predict_false(error && waitok)) {