From patchwork Thu Sep 14 22:15:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Howells X-Patchwork-Id: 13386119 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 176B8EEAA78 for ; Thu, 14 Sep 2023 22:16:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A01446B0306; Thu, 14 Sep 2023 18:16:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B0F26B0308; Thu, 14 Sep 2023 18:16:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7DC7E6B0309; Thu, 14 Sep 2023 18:16:06 -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 68C6C6B0306 for ; Thu, 14 Sep 2023 18:16:06 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 4D1D5A0673 for ; Thu, 14 Sep 2023 22:16:06 +0000 (UTC) X-FDA: 81236611932.26.5DA6F94 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf10.hostedemail.com (Postfix) with ESMTP id 974D3C001C for ; Thu, 14 Sep 2023 22:16:04 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UP6ExVRt; spf=pass (imf10.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=1694729764; 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=kJbp/xPUEeZPZ6xlN6+ErzCN36LIEvr4JCtOzFEoqKk=; b=OnCI2ZTxqmFLOgjYLet50A9eTNQN6gjv7FyAW/L65lM+8BK6gBC41CbDbR3IFI8Jkh1ZSj IgQ3jtANtqpva8lrDVwgic1Urim9ODX9HsZMN2whuSw6mL4C6Y1M6V2GFD3MiPaK+QKdYB kwZ4Vs1kfOIDxG0olBabYgTyrPLPdL8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1694729764; a=rsa-sha256; cv=none; b=oybWWBhgp6PMkMT2NJXG4K3mWwmbU5AYDwPrDCtI8IRaOjAZzamLjeaGRDffZZGJqQjs4M DNNIVhPAKn9FdEpbzkurmd5a5KI9+GqAfXomcDHYf0hdvslk990v9LXEa+kDs4WCQvjg3d +2Xqo0pu8s7YPK9To55AjO7ux0veEVQ= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=UP6ExVRt; spf=pass (imf10.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 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1694729763; 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=kJbp/xPUEeZPZ6xlN6+ErzCN36LIEvr4JCtOzFEoqKk=; b=UP6ExVRt3EnRSBzqAe3dFicWpfExVDJ/dkY5EwVd6rgxE/9FDGHaBBl+t4r/VChS+ul2oA nteuY3OCq1imDBjSpRme8UMv7ia/Gtk+aLFH2ZNlaKL7rVaIFmXR0M/4GSwVnIl2irI9l8 a8uNBCnXQEJW6spe51dJBdrpahxN/UQ= 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-321-oafUx_6YMSSpr0ZeGoRjbg-1; Thu, 14 Sep 2023 18:15:59 -0400 X-MC-Unique: oafUx_6YMSSpr0ZeGoRjbg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (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 20ECC816525; Thu, 14 Sep 2023 22:15:58 +0000 (UTC) Received: from warthog.procyon.org.com (unknown [10.42.28.216]) by smtp.corp.redhat.com (Postfix) with ESMTP id 686E72026D4B; Thu, 14 Sep 2023 22:15:55 +0000 (UTC) From: David Howells To: Al Viro , Linus Torvalds Cc: David Howells , Jens Axboe , 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 9/9] iov_iter: Add benchmarking kunit tests for UBUF/IOVEC Date: Thu, 14 Sep 2023 23:15:26 +0100 Message-ID: <20230914221526.3153402-10-dhowells@redhat.com> In-Reply-To: <20230914221526.3153402-1-dhowells@redhat.com> References: <20230914221526.3153402-1-dhowells@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Rspamd-Queue-Id: 974D3C001C X-Rspam-User: X-Stat-Signature: i5wfkd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3xy4b/FKnNSRYHJ0mcSmym3VKfsFebnKQ3QRgtRosqjYWkQENXRnO2sEfgAlzmhslRt6s/G0zE8xQw7OGg7Iu6M50rhlFui2AcbkcYkzDrb/pdxO+qEDaR/AIcoFIU9muvNqe56Gx8qxS/0bTnbeQBp1FPW/fJbaILfLa6m2JuYb/zw6CBYEE9foDyMEJ0XgH0z+3CvoSxOzTbhFuOOraM35RVOIPd5KBaiX9c3lQj35tWL6bV82t9tL36XfKHVOGElEl7FgekZAaroOLLDlkLxG5rS/2MGv8fEkggXrpfLYvtTOqYwysbYBoimHm+3d9kX0dorbt3IQo/Y0TMnD2aDXEI/gewRXWpmjPCFxVshUeoO8cw8bw7i7nJ8FsBzbS8xOsTS9fA4/GReF7BZgfi6sFsSexR70RyUugGGD4oA1mmxJkuRNG9eJ6z1xhtksfmlYxkzlp4KmgkRuWns4CE4QNlsqE4bLm8Y285zfCMbNOO5muKUxFTCkXY08QgzHPW5yktMVBOSbuOprqmXY2llidQUuxh5sT1/Z1+EKz3IVV8kiivBjUeAjJNUwHIFYXh3axAX36oBPWMUeAvNYFITp3Q== 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 | 85 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) diff --git a/lib/kunit_iov_iter.c b/lib/kunit_iov_iter.c index f8d0cd6a2923..cc9c64663a73 100644 --- a/lib/kunit_iov_iter.c +++ b/lib/kunit_iov_iter.c @@ -1304,6 +1304,89 @@ 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++) { + iov_iter_ubuf(&iter, ITER_DEST, buffer, size); + + a = ktime_get_real(); + copied = copy_to_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_IOVEC. + */ +static void __init iov_kunit_benchmark_iovec(struct kunit *test) +{ + struct iov_iter iter; + struct iovec iov[8]; + 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; + 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); + + /* Split the target over a number of iovecs */ + copied = 0; + for (i = 0; i < ARRAY_SIZE(iov); i++) { + part = size / ARRAY_SIZE(iov); + 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_DEST, iov, ARRAY_SIZE(iov), size); + + a = ktime_get_real(); + copied = copy_to_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. */ @@ -1504,6 +1587,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),