From nobody Thu Nov 09 18:21:47 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 4SR9Jq2WV7z50qPV; Thu, 9 Nov 2023 18:21:47 +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 4SR9Jq246Wz4dGG; Thu, 9 Nov 2023 18:21:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1699554107; 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=f0Z3ljKUnHW9f7SZe4OtvAwNI5jCTAYt6bl53n/bEiM=; b=A3AzLcNlH1tHbQh4M/aoIodX8qoufE6RMd+0gmN6UFAS7qFiELWx3Ea3+8AokFl3fkYDqd lC6PPhSsYMhSBQQutE1UZfOyLTP46bWf5l7qUZ6CGW0WgS3M3Pb01k74IcYgRX7O5gKr0S 5U/KBA4FowYj6X1DZ2kdKEn5cT1m3DynEkR1Q1Bk32XjqCQ6q2mypdXyNfD8xK9demCYBa x70UCmwmkRU/DocHuEUwlJtrWmssJpNOIPSoys9IBe8LwSzWO8w43UiItEIlzmS07y1cHu OHQ8pVpDdmcJ6fWmaUskEPWnoZqDN2FzN+RgsJJnNpZnJHb8vGru0WSqmMFZHQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1699554107; 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=f0Z3ljKUnHW9f7SZe4OtvAwNI5jCTAYt6bl53n/bEiM=; b=xC9Jyk0VU7fbHf+V+nOkk+FpB2Cfa4bkAkW3PzBY7NVTYHuygSxwtn2Tu1XMV0l4EskWLV 24D5dnQFr4HbGMpOstH9Yp+xh9MQCuMFXdnSRTJ4tto2uUCVAGWumKqn8atErqjRiqXzgt 8HfcLICqB46PIdz5KzEz9Qs4hOpoYc0kdisu2YDnJys3GYaQkffGa7enAW5NGy/vUjfj3V UKq89DmOFIXESnL+YeTyJgrCxnaWOELSfyRbhlFxFu5Y5OT2mRjHpiFVk8cbkxHYbQJLMa 97HSHb/FDVQPXZ4BKrUxCkA5R8h5IzwrpX0dP8f+J9TSMS1RaqUM5TtgXCNtzw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1699554107; a=rsa-sha256; cv=none; b=CteIC1FLZbtX93bZBWXhbVL/AUbnMrFRdZBUpgZtErp1gYtLdveDW7ZuL3Uc3b2FdVKRPU NlCd3iiA/U77L1VAqgLGm4wgWYlpegHtgkBAAshi/kM6G0lmIhCiCKC8ttlOgK8mwvNsOn +HPVwIUE9YKxOhd3oAjppXuYhhIlRy5r8uudqVKmeQ649gTXl0IbzT96zMbksv+jkETFuY vhbBpYA4pUeu/vTT/Y1nR13+jOEPoua0q7FPz/VEAomRcXdfn2xeAz/a0gDPAnatJp1T6d uXSww+QhkJRuWvc8tlOvNuhAE+jNXB3X6YPCLKKecvfJDT6l2lp2DVeaFTQW+Q== 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 4SR9Jq17ldzB6S; Thu, 9 Nov 2023 18:21:47 +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 3A9ILlVu044947; Thu, 9 Nov 2023 18:21:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3A9ILlAJ044944; Thu, 9 Nov 2023 18:21:47 GMT (envelope-from git) Date: Thu, 9 Nov 2023 18:21:47 GMT Message-Id: <202311091821.3A9ILlAJ044944@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Alexander Motin Subject: git: 7c566d6cfc7b - main - uma: Micro-optimize memory trashing 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: mav X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7c566d6cfc7bfb913bad89d87386fa21dce8c2e6 Auto-Submitted: auto-generated The branch main has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=7c566d6cfc7bfb913bad89d87386fa21dce8c2e6 commit 7c566d6cfc7bfb913bad89d87386fa21dce8c2e6 Author: Alexander Motin AuthorDate: 2023-11-09 18:07:46 +0000 Commit: Alexander Motin CommitDate: 2023-11-09 18:07:46 +0000 uma: Micro-optimize memory trashing Use u_long for memory accesses instead of uint32_t. On my tests on amd64 this by ~30% reduces time spent in those functions thanks to bigger 64bit accesses. i386 still uses 32bit accesses. MFC after: 1 month --- sys/vm/uma_dbg.c | 62 ++++++++++++++++++++++++-------------------------------- 1 file changed, 26 insertions(+), 36 deletions(-) diff --git a/sys/vm/uma_dbg.c b/sys/vm/uma_dbg.c index 36567f3b3968..76dd2bfde2fe 100644 --- a/sys/vm/uma_dbg.c +++ b/sys/vm/uma_dbg.c @@ -53,7 +53,7 @@ #include #include -static const uint32_t uma_junk = 0xdeadc0de; +static const u_long uma_junk = (u_long)0xdeadc0dedeadc0de; /* * Checks an item to make sure it hasn't been overwritten since it was freed, @@ -64,27 +64,20 @@ static const uint32_t uma_junk = 0xdeadc0de; int trash_ctor(void *mem, int size, void *arg, int flags) { - int cnt; - uint32_t *p; + u_long *p = mem, *e; #ifdef DEBUG_MEMGUARD if (is_memguard_addr(mem)) return (0); #endif - cnt = size / sizeof(uma_junk); - - for (p = mem; cnt > 0; cnt--, p++) - if (*p != uma_junk) { -#ifdef INVARIANTS - panic("Memory modified after free %p(%d) val=%x @ %p\n", - mem, size, *p, p); -#else - printf("Memory modified after free %p(%d) val=%x @ %p\n", - mem, size, *p, p); -#endif - return (0); - } + e = p + size / sizeof(*p); + for (; p < e; p++) { + if (__predict_true(*p == uma_junk)) + continue; + panic("Memory modified after free %p(%d) val=%lx @ %p\n", + mem, size, *p, p); + } return (0); } @@ -97,17 +90,15 @@ trash_ctor(void *mem, int size, void *arg, int flags) void trash_dtor(void *mem, int size, void *arg) { - int cnt; - uint32_t *p; + u_long *p = mem, *e; #ifdef DEBUG_MEMGUARD if (is_memguard_addr(mem)) return; #endif - cnt = size / sizeof(uma_junk); - - for (p = mem; cnt > 0; cnt--, p++) + e = p + size / sizeof(*p); + for (; p < e; p++) *p = uma_junk; } @@ -140,8 +131,7 @@ int mtrash_ctor(void *mem, int size, void *arg, int flags) { struct malloc_type **ksp; - uint32_t *p = mem; - int cnt; + u_long *p = mem, *e; #ifdef DEBUG_MEMGUARD if (is_memguard_addr(mem)) @@ -151,15 +141,16 @@ mtrash_ctor(void *mem, int size, void *arg, int flags) size -= sizeof(struct malloc_type *); ksp = (struct malloc_type **)mem; ksp += size / sizeof(struct malloc_type *); - cnt = size / sizeof(uma_junk); - - for (p = mem; cnt > 0; cnt--, p++) - if (*p != uma_junk) { - printf("Memory modified after free %p(%d) val=%x @ %p\n", - mem, size, *p, p); - panic("Most recently used by %s\n", (*ksp == NULL)? - "none" : (*ksp)->ks_shortdesc); - } + + e = p + size / sizeof(*p); + for (; p < e; p++) { + if (__predict_true(*p == uma_junk)) + continue; + printf("Memory modified after free %p(%d) val=%lx @ %p\n", + mem, size, *p, p); + panic("Most recently used by %s\n", (*ksp == NULL)? + "none" : (*ksp)->ks_shortdesc); + } return (0); } @@ -172,8 +163,7 @@ mtrash_ctor(void *mem, int size, void *arg, int flags) void mtrash_dtor(void *mem, int size, void *arg) { - int cnt; - uint32_t *p; + u_long *p = mem, *e; #ifdef DEBUG_MEMGUARD if (is_memguard_addr(mem)) @@ -181,9 +171,9 @@ mtrash_dtor(void *mem, int size, void *arg) #endif size -= sizeof(struct malloc_type *); - cnt = size / sizeof(uma_junk); - for (p = mem; cnt > 0; cnt--, p++) + e = p + size / sizeof(*p); + for (; p < e; p++) *p = uma_junk; }