Cachefilesd: Difference between revisions
From Lolly's Wiki
Jump to navigationJump to search
No edit summary |
m (Text replacement - "</source" to "</syntaxhighlight") |
||
(7 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
[[category: Linux]] | [[category: Linux]] | ||
=Cachefilesd= | =Cachefilesd= | ||
==Create ramdisk for cache if enough ram== | |||
A dir named /cache is created and ramdisk ist mounted there! | |||
==Check if kernel supports | <syntaxhighlight lang=bash> | ||
< | # systemctl --force --full edit create-ramdisk@.service | ||
</syntaxhighlight> | |||
<syntaxhighlight lang=ini> | |||
[Unit] | |||
Description=create cache dir in ramdisk | |||
After=remote-fs.target | |||
Before=cachefilesd.service | |||
[Service] | |||
Type=oneshot | |||
RemainAfterExit=yes | |||
TimeoutSec=0 | |||
ExecStartPre=/sbin/modprobe brd rd_nr=1 rd_size=%i | |||
ExecStartPre=/sbin/sgdisk -Z --new 1:0:0 /dev/ram0 | |||
ExecStartPre=/sbin/mkfs.ext4 -m 0 /dev/ram0p1 | |||
ExecStartPre=-/bin/mkdir /cache | |||
ExecStart=/bin/mount -o user_xattr /dev/ram0p1 /cache | |||
ExecStop=/bin/umount /cache | |||
ExecStop=/sbin/rmmod brd | |||
[Install] | |||
WantedBy=multi-user.target | |||
</syntaxhighlight> | |||
Create for example a 2gb disk with: | |||
<syntaxhighlight lang=bash> | |||
# systemctl start create-ramdisk@$[ 2 * 1024 * 1024 ].service | |||
</syntaxhighlight> | |||
Destroy it again: | |||
<syntaxhighlight lang=bash> | |||
# systemctl stop create-ramdisk@$[ 2 * 1024 * 1024 ].service | |||
</syntaxhighlight> | |||
Make a 4gb one instead: | |||
<syntaxhighlight lang=bash> | |||
# systemctl start create-ramdisk@$[ 4 * 1024 * 1024 ].service | |||
</syntaxhighlight> | |||
If you found the right value, nail it for the next reboot with: | |||
<syntaxhighlight lang=bash> | |||
# systemctl enable create-ramdisk@$[ ${your_gigabyte_value} * 1024 * 1024 ].service | |||
</syntaxhighlight> | |||
==Check if kernel supports filesystem cache for your filesystem type== | |||
<syntaxhighlight lang=bash> | |||
# grep "CONFIG_.*_FSCACHE" /boot/config-`uname -r` | # grep "CONFIG_.*_FSCACHE" /boot/config-`uname -r` | ||
CONFIG_NFS_FSCACHE=y | CONFIG_NFS_FSCACHE=y | ||
Line 10: | Line 53: | ||
CONFIG_AFS_FSCACHE=y | CONFIG_AFS_FSCACHE=y | ||
CONFIG_9P_FSCACHE=y | CONFIG_9P_FSCACHE=y | ||
</ | </syntaxhighlight> | ||
== Setup /etc/cachefilesd.conf == | == Setup /etc/cachefilesd.conf == | ||
< | <syntaxhighlight> | ||
############################################################################### | ############################################################################### | ||
# | # | ||
Line 26: | Line 69: | ||
############################################################################### | ############################################################################### | ||
# | # obviously this should be a path to a ramdisk if you have enough ram | ||
dir /var/cache/fscache | dir /var/cache/fscache | ||
secctx cachefiles_kernel_t | secctx cachefiles_kernel_t | ||
Line 41: | Line 84: | ||
# this package | # this package | ||
# secctx system_u:system_r:cachefiles_kernel_t:s0 | # secctx system_u:system_r:cachefiles_kernel_t:s0 | ||
</ | </syntaxhighlight> | ||
== Problems with autofs mounted filesystems == | == Problems with autofs mounted filesystems == | ||
In case of using automount with caching the cachefilesd must be running <b>before</b> autofs comes up an might mount the filesystem. | |||
=== Make sure it is started by systemd === | === Make sure it is started by systemd === | ||
==== Disable the SYSV way of starting ==== | ==== Disable the SYSV way of starting ==== | ||
< | <syntaxhighlight lang=bash> | ||
# update-rc.d cachefilesd disable | # update-rc.d cachefilesd disable | ||
</ | </syntaxhighlight> | ||
==== Make cachefilesd started by systemd ==== | ==== Make cachefilesd started by systemd ==== | ||
< | <syntaxhighlight lang=bash> | ||
# systemctl edit --force --full cachefilesd.service | # systemctl edit --force --full cachefilesd.service | ||
</ | </syntaxhighlight> | ||
< | <syntaxhighlight lang=ini> | ||
[Unit] | [Unit] | ||
Documentation=man:cachefilesd | Documentation=man:cachefilesd | ||
Line 74: | Line 119: | ||
[Install] | [Install] | ||
WantedBy=multi-user.target | WantedBy=multi-user.target | ||
</ | </syntaxhighlight> | ||
==== Enable starting new service ==== | ==== Enable starting new service ==== | ||
< | <syntaxhighlight lang=bash> | ||
# systemctl enable cachefilesd.service | # systemctl enable cachefilesd.service | ||
</ | </syntaxhighlight> | ||
==== Verify autofs is depending on cachefilesd.service ==== | ==== Verify autofs is depending on cachefilesd.service ==== | ||
< | <syntaxhighlight lang=bash> | ||
# systemctl show -p After,Before autofs.service | grep cachefilesd.service | # systemctl show -p After,Before autofs.service | grep cachefilesd.service | ||
After=cachefilesd.service network.target network-online.target sysinit.target ypbind.service basic.target system.slice sssd.service systemd-journald.socket remote-fs.target | After=cachefilesd.service network.target network-online.target sysinit.target ypbind.service basic.target system.slice sssd.service systemd-journald.socket remote-fs.target | ||
</ | </syntaxhighlight> | ||
== Define a cached CIFS share with autofs == | == Define a cached CIFS share with autofs == | ||
=== Install needed packages === | === Install needed packages === | ||
< | <syntaxhighlight lang=bash> | ||
# apt install cachefilesd autofs cifs-utils | # apt install cachefilesd autofs cifs-utils | ||
</ | </syntaxhighlight> | ||
=== Create the credentials file === | === Create the credentials file === | ||
< | <syntaxhighlight lang=bash> | ||
# mkdir --mode=0700 /etc/cifs_cred | # mkdir --mode=0700 /etc/cifs_cred | ||
# touch /etc/cifs_cred/credentials | # touch /etc/cifs_cred/credentials | ||
Line 100: | Line 145: | ||
password=mypass | password=mypass | ||
EOF | EOF | ||
</ | </syntaxhighlight> | ||
=== Create basedir of your cifs mounts === | === Create basedir of your cifs mounts === | ||
< | <syntaxhighlight lang=bash> | ||
# mkdir --mode=0755 /data/cifs | # mkdir --mode=0755 /data/cifs | ||
</ | </syntaxhighlight> | ||
===/etc/auto.master=== | ===/etc/auto.master=== | ||
< | <syntaxhighlight> | ||
... | ... | ||
/data/cifs /etc/auto.cifs-shares --timeout=0 --ghost | /data/cifs /etc/auto.cifs-shares --timeout=0 --ghost | ||
... | ... | ||
</ | </syntaxhighlight> | ||
===/etc/auto.cifs-shares=== | ===/etc/auto.cifs-shares=== | ||
The option {{strong|fsc}} enables caching: | The option {{strong|fsc}} enables caching: | ||
< | <syntaxhighlight> | ||
myshare -fstype=cifs,credentials=/etc/cifs_cred/credentials,nounix,file_mode=0644,vers=3.0,dir_mode=0755,noperm,fsc ://cifsserver.my.dom/the_cifs_share | myshare -fstype=cifs,credentials=/etc/cifs_cred/credentials,nounix,file_mode=0644,vers=3.0,dir_mode=0755,noperm,fsc ://cifsserver.my.dom/the_cifs_share | ||
</ | </syntaxhighlight> | ||
== Check if things are getting cached == | == Check if things are getting cached == | ||
Initially there is nothing in the cache (almost all values are zero): | Initially there is nothing in the cache (almost all values are zero): | ||
< | <syntaxhighlight lang=bash> | ||
# cat /proc/fs/fscache/stats | # cat /proc/fs/fscache/stats | ||
FS-Cache statistics | FS-Cache statistics | ||
Line 149: | Line 194: | ||
CacheOp: rap=0 ras=0 alp=0 als=0 wrp=0 ucp=0 dsp=0 | CacheOp: rap=0 ras=0 alp=0 als=0 wrp=0 ucp=0 dsp=0 | ||
CacheEv: nsp=0 stl=0 rtr=0 cul=0 | CacheEv: nsp=0 stl=0 rtr=0 cul=0 | ||
</ | </syntaxhighlight> | ||
but after a few requests: | but after a few requests: | ||
< | <syntaxhighlight lang=bash> | ||
# cat /proc/fs/fscache/stats | # cat /proc/fs/fscache/stats | ||
FS-Cache statistics | FS-Cache statistics | ||
Line 177: | Line 222: | ||
CacheOp: rap=0 ras=0 alp=0 als=0 wrp=0 ucp=0 dsp=0 | CacheOp: rap=0 ras=0 alp=0 als=0 wrp=0 ucp=0 dsp=0 | ||
CacheEv: nsp=1 stl=0 rtr=0 cul=0 | CacheEv: nsp=1 stl=0 rtr=0 cul=0 | ||
</ | </syntaxhighlight> |
Latest revision as of 22:35, 25 November 2021
Cachefilesd
Create ramdisk for cache if enough ram
A dir named /cache is created and ramdisk ist mounted there!
# systemctl --force --full edit create-ramdisk@.service
[Unit]
Description=create cache dir in ramdisk
After=remote-fs.target
Before=cachefilesd.service
[Service]
Type=oneshot
RemainAfterExit=yes
TimeoutSec=0
ExecStartPre=/sbin/modprobe brd rd_nr=1 rd_size=%i
ExecStartPre=/sbin/sgdisk -Z --new 1:0:0 /dev/ram0
ExecStartPre=/sbin/mkfs.ext4 -m 0 /dev/ram0p1
ExecStartPre=-/bin/mkdir /cache
ExecStart=/bin/mount -o user_xattr /dev/ram0p1 /cache
ExecStop=/bin/umount /cache
ExecStop=/sbin/rmmod brd
[Install]
WantedBy=multi-user.target
Create for example a 2gb disk with:
# systemctl start create-ramdisk@$[ 2 * 1024 * 1024 ].service
Destroy it again:
# systemctl stop create-ramdisk@$[ 2 * 1024 * 1024 ].service
Make a 4gb one instead:
# systemctl start create-ramdisk@$[ 4 * 1024 * 1024 ].service
If you found the right value, nail it for the next reboot with:
# systemctl enable create-ramdisk@$[ ${your_gigabyte_value} * 1024 * 1024 ].service
Check if kernel supports filesystem cache for your filesystem type
# grep "CONFIG_.*_FSCACHE" /boot/config-`uname -r`
CONFIG_NFS_FSCACHE=y
CONFIG_CEPH_FSCACHE=y
CONFIG_CIFS_FSCACHE=y
CONFIG_AFS_FSCACHE=y
CONFIG_9P_FSCACHE=y
Setup /etc/cachefilesd.conf
###############################################################################
#
# Copyright (C) 2006,2010 Red Hat, Inc. All Rights Reserved.
# Written by David Howells (dhowells@redhat.com)
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version
# 2 of the License, or (at your option) any later version.
#
###############################################################################
# obviously this should be a path to a ramdisk if you have enough ram
dir /var/cache/fscache
secctx cachefiles_kernel_t
tag mycache
debug 1
brun 10%
bcull 7%
bstop 3%
frun 10%
fcull 7%
fstop 3%
# Assuming you're using SELinux with the default security policy included in
# this package
# secctx system_u:system_r:cachefiles_kernel_t:s0
Problems with autofs mounted filesystems
In case of using automount with caching the cachefilesd must be running before autofs comes up an might mount the filesystem.
Make sure it is started by systemd
Disable the SYSV way of starting
# update-rc.d cachefilesd disable
Make cachefilesd started by systemd
# systemctl edit --force --full cachefilesd.service
[Unit]
Documentation=man:cachefilesd
Description=LSB: CacheFiles daemon
After=remote-fs.target
Before=autofs.service
[Service]
Type=simple
Restart=no
TimeoutSec=5min
IgnoreSIGPIPE=no
KillMode=process
GuessMainPID=no
RemainAfterExit=yes
SuccessExitStatus=5 6
RuntimeDirectory=cachefilesd
ExecStartPre=-/sbin/modprobe -qab cachefiles
ExecStart=/sbin/cachefilesd -n -p /run/cachefilesd/cachefilesd.pid
[Install]
WantedBy=multi-user.target
Enable starting new service
# systemctl enable cachefilesd.service
Verify autofs is depending on cachefilesd.service
# systemctl show -p After,Before autofs.service | grep cachefilesd.service
After=cachefilesd.service network.target network-online.target sysinit.target ypbind.service basic.target system.slice sssd.service systemd-journald.socket remote-fs.target
Install needed packages
# apt install cachefilesd autofs cifs-utils
Create the credentials file
# mkdir --mode=0700 /etc/cifs_cred
# touch /etc/cifs_cred/credentials
# chmod 0600 /etc/cifs_cred/credentials
# cat > /etc/cifs_cred/credentials <<EOF
username=myuser
password=mypass
EOF
Create basedir of your cifs mounts
# mkdir --mode=0755 /data/cifs
/etc/auto.master
...
/data/cifs /etc/auto.cifs-shares --timeout=0 --ghost
...
The option Template:Strong enables caching:
myshare -fstype=cifs,credentials=/etc/cifs_cred/credentials,nounix,file_mode=0644,vers=3.0,dir_mode=0755,noperm,fsc ://cifsserver.my.dom/the_cifs_share
Check if things are getting cached
Initially there is nothing in the cache (almost all values are zero):
# cat /proc/fs/fscache/stats
FS-Cache statistics
Cookies: idx=2 dat=0 spc=0
Objects: alc=0 nal=0 avl=0 ded=0
ChkAux : non=0 ok=0 upd=0 obs=0
Pages : mrk=0 unc=0
Acquire: n=2 nul=0 noc=0 ok=2 nbf=0 oom=0
Lookups: n=0 neg=0 pos=0 crt=0 tmo=0
Invals : n=0 run=0
Updates: n=0 nul=0 run=0
Relinqs: n=0 nul=0 wcr=0 rtr=0
AttrChg: n=0 ok=0 nbf=0 oom=0 run=0
Allocs : n=0 ok=0 wt=0 nbf=0 int=0
Allocs : ops=0 owt=0 abt=0
Retrvls: n=0 ok=0 wt=0 nod=0 nbf=0 int=0 oom=0
Retrvls: ops=0 owt=0 abt=0
Stores : n=0 ok=0 agn=0 nbf=0 oom=0
Stores : ops=0 run=0 pgs=0 rxd=0 olm=0
VmScan : nos=0 gon=0 bsy=0 can=0 wt=0
Ops : pend=0 run=0 enq=0 can=0 rej=0
Ops : ini=0 dfr=0 rel=0 gc=0
CacheOp: alo=0 luo=0 luc=0 gro=0
CacheOp: inv=0 upo=0 dro=0 pto=0 atc=0 syn=0
CacheOp: rap=0 ras=0 alp=0 als=0 wrp=0 ucp=0 dsp=0
CacheEv: nsp=0 stl=0 rtr=0 cul=0
but after a few requests:
# cat /proc/fs/fscache/stats
FS-Cache statistics
Cookies: idx=3 dat=77 spc=0
Objects: alc=80 nal=0 avl=80 ded=70
ChkAux : non=0 ok=1 upd=0 obs=1
Pages : mrk=3138215 unc=181438
Acquire: n=150 nul=0 noc=0 ok=80 nbf=0 oom=0
Lookups: n=80 neg=78 pos=2 crt=78 tmo=0
Invals : n=0 run=0
Updates: n=0 nul=0 run=0
Relinqs: n=70 nul=0 wcr=0 rtr=70
AttrChg: n=0 ok=0 nbf=0 oom=0 run=0
Allocs : n=0 ok=0 wt=0 nbf=0 int=0
Allocs : ops=0 owt=0 abt=0
Retrvls: n=72447 ok=0 wt=6 nod=72447 nbf=0 int=0 oom=0
Retrvls: ops=72447 owt=15 abt=0
Stores : n=3136954 ok=3136954 agn=0 nbf=0 oom=0
Stores : ops=67042 run=3203996 pgs=3136954 rxd=3136954 olm=0
VmScan : nos=180177 gon=0 bsy=0 can=0 wt=0
Ops : pend=15 run=139489 enq=3203996 can=0 rej=0
Ops : ini=3209401 dfr=266 rel=3209401 gc=266
CacheOp: alo=0 luo=0 luc=0 gro=0
CacheOp: inv=0 upo=0 dro=0 pto=0 atc=0 syn=0
CacheOp: rap=0 ras=0 alp=0 als=0 wrp=0 ucp=0 dsp=0
CacheEv: nsp=1 stl=0 rtr=0 cul=0