From owner-freebsd-questions@freebsd.org Thu Oct 11 03:52:40 2018 Return-Path: Delivered-To: freebsd-questions@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 964F310CC557 for ; Thu, 11 Oct 2018 03:52:40 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from mout.kundenserver.de (mout.kundenserver.de [212.227.126.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "mout.kundenserver.de", Issuer "TeleSec ServerPass DE-2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id F3D5D8255E for ; Thu, 11 Oct 2018 03:52:39 +0000 (UTC) (envelope-from freebsd@edvax.de) Received: from r56.edvax.de ([92.195.106.107]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPA (Nemesis) id 1MxV4T-1fmKVQ1Em9-00xtW3; Thu, 11 Oct 2018 05:52:37 +0200 Received: from r56.edvax.de ([92.195.106.107]) by mrelayeu.kundenserver.de (mreue011 [212.227.15.167]) with ESMTPA (Nemesis) id 1MxV4T-1fmKVQ1Em9-00xtW3; Thu, 11 Oct 2018 05:52:37 +0200 Date: Thu, 11 Oct 2018 05:52:36 +0200 From: Polytropon To: Victor Sudakov Cc: freebsd-questions@freebsd.org Subject: Re: swap to a sparse file Message-Id: <20181011055236.138279b2.freebsd@edvax.de> In-Reply-To: <20181011014705.GA17798@admin.sibptus.ru> References: <20181011014705.GA17798@admin.sibptus.ru> Reply-To: Polytropon Organization: EDVAX X-Mailer: Sylpheed 3.1.1 (GTK+ 2.24.5; i386-portbld-freebsd8.2) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K1:acfqdj1P/mz2mnqKg4G7kTHPmN2tMD+WCTMz4iOtw2NDnIf7IQC Tvv398sHgBzkQaYFCXZ2CsM/7k2SD3o91Gzg/u9VzMWYaw6emKJ+oqTk0KkucMhk1cTeST3 m9FIsK/dIvaiGm66m3HfFV9I2715M3eiKDBoxRdq2s5BDSd94raSSSwmmYvtsYoohGDjkyh qI5J6GizS9uMZtJc7B78w== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V01:K0:5yXOlIGwzh0=:/ftEMWute2bhScfq+krZ5D 7EB0zNSSYVR1sSIMhaOjJgh6/0PIh57i0XkC2ZSRrofMsK8oPsjCMaXkoZpdlHlgGH3yDYoYj YjI91VwseN1as/vbsgTxz+veZi8SxdMGtHD1fPb2+EWn6IJWBJxjPMiav5GdphG+SdbS0g2KD VrKt4drE5EiSkjW4Sf5EsbyWGjYkkVvVU+yzGb2N7uZclJeClI0leZ1sd+1v6uJu48Vy4P1hE +P/+ZUluRPltEqpcfFcxgbokqyxTVI8cjHrBqfZpS4I7Esx8X5rubfQxaD4LLQQylA0TJLTiB petYfD9ZNfa0AsMyz4Co2qUPjidwhVITI6Q38EKD5wd6yPjmFNgfshCvjCyTMeCkIrksy/BTw mqqxgn15BxhMvmI/pt1nnMHHvTCRnjbugsgmoNY1W+okMMkyQSC8otaHCANoYHdUlnQ2cfvbs 4+fjOE54MzRIF9hZA8YaScAlKc+fnKd9o5KGkYvA6ZosfDY7p2R1XBoQdJwTX33Avn39cnjnh JbpDUpNAJFtZ8jJ1Wnz+IRMsKTw0Mg13j2zAIOTgVzC+NP9gvd+AShFzigoklkUp+yUX/JDgz 7ETNpI5xTE6K/bf6web9O8HNJHdLSi9Oo4Ae9PmuznbuoboiQesrCxhCqwcmoiwG3s7LR+HAG vYLxYDFYyL4i9PoWo/5Dk6EhqcNtchYkVKf1P6vYKltUlYfsWaJ2oXv0Qtgba0Njw+rstjmxK 5/RY3fPZHGaJmYWG X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 11 Oct 2018 03:52:40 -0000 On Thu, 11 Oct 2018 08:47:05 +0700, Victor Sudakov wrote: > I've inherited a swapless FreeBSD 11.2 host with no unused disk space. > I would like to add some swap to be on the safe side: in case there is > a memory leak etc. > > On the other hand, I don't like to waste several gigabytes on a > precious SSD because perhaps the system will never need this swap > space anyway. Exactly my thoughts. :-) > The FreeBSD Handbook prescribes creating a swap file with "dd if=/dev/zero ..." > which would waste the space. A regular file as swap space also places additional load into the virtual file system, whereas one of the key advantages of a swap _partition_ is that no file access (through a filesystem) has to take place. > Is there any good reason I can't just "truncate -s2G /swap0" and > make the swap a sparse file? I'm using a "pseudo-file" approach which hasn't shown any problems so far. I'm using dd, but no actual disk space will be allocated for the target file. That file then is used like a regular swap partition via mdconfig's virtual node facility, and also deleted. Sure, it probably isn't the ideal solution, but it works. Maybe you can use this for further inspiration? In /etc/rc.local: SWAP="/swap0" /bin/rm -f $SWAP /bin/dd if=/dev/zero of=$SWAP bs=16m seek=500 count=0 /sbin/mdconfig -a -t vnode -u 0 -f $SWAP || /bin/sh /bin/chflags nodump $SWAP /bin/rm $SWAP /sbin/swapctl -a /dev/md0 echo -n " swap" In /etc/rc.shutdown.local: /sbin/swapctl -d /dev/md0 > /dev/null 2>&1 /sbin/mdconfig -d -u 0 echo -n " swap" -- Polytropon Magdeburg, Germany Happy FreeBSD user since 4.0 Andra moi ennepe, Mousa, ...