Module Name: src Committed By: chs Date: Sun Oct 18 18:31:31 UTC 2020
Modified Files: src/sys/uvm: uvm_page.c uvm_pgflcache.c Log Message: In the current code, CPU_COUNT_FREEPAGES counts pages in the global freelists AND the per-CPU pgflcache free pages caches, and that is the number of pages that the pagedaemon considers to be available. However, most pages in the pgflcache per-CPU free page caches are NOT actually available for any particular allocation, and thus allocating a page can fail even though the pagedaemon thinks enough pages are available. This change makes CPU_COUNT_FREEPAGES only count pages in the global freelists and not pages in the pgflcache per-CPU free page caches, thus better aligning the pagedaemon's view of how many pages are available with the number of pages that can actually be allocated by any particular request. This fixes a hang that Christos was hitting. To generate a diff of this commit: cvs rdiff -u -r1.248 -r1.249 src/sys/uvm/uvm_page.c cvs rdiff -u -r1.5 -r1.6 src/sys/uvm/uvm_pgflcache.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/uvm/uvm_page.c diff -u src/sys/uvm/uvm_page.c:1.248 src/sys/uvm/uvm_page.c:1.249 --- src/sys/uvm/uvm_page.c:1.248 Sun Oct 18 18:22:29 2020 +++ src/sys/uvm/uvm_page.c Sun Oct 18 18:31:31 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: uvm_page.c,v 1.248 2020/10/18 18:22:29 chs Exp $ */ +/* $NetBSD: uvm_page.c,v 1.249 2020/10/18 18:31:31 chs Exp $ */ /*- * Copyright (c) 2019, 2020 The NetBSD Foundation, Inc. @@ -95,7 +95,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.248 2020/10/18 18:22:29 chs Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uvm_page.c,v 1.249 2020/10/18 18:31:31 chs Exp $"); #include "opt_ddb.h" #include "opt_uvm.h" @@ -1069,6 +1069,7 @@ uvm_pagealloc_pgb(struct uvm_cpu *ucpu, KASSERT(pg->flags == PG_FREE); pg->flags = PG_BUSY | PG_CLEAN | PG_FAKE; pgb->pgb_nfree--; + CPU_COUNT(CPU_COUNT_FREEPAGES, -1); /* * While we have the bucket locked and our data @@ -1270,7 +1271,6 @@ uvm_pagealloc_strat(struct uvm_object *o * while still at IPL_VM, update allocation statistics. */ - CPU_COUNT(CPU_COUNT_FREEPAGES, -1); if (anon) { CPU_COUNT(CPU_COUNT_ANONCLEAN, 1); } @@ -1567,7 +1567,6 @@ uvm_pagefree(struct vm_page *pg) /* Try to send the page to the per-CPU cache. */ s = splvm(); - CPU_COUNT(CPU_COUNT_FREEPAGES, 1); ucpu = curcpu()->ci_data.cpu_uvm; bucket = uvm_page_get_bucket(pg); if (bucket == ucpu->pgflbucket && uvm_pgflcache_free(ucpu, pg)) { @@ -1585,6 +1584,7 @@ uvm_pagefree(struct vm_page *pg) pg->flags = PG_FREE; LIST_INSERT_HEAD(&pgb->pgb_colors[VM_PGCOLOR(pg)], pg, pageq.list); pgb->pgb_nfree++; + CPU_COUNT(CPU_COUNT_FREEPAGES, 1); mutex_spin_exit(lock); splx(s); } Index: src/sys/uvm/uvm_pgflcache.c diff -u src/sys/uvm/uvm_pgflcache.c:1.5 src/sys/uvm/uvm_pgflcache.c:1.6 --- src/sys/uvm/uvm_pgflcache.c:1.5 Sun Jun 14 21:41:42 2020 +++ src/sys/uvm/uvm_pgflcache.c Sun Oct 18 18:31:31 2020 @@ -1,4 +1,4 @@ -/* $NetBSD: uvm_pgflcache.c,v 1.5 2020/06/14 21:41:42 ad Exp $ */ +/* $NetBSD: uvm_pgflcache.c,v 1.6 2020/10/18 18:31:31 chs Exp $ */ /*- * Copyright (c) 2019 The NetBSD Foundation, Inc. @@ -43,7 +43,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: uvm_pgflcache.c,v 1.5 2020/06/14 21:41:42 ad Exp $"); +__KERNEL_RCSID(0, "$NetBSD: uvm_pgflcache.c,v 1.6 2020/10/18 18:31:31 chs Exp $"); #include "opt_uvm.h" #include "opt_multiprocessor.h" @@ -151,6 +151,7 @@ uvm_pgflcache_fill(struct uvm_cpu *ucpu, pg->pageq.list.le_prev = &head->lh_first; } pgb->pgb_nfree -= (count - pcc->count); + CPU_COUNT(CPU_COUNT_FREEPAGES, -(count - pcc->count)); pcc->count = count; } @@ -188,6 +189,7 @@ uvm_pgflcache_spill(struct uvm_cpu *ucpu LIST_INSERT_HEAD(head, pcc->pages[pcc->count], pageq.list); } pgb->pgb_nfree += adj; + CPU_COUNT(CPU_COUNT_FREEPAGES, adj); mutex_spin_exit(lock); }