ref: 0af752a657ea0a003e5f9bd3d9a883fc807e474e
parent: fd8f946181181afcff53d8fdf200414bc9a935be
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Sun Jul 13 08:43:26 EDT 2025
kernel: cap the amount of work to reclaim pages form hash cain When looking for free pages in a Image, we want to skip over recently used pages as they'r at the head of hash chains. However, if the cache is very full, this takes too long. So cap how deep we walk into each chain and just take what we have.
--- a/sys/src/9/port/page.c
+++ b/sys/src/9/port/page.c
@@ -113,6 +113,7 @@
Page **h, **l, **x, *p;
Page *fh, *ft;
ulong np;
+ int c;
lock(i);
if(i->pgref == 0){
@@ -124,9 +125,15 @@
for(h = i->pghash; h < &i->pghash[PGHSIZE]; h++){
l = h;
x = nil;
+ c = 1;
for(p = *l; p != nil; p = p->next){
- if(p->ref == 0)
+ if(p->ref == 0){
x = l;
+ /* too many collisions, take what we have */
+ if(c >= 64)
+ break;
+ }
+ c++;
l = &p->next;
}
if(x == nil)
--
⑨