Score:3

( fuse-zip ) Using cp reported running out of virtual memory

im flag

Hello I am using this command

find ./"DCIM/Camera" -name "Camera" -print -exec cp -n -a -p -R -v "{}" "/home/username/path/to/destination/folder" \;

to copy files and folders from a zip file mounted as a folder using fuse-zip to another fuse-zip folder. There are 1,524 files in total inside the Camera/ folder. After some time, my PC gets hot, fan spins faster and I am given this error on the top of my screen

Virtual Terminal Stopped Device memory is nearly full. Virtual terminal processes were using a lot of memory and were forced to stop.

In terminal the error message received is

cp: error copying '...': Transport endpoint is not connected

The odd thing is, when I set the destination to home/username/Documents -- local folder, the entire copying process completed without errors or interruptions. I have 16 GB of RAM. What and why is there a problem when copying inside a fuse-zip folder?

uz flag
Jos
Your `find` command tries to spawn 1524 copy processes at once. Instead, use the `xargs` command to build one big `cp` process that handles copies sequentially.
Raffa avatar
jp flag
I don't think that the "1524 copy processes are spawned at once" ... What might be related is how the ZIP files are mounted e.g. using the `-d` or `-f` options of [`fuse-zip`](https://manpages.ubuntu.com/manpages/jammy/man1/fuse-zip.1.html) ... Please tell us how you mount both source and destination ZIP files ... Also, you don't need the `-print` action and removing it will save some memory ... Removing the `-v` option of `cp` will help in that as well.
ghostanime2001 avatar
im flag
I mount zip files on a empty folder like this in terminal fuse-zip "name of zip file.zip" "folder name to be mounted to"
Raffa avatar
jp flag
Also the `-R` option of `cp` might copy directories recursively and then afterwards the same files might get passed again to `cp` as results by `find` to be copied again ... what is that name in `-name "Camera"` is it a filename or you have subdirectories with that same name? ... You might need to reconsider your searching/copying methods.
ghostanime2001 avatar
im flag
if I leave out the -name "Camera" then somehow find copies the Camera folder in the destination folder but it also copies the subdirectories to the root folder as well. I dont know why. So instead, by defining the -name Camera then only once instance of the Camera folder and it's subdirectories, files are copied
ghostanime2001 avatar
im flag
tried to use find ./"DCIM/Camera" -exec cp -n -a -p "{}" "/home/username/Downloads/path/to/destination" \; without -v and without -print and without -R and the error I got is cp: error copying '...': Transport endpoint is not connected
ghostanime2001 avatar
im flag
How can I see how much ram is used when the find and cp command is taking place ??
Raffa avatar
jp flag
Why not use `cp -n -a -p -R ./DCIM/Camera /home/username/path/to/destination/folder` … You appear to want to copy the whole `Camera` directory and in which case, I don’t see why you want to use `find`
Raffa avatar
jp flag
You probably don’t need the `-p` option as it’s implied by `-a` and you can check memory usage with the `top` command
ghostanime2001 avatar
im flag
Because cp also doesn't work after some time, I get the same message that I ran out of virtual memory. Also doing the same process on a dedicated PC, the entire machine freezes and is unresponsive, so I am guessing the same problem is occuring there. I wanted to use find because it allows me to narrow down the searches, sometimes it could be that I want to copy just the .mp4 files or just .jpg files instead of the whole folder (even thought thats the goal).
cn flag
eh don't use `cp` when it is a large amount of files. use `rsync` , as it has a "continue" option.
ghostanime2001 avatar
im flag
does rsync copy the same way cp does?
Score:3
jp flag

Overlooking your searching/copying methods as they appear irrelevant to the error you get.

Okay! ... I had never tried this before ... But, guess what ... I couldn't resist and have tried it a few minutes ago, and here are the results.

$ # Make mount points
$ mkdir fuse_mount1 fuse_mount2
$ # Create 2000 files of 1M each
$ truncate -s 1M file{0000..1999}
$ # Zip each 1000 files in a different archive
$ zip archive1 file{0000..0999}
$ zip archive2 file{1000..1999}
$ # Mount both the archives
$ fuse-zip archive1.zip fuse_mount1/
$ fuse-zip archive2.zip fuse_mount2/
$ # Copy "fuse_mount1" under "fuse_mount2"
$ cp -n -a -r ./fuse_mount1 ./fuse_mount2
$ # Unmount the two fuse filesystems
$ fusermount -u fuse_mount1/
$ fusermount -u fuse_mount2/

Which needed around 1G memory of my test machine's RAM of 20G ... So, nothing out of the normal.

So, I changed the formula:

$ # remove previous files and archives
$ rm file* *.zip*
$ # Create 200 files of 100M each
$ truncate -s 100M file{000..199}
$ # Zip each 100 file in a different archive
$ zip archive1 file{000..099}
$ zip archive2 file{100..199}
$ # Mount both the archives
$ fuse-zip archive1.zip fuse_mount1/
$ fuse-zip archive2.zip fuse_mount2/
$ # Copy "fuse_mount1" under "fuse_mount2"
$ cp -n -a -r ./fuse_mount1 ./fuse_mount2
$ # Unmount the two fuse filesystems
$ fusermount -u fuse_mount1/
$ fusermount -u fuse_mount2/

Which needed around 10G memory of my test machine's RAM of 20G ... Which is not something an average consumer machine can handle.

Bottom line, fuse-zip can use/need huge amounts of memory in some situations and if your RAM memory is limited or even average then doing huge/massive file operation such as copying is not recommended and might not work due to it exhausting system memory.

I did use the debug option i.e. fuse-zip -d … mounting the archives from other terminals and noticed excessive logging on the target mount for cp that appeared to print a lot of memory addresses which indicated big memory usage on the target i.e. fuse_mount2 while that appeared to be much less on the source mount … I haven’t had time to deeply look into it, but you can do that and investigate more with debugging enabled … So, it appears copying from is less memory demanding than copying to a fuse-zip mount.

And this is actually stated on the fuse-zip project page:

Added/changed files resides into memory until you unmount file system.

Adding/unpacking very big files(more than one half of available memory) may cause your system swapping. It is a good idea to use zip/unzip in that case :)

And that explains the whole thing.

Therefor, for such operations, extract the archives, do whatever you want with them and then compress them again.

If, however, you must do it your way anyway ... Then, copy some files while monitoring your memory usage and when your memory gets near to full, stop copying and unmount the target fuse-zip mount wait for it to finish processing, then mount it again to copy another batch of files and so on ... However, I don't know of a tool that will let you do that automatically ... So, I wrote this bash function(fault proofing is minimal and it's meant to be a template):

fzcp ()
{
    [ -z "$1" ] || [ -z "$2" ] && echo "Insufficient arguments" >&2 && return 1
    source="${1%/}"
    target="${2%/}"

    read -r -p "What is the full pathe to the target fuse-zip mount point? : " mount_point
    read -r -p 'What is the full path(including filename) to the ZIP archive mounted on it? : ' zip_file
    [ -z "$mount_point" ] || [ -z "$zip_file" ] && echo "Insufficient arguments" >&2 && return 1

    total_m=$(free | awk '/Mem:/{print $2}')
    total_m_percent=$(("$total_m" / 100))

    shopt -s globstar

    for f in "$source"/**/*
      do
        [ -f "$f" ] || continue
        free_m=$(free | awk '/Mem:/{print $7}')
        free_m_percent=$(("$free_m" / "$total_m_percent"))
        if [ "$free_m_percent" -lt 20 ]
          then
            echo "Unmounting $mount_point ..."
            fusermount -u "$mount_point" || break
            while pkill -0 -f "${zip_file##*/}"
              do
                printf "%s\r" "$(date) :: Waiting for fuse-zip to finish adding copied files to $zip_file ..."
                sleep 1
                done
            echo
            echo "Mounting $zip_file on $mount_point ..."
            fuse-zip "$zip_file" "$mount_point" || break
            fi
        cp -n -v --preserve=all --parents -- "$f" "$target"
        done
        
    shopt -u globstar
}

That works like cp(However doesn't accept options) but for copying to target fuse-zip mount points ... It takes two arguments and used like so:

fzcp ./fuse_mount1/source_directory /home/user/fuse_mount2/target_directory

It will then ask you to provide the path to the target fuse-zip mount and the path to the ZIP file that is mounted at it … Then it will do the job … Test it first to get used to how it works before you rely on it for copying important data … The parent directories that will be created on the target depend on the source directory path that you provide so running the function from the very first/closest parent to your source directory and providing the path in as short as ./source_dorectory should give you only the tree of this directory and its sub-directories excluding real full system paths up to its root directory i.e. /.

ghostanime2001 avatar
im flag
but then how come when copying inside from fuse-zip folder to a local folder there was no problem with copying out ?
Raffa avatar
jp flag
@ghostanime2001 I did use the debug option i.e. `fuse-zip -d …` mounting the archives from other terminals and noticed excessive logging on the target mount for `cp` that appeared to print a lot of memory addresses which indicates big memory usage on the target i.e. `fuse_mount2` while that appeared to be much less on the source mount … I haven’t had time to deeply look into it, but you can do that and investigate more with debugging enabled … So, it appears copying from is less memory demanding than copying to a `fuse-zip` mount.
Raffa avatar
jp flag
@ghostanime2001 No need for further investigation … The `fuse-zip` project page cleared it all out … Please see my updated answer.
ghostanime2001 avatar
im flag
The size of the Camera folder itself that I needed to transfer is 19.4 GB and the total size of the DCIM folder is 23.3 GB. With my 16 GB of ram maybe that's why I was running out of memory. Should I upgrade to 32 GB ? As my system is quite old with DDR3 ram and it's not very expensive to max it out.
Raffa avatar
jp flag
@ghostanime2001 19.4 GB wouldn’t work even on my 20 GB system … The effect of RAM generation or speed is minimal … Size is the culprit … As for upgrading to 32 GB is up to you … If your system supports it, it certainly would help, but I wouldn’t advise that as just a solution to mounting big ZIP files as bigger ZIP files will happen later as they have no limit … 16 GB is not small though … I would however advise to unzip then zip large files instead as the `fuse-zip` project page clearly suggests as this is the ultimate solution.
ghostanime2001 avatar
im flag
is there another alternative to fuse-zip or another method besides extracting and recompressing ? How about still using fuse-zip but copying files 100 at a time isntead of all 1500 or so ? Or just copying files based on a size limit and then later adding the remaining sizes? Basically, if it ALL can't be copied, then how do I copy in chunks or blocks then unmount then remount and copy more..unmount ..so on...
Raffa avatar
jp flag
@ghostanime2001 I updated the answer for that ... Kindly, see it.
Raffa avatar
jp flag
@Rinzwind HAY HELLO … Long time, no see :D … The problem is `fuse-zip` keeps the copied files in memory until the ZIP archive is unmounted and only then it will process them into the ZIP archive compressing them on the way and that takes time and resources as well … If the process crashes or get killed by the system then all that is lost as if no files have ever been copied … Therefore, waiting for it to crash so the user can resume is not an option … I haven’t used `fuse-zip` before and I don’t know why people need to use it either when ZIP supports listing and updating archives. Do you?
cn flag
No not really sorry :D
Raffa avatar
jp flag
@Rinzwind That’s very comforting … Thanks! :-) … I thought I was alone thinking like that … Which seemed odd.
ghostanime2001 avatar
im flag
I have tried to use find with zip before multiple times and the problem with that is..that it fails to copy files with the zip -0 (store) only option because then it tells you zip I/O error: bad address -- this is when the source is a webdav server pro app from android and storing the zip on local folder. I made a post about this also Let me try that bash command to see what effect it has
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.