Re: agressive swap-out/performance tests.

Andrew P. Mullhaupt (amullhau@ix.netcom.com)
Mon, 21 Apr 1997 21:36:02 -0400


This is a multi-part message in MIME format.

--------------3B4D6AD6415F
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Harvey J. Stein wrote:
>
> I have similar problems with swap behavior, and I've been trying to
> figure this out how to tune it for a while now. I have the opposite
> problem that you have - I have 32mb of RAM & it seems like the system
> preserves the disk cache at the expense of large programs.

Well, it's sort of related to the questions I asked a while back about
Linux VM, and I finally got around to putting together a little package
of code which people have asked for. It is attached to this post.

I used what I believe to be a vanilla shar, and I hope this form doesn't
drive any one to leave the known universe...

Later,
Andrew Mullhaupt

--------------3B4D6AD6415F
Content-Type: application/x-shar; name="dbl.shar"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="dbl.shar"

#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.1).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 1997-04-21 21:25 EDT by <andrew@krug>.
# Source directory was `/home/andrew/src'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
# This format requires very little intelligence at unshar time.
# "if test", "echo", and "sed" may be needed.
#
# This shar contains:
# length mode name
# ------ ---------- ------------------------------------------
# 237 -rw-r--r-- doubles/Makefile
# 150 -rw-r--r-- doubles/README
# 207 -rw-r--r-- doubles/double.c
# 446 -rw-r--r-- doubles/double_msync.c
# 344 -rw-r--r-- doubles/double_munmap.c
# 244 -rwxr-xr-x doubles/runme
# 171 -rw-r--r-- doubles/file_create.c
# 259 -rw-r--r-- doubles/double_write.c
# 792 -rw-r--r-- doubles/mm.c
# 295 -rw-r--r-- doubles/mm.h
#
# ============= doubles/Makefile ==============
if test ! -d 'doubles'; then
echo 'x - creating directory doubles'
mkdir 'doubles'
fi
if test -f 'doubles/Makefile' && test X"$1" != X"-c"; then
echo 'x - skipping doubles/Makefile (file already exists)'
else
echo 'x - extracting doubles/Makefile (text)'
sed 's/^X//' << 'SHAR_EOF' > 'doubles/Makefile' &&
X
XCC=cc
XCFLAGS=-static -s -O3 -omit-frame-pointer
X
XTARGETS=double double_munmap double_msync double_write file_create
X
Xall: $(TARGETS)
X
X$(TARGETS): mm.o
X $(CC) $(CFLAGS) $@.c mm.o -o $@
X
Xclean:
X rm -f *.o core
X
Xdist: clean
X rm $(TARGETS)
SHAR_EOF
: || echo 'restore of doubles/Makefile failed'
fi
# ============= doubles/README ==============
if test -f 'doubles/README' && test X"$1" != X"-c"; then
echo 'x - skipping doubles/README (file already exists)'
else
echo 'x - extracting doubles/README (text)'
sed 's/^X//' << 'SHAR_EOF' > 'doubles/README' &&
X
XIn order to run the file-doubling timing examples, you should only
Xhave to run a make, and then, to use a file size of, say, 2000 bytes
X
Xrunme 2000
X
SHAR_EOF
: || echo 'restore of doubles/README failed'
fi
# ============= doubles/double.c ==============
if test -f 'doubles/double.c' && test X"$1" != X"-c"; then
echo 'x - skipping doubles/double.c (file already exists)'
else
echo 'x - extracting doubles/double.c (text)'
sed 's/^X//' << 'SHAR_EOF' > 'doubles/double.c' &&
X
X#include "mm.h"
X
Xmain(int argc, char **argv)
X{
X
X int i, n;
X char *x, *y;
X
X x = (char *) map_open(argv[1], &n);
X y = (char *) map_alloc(argv[2], 2*n);
X
X memcpy(y, x, n);
X memcpy(y+n, x, n);
X
X exit(0);
X
X}
X
X
X
SHAR_EOF
: || echo 'restore of doubles/double.c failed'
fi
# ============= doubles/double_msync.c ==============
if test -f 'doubles/double_msync.c' && test X"$1" != X"-c"; then
echo 'x - skipping doubles/double_msync.c (file already exists)'
else
echo 'x - extracting doubles/double_msync.c (text)'
sed 's/^X//' << 'SHAR_EOF' > 'doubles/double_msync.c' &&
X
X#include "mm.h"
X
Xmain(int argc, char **argv)
X{
X
X int i, n;
X char *x, *y;
X
X x = (char *) map_open(argv[1], &n);
X y = (char *) map_alloc(argv[2], 2*n);
X
X memcpy(y, x, n);
X
X /*
X * Tell the kernel we're done with the first half of y -
X * This is not normally what you think of msync() for
X * but Kevin Sheehan points out that some kernels can
X * take this hint.
X */
X msync(y, n, MS_INVALIDATE | MS_ASYNC);
X
X memcpy(y+n, x, n);
X
X exit(0);
X
X}
X
X
X
SHAR_EOF
: || echo 'restore of doubles/double_msync.c failed'
fi
# ============= doubles/double_munmap.c ==============
if test -f 'doubles/double_munmap.c' && test X"$1" != X"-c"; then
echo 'x - skipping doubles/double_munmap.c (file already exists)'
else
echo 'x - extracting doubles/double_munmap.c (text)'
sed 's/^X//' << 'SHAR_EOF' > 'doubles/double_munmap.c' &&
X
X#include "mm.h"
X
Xvoid main(int argc, char **argv)
X{
X
X int i, n;
X char *x, *y;
X int pagesize = sysconf(_SC_PAGESIZE);
X
X x = (char *) map_open(argv[1], &n);
X y = (char *) map_alloc(argv[2], 2*n);
X
X memcpy(y, x, n);
X
X /*
X * Unmap the pages in the first half of y
X */
X munmap(y, (n / pagesize) * pagesize);
X
X memcpy(y+n, x, n);
X
X exit();
X
X}
X
X
X
SHAR_EOF
: || echo 'restore of doubles/double_munmap.c failed'
fi
# ============= doubles/runme ==============
if test -f 'doubles/runme' && test X"$1" != X"-c"; then
echo 'x - skipping doubles/runme (file already exists)'
else
echo 'x - extracting doubles/runme (text)'
sed 's/^X//' << 'SHAR_EOF' > 'doubles/runme' &&
X#!/bin/sh
X
Xfor program in double_write double double_msync double_munmap
Xdo
X echo Creating foo
X file_create foo $1
X ls -ls foo
X echo
X echo Timing $program
X echo
X for i in 1 2 3 4 5 6
X do
X time -p $program foo goo
X echo
X done
Xdone
X
Xrm foo goo
SHAR_EOF
: || echo 'restore of doubles/runme failed'
fi
# ============= doubles/file_create.c ==============
if test -f 'doubles/file_create.c' && test X"$1" != X"-c"; then
echo 'x - skipping doubles/file_create.c (file already exists)'
else
echo 'x - extracting doubles/file_create.c (text)'
sed 's/^X//' << 'SHAR_EOF' > 'doubles/file_create.c' &&
X
X#include "mm.h"
X
Xmain(int argc, char **argv)
X{
X
X int i, n, fd;
X char *x, *y;
X
X n = atoi(argv[2]);
X
X x = (char *) map_alloc(argv[1], n);
X
X memset(x, 0, n);
X
X exit(0);
X
X}
X
SHAR_EOF
: || echo 'restore of doubles/file_create.c failed'
fi
# ============= doubles/double_write.c ==============
if test -f 'doubles/double_write.c' && test X"$1" != X"-c"; then
echo 'x - skipping doubles/double_write.c (file already exists)'
else
echo 'x - extracting doubles/double_write.c (text)'
sed 's/^X//' << 'SHAR_EOF' > 'doubles/double_write.c' &&
X
X#include "mm.h"
X
Xmain(int argc, char **argv)
X{
X
X int i, n, fd;
X char *x, *y;
X
X x = (char *) map_open(argv[1], &n);
X
X if((fd = open(argv[2], O_CREAT | O_RDWR, 0644)) < 0) {
X perror(argv[2]);
X exit(1);
X }
X
X write(fd, x, n);
X write(fd, x, n);
X
X exit(0);
X
X}
X
SHAR_EOF
: || echo 'restore of doubles/double_write.c failed'
fi
# ============= doubles/mm.c ==============
if test -f 'doubles/mm.c' && test X"$1" != X"-c"; then
echo 'x - skipping doubles/mm.c (file already exists)'
else
echo 'x - extracting doubles/mm.c (text)'
sed 's/^X//' << 'SHAR_EOF' > 'doubles/mm.c' &&
X
X#include "mm.h"
X
Xcaddr_t map_open(char *filename, int *pn)
X{
X int fd, n;
X caddr_t pa;
X if((fd = open(filename, O_CREAT | O_RDONLY)) < 0) {
X perror(filename);
X exit(1);
X }
X n = lseek(fd, 0L, SEEK_END);
X pa = mmap((caddr_t) 0, n, PROT_READ, MAP_SHARED, fd, (off_t) 0);
X if (pa == (caddr_t) -1) {
X printf("mmap errno: %ld\n", errno);
X perror("mmap");
X exit(1);
X }
X close(fd);
X *pn = n;
X return pa;
X}
X
Xcaddr_t map_alloc(char *filename, unsigned n)
X{
X int fd;
X caddr_t pa;
X if((fd = open(filename, O_CREAT | O_RDWR, 0644)) < 0) {
X perror(filename);
X exit(1);
X }
X ftruncate(fd, n);
X pa = mmap((caddr_t) 0, n,
X PROT_READ | PROT_WRITE, MAP_SHARED, fd, (off_t) 0);
X if (pa == (caddr_t) -1) {
X printf("mmap errno: %ld\n", errno);
X perror("mmap");
X exit(1);
X }
X close(fd);
X return pa;
X}
X
SHAR_EOF
: || echo 'restore of doubles/mm.c failed'
fi
# ============= doubles/mm.h ==============
if test -f 'doubles/mm.h' && test X"$1" != X"-c"; then
echo 'x - skipping doubles/mm.h (file already exists)'
else
echo 'x - extracting doubles/mm.h (text)'
sed 's/^X//' << 'SHAR_EOF' > 'doubles/mm.h' &&
X
X#ifndef __MM_H__
X
X#include <stdio.h>
X#include <string.h>
X#include <sys/types.h>
X#include <sys/mman.h>
X#include <sys/stat.h>
X#include <fcntl.h>
X#include <unistd.h>
X
Xextern int errno;
X
Xcaddr_t map_open(char *filename, int *pn);
Xcaddr_t map_alloc(char *filename, unsigned n);
X
X#endif /* _MM_H_ */
SHAR_EOF
: || echo 'restore of doubles/mm.h failed'
fi
exit 0

--------------3B4D6AD6415F--