9

There's an issue with Ubuntu that hasn't been fixed yet, where the PC freezes or gets really slow whenever it is copying to an USB stick (see Why is my PC freezing while I'm copying a file to a pendrive?, http://lwn.net/Articles/572911/ and https://askubuntu.com/q/508108/234374).

A workaround is to execute the following commands as root (see here for an explanation) as root:

echo $((16*1024*1024)) > /proc/sys/vm/dirty_background_bytes
echo $((48*1024*1024)) > /proc/sys/vm/dirty_bytes

How do I revert these changes? When I restart my PC, will it get rolled back to default values?

a06e
  • 1,727
  • You need to write an init file. I would rewrite you question to ask about persisting changes to /proc, and not mention usb-sticks in the title. But keep the detail as an appendix to the question. – ctrl-alt-delor Aug 07 '14 at 16:07

2 Answers2

7

These are sysctl parameters. You can set them either by writing to /proc/sys/CATEGORY/ENTRY or by calling the sysctl command with the argument CATEGORY.ENTRY=VALUE. These settings affect the running kernel, they are not persistent.

If you want to make these settings persistent, you need to set them at boot time. On Ubuntu, create a file in the directory /etc/sysctl.d called becko-vm-dirty.conf containing

# Shrink the disk buffers to a more reasonable size. See http://lwn.net/Articles/572911/
vm.dirty_background_bytes = 16777216
vm.dirty_bytes = 50331648

To revert the changes, write the old value back. There is no “restore defaults” command.

Note that these parameters are a bit peculiar: there are also parameters called vm.dirty_ratio and vm.dirty_background_ratio, which control the same setting but express the size as a percentage of total memory instead of a number of bytes. For each of the two settings, whichever of ratio or bytes was set last takes precedence.

Zoltan
  • 476
  • 1
    A thousand times thank you for revealing to me where this can be set at boot time. But this is quite "global", if you will - are there ways of being more specific (setting these variables at boot time for I/O directed towards removable media only, because I might be otherwise happy with the Linux kernel's I/O policy towards internal HDDs/SSDs)? – Iwillnotexist Idonotexist Dec 10 '14 at 05:55
  • 3
    @IwillnotexistIdonotexist AFAIK this setting is global because the kernel doesn't maintain separate totals for dirty buffers on different block devices, but I'm not an I/O tuning expert. – Gilles 'SO- stop being evil' Dec 10 '14 at 09:53
1

There is no way to reset these values to their default of 0. As of kernel 4.4, doing so fails with EINVAL.

kynan
  • 225