xref: /freebsd/tools/test/stress2/misc/unlink.sh (revision a03411e84728e9b267056fd31c7d1d9d1dc1b01e)
1#!/bin/sh
2
3# File-backed shared memory performance
4# https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=222356
5
6# For unlinked files, do not msync(2) or sync on inactivation.
7# https://reviews.freebsd.org/D12411
8
9# Original test scenario by: tijl@FreeBSD.org
10
11# Fixed by r323768
12
13. ../default.cfg
14
15cat > /tmp/unlink.c <<EOF
16#include <sys/mman.h>
17#include <sys/time.h>
18
19#include <err.h>
20#include <fcntl.h>
21#include <stdio.h>
22#include <string.h>
23#include <unistd.h>
24
25int
26main(void) {
27	struct timeval diff, start, stop;
28	size_t sz;
29	void *base;
30	uint64_t usec;
31	int fd;
32
33	sz = 128 * 1024 * 1024;
34	fd = open("nosync.data", O_RDWR | O_CREAT, 0600);
35	if (fd == -1)
36		err(1, "open");
37	if (unlink("nosync.data") == -1)
38		err(1, "unlink");
39	if (ftruncate(fd, sz) == -1)
40		err(1, "ftruncate");
41	base = mmap(NULL, sz, PROT_READ | PROT_WRITE,
42		     MAP_SHARED | MAP_NOSYNC, fd, 0);
43	if (base == MAP_FAILED)
44		err(1, "mmap");
45	memset(base, '0', sz);
46	if (munmap(base, sz) == -1)
47		err(1, "unmap");
48	gettimeofday(&start, NULL);
49	close(fd);
50	gettimeofday(&stop, NULL);
51	timersub(&stop, &start, &diff);
52	usec  = ((uint64_t)1000000 * diff.tv_sec + diff.tv_usec);
53	if (usec > 500000) {
54		fprintf(stdout, "%.3f seconds elapsed\n",
55		    (double)usec / 1000000);
56		return (0); /* Ignore error for now */
57	} else
58		return(0);
59}
60EOF
61
62mycc -o /tmp/unlink -Wall -Wextra -O2 -g /tmp/unlink.c || exit 1
63rm /tmp/unlink.c
64
65cd $RUNDIR
66/tmp/unlink; s=$?
67
68rm /tmp/unlink
69exit $s
70