Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 3 Nov 2014 06:40:57 +0300
From:      rozhuk.im@gmail.com
To:        <freebsd-hackers@freebsd.org>
Subject:   pagedaemon + rtorrent = fail
Message-ID:  <5456f94c.247d700a.771d.ffff869e@mx.google.com>

next in thread | raw e-mail | index | archive | help
This is a multi-part message in MIME format.

------=_NextPart_000_0072_01CFF731.211E8460
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit


Problem described here:
https://forums.freebsd.org/threads/heavy-use-rtorrent-ufs-issues.14503/
http://www.bsdportal.ru/viewtopic.php?f=9&t=25194
http://forum.lissyara.su/viewtopic.php?f=53&t=39944

Swap is off: vm.swap_enabled=0
and no swap devices.

I wrote a small program to demonstrate the problem. 
The program creates a file size of 2*"RAM size", map() block size specified,
records in each page by byte, unmap(), map() next block... 
Once a file is written to more "RAM size" OOM kills the program and random
demons. 
In the TOP program does not consume more than the write_block size (32 mb)
for recording.
Check the parameters before the test run.






------=_NextPart_000_0072_01CFF731.211E8460
Content-Type: text/plain;
	name="testvm.c"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="testvm.c"

=0A=
/* rtorrent + FreeBSD pagedaemon prombel simulator=0A=
 * 2014 Rozhuk Ivan <rozhuk.im@gmail.com>=0A=
 *=0A=
 * compile-command: "clang -Wall -O2 -o testvm testvm.c"=0A=
 */=0A=
=0A=
=0A=
#include <sys/cdefs.h>=0A=
#include <sys/types.h>=0A=
#include <sys/stat.h> // chmod, fchmod, umask=0A=
#include <sys/uio.h> /* readv, preadv, writev, pwritev */=0A=
#include <sys/mman.h> /* mmap, munmap */=0A=
=0A=
#include <errno.h>=0A=
#include <fcntl.h> /* open, fcntl */=0A=
#include <stdio.h>  /* snprintf, fprintf */=0A=
#include <string.h> /* bcopy, bzero, memcpy, memmove, memset, strnlen, =
strerror... */=0A=
#include <unistd.h> /* close, write, sysconf */=0A=
#include <stdlib.h> /* malloc, exit */=0A=
=0A=
#define LOG_ERR(error, descr)							\=0A=
	fprintf(stdout, "fn: %s, line: %i, error: %i - %s, %s\n",		\=0A=
		__FUNCTION__, __LINE__, error, strerror(error), descr);=0A=
=0A=
int=0A=
main(int argc, char *argv[]) {=0A=
	int error =3D 0, fd;=0A=
	const char *file_name =3D (const char *)"/testvn.tmp";=0A=
	off_t mb =3D (1024 * 1024); /* 1 megabyte. */=0A=
	off_t file_size =3D (10 * 1024 * mb); /* Set to x2 RAM size. */=0A=
	off_t write_size =3D (32 * mb); /* Write block size. */=0A=
	off_t i, j, page_size;=0A=
	uint8_t *mem;=0A=
=0A=
	fd =3D open(file_name, (O_RDWR | O_CREAT), 0600);=0A=
	if (-1 =3D=3D fd) {=0A=
		error =3D errno;=0A=
		LOG_ERR(error, "open()");=0A=
		goto err_out;=0A=
	}=0A=
	if (0 !=3D flock(fd, LOCK_EX)) {=0A=
		error =3D errno;=0A=
		LOG_ERR(error, "flock()");=0A=
		goto err_out;=0A=
	}=0A=
	if (0 !=3D ftruncate(fd, file_size)) {=0A=
		error =3D errno;=0A=
		LOG_ERR(error, "ftruncate()");=0A=
		goto err_out;=0A=
	}=0A=
=0A=
	page_size =3D sysconf(_SC_PAGE_SIZE);=0A=
	for (i =3D 0; i < (file_size / write_size); i ++) {=0A=
		mem =3D mmap(NULL, write_size, (PROT_READ | PROT_WRITE),=0A=
		    (MAP_SHARED | MAP_NOCORE), fd, (i * write_size));=0A=
		if (MAP_FAILED =3D=3D mem) {=0A=
			error =3D errno;=0A=
			LOG_ERR(error, "mmap()");=0A=
			goto err_out;=0A=
		}=0A=
		for (j =3D 0; j < (write_size / page_size); j ++) {=0A=
			mem[(j * page_size)] =3D 1;=0A=
		}=0A=
		munmap(mem, file_size);=0A=
	}=0A=
=0A=
err_out:=0A=
	close(fd);=0A=
	//unlink(file_name); /* Delete file to free all mem. */=0A=
=0A=
	return (error);=0A=
}=0A=

------=_NextPart_000_0072_01CFF731.211E8460--




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?5456f94c.247d700a.771d.ffff869e>