Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to disable caching in CIFS (samba) on client side in linux

have developed an application to run on a target with 2.6.10 kernel. A shared folder on a windows machine is mounted via command:

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

As you can understand from the command option forcedirectio, I want to disable caching on the client side. But I can't.

The amount of free RAM on target is 40 MB. When I copy a file sized about 10MB, free RAM size decreases to 30 MB.

The kernel 2.6.10 uses cifs.1.28. I also set oplockEnabled as 0 (in both source code and /proc/fs/cifs/OplockEnabled). But it did not stop caching. How can I disable caching on cifs client for real?

like image 750
shaneess Avatar asked Feb 17 '13 11:02

shaneess


1 Answers

Perhaps too late, but in Arch I accomplish this with the following:

/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

Here's a handy function to determine valid module options.

# 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
}

See man 5 modprobe.d for more information on modprobe.d syntax.

Additionally, CIFS mounts respect a cache option. According to the mount.cifs manual, setting cache=none should disable caching, while the default is cache=strict.

like image 199
ymek Avatar answered Nov 15 '22 11:11

ymek