From nobody Wed Oct 05 19:18:19 2022 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 4MjPVg4kdGz4dsPk; Wed, 5 Oct 2022 19:18:19 +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 4MjPVg2Y4Dz44PS; Wed, 5 Oct 2022 19:18:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664997499; 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=alds+r/nf9J5uImYXYYO24+dHNakPgHnAHoElNUDS8c=; b=b62oCmg2vOKPGdmkAPekyZzMgi5YBFORhjWxLd1jpchC9pm9jWLM0FbxKxeuKKQWYkYea1 3d7LM9gVnMpP5602e/RdIZzYmGiq3tmyNqGmcvMWlpRwfgXmmpi+4fsn2rchSVBfQrRrgK aFf/skhUaPi0+COxcl80jZSbccflVdIKUrQ3CZ1FAyXjpOTWYAHFRJ3wCCTIWLjmYTtztA 3n6DhafU2AzlYlzjrUjuw+kOm+Xt4KD/Gs/LpenfhkAVOE+no3jWSHwX7CLu789TjtFDYq 8hWE+bgwLbeuOfV5hFCyQmZTeKKW2AYTJ5jLF19qo92Pw1sO5DgsnbSbBVxfmw== 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 4MjPVg1HPQz10wJ; Wed, 5 Oct 2022 19:18:19 +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 295JIJvn052579; Wed, 5 Oct 2022 19:18:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 295JIJ07052578; Wed, 5 Oct 2022 19:18:19 GMT (envelope-from git) Date: Wed, 5 Oct 2022 19:18:19 GMT Message-Id: <202210051918.295JIJ07052578@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 2c9dc2384f85 - main - vm_page: Fix a logic error in the handling of PQ_ACTIVE operations 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: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2c9dc2384f85a4ccc44a79b349f4fb0253a2f254 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1664997499; 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=alds+r/nf9J5uImYXYYO24+dHNakPgHnAHoElNUDS8c=; b=q20kklU7rrVl0XY9I+ziMM9/FuxsahVGaewCMxq09vszzyLP/HjXwcdEH8z2wtstnCuWv4 Fb79+PlMiQNec4YYxKzrMvrVVJmmAvhu6/m6TyqVp5SKsPxN4xy8ABGxINhLOoqnbZ3/rw ZT4C72PEqa6llIsiL6kUm8LlIr+Vwa8YEwcvZ9OKd+4s/kwfEZwXR8a7CBa0E6X2xLcqov q0YVmveD2Gbuo/2oajkkO55v8EaPTINAIcg6hrG2SDlh7hPQDlI2iGLD+O9kwQ+B+/E+Ji bcAnqDPYKHAA3YA6WfQnUQRApnzng3pHkb6mPvEXAnUDF/xojWdVS+fCQqL/tQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1664997499; a=rsa-sha256; cv=none; b=MZeF/PlbLSqwmQVIJ8royf92H1oT8D1Cres3ZyFijdb6mz1Vyjy5AtBVHIFq0mw+i2Zt7a Cczsxs0FQVjRNwvbSdb8GqQOzlD5usQcq/551zLltIkDGs89qkA/LEAwR1t6ZQyDa/iWUO 9x4d4AqU/BC+bE8M+4KW1IafhSEyu7w0RU5stBvHh/m1nT6ab3HkCHsGTXNf4vlQOSVCfg x5JidK0ShVJINEyGxBCYg22gVH7Vp8ZYnUNxXlAE8t8whn7iGeoV+IxirYMU3jCc7rF3ox R83r7/T45p7zKBjCRIKuDvsnvkCo3wi1I3GJ4v/S41aojh3GZJxLjYpyGAHI3w== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=2c9dc2384f85a4ccc44a79b349f4fb0253a2f254 commit 2c9dc2384f85a4ccc44a79b349f4fb0253a2f254 Author: Mark Johnston AuthorDate: 2022-10-05 19:12:46 +0000 Commit: Mark Johnston CommitDate: 2022-10-05 19:12:46 +0000 vm_page: Fix a logic error in the handling of PQ_ACTIVE operations As an optimization, vm_page_activate() avoids requeuing a page that's already in the active queue. A page's location in the active queue is mostly unimportant. When a page is unwired and placed back in the page queues, vm_page_unwire() avoids moving pages out of PQ_ACTIVE to honour the request, the idea being that they're likely mapped and so will simply get bounced back in to PQ_ACTIVE during a queue scan. In both cases, if the page was logically in PQ_ACTIVE but had not yet been physically enqueued (i.e., the page is in a per-CPU batch), we would end up clearing PGA_REQUEUE from the page. Then, batch processing would ignore the page, so it would end up unwired and not in any queues. This can arise, for example, when a page is allocated and then vm_page_activate() is called multiple times in quick succession. The result is that the page is hidden from the page daemon, so while it will be freed when its VM object is destroyed, it cannot be reclaimed under memory pressure. Fix the bug: when checking if a page is in PQ_ACTIVE, only perform the optimization if the page is physically enqueued. PR: 256507 Fixes: f3f38e2580f1 ("Start implementing queue state updates using fcmpset loops.") Reviewed by: alc, kib MFC after: 1 week Sponsored by: E-CARD Ltd. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D36839 --- sys/vm/vm_page.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sys/vm/vm_page.c b/sys/vm/vm_page.c index e7500e9d3e71..d6084a5b052b 100644 --- a/sys/vm/vm_page.c +++ b/sys/vm/vm_page.c @@ -4141,7 +4141,12 @@ vm_page_mvqueue(vm_page_t m, const uint8_t nqueue, const uint16_t nflag) if (nqueue == PQ_ACTIVE) new.act_count = max(old.act_count, ACT_INIT); if (old.queue == nqueue) { - if (nqueue != PQ_ACTIVE) + /* + * There is no need to requeue pages already in the + * active queue. + */ + if (nqueue != PQ_ACTIVE || + (old.flags & PGA_ENQUEUED) == 0) new.flags |= nflag; } else { new.flags |= nflag; @@ -4238,7 +4243,8 @@ vm_page_release_toq(vm_page_t m, uint8_t nqueue, const bool noreuse) * referenced and avoid any queue operations. */ new.flags &= ~PGA_QUEUE_OP_MASK; - if (nflag != PGA_REQUEUE_HEAD && old.queue == PQ_ACTIVE) + if (nflag != PGA_REQUEUE_HEAD && old.queue == PQ_ACTIVE && + (old.flags & PGA_ENQUEUED) != 0) new.flags |= PGA_REFERENCED; else { new.flags |= nflag;