Bug 281270 - When copying files to a removable disk, speed and progress reflect copying to the local cache not to the disk itself
Summary: When copying files to a removable disk, speed and progress reflect copying to...
Status: ASSIGNED
Alias: None
Product: frameworks-kio
Classification: Frameworks and Libraries
Component: general (show other bugs)
Version: unspecified
Platform: Arch Linux Linux
: VHI critical
Target Milestone: ---
Assignee: KIO Bugs
URL:
Keywords:
: 326744 335851 361224 383995 416248 416783 442536 443126 457959 497286 500917 (view as bug list)
Depends on:
Blocks:
 
Reported: 2011-09-03 14:01 UTC by Alexander
Modified: 2025-03-03 12:20 UTC (History)
58 users (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments
video example (752.94 KB, video/mp4)
2022-03-15 07:34 UTC, MarcSerra
Details
It fails to recognize that the transfer is completed. (3.86 MB, video/x-matroska)
2025-01-09 20:14 UTC, Fernando M. Muniz
Details
Reaching 100% completion doesn't mean it's 100% completed. (125.35 KB, image/png)
2025-01-09 20:15 UTC, Fernando M. Muniz
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Alexander 2011-09-03 14:01:13 UTC
Version:           4.7 (using KDE 4.7.0) 
OS:                Linux

All going fine when I copy files from my USB device and the problem occurs only when I copy files TO it. The KDE's notification shows that copying speed is about 50Mb/s (yes, namely megabytes), so it is about 400 megabits per second and it is too fast for a full-speed USB device (12MB/s is maximum for USB 1.1).

Alan Stern, one of the kernel developers, described to me what actually happens. The problem is in that actually it show the speed with which files are copied into the RAM (it could be even faster if the HDD allow it), therefore it shows that the copying operation is finished when it has not even been started. Also when target files are too small the "operation progress" popup will not appears at all.

Reproducible: Always

Steps to Reproduce:
Plug in any USB device and try to send any files to it.

Actual Results:  
The operation progress show the progress but for the wrong operation. It also doesn't give me a possibility to pause/cancel the operation.

Expected Results:  
The operation progress notification should display actual data transfer progress and should also allow to user to pause/stop the operation.

https://bugzilla.kernel.org/show_bug.cgi?id=41472#c7
> Yes, the information displayed in the progress window is off. This really
> isn't a kernel problem so much as a problem in KDE.
Comment 1 Christoph Feck 2011-09-05 01:46:17 UTC
> therefore it shows that the copying operation is finished when it has not even been started

Do kernel developers also know a POSIX interface way to tell us when and how fast this buffered data is actually written to the disk, without causing massive slow downs that any "sync" type calls would cause?
Comment 2 Alexander 2011-09-06 09:45:04 UTC
This is sad, but seems that they do not know how to do it without sync :-( But if you agree that the progress information is wrong and there is no way to implement it correctly, we probably should send a feature request/bug report to kernel devs? How you think, should we? Actually, this is weird to have such problems after 20 years of development :)
Comment 3 Alexander 2011-09-19 15:57:54 UTC
Hello.
Sorry, forgot to post this earlier. I got next mail from Alan:
"Bugzilla is currently down, so I have to send this reply by regular 
email.

On Mon, 5 Sep 2011 bugzilla-daemon@bugzilla.kernel.org wrote:
>...

I did some asking around, and people said to look at the
sync_file_range(2) system call (see also fsync and fdatasync).  It's
not a POSIX interface but it should solve the KDE problem.

Alan Stern"

Could it be useful?
Comment 4 Christoph Feck 2011-09-24 11:55:58 UTC
I haven't checked if it degrades performance, but looking from the description, it looks like it would be exactly what we need. Thanks for the pointer!
Comment 5 Alexander 2011-12-03 23:20:36 UTC
Sorry for noise, but is there any progress with this? I working with the different usb drives all the time and this issue makes me crazy. I trying to detect the operation progress using htop, orienting by I/O indication...
Comment 6 Alassane 2013-10-17 00:49:01 UTC
I have this issue with the latest stable release. When I transfer fairly large files, the plasma notification report that 100% have been transferred well before the actual transfer is complete.

KDE 4.11.2 with OpenSuse packages.
Comment 7 Rune Jensen 2013-10-27 13:10:09 UTC
*** This bug has been confirmed by popular vote. ***
Comment 8 Christoph Feck 2014-06-06 00:29:06 UTC
*** Bug 335851 has been marked as a duplicate of this bug. ***
Comment 9 Christoph Feck 2016-04-05 01:31:09 UTC
*** Bug 361224 has been marked as a duplicate of this bug. ***
Comment 10 dexy 2016-04-05 02:57:08 UTC
On 05/04/16 13:31, Christoph Feck via KDE Bugzilla wrote:
> https://bugs.kde.org/show_bug.cgi?id=281270
>
> Christoph Feck <cfeck@kde.org> changed:
>
>             What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                   CC|                            |dexy@xtra.co.nz
>
> --- Comment #9 from Christoph Feck <cfeck@kde.org> ---
> *** Bug 361224 has been marked as a duplicate of this bug. ***
>
HI Christoph

    From this I take it the KIO team has assumed the task, and it's 
still in progress?

    The companion email has it marked as resolved in the Dolpin stream.

Cheers
Dex (Fester :) )
Comment 11 Christoph Feck 2016-04-06 22:26:10 UTC
> still in progress?

No, work has not started yet (if it is, the bug gets status ASSIGNED).
Comment 12 Christoph Feck 2017-09-17 17:04:38 UTC
*** Bug 383995 has been marked as a duplicate of this bug. ***
Comment 13 Nate Graham 2018-05-08 17:31:55 UTC
Is this still applicable with KDE Frameworks 5.45?
Comment 14 CnZhx 2018-05-08 19:13:45 UTC
I am using openSUSE Tumbleweed with KDE Frameworks 5.25.0 now. This problem seems still there.

I just copied a 800MB file to a Kingston USB drive that has usually 10+MB/s write-in capacity. The copying progress is showing for about several seconds at a speed of around 100MB/s. After this, the Notifier said the copy finished. But when I tried to reject the USB drive, it took about 2 minutes for removing. Then, the Notifier said the device can be removed then.
Comment 15 CnZhx 2018-05-08 19:14:24 UTC
Sorry, it is 5.45.0 instead of 5.25.0.
Comment 16 Nate Graham 2018-05-08 19:22:02 UTC
Thanks for confirming!
Comment 17 dexy 2018-05-08 19:43:59 UTC
Hi Nate.

Firstly, how deep is your 'to-do' queue? I asked this years ago, several 
OS upgrades ago.
Secondly, how can I tell which KDE Frameworks? I'm a user not a 
programmer. I'm running a fully-upgraded Kubuntu 18.04 amd64 now, and 
it's still this way - has been since seemingly year dot, certainly 
14.04,last LTS.
Thirdly, I'm also running a Raspberry Pi, and that's got the same 
'gotcha'. Is this a Deeeep-OS 'feature' of Debian? or Linux itself? Not 
closing off a file on completion of a transfer?  I transfer to a USB 
stick or external disk and after 'completion' go have a cuppa before the 
LED stops flashing.

Cheers
Dex

On 09/05/18 05:31, Nate Graham wrote:
> https://bugs.kde.org/show_bug.cgi?id=281270
>
> Nate Graham <nate@kde.org> changed:
>
>             What    |Removed                     |Added
> ----------------------------------------------------------------------------
>               Status|CONFIRMED                   |NEEDSINFO
>           Resolution|---                         |WAITINGFORINFO
>                   CC|                            |nate@kde.org
>
> --- Comment #13 from Nate Graham <nate@kde.org> ---
> Is this still applicable with KDE Frameworks 5.45?
>
Comment 18 dexy 2018-06-18 09:18:27 UTC
On 09/05/18 07:22, Nate Graham wrote:
> https://bugs.kde.org/show_bug.cgi?id=281270
>
> Nate Graham <nate@kde.org> changed:
>
>             What    |Removed                     |Added
> ----------------------------------------------------------------------------
>              Product|kio                         |frameworks-kio
>                   CC|                            |kdelibs-bugs@kde.org
>           Resolution|WAITINGFORINFO              |---
>            Component|general                     |general
>               Status|NEEDSINFO                   |CONFIRMED
>              Summary|Show progress actually      |When copying files to a
>                     |transferred to disk instead |removable disk, speed and
>                     |of to caches                |progress reflect copying to
>                     |                            |the local cache not to the
>                     |                            |disk itself
>
> --- Comment #16 from Nate Graham <nate@kde.org> ---
> Thanks for confirming!
>
FYI: this occurs on ALL transfers - USB, Network , and same-machine 
either inter-disk or inter-directory!
My attempt at a semi-graphical user's view:
Present system:

Source  Buffer Medium  Destination
|   ---|-->   |-------|        |
  ^        v
Command Report/Display

1.Command is given to transfer x(GB?) to Destination.
2. Source looks and sees Buffer- 100'of MB?. Fills Buffer.
3. Buffer reports quantity Q filled, system displays Q/x transferred.
WRONG! data hasn't even got as far as the Medium.
4. Medium meanwhile reports "I accept quantity q at a time for transport".
5. Buffer delivers q to Medium, it's sent and Medium reports Q-q to 
system, "I need filling".
6. Source delivers q to refill Buffer, return to step 3 until Q = 0.

Better system?

Source  Buffer Medium  Destination
|   ---|-->   |-------|->        |
  ^           v<- - - - -(checksum)
Command <- calc/check
              v
            Report/Display

1.Command is given to transfer x(GB?) to Destination.
2. Source looks through chain to destination and sees Medium (or 
sequence of).
3. System creates Buffer q, enough to fill smallest (or first?) buffer 
in Medium chain.
4. System fills Buffer.
5. Buffer delivers q to Medium, it's sent and Medium reports "I need 
filling".
6. Using checksum 'back-channel', verify arrival intact.  If incorrect 
checksum, error code sent to Buffer,Medium,Destination and transfer 
abandoned, else add q to 'delivered' sum D.
7. System displays D/x transferred
8. If D<x, return to step 4 ...

Realistic? Helpful?
Cheers, Dex
Comment 19 Christoph Feck 2018-11-20 10:57:50 UTC
*** Bug 326744 has been marked as a duplicate of this bug. ***
Comment 20 Christoph Feck 2020-01-14 18:15:43 UTC
*** Bug 416248 has been marked as a duplicate of this bug. ***
Comment 21 Nate Graham 2020-11-25 01:08:56 UTC
*** Bug 416783 has been marked as a duplicate of this bug. ***
Comment 22 Riyadul Islam Mollick 2021-06-15 12:25:00 UTC
I am still getting this bug on plasma 5.22, OS: KDE Neon
Comment 23 dave 2021-07-13 16:21:00 UTC
Still experiencing this issue in Kubuntu 21.04 and Manjaro 21.0.7 and I believe it affects any file transfer from one medium to another; I can replicate the issue with SATA to SATA, SATA to USB and SATA to WEBDAV.

As far as I can tell, this is not an issue within other DEs I have used (mainly XFCE and Cinnamon).

This is the difference between a complete, beautiful, fun-to-use D.E. and a broken system.  It is a deal-breaker, for me.

I don't feel like it is my place to criticise people doing things that are beyond my ken, and if it was a simple fix, it would have been done by now.

Additionally, I suspect it causes large webdav file transfers to fail under KDE.  My experience is, transferring files larger than 2GB by webdav fails in KDE but never demonstrates an issue in other DEs.
Comment 24 Nate Graham 2021-09-16 18:20:32 UTC
*** Bug 442536 has been marked as a duplicate of this bug. ***
Comment 25 Nate Graham 2021-09-16 18:21:11 UTC
Marking critical as this can result in data loss if the user does a move operation rather than a copy operation.
Comment 26 Nate Graham 2021-09-30 15:28:46 UTC
*** Bug 443126 has been marked as a duplicate of this bug. ***
Comment 27 sg7e0f7m 2021-09-30 16:47:38 UTC
Does anyone have any suggestions on how to fix this issue that has been around for nearly 10 years now?
Comment 28 sg7e0f7m 2021-10-02 06:43:16 UTC
Disabling write cache for a USB stick did show the real write rate, but it caused a 75% increase in overall transfer time.

Would KDE be able to read the write rate to the USB stick instead of the write rate to the cache?
Comment 29 romuluspb 2021-12-06 20:23:03 UTC
(In reply to francois072 from comment #27)
> Does anyone have any suggestions on how to fix this issue that has been
> around for nearly 10 years now?

I have a C demonstration on how to fix this:

https://github.com/RomuloPBenedetti/SaneFileTransfer

Basically it consists on creating a dynamic buffer in userspace that monitors fdatasync and through this, calculate ideal user space buffer size, so we don't send the entire file to the system cache.
Comment 30 romuluspb 2021-12-06 20:36:55 UTC
(In reply to Christoph Feck from comment #1)
> > therefore it shows that the copying operation is finished when it has not even been started
> 
> Do kernel developers also know a POSIX interface way to tell us when and how
> fast this buffered data is actually written to the disk, without causing
> massive slow downs that any "sync" type calls would cause?

About sync slowdowns, not sure about back there in 2011 but I believe calling fdatasync on the destiny file descriptor will not perturb system performance.
Comment 31 Gilberto Caetano de Andrade 2021-12-29 17:16:27 UTC
I confirm this issue. Copying an ISO file to usb stick takes some minutes but clicking remove with security takes longer than normal. It disappears in Dolphin but in notifications continues with msg: removing device....

OpenSUSE 15.3
Dolphin 20.04.2
Comment 32 Nate Graham 2022-01-18 16:27:00 UTC
The message displayed in the Disks & Devices applet was just improved to handle this case: https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/1367
Comment 33 Gilberto Caetano de Andrade 2022-01-19 16:31:24 UTC
(In reply to Nate Graham from comment #32)
> The message displayed in the Disks & Devices applet was just improved to
> handle this case:
> https://invent.kde.org/plasma/plasma-workspace/-/merge_requests/1367

I don't see problem with the actual msg, but thus with the operation that never finishes and invariably corrupts usb content.
Comment 34 Nate Graham 2022-01-19 16:32:30 UTC
It should finish *eventually*, even if it takes a long time.

If it doesn't, that's a separate bug.
Comment 35 MarcSerra 2022-03-15 07:34:41 UTC
Created attachment 147502 [details]
video example

As you can see at the attached video (don't pay attention to the second 11 glitch, I moved a window by mistake while recording the video), after the progress bar has arribed to the end, we must wait for a minute (or more) before can unplug the USB disk.
Comment 36 MarcSerra 2022-03-15 07:35:28 UTC
This happens to me in KDE neon when show to my wife how to move a cartoon film for our son to an USB drive.

If don't pay attention to this notification, you cannot unplug the disk safely.

Maybe can be included into 15-minute bug initiative?
Comment 37 Nate Graham 2022-03-15 15:03:28 UTC
Once we broaden it to include Frameworks bugs, definitely. Right now we're only doing bugs in Plasma-aligned software.

None of that prevents anyone from fixing it anyway, of course. :)
Comment 38 Nate Graham 2022-08-17 19:41:30 UTC
*** Bug 457959 has been marked as a duplicate of this bug. ***
Comment 39 Christoph Feck 2023-10-27 13:29:23 UTC
The Linux kernel recently got a new "cachestat" syscall. It might help to find out if pages have been written to disk.
Comment 40 Méven Car 2023-10-28 19:19:26 UTC
(In reply to Christoph Feck from comment #39)
> The Linux kernel recently got a new "cachestat" syscall. It might help to
> find out if pages have been written to disk.

https://www.phoronix.com/news/Linux-6.5-MM-cachestat

Next glibc will expose it:
https://sourceware.org/git/?p=glibc.git;a=commit;h=72511f539cc34681ec61c6a0dc2fe6d684760ffe
Comment 41 daf 2024-07-14 20:09:49 UTC
Does glibc 3.39 already have cachestat or is it pending for glibc 3.40?
Comment 42 Christoph Feck 2024-07-25 17:40:15 UTC
__NR_cachestat is exposed with glib 2.39. I quickly wrote a test, and the syscall works (nr_dirty shrinks gradually while the data is being written). I only tested with rotating rust, not slow USB, though.

Some issues:

* The call is per file, not per fs.

* You have to keep all files open and repeatedly call it for them as long as nr_dirty != 0. An idea could be to try the largest files first, and hope that the smaller files have "long" been written out.

* Unsure if nr_dirty is set to 0 when the mm requested the last page to be written out, or if it waits for the device driver to indicate that the device has _actually_ finished writing the data.

* The fs needs to update metadata, so even if the last file has nr_dirty == 0, you wouldn't know how long the fs needs to write it.

So the "unmount spinning indicator" MUST STILL BE RESPECTED to avoid data loss, even if this syscall was used to monitor writeback progress.
Comment 43 tagwerk19 2024-08-28 05:36:12 UTC
(In reply to Christoph Feck from comment #42)
> ... __NR_cachestat is exposed with glib 2.39. I quickly wrote a test ...
How do you call this? Do you have a code snippet you can share?

And, sorry naive question, what would happen with systems that do not support it?
Comment 44 Méven Car 2024-09-09 11:50:12 UTC
io_uring can do partial fsync, https://man7.org/linux/man-pages/man3/io_uring_prep_fsync.3.html
Potentially as the input file is read, that is it should have a negligeable impact on perf.
io_uring should be more performant than the current copy_file_range implementation.
Comment 45 Bug Janitor Service 2024-09-15 19:01:45 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kio/-/merge_requests/1718
Comment 46 Bug Janitor Service 2024-11-24 12:00:08 UTC
A possibly relevant merge request was started @ https://invent.kde.org/frameworks/kio/-/merge_requests/1764
Comment 47 Bug Janitor Service 2024-11-24 13:51:39 UTC
A possibly relevant merge request was started @ https://invent.kde.org/system/dolphin/-/merge_requests/862
Comment 48 Akseli Lahtinen 2025-01-09 19:35:13 UTC
*** Bug 497286 has been marked as a duplicate of this bug. ***
Comment 49 Fernando M. Muniz 2025-01-09 20:14:29 UTC
Created attachment 177238 [details]
It fails to recognize that the transfer is completed.

File transfer box is stuck at 99% with no transfer speed when moving massive files to an Android phone.

This must be a bug on Dolphin's end because I always manage to fully extract the supposedly 1% unfinished .tar.gz file after I copy the same file from the phone back into my notebook. Curiously enough, the file transfer always concludes when transferring back.

Which means that Dolphin doesn't recognize the fact that the transferring has completed, even though its transfer speed has stopped and disappeared from the box.
Comment 50 Fernando M. Muniz 2025-01-09 20:15:59 UTC
Created attachment 177239 [details]
Reaching 100% completion doesn't mean it's 100% completed.
Comment 51 Bruno Gonçalves 2025-01-15 14:31:08 UTC
Reducing the cache usage for saving files to USB devices has been solving this problem for the past 2 years.

Here is how we are using it, but basically it is a noudev rule that calls a simple script, where $1 is the USB device to limit the RAM cache size while copying files, we are using a 16 MB limit, which is enough so that the recording does not become too slow and at the same time when completing a recording, almost immediately the device can be ejected.

echo 1 > /sys/block/$1/bdi/strict_limit
echo 16777216 > /sys/block/$1/bdi/max_bytes

https://github.com/biglinux/usb-dirty-pages-udev
Comment 52 Akseli Lahtinen 2025-03-03 12:20:36 UTC
*** Bug 500917 has been marked as a duplicate of this bug. ***