From patchwork Tue Jun 7 09:34:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uladzislau Rezki X-Patchwork-Id: 12871638 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD1B4C433EF for ; Tue, 7 Jun 2022 09:35:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 086828D000B; Tue, 7 Jun 2022 05:35:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id F2BF68D0001; Tue, 7 Jun 2022 05:35:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D561C8D000B; Tue, 7 Jun 2022 05:35:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id BB7658D0001 for ; Tue, 7 Jun 2022 05:35:06 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 8C4A033D8B for ; Tue, 7 Jun 2022 09:35:06 +0000 (UTC) X-FDA: 79550931012.20.4EA28D3 Received: from mail-lj1-f169.google.com (mail-lj1-f169.google.com [209.85.208.169]) by imf09.hostedemail.com (Postfix) with ESMTP id 2087614001A for ; Tue, 7 Jun 2022 09:34:49 +0000 (UTC) Received: by mail-lj1-f169.google.com with SMTP id b12so7543163ljq.3 for ; Tue, 07 Jun 2022 02:35:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=O9Luysd5PeLuzQcmOTrN0C4TCxyraTACP2lGutp0njA=; b=OEFcGHiOWs02B1U8ZYucL+4EF4y74Ze4l8dk9hmWMK3FoD023sKgQyHBsewvH7pJJl YvTh8LFtnuzqGOI9PLLplzSzXYJZFK1gYVHuzABkUbwQsoGxgOQgNEusCnjNcnFvnjkd Yl9vUMntxnBPqg1POJJlwrG5civzSjESScL8j/tnlRVv2mn5cmcGkdIeLN7YA/CbyZav 2YVtDUw6X4+2rEN7OA2BrLqdkiZyumlkDfUd5zqAO5M+qMIjTDWVTlyAICItcGoGiyLT YBlyritdBTzazGnA/7VDfcoiLM939ljQagYCiIs7486TAFH38GeJvgIxpjgwoKGRT33Y +CYQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O9Luysd5PeLuzQcmOTrN0C4TCxyraTACP2lGutp0njA=; b=JBg18xrV0GkDZmFoSvOZyHQVAr4FoPei/PyBP8uAOWCoKeRqFolx9+PhxgBsAeCA+V VfGmL+wF/kzk2gKnO/HY1A1cjXfjLmHt+3XmTXcXarJRYkma9GKG3RrH91oZzMRDq4Ap Lh+JlS8qW7gvwU9m/g6J2+MFyVGyPsIvEMr2rj0RMBTS2wXnLpmJA3S+STmt1MVyjgZI ifV5AmD/unFLgrvTPcBrcQ593rhs9LrNK2/ozoW3QsAuXfZgB7Q7FMtgZklHzzxNVN4H uTwucS0YA8UOAVzyUjKjXkx05UchuknWTr0AZuzbSDx5OwvClPpe8a2SMjKSEbz2o/kT APqA== X-Gm-Message-State: AOAM532dhkzKz+C9e7is1qdinsPXSfWFhBAAldyFzkmFiXB5dJif042P HnCH4u3XfchL4Dn4R/GNzgE= X-Google-Smtp-Source: ABdhPJwUTjbgFpjRhKBjUdEBBKYoMmoQ2FYhd4s1qcIF4yVZY8JkiVy+ymXc7TQCD8Ki1L7N7af7eQ== X-Received: by 2002:a2e:946:0:b0:255:8750:dfeb with SMTP id 67-20020a2e0946000000b002558750dfebmr9193023ljj.421.1654594504568; Tue, 07 Jun 2022 02:35:04 -0700 (PDT) Received: from pc638.lan ([155.137.26.201]) by smtp.gmail.com with ESMTPSA id r27-20020a2e575b000000b002554a4ebf5fsm2748043ljd.74.2022.06.07.02.35.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 02:35:04 -0700 (PDT) From: "Uladzislau Rezki (Sony)" To: Andrew Morton Cc: linux-mm@kvack.org, LKML , Christoph Hellwig , Matthew Wilcox , Nicholas Piggin , Uladzislau Rezki , Oleksiy Avramchenko Subject: [PATCH 5/5] lib/test_vmalloc: Switch to prandom_u32() Date: Tue, 7 Jun 2022 11:34:49 +0200 Message-Id: <20220607093449.3100-6-urezki@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20220607093449.3100-1-urezki@gmail.com> References: <20220607093449.3100-1-urezki@gmail.com> MIME-Version: 1.0 X-Stat-Signature: 7zzjtxp5tz7gwwztpi9s8s7kasbjnbtx X-Rspam-User: Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=OEFcGHiO; spf=pass (imf09.hostedemail.com: domain of urezki@gmail.com designates 209.85.208.169 as permitted sender) smtp.mailfrom=urezki@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 2087614001A X-HE-Tag: 1654594489-715330 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: A get_random_bytes() function can cause a high contention if it is called across CPUs simultaneously. Because it shares one lock per all CPUs: class name con-bounces contentions waittime-min waittime-max waittime-total waittime-avg acq-bounces acquisitions holdtime-min holdtime-max holdtime-total holdtime-avg &crng->lock: 663145 665886 0.05 8.85 261966.66 0.39 7188152 13731279 0.04 11.89 2181582.30 0.16 ----------- &crng->lock 307835 [<00000000acba59cd>] _extract_crng+0x48/0x90 &crng->lock 358051 [<00000000f0075abc>] _crng_backtrack_protect+0x32/0x90 ----------- &crng->lock 234241 [<00000000f0075abc>] _crng_backtrack_protect+0x32/0x90 &crng->lock 431645 [<00000000acba59cd>] _extract_crng+0x48/0x90 Switch from the get_random_bytes() to prandom_u32() that does not have any internal contention when a random value is needed for the tests. The reason is to minimize CPU cycles introduced by the test-suite itself from the vmalloc performance metrics. Signed-off-by: Uladzislau Rezki (Sony) --- lib/test_vmalloc.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/lib/test_vmalloc.c b/lib/test_vmalloc.c index cf41fd6df42a..4f2f2d1bac56 100644 --- a/lib/test_vmalloc.c +++ b/lib/test_vmalloc.c @@ -74,12 +74,13 @@ test_report_one_done(void) static int random_size_align_alloc_test(void) { - unsigned long size, align, rnd; + unsigned long size, align; + unsigned int rnd; void *ptr; int i; for (i = 0; i < test_loop_count; i++) { - get_random_bytes(&rnd, sizeof(rnd)); + rnd = prandom_u32(); /* * Maximum 1024 pages, if PAGE_SIZE is 4096. @@ -150,7 +151,7 @@ static int random_size_alloc_test(void) int i; for (i = 0; i < test_loop_count; i++) { - get_random_bytes(&n, sizeof(i)); + n = prandom_u32(); n = (n % 100) + 1; p = vmalloc(n * PAGE_SIZE); @@ -294,14 +295,14 @@ pcpu_alloc_test(void) for (i = 0; i < 35000; i++) { unsigned int r; - get_random_bytes(&r, sizeof(i)); + r = prandom_u32(); size = (r % (PAGE_SIZE / 4)) + 1; /* * Maximum PAGE_SIZE */ - get_random_bytes(&r, sizeof(i)); - align = 1 << ((i % 11) + 1); + r = prandom_u32(); + align = 1 << ((r % 11) + 1); pcpu[i] = __alloc_percpu(size, align); if (!pcpu[i]) @@ -396,7 +397,7 @@ static void shuffle_array(int *arr, int n) int i, j; for (i = n - 1; i > 0; i--) { - get_random_bytes(&rnd, sizeof(rnd)); + rnd = prandom_u32(); /* Cut the range. */ j = rnd % i;