aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlexander Motin <mav@FreeBSD.org>2017-10-01 16:59:02 +0000
committerAlexander Motin <mav@FreeBSD.org>2017-10-01 16:59:02 +0000
commite975a1aba0fba62ab998cbde8df2a18b1adb3909 (patch)
tree837166fc89386059f8c52003583b90cfdc233d0b
parent3e52a0557016274d28435293f859ca4a31a156d9 (diff)
downloadsrc-e975a1aba0fba62ab998cbde8df2a18b1adb3909.tar.gz
src-e975a1aba0fba62ab998cbde8df2a18b1adb3909.zip
Align test I/O buffer to page boundary.
This is more alike to typical kernel behavior, that can be useful from benchmarking point of view. MFC after: 1 week
Notes
Notes: svn path=/head/; revision=324172
-rw-r--r--usr.sbin/diskinfo/diskinfo.c21
1 files changed, 12 insertions, 9 deletions
diff --git a/usr.sbin/diskinfo/diskinfo.c b/usr.sbin/diskinfo/diskinfo.c
index 933d30de11ca..7a8db3d87f42 100644
--- a/usr.sbin/diskinfo/diskinfo.c
+++ b/usr.sbin/diskinfo/diskinfo.c
@@ -50,6 +50,8 @@
#include <sys/time.h>
#define NAIO 128
+#define MAXTX (8*1024*1024)
+#define MEGATX (1024*1024)
static void
usage(void)
@@ -67,12 +69,14 @@ static void slogbench(int fd, int isreg, off_t mediasize, u_int sectorsize);
static int zonecheck(int fd, uint32_t *zone_mode, char *zone_str,
size_t zone_str_len);
+static uint8_t *buf;
+
int
main(int argc, char **argv)
{
struct stat sb;
int i, ch, fd, error, exitval = 0;
- char buf[BUFSIZ], ident[DISK_IDENT_SIZE], physpath[MAXPATHLEN];
+ char tstr[BUFSIZ], ident[DISK_IDENT_SIZE], physpath[MAXPATHLEN];
char zone_desc[64];
struct diocgattr_arg arg;
off_t mediasize, stripesize, stripeoffset;
@@ -129,11 +133,13 @@ main(int argc, char **argv)
usage();
}
+ if (posix_memalign((void **)&buf, PAGE_SIZE, MAXTX))
+ errx(1, "Can't allocate memory buffer");
for (i = 0; i < argc; i++) {
fd = open(argv[i], (opt_w ? O_RDWR : O_RDONLY) | O_DIRECT);
if (fd < 0 && errno == ENOENT && *argv[i] != '/') {
- snprintf(buf, BUFSIZ, "%s%s", _PATH_DEV, argv[i]);
- fd = open(buf, O_RDONLY);
+ snprintf(tstr, sizeof(tstr), "%s%s", _PATH_DEV, argv[i]);
+ fd = open(tstr, O_RDONLY);
}
if (fd < 0) {
warn("%s", argv[i]);
@@ -216,12 +222,12 @@ main(int argc, char **argv)
printf("\t%u", fwsectors);
}
} else {
- humanize_number(buf, 5, (int64_t)mediasize, "",
+ humanize_number(tstr, 5, (int64_t)mediasize, "",
HN_AUTOSCALE, HN_B | HN_NOSPACE | HN_DECIMAL);
printf("%s\n", argv[i]);
printf("\t%-12u\t# sectorsize\n", sectorsize);
printf("\t%-12jd\t# mediasize in bytes (%s)\n",
- (intmax_t)mediasize, buf);
+ (intmax_t)mediasize, tstr);
printf("\t%-12jd\t# mediasize in sectors\n",
(intmax_t)mediasize/sectorsize);
printf("\t%-12jd\t# stripesize\n", stripesize);
@@ -255,13 +261,10 @@ main(int argc, char **argv)
out:
close(fd);
}
+ free(buf);
exit (exitval);
}
-#define MAXTX (8*1024*1024)
-#define MEGATX (1024*1024)
-static uint8_t buf[MAXTX];
-
static void
rdsect(int fd, off_t blockno, u_int sectorsize)
{