From patchwork Fri Sep 22 11:30:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13395608 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 B10A7CD4F49 for ; Fri, 22 Sep 2023 11:31:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 489656B02B9; Fri, 22 Sep 2023 07:31:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 434DC6B02BA; Fri, 22 Sep 2023 07:31:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2D5516B02BC; Fri, 22 Sep 2023 07:31:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 152626B02B9 for ; Fri, 22 Sep 2023 07:31:22 -0400 (EDT) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E2A2241087 for ; Fri, 22 Sep 2023 11:31:21 +0000 (UTC) X-FDA: 81264017562.16.5CECCCA Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf08.hostedemail.com (Postfix) with ESMTP id 33DD6160004 for ; Fri, 22 Sep 2023 11:31:20 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ec2vwQGJ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695382280; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ccEdlostLZ9hW/Y+0NbfOfNDQJd+s3hdO6ELIs/CNv4=; b=3y1+QXSyx/fYqnxVDNKGDj+b+lNXaN6Kp95Qa3vGnlnHGzUElQpC6xjkCOrAW+jC3uVHhh cuSEvwKtMwaXqf+IhhWYyOiG4mAVr+/jQHnhSYqxYSOVBvc6BKJ6eVaRAX1JT8HK1GSum5 37HrCZo+8ej6YnbR4B8oSj63ExnO41g= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Ec2vwQGJ; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of dhowells@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695382280; a=rsa-sha256; cv=none; b=het7aE7k9j/hqwE+KTmyS4rv7ghb6F8lFWaDVWdjNjnqkHu1F+an/eyE76SoApQUAZ9tdh yITln7c5blQQkAsVu1j2czjv8Si7Ag7DZFz6HRkpZ/cTn6DVN2x36bf1jsxDeYPf54bnfp D41wXEJTq0u6s5ICTZqoCiL4eVdCBy0= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695382279; 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=Ec2vwQGJrhcedGKuXMrb4ZxFw+K015WW1v4r3pVBNZ2kxKmA5YnlNJ78WOSMCHCI2iwR/K RFPYdr3VcO4Co67U+2vrdTAB4gWYNNQVltUHqXPACxfv1Ey2YlFVFwaUCJeMCiwbZY00G/ W6H/DuDdobphFmK+Prz0XS9k4o97juo= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-10-gL529IiFPli31fOxi3rVow-1; Fri, 22 Sep 2023 07:31:13 -0400 X-MC-Unique: gL529IiFPli31fOxi3rVow-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 55A34101A529; Fri, 22 Sep 2023 11:31:12 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 161112156701; Fri, 22 Sep 2023 11:31:09 +0000 (UTC) From: David Howells To: Jens Axboe Cc: David Howells , Al Viro , Linus Torvalds , Christoph Hellwig , Christian Brauner , 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: Fri, 22 Sep 2023 12:30:37 +0100 Message-ID: <20230922113038.1135236-10-dhowells@redhat.com> In-Reply-To: <20230922113038.1135236-1-dhowells@redhat.com> References: <20230922113038.1135236-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Rspamd-Queue-Id: 33DD6160004 X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: cwxdgxqwctk5ek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UtjjA4sfI4rWcPQXMzXsixM7/HYcwkitMD/Qjlrwq6ONQlPIOgql6EdchH4n6oo6jWs01opZsFCgh4rMnRh/6Uixq9qin9YCtbCbCK2Urdl+h2fnsf9dWwCbUdytCOBLS2RpUtpg3aZ2lqNZAkXc9xWdljTrPyhyYw14dOKIxfQDsG41IwrZSDmG+ddxLj7TVvSxbxsTLxTUV6vw26LimlwAOmQkxcOJ6ZyBeUPlHe5ZMcuh9P/uIxMBSvVvEJUkyCzEgyjyoxa5IVgJU4vVwZLPjq4Xw3h21RZgmq5iMZTlTffba5hXU4dA8Ioqz4n9TOR4kQiLNy5amoi0KWYVCqUJleRDY4l+iA/1aYCoLG/8RKYrw85riVKkItYDLYgbCo6+rUwSh8+H5C70Mt/FWZxF45VDCX/NEvG6bnqHNfegMUZSVJDMl3/EOWR3w54Mcwuk6Cv8n/gD8BYlIQBjEftiygiBjeFeG8 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: 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), {} };