From nobody Thu Feb 10 14:55:17 2022 X-Original-To: dev-commits-src-main@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 0A7ED19B5EC1; Thu, 10 Feb 2022 14:55:18 +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 4JvftY6kWdz3Jcx; Thu, 10 Feb 2022 14:55:17 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644504918; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6Jj8QtbFfSuAqSrySzTOMTrIcPoa4HHLkPht+BaH6+4=; b=RUw00QZlnLhPUonAn6Dn5g0CTA6Y/q2l3W3lEzND9FEecdT0R4wOb+GDyxwxqQgOUhacTC //ApQ41coOXr226nWj1a9JUzGp6k7aeMh6Y+VeZeSXrgYDjTbI4Do3vkOt9xlK0Bwdz7LH 5OWr3JU6hNrYgm6A3WpGA0LG3AX5xL9/nYhT6XvnpvcyO/0btIppQzRmu9/Ewn/gp2i/99 YG+8Tc4IxreMzSDeNCh0rIZ6upXjvZ58wvqih1tLS70stQ7YP6Uj84VFilyfXf3qHeSKrJ /9Q/dtqv+bHaO5r9ZOffFvx7Y4kLhavfEfSt+I2jaBDF4k0GkjkahdVxAvpklg== 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 C754B22824; Thu, 10 Feb 2022 14:55:17 +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 21AEtHBw043754; Thu, 10 Feb 2022 14:55:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 21AEtH81043753; Thu, 10 Feb 2022 14:55:17 GMT (envelope-from git) Date: Thu, 10 Feb 2022 14:55:17 GMT Message-Id: <202202101455.21AEtH81043753@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Konstantin Belousov Subject: git: b51927b7b018 - main - Revert "vm_pageout_scans: correct detection of active object" List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@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/main X-Git-Reftype: branch X-Git-Commit: b51927b7b018d268c91b2127d82786caf68254de Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1644504918; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=6Jj8QtbFfSuAqSrySzTOMTrIcPoa4HHLkPht+BaH6+4=; b=Vl0/hT/Jwdb7wsWWoItgofKAC7s7jwF2znHJc1xkZMwjASqI8X7bYKGoUxakWHgzeTUYtP J+Pm3erLgSHHBJHpFvnWsMVnYfqcjgGkyWhEJrEeuNduMMwxRlXTjbIQZagHwOy/ZaDjm+ U+rRSO8gov8QdVfxl8OyDJJUiDUfa2UPFlCLMsqVdtPQFVSeHiwpddUy0wKzifw93r/dwo CbE9EDEHvXLTWLJJtzfUO4Bh1Z1h+HfC2J9iAS4l2LEKVSheBgNBqEEcdlJjGXskXev549 TWLFkfQMtKQox9oT8c54IRl3kOIExacAo6dtcD0d+SYoMTYiGJu3XFUheOl15w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1644504918; a=rsa-sha256; cv=none; b=g+2dGMH002xIwjyT4DX5MjAViiDJ/0h5x2Tg8ypH5HJqb6yz1340Pb3+CxvxSOpciGkqsp 2XYwvzwHE49FHdjRBdxO/MYTghPee/tff0etwsKzGvXorYpYnnm7hr7891Ohf2c/0Dtftc q2/O/qeS7SuxqRyPxfU5awZHHUxbf46wZH+hrTJqN5i1spbXbaSvTi65nMpgAOHyC3D2zI xoE7pZMDhbLkEidUH9/fzUk064yWj8rgvlNfuuJ+R5PD0HRDKtLC6sqAWAuPr0pi1oZJsc 8u1NfDxz/JwwSb545tf5lAklpNp3tmUliTfo1Sa5b6Y75ayBE3kI4umyWGPYZQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kib: URL: https://cgit.FreeBSD.org/src/commit/?id=b51927b7b018d268c91b2127d82786caf68254de commit b51927b7b018d268c91b2127d82786caf68254de Author: Konstantin Belousov AuthorDate: 2022-02-10 14:50:42 +0000 Commit: Konstantin Belousov CommitDate: 2022-02-10 14:55:10 +0000 Revert "vm_pageout_scans: correct detection of active object" This reverts commit 3de96d664aaaf8e3fb1ca4fc4bd864d2cf734b24. Problem is that it is possible to reach the state with ref_count == 1 for the mapped non-anonymous object. For instance, anonymous posix shmfd or linux shmfs object could be mapped, and then corresponding file descriptor closed, dropping the object reference owned by the shmfd/shmfs file. Then the check in inactive scan assumes that the object and page are not mapped and frees the page, while they are not. PR: 261707 Discussed with: markj Sponsored by: The FreeBSD Foundation MFC after: now --- sys/vm/vm_pageout.c | 56 +++++++++++++++++------------------------------------ 1 file changed, 18 insertions(+), 38 deletions(-) diff --git a/sys/vm/vm_pageout.c b/sys/vm/vm_pageout.c index 7d5c90c78f83..36d5f3275800 100644 --- a/sys/vm/vm_pageout.c +++ b/sys/vm/vm_pageout.c @@ -712,38 +712,6 @@ unlock_mp: return (error); } -/* - * Check if the object is active. Non-anonymous swap objects are - * always referenced by the owner, for them require ref_count > 1 in - * order to ignore the ownership ref. - * - * Perform an unsynchronized object ref count check. While - * the page lock ensures that the page is not reallocated to - * another object, in particular, one with unmanaged mappings - * that cannot support pmap_ts_referenced(), two races are, - * nonetheless, possible: - * 1) The count was transitioning to zero, but we saw a non- - * zero value. pmap_ts_referenced() will return zero - * because the page is not mapped. - * 2) The count was transitioning to one, but we saw zero. - * This race delays the detection of a new reference. At - * worst, we will deactivate and reactivate the page. - */ -static bool -vm_pageout_object_act(vm_object_t object) -{ - return (object->ref_count > - ((object->flags & (OBJ_SWAP | OBJ_ANON)) == OBJ_SWAP ? 1 : 0)); -} - -static int -vm_pageout_page_ts_referenced(vm_object_t object, vm_page_t m) -{ - if (!vm_pageout_object_act(object)) - return (0); - return (pmap_ts_referenced(m)); -} - /* * Attempt to launder the specified number of pages. * @@ -838,7 +806,7 @@ scan: if (vm_page_none_valid(m)) goto free_page; - refs = vm_pageout_page_ts_referenced(object, m); + refs = object->ref_count != 0 ? pmap_ts_referenced(m) : 0; for (old = vm_page_astate_load(m);;) { /* @@ -858,7 +826,7 @@ scan: } if (act_delta == 0) { ; - } else if (vm_pageout_object_act(object)) { + } else if (object->ref_count != 0) { /* * Increase the activation count if the page was * referenced while in the laundry queue. This @@ -1295,8 +1263,20 @@ act_scan: * Test PGA_REFERENCED after calling pmap_ts_referenced() so * that a reference from a concurrently destroyed mapping is * observed here and now. + * + * Perform an unsynchronized object ref count check. While + * the page lock ensures that the page is not reallocated to + * another object, in particular, one with unmanaged mappings + * that cannot support pmap_ts_referenced(), two races are, + * nonetheless, possible: + * 1) The count was transitioning to zero, but we saw a non- + * zero value. pmap_ts_referenced() will return zero + * because the page is not mapped. + * 2) The count was transitioning to one, but we saw zero. + * This race delays the detection of a new reference. At + * worst, we will deactivate and reactivate the page. */ - refs = vm_pageout_page_ts_referenced(object, m); + refs = object->ref_count != 0 ? pmap_ts_referenced(m) : 0; old = vm_page_astate_load(m); do { @@ -1546,7 +1526,7 @@ vm_pageout_scan_inactive(struct vm_domain *vmd, int page_shortage) if (vm_page_none_valid(m)) goto free_page; - refs = vm_pageout_page_ts_referenced(object, m); + refs = object->ref_count != 0 ? pmap_ts_referenced(m) : 0; for (old = vm_page_astate_load(m);;) { /* @@ -1566,7 +1546,7 @@ vm_pageout_scan_inactive(struct vm_domain *vmd, int page_shortage) } if (act_delta == 0) { ; - } else if (vm_pageout_object_act(object)) { + } else if (object->ref_count != 0) { /* * Increase the activation count if the * page was referenced while in the @@ -1604,7 +1584,7 @@ vm_pageout_scan_inactive(struct vm_domain *vmd, int page_shortage) * mappings allow write access, then the page may still be * modified until the last of those mappings are removed. */ - if (vm_pageout_object_act(object)) { + if (object->ref_count != 0) { vm_page_test_dirty(m); if (m->dirty == 0 && !vm_page_try_remove_all(m)) goto skip_page;