From nobody Thu Dec 21 13:44:02 2023 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 4Sws8y6Hlqz54pb2; Thu, 21 Dec 2023 13:44:02 +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 4Sws8y2YS8z4PTf; Thu, 21 Dec 2023 13:44:02 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703166242; 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=zTAa8nRMEQ6rFNIA2yT9vlG0XSntSZ2OFx5cbgRl3VE=; b=pF9/6lOWjl5pi2o3aA7Oy9Bb9qUC9CRFlP4dY5ggqrPsFbh4RuI+saA/nAI3smSDxEJgzq dNH/oIAFM55jAl87V1+TPtWzGeT4d94vTXk933mVVYL7BLgBuW3P9m6RKg53zXhh1v/eUg nhQwhNlcOY/t8MMwMGybxWut5BLlqL21WWiVp7xJCb6T8Lqb5Z6NMWlCzrC4e/hBCUSURR VQWBWgo+m0XAdXQsUvbLRw6EFGdyh8uKi+yq6cOrT88kMFUO5oxCXgehkc0e/AVwgFq1VR hc3KiTnA20eKu4U7N9beIuCctxqXT5ggWTbQXLzTXpezMkpfmzKKXdNjbCGmbw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1703166242; a=rsa-sha256; cv=none; b=A2odoQEGPm8ldmdHk8ZnuQB3Gk6oLSt2CLLeVblE37RiiQrk38Py9WU/vCSkHxVXJvtO2f InUMXfrDY6hB+iFzfffZMl1sXYYUJZhF/jRosM74umkVtDt28pQQVqQkwT5wFYecVvkVm2 zzngT8kMC3F2+xCTNCNjcQ2kncfoy3b+pGa8sTVC/MAHpC9dBB3MuPhGGH1noL8C+mDywl cn4O8PCGTaTPxWBY3aj9o5d82EIVRPGJhyv/vcd/xtYC/knh0QekF9XLeIjMcCmWybJufb BzYHH+XE+XMKGSE4ZMYjsgDvW71V2GbyuNHKov0YAw+XubH+pvLJwpWcf47xoQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1703166242; 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=zTAa8nRMEQ6rFNIA2yT9vlG0XSntSZ2OFx5cbgRl3VE=; b=TCdmoiLcdxKoKxYtxPjUyesEP80mzBgeIo0GOSAZt2yY7WMPh62FwE4c9qJxh6dD8lxTIN gy5t0sLYtMOdsvYGixGpwP5fm7J8No8KZsi25OSFj5TTvhRIaJZKbyX0nhYZrkq1xRrHtq hPH1rIvzmcbT28BCCEkehNxeniZ7bpOGU0bEo1LCV3hH70mSq3pZoqp1sEUJsnt2aSZvz9 d0/XmDZRaTI5B31MtqUxTm4wUwAwy2NqB42sPkMdd2A0rW4kUW2Gf3dux3U6ZF/wo4aG/l ucus8pfzUAOJVmZCBkwpx6ZbnUZJ4RCI+xhWATroyOrzecg4NccRNYjDrTPAVg== 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 4Sws8y1dFlzb7h; Thu, 21 Dec 2023 13:44:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 3BLDi2TV080244; Thu, 21 Dec 2023 13:44:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3BLDi2hi080241; Thu, 21 Dec 2023 13:44:02 GMT (envelope-from git) Date: Thu, 21 Dec 2023 13:44:02 GMT Message-Id: <202312211344.3BLDi2hi080241@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Olivier Certner Subject: git: 706303829968 - stable/13 - Ensure 'struct thread' is aligned to a cache line 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: olce X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 7063038299682f421a3b56ade0dbd40c2ce69292 Auto-Submitted: auto-generated The branch stable/13 has been updated by olce: URL: https://cgit.FreeBSD.org/src/commit/?id=7063038299682f421a3b56ade0dbd40c2ce69292 commit 7063038299682f421a3b56ade0dbd40c2ce69292 Author: Olivier Certner AuthorDate: 2023-10-13 08:52:31 +0000 Commit: Olivier Certner CommitDate: 2023-12-21 13:40:10 +0000 Ensure 'struct thread' is aligned to a cache line Using the new UMA_ALIGN_CACHE_AND_MASK() facility, which allows to simultaneously guarantee a minimum of 32 bytes of alignment (the 5 lower bits are always 0). For the record, to this day, here's a (possibly non-exhaustive) list of synchronization primitives using lower bits to store flags in pointers to thread structures: - lockmgr, rwlock and sx all use the 5 bits directly. - rmlock indirectly relies on sx, so can use the 5 bits. - mtx (non-spin) relies on the 3 lower bits. Reviewed by: markj, kib Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D42266 (cherry picked from commit 7d1469e555bdce32b3dfc898478ae5564d5072b1) Approved by: markj (mentor) --- sys/kern/kern_thread.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sys/kern/kern_thread.c b/sys/kern/kern_thread.c index cab0d7446d2a..14015ef5fdc2 100644 --- a/sys/kern/kern_thread.c +++ b/sys/kern/kern_thread.c @@ -525,9 +525,15 @@ threadinit(void) */ flags |= UMA_ZONE_CONTIG; #endif + /* + * Thread structures are specially aligned so that (at least) the + * 5 lower bits of a pointer to 'struct thead' must be 0. These bits + * are used by synchronization primitives to store flags in pointers to + * such structures. + */ thread_zone = uma_zcreate("THREAD", sched_sizeof_thread(), thread_ctor, thread_dtor, thread_init, thread_fini, - 32 - 1, flags); + UMA_ALIGN_CACHE_AND_MASK(32 - 1), flags); tidhashtbl = hashinit(maxproc / 2, M_TIDHASH, &tidhash); tidhashlock = (tidhash + 1) / 64; if (tidhashlock > 0)