kernel config
# set max number of allowed processes to 1044
maxusers 64
# Alternate buffer queue strategies for better responsiveness under high
# disk I/O load.
options BUFQ_READPRIO
options BUFQ_PRIOCSCAN
# SVR4-style scheduling
no options SCHED_4BSD
options SCHED_M2
resource limits
Append this to your /etc/login.conf in order to increase 'capabilities' (loosen session resource limits) for the staff class, system-wide:
#
# Staff have fewer restrictions
#
staff:\ :datasize-cur=1024M:\
:datasize-max=infinity:\
:maxproc-max=1024:\
:maxproc-cur=128:\
:requirehome@:
Recompile a hashed class capabilities database:
$ cap_mkdb /etc/login.conf
Now change your regular user's login class to staff:
$ usermod -L staff <username>
kernel state tunables
Set those sysctl(7) values permanently at boot time but adding what follows to your /etc/sysctl.conf
## KERNEL
# increase max PAGE_SIZE
kern.ipc.shmmaxpgs=580205
# increase max file descriptors
kern.maxfiles=12286
## TCP/IP stack
# automatic network buffers resize
net.inet.tcp.recvbuf_auto=1
net.inet.tcp.sendbuf_auto=1
# Toggle JIT compilation of new filter programs on
net.bpf.jit=1
# 4x BPF buffer max size
net.bpf.maxbufsize=4194304
# 16MB buffers upper limit
net.inet.tcp.sendbuf_max=16777216
net.inet.tcp.recvbuf_max=16777216
# Maximum allowed output queue length
net.inet.ip.ifq.maxlen = 4096
# Maximum segment size
net.inet.tcp.mssdflt=1072
FFSv2 WAPBL
WAPBL provides data journaling on NetBSD for the FFSv{1,2} filesystems .
Journaling improves writing performance noticeably by reducing synchronization, especially when creating a large number of inodes. It also avoids having to go through a thorough file-systems check during a crash recovery , speeding up boot time significantly in those cases
Enabling WAPBL on NetBSD is as easy as appending 'log' to FS mount options for each FFSv{1,2} partition found in /etc/fstab:
/dev/wd0a / ffs rw,log 1 1
/dev/wd0e /usr ffs rw,log 1 2
/dev/wd0f /var ffs rw,log 1 2
/dev/wd0g /home ffs rw,log 1 2
noatime
Another possible tweak is to disable last access timestamps on filesystems. These decreases the number of metadata updates to files, and is useful for optimizing read performance. A side effect will be reducing power consumption on laptops. This is a default option on evbarm, since most people will be using SD cards on SBC.
Append noatime
to your mount options list inside /etc/fstab, as you did above with log
.
tmpfs
mount a tmpfs disk on directories with a high r/w turnover so as to decrease access time and increase maximum throughput, by adding suitable entries to /etc/fstab
tmpfs /tmp tmpfs rw,-m=1777,-s=4295467008
tmpfs /var/shm tmpfs rw,-m1777,-sram%25
tmpfs /var/tmp tmpfs rw,-m1777,-sram%25
Now, providing you have enough ram, you can also build packages on volatile memory by adding:
# build on tmpfs
WRKOBJDIR = /var/tmp/pkg
to your mk.conf(5)
pkgsrc options
compiler optimization
Use devel/cpuflags to determine the best compiler flags to set for your CPU;
Now you can specify them inside your /etc/mk.conf
MAKE_JOBS = $(/sbin/sysctl -n hw.ncpuonline)
.if defined(BSD_PKG_MK)
#.include "/etc/mk.extra.conf"
GZIP? = --fast
CPUFLAGS+ = -O2 -pipe -fomit-frame-pointer -mfpmath=sse -msse3 -march=native
#CFLAGS+ = -Wfatal-errors
INSTALL_UNSTRIPPED = yes
.endif
speed up recompilation by caching previous compilations
After installing devel/ccache, you may add:
PKGSRC_COMPILER = ccache gcc
CCACHE_DIR = ${HOME}/.cache/ccache
to your /etc/mk.conf
faster distfile fetching
## FETCHING DISTFILES
FETCH_FAILOVER = YES
# resume downloads
PKG_RESUME_TRANSFERS = YES
# fetch using wget
.if exists(${LOCALBASE}/bin/wget)
FETCH_CMD = ${LOCALBASE}/bin/wget
.endif
FETCH_BEFORE_ARGS = –passive-ftp
FETCH_RESUME_ARGS = -c
FETCH_OUTPUT_ARGS = -O
# preferred domains list (this is set for TZ=Europe/Rome and provided as example)
MASTER_SORT_RANDOM= no
MASTER_SORT = .eu .it .ch .at .fr .de .es .nl .uk .at .be .cz .pl .se .fi .no .dk
tips
- Add swap space to a running system
% dd if=/dev/zero bs=1M count=128 of=<FS>/swap
% chmod 600 <FS>/swap
% swapctl -a -p 1 <FS>/swap
Providing file-based swap is slower than a swap partition, giving the additional swap space a priority of 1 (through '-p 1', least is a value of '0' ) forces it be relied upon for paging only when the swap partition has been used up.
- check for memory in use
- using
top(1)
% top -n 1 | head -n 5 | tail -n 2
Memory: 665M Act, 74M Inact, 14M Wired, 113M Exec, 119M File, 3045M Free
Swap: 6144M Total, 6144M Free
- using sysutils/free
$ free -m
total used free buffers
Mem: 3923 885 3037 232
Swap: 6144 0 6144
reading /proc/meminfo
$ cat /proc/meminfo
total: used: free: shared: buffers: cached:
Mem: 4113620992 925655040 3187965952 0 126500864 794152960
Swap: 6442938368 0 6442938368
MemTotal: 4017208 kB
MemFree: 3113248 kB
MemShared: 0 kB
Buffers: 123536 kB
Cached: 775540 kB
SwapTotal: 6291932 kB
SwapFree: 6291932 kB
To get a percentage of free memory:
$ cat /proc/meminfo | awk 'FNR== 2 {print $3/$2 *100}'