From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58165C4338F for ; Wed, 4 Aug 2021 03:41:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CA8E96023B for ; Wed, 4 Aug 2021 03:41:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org CA8E96023B Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id 1A8746B00A2; Tue, 3 Aug 2021 23:41:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 15A986B00A3; Tue, 3 Aug 2021 23:41:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 047C68D000F; Tue, 3 Aug 2021 23:41:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0053.hostedemail.com [216.40.44.53]) by kanga.kvack.org (Postfix) with ESMTP id DB3936B00A2 for ; Tue, 3 Aug 2021 23:41:44 -0400 (EDT) Received: from smtpin14.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 79B1B23E6C for ; Wed, 4 Aug 2021 03:41:44 +0000 (UTC) X-FDA: 78435998928.14.80E7DD0 Received: from mail-ed1-f52.google.com (mail-ed1-f52.google.com [209.85.208.52]) by imf16.hostedemail.com (Postfix) with ESMTP id 0D83DF0017DC for ; Wed, 4 Aug 2021 03:41:43 +0000 (UTC) Received: by mail-ed1-f52.google.com with SMTP id z11so1698347edb.11 for ; Tue, 03 Aug 2021 20:41:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Jqn3cUSXhL86/aR8CXIntvMigSyWyrxcTEh0ioBgKjc=; b=Mfkfku6RzIh9PU9VB5qCOgW8WPVleuDk9MDb+AtkTfLnzUJypUSiqNvVbRdiH9x9qL MZP9SjW8oyhlmRzbHUP/2gJ+6kXh3+rI/VAaLH20TTvlTX1UTzihrxkV81EzOX2YZVV3 SHByZMnPSJzR26K8RUWZO6dQcs1gcGr3sQEv/OSVDYrGzE2E5Dbm2DdrKrxIMnQcaaGo 9hxzJZ8wRDhSwzboDQLOaCO75FvoxSAOZGfhIYUtTjYa0YFV/XJnbB8ghi0RUfgtyNsM Nbd/YJcdPOKwsyhsHy7vzZrskbK4f/21IDo4QFCBMdqKUVY2C8bfdZgpOvTTrt7VmUGc H3xw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Jqn3cUSXhL86/aR8CXIntvMigSyWyrxcTEh0ioBgKjc=; b=KYH4Pui2JmE7+cLDMWdHqJf8RpuyDUr27QEIBWl4a06xgQESE4vNze5/GhKxRFUius kLyMpm6BrDMYo5PkbP2zjRE8vBGh5MKqmE4SNIVrwT5qwGuarhCFP4v1rY+PEzx6bBI/ TuDc8g+/+WfY/G7kpQlKXr77pZvnV784FMeoHbE24IdLvuokD9TQ62f0iA0SIjy71Vj0 7GgUiPp8yGh1qvKewukqXTQDX4EliWTHxd2Q7Hy6ByBzUY3edX4P3b+fvD6cxy3uHZP+ 53JTMn0E1n8dWMGsuEDkoL+5Ge7CsajKtE1XdOH3cOt3GrmFuhvsARTH1Zv6zHC/CEt7 uMuQ== X-Gm-Message-State: AOAM531WkZ2wSNSsR7WFXP85VbCzlyx19sg6PSLvjx0yozPRVM2fO1sv n3/iskJ3uPd0rsVyZ5WUozHcywMmEeZx1ZFhequydA== X-Google-Smtp-Source: ABdhPJyJKo0Trisq81aGbNLYiUV00k9Ixck93Dwg1xDSDp9cPcYPvKUVlMntKjkWjIBFpnJkSaGPG6+/MfNYMUkJsEI= X-Received: by 2002:a05:6402:2043:: with SMTP id bc3mr29579404edb.62.1628048502976; Tue, 03 Aug 2021 20:41:42 -0700 (PDT) MIME-Version: 1.0 References: <26a3cc3d02dc4fa65cc9b135be76e7d795c44877.1627828548.git.zhansayabagdaulet@gmail.com> In-Reply-To: <26a3cc3d02dc4fa65cc9b135be76e7d795c44877.1627828548.git.zhansayabagdaulet@gmail.com> From: Pavel Tatashin Date: Tue, 3 Aug 2021 23:41:07 -0400 Message-ID: Subject: Re: [PATCH 2/2] selftests: vm: add COW time test for KSM pages To: Zhansaya Bagdauletkyzy Cc: Andrew Morton , shuah@kernel.org, linux-mm , linux-kselftest@vger.kernel.org, LKML , Tyler Hicks Content-Type: text/plain; charset="UTF-8" X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 0D83DF0017DC Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=soleen.com header.s=google header.b=Mfkfku6R; dmarc=none; spf=pass (imf16.hostedemail.com: domain of pasha.tatashin@soleen.com designates 209.85.208.52 as permitted sender) smtp.mailfrom=pasha.tatashin@soleen.com X-Stat-Signature: nu74euisiqjdupkyf3qiuy47sriqc6wf X-HE-Tag: 1628048503-217929 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: On Sun, Aug 1, 2021 at 11:43 AM Zhansaya Bagdauletkyzy wrote: > > Since merged pages are copied every time they need to be modified, > the write access time is different between shared and non-shared pages. > Add ksm_cow_time() function which evaluates latency of these COW > breaks. First, duplicated pages are merged and then the time required > to write to each of the pages is detected. Hi Zhansaya, This test would make more sense if we also had a baseline on how long it takes to modify unmerged pages. This way it would show the true cost of having a write on a previously merged page vs. if it was never merged. Also, instead of having all pages merged together, I'd rather see a collection of merged pairs of pages, which are decoupled as one of the pages gets modified: i.e. Page1 - Page2: merged Page3 - Page4: merged ... then, go through pages: Page2, Page4, ... and modify the first byte in each of them and measure the time it takes. Do the same when these pages are not merged, and print both numbers so the cost of KSM and COW can be calculated. Thanks, Pasha > > The test is run as follows: ./ksm_tests -C -p 5000 > The output: > Total COW time: 0.012612 s > The number of pages: 5000 > Average speed: 1623 MB/s > > Signed-off-by: Zhansaya Bagdauletkyzy > --- > tools/testing/selftests/vm/ksm_tests.c | 66 ++++++++++++++++++++++++-- > 1 file changed, 63 insertions(+), 3 deletions(-) > > diff --git a/tools/testing/selftests/vm/ksm_tests.c b/tools/testing/selftests/vm/ksm_tests.c > index 91c6ff496655..3ffd899b2bd9 100644 > --- a/tools/testing/selftests/vm/ksm_tests.c > +++ b/tools/testing/selftests/vm/ksm_tests.c > @@ -33,7 +33,8 @@ enum ksm_test_name { > CHECK_KSM_UNMERGE, > CHECK_KSM_ZERO_PAGE_MERGE, > CHECK_KSM_NUMA_MERGE, > - KSM_MERGE_TIME > + KSM_MERGE_TIME, > + KSM_COW_TIME > }; > > static int ksm_write_sysfs(const char *file_path, unsigned long val) > @@ -98,7 +99,9 @@ static void print_help(void) > " -U (page unmerging)\n" > " -P evaluate merging time and speed.\n" > " For this test, the size of duplicated memory area (in MB)\n" > - " must be provided using -s option\n\n"); > + " must be provided using -s option\n" > + " -C evaluate the time required to break COW of merged pages.\n" > + " The number of pages can be defined using -p option.\n\n"); > > printf(" -a: specify the access protections of pages.\n" > " must be of the form [rwx].\n" > @@ -457,6 +460,56 @@ static int ksm_merge_time(int mapping, int prot, int timeout, size_t map_size) > return KSFT_FAIL; > } > > +static int ksm_cow_time(int mapping, int prot, int timeout, size_t page_size, long page_count) > +{ > + void *map_ptr; > + struct timespec start_time, end_time; > + long cow_time_s, cow_time_ns; > + int avg_speed; > + > + if (clock_gettime(CLOCK_MONOTONIC_RAW, &start_time)) { > + perror("clock_gettime"); > + return KSFT_FAIL; > + } > + > + map_ptr = allocate_memory(NULL, prot, mapping, '*', page_size * page_count); > + if (!map_ptr) > + return KSFT_FAIL; > + > + if (ksm_merge_pages(map_ptr, page_size * page_count, start_time, timeout)) > + goto err_out; > + > + if (clock_gettime(CLOCK_MONOTONIC_RAW, &start_time)) { > + perror("clock_gettime"); > + goto err_out; > + } > + for (size_t i = 0; i < page_count; i++) > + memset(map_ptr + page_size * i, '-', 1); > + if (clock_gettime(CLOCK_MONOTONIC_RAW, &end_time)) { > + perror("clock_gettime"); > + goto err_out; > + } > + > + cow_time_ns = (end_time.tv_sec - start_time.tv_sec) * NSEC_PER_SEC + > + (end_time.tv_nsec - start_time.tv_nsec); > + cow_time_s = cow_time_ns / NSEC_PER_SEC; > + cow_time_ns %= NSEC_PER_SEC; > + avg_speed = (page_size * page_count) / (cow_time_s * USEC_PER_SEC + > + cow_time_ns / NSEC_PER_USEC); > + > + printf("Total COW time: %ld.%06ld s\n", cow_time_s, cow_time_ns / NSEC_PER_USEC); > + printf("The number of pages: %ld\n", page_count); > + printf("Average speed: %d MB/s\n", avg_speed); > + > + munmap(map_ptr, page_size * page_count); > + return KSFT_PASS; > + > +err_out: > + printf("Not OK\n"); > + munmap(map_ptr, page_size * page_count); > + return KSFT_FAIL; > +} > + > int main(int argc, char *argv[]) > { > int ret, opt; > @@ -470,7 +523,7 @@ int main(int argc, char *argv[]) > bool merge_across_nodes = KSM_MERGE_ACROSS_NODES_DEFAULT; > long size_MB = 0; > > - while ((opt = getopt(argc, argv, "ha:p:l:z:m:s:MUZNP")) != -1) { > + while ((opt = getopt(argc, argv, "ha:p:l:z:m:s:MUZNPC")) != -1) { > switch (opt) { > case 'a': > prot = str_to_prot(optarg); > @@ -524,6 +577,9 @@ int main(int argc, char *argv[]) > case 'P': > test_name = KSM_MERGE_TIME; > break; > + case 'C': > + test_name = KSM_COW_TIME; > + break; > default: > return KSFT_FAIL; > } > @@ -573,6 +629,10 @@ int main(int argc, char *argv[]) > ret = ksm_merge_time(MAP_PRIVATE | MAP_ANONYMOUS, prot, ksm_scan_limit_sec, > size_MB); > break; > + case KSM_COW_TIME: > + ret = ksm_cow_time(MAP_PRIVATE | MAP_ANONYMOUS, prot, ksm_scan_limit_sec, > + page_size, page_count); > + break; > } > > if (ksm_restore(&ksm_sysfs_old)) { > -- > 2.25.1 >