From patchwork Thu Nov 7 19:14:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laura Abbott X-Patchwork-Id: 11233643 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7F9DD139A for ; Thu, 7 Nov 2019 19:14:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 557B121882 for ; Thu, 7 Nov 2019 19:14:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 557B121882 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 0B9246B0003; Thu, 7 Nov 2019 14:14:55 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 098116B0005; Thu, 7 Nov 2019 14:14:55 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE7B26B0007; Thu, 7 Nov 2019 14:14:54 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0063.hostedemail.com [216.40.44.63]) by kanga.kvack.org (Postfix) with ESMTP id D846E6B0003 for ; Thu, 7 Nov 2019 14:14:54 -0500 (EST) Received: from smtpin08.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with SMTP id 6CE00180AD82F for ; Thu, 7 Nov 2019 19:14:54 +0000 (UTC) X-FDA: 76130433708.08.vase72_db0287c3f74b X-Spam-Summary: 1,0,0,,d41d8cd98f00b204,labbott@redhat.com,:glider@google.com:keescook@chromium.org:labbott@redhat.com:cl@linux.com:ndesaulniers@google.com:kcc@google.com:dvyukov@google.com:sspatil@android.com:jannh@google.com:elver@google.com::linux-kernel@vger.kernel.org:akpm@linux-foundation.org,RULES_HIT:30054:30070,0,RBL:209.132.183.28:@redhat.com:.lbl8.mailshell.net-62.18.0.0 64.10.201.10,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:23,LUA_SUMMARY:none X-HE-Tag: vase72_db0287c3f74b X-Filterd-Recvd-Size: 4661 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by imf08.hostedemail.com (Postfix) with ESMTP for ; Thu, 7 Nov 2019 19:14:53 +0000 (UTC) Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id D40503689E for ; Thu, 7 Nov 2019 19:14:52 +0000 (UTC) Received: by mail-qk1-f199.google.com with SMTP id 125so3355669qkj.12 for ; Thu, 07 Nov 2019 11:14:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=Db1sKYv4li8Fx0mnSJRg6cnhmGpTf7bM9BzTT3nWzCw=; b=SshggJRI9DPrurmqPcyGuhwhvdiL4kJdrTHI7OWwC3P8B+puguXj39hIB4Xrb2rRNP oaj6miOpRhOniBr+M3wuHKJTcm0Gixg4scZEYf40qTvhKFzZXPbTgmBRIX6gmyUKLRnH hevuhjohNgLwaFmhcK8ZmVlpVkXtf6suq1xKRqYSk7tnOm3i6439oTXe6QQV7lPiSLFe L2ZfmQ9fBB6OfRH8sAYexEoLmLUM94nKUnn+PZfncdfpkejXGMo7yMlFlDUumzkUBhpw acQ+jV/NcLfDx2oe2h+gARMf0jXLtZ2tvj5hqxoN7FXSSn4+Uy2BI0Ag2lchOa9JYUzx 6AFQ== X-Gm-Message-State: APjAAAXVB/B03RNd4/REX4hVwcyqlE9V9Wcpx5GKPy0sScR9ePrAeU8H aiymLKRdIJVhdjkWns6140wDVsubf1dcpLeUQYMWvlWFok2TkX8Hs43H1r0T6pf5vSsVFn+DSrF BZb4MiBkE/P4= X-Received: by 2002:ac8:22d9:: with SMTP id g25mr5690592qta.238.1573154092109; Thu, 07 Nov 2019 11:14:52 -0800 (PST) X-Google-Smtp-Source: APXvYqz1HSOtXnTHcrA8WP6hedLySfPxynCtPMQPvXsizGqr/cCfleY+sFvwfvz/I1vijoKir9RTqw== X-Received: by 2002:ac8:22d9:: with SMTP id g25mr5690533qta.238.1573154091808; Thu, 07 Nov 2019 11:14:51 -0800 (PST) Received: from labbott-redhat.redhat.com (pool-96-235-39-235.pitbpa.fios.verizon.net. [96.235.39.235]) by smtp.gmail.com with ESMTPSA id l14sm1604372qkj.61.2019.11.07.11.14.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Nov 2019 11:14:50 -0800 (PST) From: Laura Abbott To: Alexander Potapenko , Kees Cook Cc: Laura Abbott , Christoph Lameter , Nick Desaulniers , Kostya Serebryany , Dmitry Vyukov , Sandeep Patil , Jann Horn , Marco Elver , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton Subject: [PATCH] lib/test_meminit.c: Add bulk alloc/free tests Date: Thu, 7 Nov 2019 14:14:47 -0500 Message-Id: <20191107191447.23058-1-labbott@redhat.com> X-Mailer: git-send-email 2.21.0 MIME-Version: 1.0 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: kmem_cache_alloc_bulk/kmem_cache_free_bulk are used to make multiple allocations of the same size to avoid the overhead of multiple kmalloc/kfree calls. Extend the kmem_cache tests to make some calls to these APIs. Signed-off-by: Laura Abbott Reviewed-by: Kees Cook --- lib/test_meminit.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/test_meminit.c b/lib/test_meminit.c index 9729f271d150..20f330948b92 100644 --- a/lib/test_meminit.c +++ b/lib/test_meminit.c @@ -183,6 +183,9 @@ static bool __init check_buf(void *buf, int size, bool want_ctor, return fail; } +#define BULK_SIZE 100 +static void *bulk_array[BULK_SIZE]; + /* * Test kmem_cache with given parameters: * want_ctor - use a constructor; @@ -203,9 +206,24 @@ static int __init do_kmem_cache_size(size_t size, bool want_ctor, want_rcu ? SLAB_TYPESAFE_BY_RCU : 0, want_ctor ? test_ctor : NULL); for (iter = 0; iter < 10; iter++) { + /* Do a test of bulk allocations */ + if (!want_rcu && !want_ctor) { + int ret; + + ret = kmem_cache_alloc_bulk(c, alloc_mask, BULK_SIZE, bulk_array); + if (!ret) { + fail = true; + } else { + int i; + for (i = 0; i < ret; i++) + fail |= check_buf(bulk_array[i], size, want_ctor, want_rcu, want_zero); + kmem_cache_free_bulk(c, ret, bulk_array); + } + } + buf = kmem_cache_alloc(c, alloc_mask); /* Check that buf is zeroed, if it must be. */ - fail = check_buf(buf, size, want_ctor, want_rcu, want_zero); + fail |= check_buf(buf, size, want_ctor, want_rcu, want_zero); fill_with_garbage_skip(buf, size, want_ctor ? CTOR_BYTES : 0); if (!want_rcu) {