Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2686410rdb; Wed, 15 Nov 2023 07:52:28 -0800 (PST) X-Google-Smtp-Source: AGHT+IG23w1D5j7p2Y9JH2X+8GD0KLHmygWrrTSs00juqjJCwUqnSKGTc+vtpMNaVX/5T0G0tped X-Received: by 2002:aa7:818b:0:b0:68a:6018:a66f with SMTP id g11-20020aa7818b000000b0068a6018a66fmr7245803pfi.2.1700063548317; Wed, 15 Nov 2023 07:52:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700063548; cv=none; d=google.com; s=arc-20160816; b=wbZuxzl5L28IkOx1t5DzKQKV+g67in0UOzx2zZLgAzqUo7XRGfW640zl+Jh/0Lkqd8 MzzDMvFCATHb9LrgNUdh+JN6cvpgVnZvKGHPWZjmP4JMFnlSz+wvalDy0XX+UlqGzgQn DS+Mq29zWnqmKE82D6NdY1G3TdSyGfxpb9viVszRr8GbfJseW0lX8E1Ov4eSCuhObZ50 OIiTs9JvsDdmlQ/IJNvclDvRzHJ131UaHjuACSbzl0RJaJsqN/3p+gMfpOX2mqmlSW8p ujiWxE6XGZYibX7yxD6e5fDzWhrVhZK5rXP3ywtIM+ba8aBK91BcLxcBBJDpq3A83JW6 1t3A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ccEdlostLZ9hW/Y+0NbfOfNDQJd+s3hdO6ELIs/CNv4=; fh=IZWgNEdnSw9shF1BETacU82Ax9k84Q5rQwPVSWNWaNM=; b=aoHLfwYJp8qOl1SkETPyNYEQaMtVWa5DN0pCoTGg7b5BkZQ8iSfG5eddr3naLwHQxC sagTnogs89cdc10IpDathyVIHHstJxuaUAPZ7rrDCK7JDqzdKdgIzwy/F1tUyzCr+OCz yTZL/xsKjnIFdwoWswnoSGr/DC6qCfY73f14ZtlR1rC6dHTRgtzekvWkDk7SjEhIPHOt ueabUQJIao4IZyqxmHLQpYxtEu/03eKDODDLYDES4dkljlPoZQHPbojbvoczZ+Cusb2y 8Px/LF/f4UUpP3ZjLU1Y1LXKDiFf6eC0gPMgOM7+EuZ2I6XQDtm8HZNQufpio18JU4E+ BTbg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VKTNFClB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id i14-20020a6561ae000000b005bdbe26500fsi10040558pgv.550.2023.11.15.07.52.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 07:52:28 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=VKTNFClB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 3034881CC870; Wed, 15 Nov 2023 07:51:46 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232493AbjKOPvW (ORCPT + 99 others); Wed, 15 Nov 2023 10:51:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37456 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232528AbjKOPvC (ORCPT ); Wed, 15 Nov 2023 10:51:02 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EC3DF1BEA for ; Wed, 15 Nov 2023 07:50:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1700063432; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ccEdlostLZ9hW/Y+0NbfOfNDQJd+s3hdO6ELIs/CNv4=; b=VKTNFClBudivKhdfLz+g4bUKenNSRHwl+gDZ9DXJQBFbXImTapOtIIGbF5kg8ccjg+ZQ4K oNZA251bf1NP/tcLJDSzT4aODM4qcqr41TsQOcsQMWCoDSSSXsVOMXPhKxUfdFQKz4C1KO TyLT5OXqk9os+zyN2YjOxPiB8kZM31Y= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-417-p2AxTLinOM6LKeQW9-98gg-1; Wed, 15 Nov 2023 10:50:27 -0500 X-MC-Unique: p2AxTLinOM6LKeQW9-98gg-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E13468058EE; Wed, 15 Nov 2023 15:50:26 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.16]) by smtp.corp.redhat.com (Postfix) with ESMTP id 177271121306; Wed, 15 Nov 2023 15:50:22 +0000 (UTC) From: David Howells To: Christian Brauner Cc: David Howells , Jens Axboe , Al Viro , Linus Torvalds , Christoph Hellwig , David Laight , Matthew Wilcox , Brendan Higgins , David Gow , linux-fsdevel@vger.kernel.org, linux-block@vger.kernel.org, linux-mm@kvack.org, netdev@vger.kernel.org, linux-kselftest@vger.kernel.org, kunit-dev@googlegroups.com, linux-kernel@vger.kernel.org, Christian Brauner , David Hildenbrand , John Hubbard Subject: [PATCH v3 09/10] iov_iter: Add kunit to benchmark decanting of xarray to bvec Date: Wed, 15 Nov 2023 15:49:45 +0000 Message-ID: <20231115154946.3933808-10-dhowells@redhat.com> In-Reply-To: <20231115154946.3933808-1-dhowells@redhat.com> References: <20231115154946.3933808-1-dhowells@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.3 X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 15 Nov 2023 07:51:46 -0800 (PST) Add a kunit test to benchmark an xarray containing 256MiB of data getting decanted into 256-page BVEC iterators that get copied from - modelling bufferage being drawn from the pagecache and batched up for I/O. Signed-off-by: David Howells cc: Christoph Hellwig cc: Christian Brauner cc: Jens Axboe cc: Al Viro cc: David Hildenbrand cc: John Hubbard cc: Brendan Higgins cc: David Gow cc: linux-kselftest@vger.kernel.org cc: kunit-dev@googlegroups.com cc: linux-fsdevel@vger.kernel.org cc: linux-mm@kvack.org --- lib/kunit_iov_iter.c | 87 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) diff --git a/lib/kunit_iov_iter.c b/lib/kunit_iov_iter.c index 1a43e9518a63..2fbe6f2afb26 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -1509,6 +1509,92 @@ static void __init iov_kunit_benchmark_xarray(struct kunit *test) KUNIT_SUCCEED(); } +/* + * Time copying 256MiB through an ITER_XARRAY, decanting it to ITER_BVECs. + */ +static void __init iov_kunit_benchmark_xarray_to_bvec(struct kunit *test) +{ + struct iov_iter xiter; + struct xarray *xarray; + struct page *page; + unsigned int samples[IOV_KUNIT_NR_SAMPLES]; + ktime_t a, b; + ssize_t copied; + size_t size = 256 * 1024 * 1024, npages = size / PAGE_SIZE; + void *scratch; + int i; + + /* Allocate a page and tile it repeatedly in the buffer. */ + page = alloc_page(GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, page); + kunit_add_action_or_reset(test, iov_kunit_free_page, page); + + xarray = iov_kunit_create_xarray(test); + + for (i = 0; i < npages; i++) { + void *x = xa_store(xarray, i, page, GFP_KERNEL); + + KUNIT_ASSERT_FALSE(test, xa_is_err(x)); + } + + /* Create a single large buffer to copy to/from. */ + scratch = iov_kunit_create_source(test, npages); + + /* Perform and time a bunch of copies. */ + kunit_info(test, "Benchmarking copy_to_iter() over BVECs decanted from an XARRAY:\n"); + for (i = 0; i < IOV_KUNIT_NR_SAMPLES; i++) { + size = 256 * 1024 * 1024; + iov_iter_xarray(&xiter, ITER_SOURCE, xarray, 0, size); + a = ktime_get_real(); + + do { + struct iov_iter biter; + struct bio_vec *bvec; + struct page **pages; + size_t req, part, offset0, got; + int j; + + npages = 256; + req = min_t(size_t, size, npages * PAGE_SIZE); + bvec = kunit_kmalloc_array(test, npages, sizeof(bvec[0]), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, bvec); + + pages = (void *)bvec + array_size(npages, sizeof(bvec[0])) - + array_size(npages, sizeof(*pages)); + + part = iov_iter_extract_pages(&xiter, &pages, req, + npages, 0, &offset0); + KUNIT_EXPECT_NE(test, part, 0); + KUNIT_EXPECT_GT(test, part, 0); + + j = 0; + got = part; + do { + size_t chunk = min_t(size_t, got, PAGE_SIZE - offset0); + + bvec_set_page(&bvec[j++], page, chunk, offset0); + offset0 = 0; + got -= chunk; + } while (got > 0); + + iov_iter_bvec(&biter, ITER_SOURCE, bvec, j, part); + copied = copy_from_iter(scratch, part, &biter); + KUNIT_EXPECT_EQ(test, copied, part); + size -= copied; + if (test->status == KUNIT_FAILURE) + break; + } while (size > 0); + + b = ktime_get_real(); + samples[i] = ktime_to_us(ktime_sub(b, a)); + if (test->status == KUNIT_FAILURE) + break; + } + + iov_kunit_benchmark_print_stats(test, samples); + KUNIT_SUCCEED(); +} + static struct kunit_case __refdata iov_kunit_cases[] = { KUNIT_CASE(iov_kunit_copy_to_ubuf), KUNIT_CASE(iov_kunit_copy_from_ubuf), @@ -1529,6 +1615,7 @@ static struct kunit_case __refdata iov_kunit_cases[] = { KUNIT_CASE(iov_kunit_benchmark_bvec), KUNIT_CASE(iov_kunit_benchmark_bvec_split), KUNIT_CASE(iov_kunit_benchmark_xarray), + KUNIT_CASE(iov_kunit_benchmark_xarray_to_bvec), {} };