diff options
author | dillon <dillon@FreeBSD.org> | 2000-11-18 23:06:26 +0000 |
---|---|---|
committer | dillon <dillon@FreeBSD.org> | 2000-11-18 23:06:26 +0000 |
commit | 2ace35208525bb250b47fe7af60ec2ce681c6c92 (patch) | |
tree | 8b9f3edb21d176840f55c8efbf3c9ffe76fdabc6 /sys/vm/vm_page.c | |
parent | 59e131028ff3997be98ab838d5ab9f965b1589ca (diff) | |
download | FreeBSD-src-2ace35208525bb250b47fe7af60ec2ce681c6c92.zip FreeBSD-src-2ace35208525bb250b47fe7af60ec2ce681c6c92.tar.gz |
Implement a low-memory deadlock solution.
Removed most of the hacks that were trying to deal with low-memory
situations prior to now.
The new code is based on the concept that I/O must be able to function in
a low memory situation. All major modules related to I/O (except
networking) have been adjusted to allow allocation out of the system
reserve memory pool. These modules now detect a low memory situation but
rather then block they instead continue to operate, then return resources
to the memory pool instead of cache them or leave them wired.
Code has been added to stall in a low-memory situation prior to a vnode
being locked.
Thus situations where a process blocks in a low-memory condition while
holding a locked vnode have been reduced to near nothing. Not only will
I/O continue to operate, but many prior deadlock conditions simply no
longer exist.
Implement a number of VFS/BIO fixes
(found by Ian): in biodone(), bogus-page replacement code, the loop
was not properly incrementing loop variables prior to a continue
statement. We do not believe this code can be hit anyway but we
aren't taking any chances. We'll turn the whole section into a
panic (as it already is in brelse()) after the release is rolled.
In biodone(), the foff calculation was incorrectly
clamped to the iosize, causing the wrong foff to be calculated
for pages in the case of an I/O error or biodone() called without
initiating I/O. The problem always caused a panic before. Now it
doesn't. The problem is mainly an issue with NFS.
Fixed casts for ~PAGE_MASK. This code worked properly before only
because the calculations use signed arithmatic. Better to properly
extend PAGE_MASK first before inverting it for the 64 bit masking
op.
In brelse(), the bogus_page fixup code was improperly throwing
away the original contents of 'm' when it did the j-loop to
fix the bogus pages. The result was that it would potentially
invalidate parts of the *WRONG* page(!), leading to corruption.
There may still be cases where a background bitmap write is
being duplicated, causing potential corruption. We have identified
a potentially serious bug related to this but the fix is still TBD.
So instead this patch contains a KASSERT to detect the problem
and panic the machine rather then continue to corrupt the filesystem.
The problem does not occur very often.. it is very hard to
reproduce, and it may or may not be the cause of the corruption
people have reported.
Review by: (VFS/BIO: mckusick, Ian Dowse <iedowse@maths.tcd.ie>)
Testing by: (VM/Deadlock) Paul Saab <ps@yahoo-inc.com>
Diffstat (limited to 'sys/vm/vm_page.c')
-rw-r--r-- | sys/vm/vm_page.c | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/sys/vm/vm_page.c b/sys/vm/vm_page.c index 038a5ad..9c868fc 100644 --- a/sys/vm/vm_page.c +++ b/sys/vm/vm_page.c @@ -860,7 +860,7 @@ loop: * Don't wakeup too often - wakeup the pageout daemon when * we would be nearly out of memory. */ - if (vm_paging_needed() || cnt.v_free_count < cnt.v_pageout_free_min) + if (vm_paging_needed()) pagedaemon_wakeup(); splx(s); @@ -882,10 +882,10 @@ vm_wait() s = splvm(); if (curproc == pageproc) { vm_pageout_pages_needed = 1; - tsleep(&vm_pageout_pages_needed, PSWP, "vmwait", 0); + tsleep(&vm_pageout_pages_needed, PSWP, "VMWait", 0); } else { if (!vm_pages_needed) { - vm_pages_needed++; + vm_pages_needed = 1; wakeup(&vm_pages_needed); } tsleep(&cnt.v_free_count, PVM, "vmwait", 0); @@ -1030,7 +1030,8 @@ vm_page_free_wakeup() * if pageout daemon needs pages, then tell it that there are * some free. */ - if (vm_pageout_pages_needed) { + if (vm_pageout_pages_needed && + cnt.v_cache_count + cnt.v_free_count >= cnt.v_pageout_free_min) { wakeup(&vm_pageout_pages_needed); vm_pageout_pages_needed = 0; } @@ -1039,9 +1040,9 @@ vm_page_free_wakeup() * high water mark. And wakeup scheduler process if we have * lots of memory. this process will swapin processes. */ - if (vm_pages_needed && vm_page_count_min()) { - wakeup(&cnt.v_free_count); + if (vm_pages_needed && !vm_page_count_min()) { vm_pages_needed = 0; + wakeup(&cnt.v_free_count); } } @@ -1240,6 +1241,9 @@ vm_page_wire(m) * processes. This optimization causes one-time-use metadata to be * reused more quickly. * + * BUT, if we are in a low-memory situation we have no choice but to + * put clean pages on the cache queue. + * * A number of routines use vm_page_unwire() to guarantee that the page * will go into either the inactive or active queues, and will NEVER * be placed in the cache - for example, just after dirtying a page. @@ -1326,6 +1330,25 @@ vm_page_deactivate(vm_page_t m) } /* + * vm_page_try_to_cache: + * + * Returns 0 on failure, 1 on success + */ +int +vm_page_try_to_cache(vm_page_t m) +{ + if (m->dirty || m->hold_count || m->busy || m->wire_count || + (m->flags & (PG_BUSY|PG_UNMANAGED))) { + return(0); + } + vm_page_test_dirty(m); + if (m->dirty) + return(0); + vm_page_cache(m); + return(1); +} + +/* * vm_page_cache * * Put the specified page onto the page cache queue (if appropriate). |