Thank you @linux-aarhus & @Aragorn, I have followed some of the indications discussed in The pernicious USB-stick stall problem.
I have used the script of cscs - maxperfwiz (Gitlab) to set the following values:
vm.swappiness=10
vm.vfs_cache_pressure=75
vm.dirty_expire_centisecs=3000
vm.dirty_writeback_centisecs=1500
vm.min_free_kbytes=117395
However, the values suggested for vm.dirty_background_ratio
and vm.dirty_ratio
by the script do not work, so I have set instead:
vm.dirty_background_bytes=16777216
vm.dirty_bytes=33554432
following the discussion Decrease dirty bytes for more reliable USB transfer.
Now USB transfer seems to work fine in my computer after testing some examples, since the transfer speed is more and less stable and it does not decay at the end abruptly.