From patchwork Wed Sep 20 13:04:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13392749 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 02A5BCE79CE for ; Wed, 20 Sep 2023 13:05:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D70716B0165; Wed, 20 Sep 2023 09:05:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D28EC6B0166; Wed, 20 Sep 2023 09:05:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B4AD16B0167; Wed, 20 Sep 2023 09:05:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 9D4066B0165 for ; Wed, 20 Sep 2023 09:05:26 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 5DDAFC0734 for ; Wed, 20 Sep 2023 13:05:26 +0000 (UTC) X-FDA: 81256997052.07.AF2CACD Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf26.hostedemail.com (Postfix) with ESMTP id 8FD69140016 for ; Wed, 20 Sep 2023 13:05:24 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LFy6dDPC; spf=pass (imf26.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1695215124; 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=WKL59oxitSx6DOUyNJ+1H0DeRSBlY0vVZI1oz1R1zFg=; b=EOWOc2Ilmd9Fzn+hfQ2ztRbZernAdsT1KF8MaEqAI4MkytHqWrlS6NLRALJWILFf+DNkwD YVmwc8j9lFMRsxH1mxYPrkLOHgow85c3Eovj3jtfKuf40IM/XAoyoiIvP4quV+R4yEvlJC HSyl2EO3MIotvFVNdwaUuFYzhKDdlMY= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=LFy6dDPC; spf=pass (imf26.hostedemail.com: domain of dhowells@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=dhowells@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1695215124; a=rsa-sha256; cv=none; b=b5OrH3Ekx9AiXAx6h7ZxsnOeFr0vnOTEz1N9hRSvplMcCQYtqXAM22X5dnO4l4bsPzsuC5 5I/nX+qXoRt9mL5n/8AqTLjw/hiiH8lneXWBUBEEUde0aw5pInIz4uOlOfIpmNwN2RlRgk xBmfOJ7j9nqm17MyNEhREIZlZruWJJg= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1695215123; 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=WKL59oxitSx6DOUyNJ+1H0DeRSBlY0vVZI1oz1R1zFg=; b=LFy6dDPC2tomJN/FwHCsi7jJ6+BDP5Iv8j50RF5G45BBRr+IZ7ui4bFYa2MnTBcXQkLxW9 liu5EaAEnvdTOskAU82xE8D99sjB2jLyImXzHsX4KTa/2SQ0RXCO4RvOJ8Rq6lRmt8ryhZ RbIbku5qh52ttdXH7sIRjwLEUw1ojV8= Received: from mimecast-mx02.redhat.com (mx-ext.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-653-5VCNNxRlNwuawrr7coWaQA-1; Wed, 20 Sep 2023 09:05:18 -0400 X-MC-Unique: 5VCNNxRlNwuawrr7coWaQA-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (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 D5BEF2999B36; Wed, 20 Sep 2023 13:05:16 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 698FE51E3; Wed, 20 Sep 2023 13:05:14 +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, Andrew Morton , Christian Brauner , David Hildenbrand , John Hubbard Subject: [RFC PATCH v2 9/9] iov_iter: Add benchmarking kunit tests for UBUF/IOVEC Date: Wed, 20 Sep 2023 14:04:00 +0100 Message-ID: <20230920130400.203330-10-dhowells@redhat.com> In-Reply-To: <20230920130400.203330-1-dhowells@redhat.com> References: <20230920130400.203330-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 X-Rspamd-Queue-Id: 8FD69140016 X-Rspam-User: X-Stat-Signature: g93c4myaex9orfkf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j4ixY9BnVZ9Ff8iMvoOWRqZHbOPIeSi44g8dpx7WV0kVgTtm/MIR7WWnf71OcA7/VL33c7sU7gx0gAn14bTVyeZo38CYrJYWWo1SQ0s7ySqlWGFJ3pO3Bifqw8PDF/OQjbQqEqzzj1/dWUfPlRDiw2Pq6XL6d1IRADzrT52O8u8Bw7OraU3qL3UPisavtZs4jQ/iC04dTNXPqSwawp1eg6hWvEuNH+xvIb6vowRb5vkTpg4RZgFZijcg17S/SpMPN81Xn7oitZ+EGvmGC2CD8l/pJ5D6g23DMJoILRzL9SELVYpHTc/jNp+oL7S07cz2bGz3i+U7O5twZQrDKBqFyuvcvrmQgrQfCP2xlEquqml+DdP4GVaAm8nKvgG76N7AwJdr4Z675lfZSS6C9Ll6Wrh0hOesRLpcwoyBKjwBK/i07+xB5HAcxbtJ8jVYbmIk3EoWT8aT1zPxpFJUwAJZ6q8U3xlsNkpLuUAKux1eckHFz7JDKkvg+m+idaNWgk9d0ZT/hPBl3vem0igT21UcfY2HnR34dg4gFBYo7JSE6ec4VwKHjbnaBPKA5ZFAXHPkiGTnPjXl/lzvGHlf4K9lQ== 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 kunit tests to benchmark 256MiB copies to a UBUF iterator and an IOVEC iterator. This attaches a userspace VM with a mapped file in it temporarily to the test thread. Signed-off-by: David Howells cc: Andrew Morton cc: Christoph Hellwig cc: Christian Brauner cc: Jens Axboe cc: Al Viro cc: Matthew Wilcox 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-mm@kvack.org cc: linux-fsdevel@vger.kernel.org --- lib/kunit_iov_iter.c | 95 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/lib/kunit_iov_iter.c b/lib/kunit_iov_iter.c index 17f85f24b239..4ee939a1c5ec 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -1324,6 +1324,99 @@ static void *__init iov_kunit_create_source(struct kunit *test, size_t npages) return scratch; } +/* + * Time copying 256MiB through an ITER_UBUF. + */ +static void __init iov_kunit_benchmark_ubuf(struct kunit *test) +{ + struct iov_iter iter; + 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; + u8 __user *buffer; + + /* Allocate a huge buffer and populate it with pages. */ + buffer = iov_kunit_create_user_buf(test, npages, NULL); + + /* 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 UBUF:\n"); + for (i = 0; i < IOV_KUNIT_NR_SAMPLES; i++) { + size_t remain = size; + + a = ktime_get_real(); + do { + size_t part = min(remain, PAGE_SIZE); + + iov_iter_ubuf(&iter, ITER_SOURCE, buffer, part); + copied = copy_from_iter(scratch, part, &iter); + KUNIT_EXPECT_EQ(test, copied, part); + remain -= part; + } while (remain > 0); + b = ktime_get_real(); + samples[i] = ktime_to_us(ktime_sub(b, a)); + } + + iov_kunit_benchmark_print_stats(test, samples); + KUNIT_SUCCEED(); +} + +/* + * Time copying 256MiB through an ITER_IOVEC. + */ +static void __init iov_kunit_benchmark_iovec(struct kunit *test) +{ + struct iov_iter iter; + struct iovec *iov; + unsigned int samples[IOV_KUNIT_NR_SAMPLES]; + ktime_t a, b; + ssize_t copied; + size_t size = 256 * 1024 * 1024, npages = size / PAGE_SIZE, part; + size_t ioc = size / PAGE_SIZE; + void *scratch; + int i; + u8 __user *buffer; + + iov = kunit_kmalloc_array(test, ioc, sizeof(*iov), GFP_KERNEL); + KUNIT_ASSERT_NOT_NULL(test, iov); + + /* Allocate a huge buffer and populate it with pages. */ + buffer = iov_kunit_create_user_buf(test, npages, NULL); + + /* Create a single large buffer to copy to/from. */ + scratch = iov_kunit_create_source(test, npages); + + /* Split the target over a number of iovecs */ + copied = 0; + for (i = 0; i < ioc; i++) { + part = size / ioc; + iov[i].iov_base = buffer + copied; + iov[i].iov_len = part; + copied += part; + } + iov[i - 1].iov_len += size - part; + + /* Perform and time a bunch of copies. */ + kunit_info(test, "Benchmarking copy_to_iter() over IOVEC:\n"); + for (i = 0; i < IOV_KUNIT_NR_SAMPLES; i++) { + iov_iter_init(&iter, ITER_SOURCE, iov, npages, size); + + a = ktime_get_real(); + copied = copy_from_iter(scratch, size, &iter); + b = ktime_get_real(); + KUNIT_EXPECT_EQ(test, copied, size); + samples[i] = ktime_to_us(ktime_sub(b, a)); + } + + iov_kunit_benchmark_print_stats(test, samples); + KUNIT_SUCCEED(); +} + /* * Time copying 256MiB through an ITER_KVEC. */ @@ -1524,6 +1617,8 @@ static struct kunit_case __refdata iov_kunit_cases[] = { KUNIT_CASE(iov_kunit_extract_pages_kvec), KUNIT_CASE(iov_kunit_extract_pages_bvec), KUNIT_CASE(iov_kunit_extract_pages_xarray), + KUNIT_CASE(iov_kunit_benchmark_ubuf), + KUNIT_CASE(iov_kunit_benchmark_iovec), KUNIT_CASE(iov_kunit_benchmark_kvec), KUNIT_CASE(iov_kunit_benchmark_bvec), KUNIT_CASE(iov_kunit_benchmark_bvec_split),