#!/bin/bash

# point this to the actual bash-shared-mapping
bash_shared_mapping=/path/to/bash-shared-mapping

ITER=30
TASKS=10

# modify as needed, make sure it has ~40G free space
MNT=/mnt/xfs
FILENAME=$MNT/foo

memsize=`free -m | grep Mem | awk '{print $2}'`
echo "memsize is $memsize MB"

# Use memsize * 1.10 to put pressure on the VM:
bsmemsize=$((memsize * 11 / 10))
# limit memsize to 2 GB due to 31-bit seek() and mmap()
if [ $((bsmemsize)) -gt 2000 ] ; then
        bsmemsize=2000
	echo "limited memsize = $bsmemsize MB"
fi

copies=$(((memsize + 1950) / 2000))
echo "using $copies copies of: bash-shared-mapping"
FILESIZE=$((bsmemsize * 1000000))
echo "bash-shared-mapping : FILESIZE = $FILESIZE"

cp=$copies
while [ $cp -gt 0 ] ; do
	date
	prms="-v -n $ITER -t $TASKS $FILENAME.$cp $FILESIZE"
	$bash_shared_mapping $prms &
	cp=$((cp - 1))
done
wait

date
echo "done!"
