From nobody Sat Dec 9 02:33:19 2023 X-Original-To: dev-commits-src-branches@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 4SnBrb3bJmz53r68; Sat, 9 Dec 2023 02:33: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 4SnBrb32WJz3V6K; Sat, 9 Dec 2023 02:33:19 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1702089199; 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=LPWeHHJEJ6+1COur0/jOpF74AYvxMdzAgvTefa/xdt8=; b=lPPD8za65x4PElPH6+DYF+zGJa6GgZUgig5FXm7oZBU+iesDFHf75IeXCfjGOwAem7zYOg W7zaHGVizoSOvj94oHYl84wP6efD9QXk5V6x/Sg45KfjfnT0L4VAgQmbH8kZ7tQ6fgmqzr YoijCGlxBHKRpyKZDqXl9y4aQtv0kObMcGJpg2vb++/ojma40Y7t2c6A6nJwN2+5+RgAdf YQK+7e/Twwsbx29V01/TWEZWSGBvemmHdSbwSt1d3mpY9Fc+yquBYfdbBjiLfBqhexwGFn eGs0Lxt1258PY3K+P1Bl+HHh7bxYEfhcSCmZMI8LM0yeEvRqXFo34ppl88JGVA== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1702089199; a=rsa-sha256; cv=none; b=By6KaAOrsPlpbxQrj4oh2mu5LeeLaLdHgw4+erAlBIS0wDdzYCk/PoBqbE48+HGhZbswW9 0rUPCcvZsQNZm6sKSUtclSu/eZPHnngy5+t9lxbfUOWkFOIfv8txCv5N+ym7pou8RADMfW Aluho/l2C3dzVV11F/FeZBmH700C9DxhxuUYa/vzdnP8oFvnVbejuvqKJ773njK6ylAc0D G3OU+D+OovGPv4xL2h0hKSQBZuJBwNsVgObtLB7v/h9cbIoJLH+7Rh6thp5+RG2Wto7Ecz vO5GnM2YYFJW/f5JpWnp9kTp9sNiJxXv4h2MyujOdB/xYCrGe0Rqx2Ri0mcPlw== 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=1702089199; 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=LPWeHHJEJ6+1COur0/jOpF74AYvxMdzAgvTefa/xdt8=; b=EWGzrJ0FRLOw+u3oyQ2y7haYWeNMfANKU5p15O3obvZK30hiUSIhnKO3ps8druGbgViE7d MFGphQAj/e5nukEdakwCB5cgC4egil7gh1qkepuiCI9lPLO76e3jFJcLeli3AUorSGWde0 O59QMM4Qddu6Tv1n9sgkL+GVYvwJdTasJSGQBWOXKqAwoexwkZ282pWcNdrg2rzX9rOKok iZCA5hA0fd8IC8OXJ5HpkAQ5euD0/boCTRnh9/SzXoRLcHKU9iCNJiJu86zZjh/WiA9uqt abzMXM+7Q8OQQhDBIN5TNDksvhUPmQfI2u/PvGwiuBUO9xlKr4QLZEnd7HmdCw== 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 4SnBrb250gzmY3; Sat, 9 Dec 2023 02:33:19 +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 3B92XJ36074612; Sat, 9 Dec 2023 02:33:19 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 3B92XJe0074610; Sat, 9 Dec 2023 02:33:19 GMT (envelope-from git) Date: Sat, 9 Dec 2023 02:33:19 GMT Message-Id: <202312090233.3B92XJe0074610@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Alexander Motin Subject: git: 58f5c260a2e6 - stable/14 - uma: Micro-optimize memory trashing List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@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/stable/14 X-Git-Reftype: branch X-Git-Commit: 58f5c260a2e65795702225354d71e1f34601db00 Auto-Submitted: auto-generated The branch stable/14 has been updated by mav: URL: https://cgit.FreeBSD.org/src/commit/?id=58f5c260a2e65795702225354d71e1f34601db00 commit 58f5c260a2e65795702225354d71e1f34601db00 Author: Alexander Motin AuthorDate: 2023-11-09 18:07:46 +0000 Commit: Alexander Motin CommitDate: 2023-12-09 02:32:43 +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 (cherry picked from commit 7c566d6cfc7bfb913bad89d87386fa21dce8c2e6) --- 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; }