LKML Archive on lore.kernel.org
 help / color / Atom feed
From: Hui Zhu <teawaterz@linux.alibaba.com>
To: fengguang.wu@intel.com, linux-kernel@vger.kernel.org
Cc: Hui Zhu <teawaterz@linux.alibaba.com>
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> (raw)

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 <teawaterz@linux.alibaba.com>
---
 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


             reply index

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-14  3:07 Hui Zhu [this message]
2019-09-14  8:05 ` Fengguang Wu

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1568430438-31372-1-git-send-email-teawaterz@linux.alibaba.com \
    --to=teawaterz@linux.alibaba.com \
    --cc=fengguang.wu@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

LKML Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lkml.kernel.org/lkml/0 lkml/git/0.git
	git clone --mirror https://lkml.kernel.org/lkml/1 lkml/git/1.git
	git clone --mirror https://lkml.kernel.org/lkml/2 lkml/git/2.git
	git clone --mirror https://lkml.kernel.org/lkml/3 lkml/git/3.git
	git clone --mirror https://lkml.kernel.org/lkml/4 lkml/git/4.git
	git clone --mirror https://lkml.kernel.org/lkml/5 lkml/git/5.git
	git clone --mirror https://lkml.kernel.org/lkml/6 lkml/git/6.git
	git clone --mirror https://lkml.kernel.org/lkml/7 lkml/git/7.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 lkml lkml/ https://lkml.kernel.org/lkml \
		linux-kernel@vger.kernel.org linux-kernel@archiver.kernel.org
	public-inbox-index lkml


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-kernel


AGPL code for this site: git clone https://public-inbox.org/ public-inbox