From nobody Wed Aug 17 10:36:32 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 4M74FD5Qh8z4Z4wg; Wed, 17 Aug 2022 10:36:32 +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 4M74FD4ztjz40GC; Wed, 17 Aug 2022 10:36:32 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660732592; 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=QNpwGNnFODH/1R95uImxuDk1jjxRoBLOnP297uRhf+0=; b=JGQg+J5M53Mnht6JGXyllJeuBmlhuwi266S5zFjauJ5LJlVJ6cHZLzd+2Dpw0bVwMKuhWP IoO8wayXAGQVGz4x+Ve6aFsvhKAjb1wGOcnlToCUbyEIJUX0tTlAD7ynW+QCpnZymnFXhp iHPh2d6rFNGbMb4bUXFdQISXUXlK/oh/JLEL+Pj0AJR/HHn5T4EB9YYVsV7mfaKNHOQKru vx/mVtYdSFI9hPtEcM5ipTiFy1b3+KkckYXQltEViuPNW1+akosTCStaOYYDAmA0d6ImYC NBuVPOIJIRtmO44D/A7cbQ786TGP1oJC9tD6GBSagufnp7Yd4Y2RSlRefprB2w== 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 4M74FD3nf9zmGT; Wed, 17 Aug 2022 10:36:32 +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 27HAaWGh001893; Wed, 17 Aug 2022 10:36:32 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 27HAaW0P001892; Wed, 17 Aug 2022 10:36:32 GMT (envelope-from git) Date: Wed, 17 Aug 2022 10:36:32 GMT Message-Id: <202208171036.27HAaW0P001892@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mateusz Guzik Subject: git: f6ffed44a8eb - main - vm: use atomic fetchadd in vm_page_sunbusy 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: mjg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f6ffed44a8eb5d1ab89a18e60fb056aab2105be7 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1660732592; 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=QNpwGNnFODH/1R95uImxuDk1jjxRoBLOnP297uRhf+0=; b=nr1OScObmdfW+2XtkV4Yt7pov1wsCDcP8hwehZwd66PFtC9CqpVlOZf8nC4U65MvCfWJgC eCFZkgqONHNvkI6xRDQkpTiFOnHGuZUm6gmcyd4121mM4VYMFmbvrmS3mgte1gWbMSoSZe 3IdkEMYPJHjuVmlkUORnlKsdywUvz0sDFDZnwGVXHRTzqHC59NPse/tjU3MddowV45PCBa MDp1a6osI8bEWRL/sJ7wNI9J+PULblzmgxjc1aXmnr5POzvpdLnMapVCbOlNGKKre3sEMo eu8ThjF73Sbaj3Tx3pzoBAlw5ypzYprp4GP/bhBwvNttxQP4dA6GLp8vxba4qQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1660732592; a=rsa-sha256; cv=none; b=NURQAPLECuaXqw1uTYzcYZLBPZTZmZ+61nesPy379mXgOWwlld8zPjCJn/g5lrPpEutc4M 72gEKu41kFwfXcv57LyHXG0mteEUiRPcxYLbfO5FzHPvXdlcnnfAaX0rPiZhWSy3sLEwHv /bgxsQ85pxTlbbllpOGZLfKNYfFGpFHoATvRAH/hJzhMq5YkZVXGw0PlfKQTdWj3cUUNeb sCrpVHt+SVvsAFgMJO3cIyp4nD9i598pHW6aZ60LxZwD/fVdh8+w5V0y7TadjzR4fIkhF8 SdLH2CAQOyN8rkKXtKD2piGeOCeYFBcdwULI4cgyjtBNC6tdBETpTpoe4gp8RA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=f6ffed44a8eb5d1ab89a18e60fb056aab2105be7 commit f6ffed44a8eb5d1ab89a18e60fb056aab2105be7 Author: Mateusz Guzik AuthorDate: 2022-08-05 14:27:55 +0000 Commit: Mateusz Guzik CommitDate: 2022-08-17 10:36:11 +0000 vm: use atomic fetchadd in vm_page_sunbusy This also fixes a bug where not-last unbusy failed to post a release fence. Reviewed by: markj (previous version), kib (previous version) Differential Revision: https://reviews.freebsd.org/D36084 --- sys/vm/vm_page.c | 26 ++++++-------------------- 1 file changed, 6 insertions(+), 20 deletions(-) diff --git a/sys/vm/vm_page.c b/sys/vm/vm_page.c index e7500e9d3e71..defcebb286ae 100644 --- a/sys/vm/vm_page.c +++ b/sys/vm/vm_page.c @@ -973,27 +973,13 @@ vm_page_sunbusy(vm_page_t m) { u_int x; - vm_page_assert_sbusied(m); - - x = vm_page_busy_fetch(m); - for (;;) { - KASSERT(x != VPB_FREED, - ("vm_page_sunbusy: Unlocking freed page.")); - if (VPB_SHARERS(x) > 1) { - if (atomic_fcmpset_int(&m->busy_lock, &x, - x - VPB_ONE_SHARER)) - break; - continue; - } - KASSERT((x & ~VPB_BIT_WAITERS) == VPB_SHARERS_WORD(1), - ("vm_page_sunbusy: invalid lock state")); - if (!atomic_fcmpset_rel_int(&m->busy_lock, &x, VPB_UNBUSIED)) - continue; - if ((x & VPB_BIT_WAITERS) == 0) - break; + atomic_thread_fence_rel(); + x = atomic_fetchadd_int(&m->busy_lock, -VPB_ONE_SHARER); + KASSERT(x != VPB_FREED, ("page %p is freed", m)); + KASSERT(x != VPB_UNBUSIED && (x & VPB_BIT_SHARED) != 0, + ("page %p not sbusied", m)); + if (x == (VPB_SHARERS_WORD(1) | VPB_BIT_WAITERS)) wakeup(m); - break; - } } /*