Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp2094044ybe; Sat, 14 Sep 2019 07:45:53 -0700 (PDT) X-Google-Smtp-Source: APXvYqwBUKY74M0SC6dmEPoU2hoKslVmhIQOuDuE5scuB9/dLsAgboUulEqCH8C6mJx5MEE52C+C X-Received: by 2002:a17:906:a416:: with SMTP id l22mr42717051ejz.302.1568472353853; Sat, 14 Sep 2019 07:45:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568472353; cv=none; d=google.com; s=arc-20160816; b=kNnAy278CGGjsbF+nPQBa7kc6q1En7AAwlz9C/503MDqJq72kPpX5F7GbQekw/yY69 SwC2qdhikrAawLxgZhKFh2IW8jZr7TjlF2JWlx1loNLoxI6rLuCGmJyoenVzGffbMdZI XDZGG5nNVaNGptv3/3GGuxANC+OrjqnRd0D23bDVjN+Lb8fFLIDy9PVev4MyH1CUvH6z diiOdqrzBByH5KY+oum3wmI7TwvaEUOO8lce3Y79xuF3qHlS3CZGfUyluSb6juG0qrMZ 8FOk/NMwRaV6L7kkH+1Sz363H724m++IH5ESK8cFI9i3SnivmyzQThe7bV7MBjBWe27q NGBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=qgtUrSyz92+Hh4Rz0KI0T/8xARXkElS4kWi88r7yynk=; b=X+b3r3EX0q7Q5hNv1u92IcTPYfbJceJjPDOCI4nfv6CpJZYj6b/HMQG1euNVdNkZ7D 6zYm+UsFg4p70gcU3cY/GtzaGraLbbVJsGRvdQ3Z0n72CF/IfL166Dd9ccf2NEBWfq58 LVsWOAnAG7irO1OXnbyT0IakFHdf7WdOTOuhvM7vs69OGWYKbsgnVl2rTDguxu0PQRu+ DthuykwxLgXyXzYpU0fjP48O0A+7emwYGJgwzCfoe1JGx8kLu6psyk/btiNjTkFcy4yD HfrS9unu5ZeLuwataTfRkyKnEJQul+krsleJTWPZDyqxvk6E813nJJlE0/h7v1DTJe3H 0xeA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id jp5si16090333ejb.258.2019.09.14.07.45.30; Sat, 14 Sep 2019 07:45:53 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730833AbfINDHn (ORCPT + 99 others); Fri, 13 Sep 2019 23:07:43 -0400 Received: from out30-131.freemail.mail.aliyun.com ([115.124.30.131]:57564 "EHLO out30-131.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728720AbfINDHm (ORCPT ); Fri, 13 Sep 2019 23:07:42 -0400 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R641e4;CH=green;DM=||false|;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e07417;MF=teawaterz@linux.alibaba.com;NM=1;PH=DS;RN=3;SR=0;TI=SMTPD_---0TcH.5Hj_1568430451; Received: from localhost(mailfrom:teawaterz@linux.alibaba.com fp:SMTPD_---0TcH.5Hj_1568430451) by smtp.aliyun-inc.com(127.0.0.1); Sat, 14 Sep 2019 11:07:36 +0800 From: Hui Zhu To: fengguang.wu@intel.com, linux-kernel@vger.kernel.org Cc: Hui Zhu Subject: [PATCH for vm-scalability] usemem: Add new option -Z|--read-again Date: Sat, 14 Sep 2019 11:07:18 +0800 Message-Id: <1568430438-31372-1-git-send-email-teawaterz@linux.alibaba.com> X-Mailer: git-send-email 2.7.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org usemem will read memory again after access the memory with this option. It can help test the speed that load page from swap to memory. Signed-off-by: Hui Zhu --- usemem.c | 46 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 40 insertions(+), 6 deletions(-) diff --git a/usemem.c b/usemem.c index 264d52a..2d31946 100644 --- a/usemem.c +++ b/usemem.c @@ -94,6 +94,7 @@ int opt_sync_rw = 0; int opt_sync_free = 0; int opt_bind_interval = 0; unsigned long opt_delay = 0; +int opt_read_again = 0; int nr_task; int nr_thread; int nr_cpu; @@ -151,6 +152,7 @@ void usage(int ok) " -e|--delay delay for each page in ns\n" " -O|--anonymous mmap with MAP_ANONYMOUS\n" " -U|--hugetlb allocate hugetlbfs page\n" + " -Z|--read-again read memory again after access the memory\n" " -h|--help show this message\n" , ourname); @@ -188,6 +190,7 @@ static const struct option opts[] = { { "sync-rw" , 0, NULL, 'y' }, { "delay" , 1, NULL, 'e' }, { "hugetlb" , 0, NULL, 'U' }, + { "read-again" , 0, NULL, 'Z' }, { "help" , 0, NULL, 'h' }, { NULL , 0, NULL, 0 } }; @@ -616,7 +619,7 @@ unsigned long do_unit(unsigned long bytes, struct drand48_data *rand_data, return rw_bytes; } -static void output_statistics(unsigned long unit_bytes) +static void output_statistics(unsigned long unit_bytes, const char *intro) { struct timeval stop; char buf[1024]; @@ -629,8 +632,8 @@ static void output_statistics(unsigned long unit_bytes) (stop.tv_usec - start_time.tv_usec); throughput = ((unit_bytes * 1000000ULL) >> 10) / delta_us; len = snprintf(buf, sizeof(buf), - "%lu bytes / %lu usecs = %lu KB/s\n", - unit_bytes, delta_us, throughput); + "%s%lu bytes / %lu usecs = %lu KB/s\n", + intro, unit_bytes, delta_us, throughput); fflush(stdout); write(1, buf, len); } @@ -690,7 +693,34 @@ long do_units(void) } while (bytes); if (!opt_write_signal_read && unit_bytes) - output_statistics(unit_bytes); + output_statistics(unit_bytes, ""); + + if (opt_read_again && unit_bytes) { + unsigned long rw_bytes = 0; + + gettimeofday(&start_time, NULL); + for (i = 0; i < nptr; i++) { + int rep; + + for (rep = 0; rep < reps; rep++) { + if (rep > 0 && !quiet) { + printf("."); + fflush(stdout); + } + + rw_bytes += do_rw_once(ptrs[i], lens[i], &rand_data, 1, &rep, reps); + + if (msync_mode) { + if ((msync(ptrs[i], lens[i], msync_mode)) == -1) { + fprintf(stderr, "msync failed with error %s \n", strerror(errno)); + exit(1); + } + } + } + } + + output_statistics(rw_bytes, "read again "); + } if (opt_write_signal_read) { struct sigaction act; @@ -731,7 +761,7 @@ long do_units(void) sigsuspend(&set); gettimeofday(&start_time, NULL); unit_bytes = do_rw_once(buffer, opt_bytes, &rand_data, 1, NULL, 0); - output_statistics(unit_bytes); + output_statistics(unit_bytes, ""); } if (opt_sync_free) @@ -879,7 +909,7 @@ int main(int argc, char *argv[]) pagesize = getpagesize(); while ((c = getopt_long(argc, argv, - "aAB:f:FPp:gqowRMm:n:t:b:ds:T:Sr:u:j:e:EHDNLWyxOUh", opts, NULL)) != -1) + "aAB:f:FPp:gqowRMm:n:t:b:ds:T:Sr:u:j:e:EHDNLWyxOUZh", opts, NULL)) != -1) { switch (c) { case 'a': @@ -1005,6 +1035,10 @@ int main(int argc, char *argv[]) map_hugetlb = MAP_HUGETLB | MAP_HUGE_2MB; break; + case 'Z': + opt_read_again = 1; + break; + default: usage(1); } -- 2.7.4