From nobody Sun Oct 10 09:24:29 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 8DB7212DF9B4; Sun, 10 Oct 2021 09:24:38 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HRxMl5JM7z3NQK; Sun, 10 Oct 2021 09:24:35 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id A2C6B2F46; Sun, 10 Oct 2021 09:24:29 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 19A9OTw3003778; Sun, 10 Oct 2021 09:24:29 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 19A9OTte003777; Sun, 10 Oct 2021 09:24:29 GMT (envelope-from git) Date: Sun, 10 Oct 2021 09:24:29 GMT Message-Id: <202110100924.19A9OTte003777@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Konstantin Belousov Subject: git: 0b29fd06dab2 - stable/13 - vm_fault: do not trigger OOM too early List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: kib X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 0b29fd06dab2c7ed97293adb82a7392f2ab3b4e2 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=0b29fd06dab2c7ed97293adb82a7392f2ab3b4e2 commit 0b29fd06dab2c7ed97293adb82a7392f2ab3b4e2 Author: Konstantin Belousov AuthorDate: 2021-10-04 06:36:02 +0000 Commit: Konstantin Belousov CommitDate: 2021-10-10 09:22:58 +0000 vm_fault: do not trigger OOM too early (cherry picked from commit 174aad047e12e8f30f9a5919ca1c08919441a217) --- sys/vm/vm_fault.c | 52 +++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/sys/vm/vm_fault.c b/sys/vm/vm_fault.c index 03ca297ea683..c0ac89e4b70f 100644 --- a/sys/vm/vm_fault.c +++ b/sys/vm/vm_fault.c @@ -125,7 +125,8 @@ struct faultstate { vm_prot_t fault_type; vm_prot_t prot; int fault_flags; - int oom; + struct timeval oom_start_time; + bool oom_started; boolean_t wired; /* Page reference for cow. */ @@ -1069,6 +1070,38 @@ vm_fault_zerofill(struct faultstate *fs) vm_page_valid(fs->m); } +/* + * Initiate page fault after timeout. Returns true if caller should + * do vm_waitpfault() after the call. + */ +static bool +vm_fault_allocate_oom(struct faultstate *fs) +{ + struct timeval now; + + unlock_and_deallocate(fs); + if (vm_pfault_oom_attempts < 0) + return (true); + if (!fs->oom_started) { + fs->oom_started = true; + getmicrotime(&fs->oom_start_time); + return (true); + } + + getmicrotime(&now); + timevalsub(&now, &fs->oom_start_time); + if (now.tv_sec < vm_pfault_oom_attempts * vm_pfault_oom_wait) + return (true); + + if (bootverbose) + printf( + "proc %d (%s) failed to alloc page on fault, starting OOM\n", + curproc->p_pid, curproc->p_comm); + vm_pageout_oom(VM_OOM_MEM_PF); + fs->oom_started = false; + return (false); +} + /* * Allocate a page directly or via the object populate method. */ @@ -1132,22 +1165,11 @@ vm_fault_allocate(struct faultstate *fs) fs->m = vm_page_alloc(fs->object, fs->pindex, alloc_req); } if (fs->m == NULL) { - unlock_and_deallocate(fs); - if (vm_pfault_oom_attempts < 0 || - fs->oom < vm_pfault_oom_attempts) { - fs->oom++; + if (vm_fault_allocate_oom(fs)) vm_waitpfault(dset, vm_pfault_oom_wait * hz); - } else { - if (bootverbose) - printf( - "proc %d (%s) failed to alloc page on fault, starting OOM\n", - curproc->p_pid, curproc->p_comm); - vm_pageout_oom(VM_OOM_MEM_PF); - fs->oom = 0; - } return (KERN_RESOURCE_SHORTAGE); } - fs->oom = 0; + fs->oom_started = false; return (KERN_NOT_RECEIVER); } @@ -1296,7 +1318,7 @@ vm_fault(vm_map_t map, vm_offset_t vaddr, vm_prot_t fault_type, fs.fault_flags = fault_flags; fs.map = map; fs.lookup_still_valid = false; - fs.oom = 0; + fs.oom_started = false; faultcount = 0; nera = -1; hardfault = false;