caching - 如何在 Linux 客户端禁用 CIFS (samba) 缓存

标签 caching embedded-linux samba cifs

已经开发了一个在具有 2.6.10 内核的目标上运行的应用程序。 Windows机器上的共享文件夹通过命令挂载:

mount -t cifs -o username=xxx,password=xxx,forcedirectio //192.168.170.67/57 /fsRecord

正如您从命令选项forcedirectio中可以理解的那样,我想禁用客户端的缓存。但我不能。

目标上的可用 RAM 量为 40 MB。当我复制大小约为 10MB 的文件时,可用 RAM 大小会减少到 30 MB。

内核 2.6.10 使用 cifs.1.28。我还将 oplockEnabled 设置为 0(在源代码和/proc/fs/cifs/OplockEnabled 中)。但它并没有停止缓存。如何真正禁用 cifs 客户端上的缓存?

最佳答案

也许为时已晚,但在 Arch 中我通过以下方式实现了这一点:

/etc/modprobe.d/cifs.conf
-------------------------
# Disable caching and the CIFS oplog for stable NTFS network shares
options cifs enable_oplocks=0

install cifs /sbin/modprobe --ignore-install cifs $CMDLINE_OPTS && echo 0 > /proc/fs/cifs/LinuxExtensionsEnabled && echo 0 > /proc/fs/cifs/LookupCacheEnabled
remove cifs /sbin/modprobe -r cifs

这里有一个方便的函数来确定有效的模块选项。

# Shamelessly ripped the Kernel_Modules ArchWiki entry:
# https://wiki.archlinux.org/index.php?title=Kernel_modules&oldid=286087#Bash_function_to_list_module_parameters 

function aa_mod_parameters ()
{
    N=/dev/null;
    C=`tput op` O=$(echo -en "\n`tput setaf 2`>>> `tput op`");
    for mod in $(cat /proc/modules|cut -d" " -f1);
    do
        md=/sys/module/$mod/parameters;
        [[ ! -d $md ]] && continue;
        m=$mod;
        d=`modinfo -d $m 2>$N | tr "\n" "\t"`;
        echo -en "$O$m$C";
        [[ ${#d} -gt 0 ]] && echo -n " - $d";
        echo;
        for mc in $(cd $md; echo *);
        do
            de=`modinfo -p $mod 2>$N | grep ^$mc 2>$N|sed "s/^$mc=//" 2>$N`;
            echo -en "\t$mc=`cat $md/$mc 2>$N`";
            [[ ${#de} -gt 1 ]] && echo -en " - $de";
            echo;
        done;
    done
}

有关 modprobe.d 语法的更多信息,请参阅 man 5 modprobe.d

此外,CIFS 挂载遵循缓存选项。根据the mount.cifs manual ,设置 cache=none 应该禁用缓存,而默认值为 cache=strict

关于caching - 如何在 Linux 客户端禁用 CIFS (samba) 缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14920591/

相关文章:

profiling - LTTng 与 OProfile

windows - 在 go 中提供 samba 文件的矛盾性能

NFS 安装上的 Java I/O

c++ - 在没有 root 权限的情况下在 C++ 中打开共享文件

php - CakePHP 缓存国际化翻译

asp.net-core - 内存缓存的 IDistributedCache 实现在哪里?

caching - RISC-V Rocket 缓存一致性

embedded - u-boot - 选择正确的 linux 镜像

linux - ARM Linux ":start_kernel is not calling after decompressing uImage"

browser - 如何验证 javascript 和图像是否已被缓存?