NetworkManager periodically writes to the disk causing wakeups

Bug #913856 reported by Colin Ian King
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
network-manager (Ubuntu)
Fix Released
Low
Mathieu Trudel-Lapierre

Bug Description

Network Manager is periocially creating dirty pages that are being written back to disk and causing uncessary drive wakeups.

Using SystemTap I was able to observe the following dirty pages being created on the following files

       0 795 1 NetworkManager sda1 D Mon Dec 19 13:54:50 2011 timestamps
       0 795 1 NetworkManager sda1 D Mon Dec 19 13:54:50 2011 timestamps.096F6V
       0 795 1 NetworkManager sda1 D Mon Dec 19 13:54:50 2011
       0 795 1 NetworkManager sda1 D Mon Dec 19 13:54:50 2011 timestamps.5RWD6V

..and this occurs regulary every 5 minutes.

Can we either reduce the frequency of these writes or better still only write the updates when really necessary (e.g. when we close NetworkManager or the user interacts with NetworkManager which requires us to really write data back to disk).

Revision history for this message
Colin Ian King (colin-king) wrote :

strace shows:

open("/var/lib/NetworkManager/timestamps", O_RDONLY) = 20
fstat(20, {st_mode=S_IFREG|0644, st_size=1646, ...}) = 0
read(20, "\n[timestamps]\n3c32aa58-a2ed-44e7"..., 4096) = 1646
read(20, "", 4096) = 0
close(20) = 0
open("/var/lib/NetworkManager/timestamps.EB5H7V", O_RDWR|O_CREAT|O_EXCL, 0666) = 20
fcntl(20, F_GETFL) = 0x8002 (flags O_RDWR|O_LARGEFILE)
fstat(20, {st_mode=S_IFREG|0644, st_size=0, ...}) = 0
mmap(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7f04b964c000
lseek(20, 0, SEEK_CUR) = 0
write(20, "\n[timestamps]\n3c32aa58-a2ed-44e7"..., 1646) = 1646
fstatfs(20, {f_type="EXT2_SUPER_MAGIC", f_bsize=4096, f_blocks=7874279, f_bfree=5238919, f_bavail=4838919, f_files=2003120, f_ffree=1658729, f_fsid={-1107732364, 115902444}, f_namelen=255, f_frsize=4096}) = 0
lstat("/var/lib/NetworkManager/timestamps", {st_mode=S_IFREG|0644, st_size=1646, ...}) = 0
fsync(20) = 0
close(20) = 0

Revision history for this message
Colin Ian King (colin-king) wrote :

The culprit is periodic_update_active_connection_timestamps() which is being called every 300 seconds because of:

        /* Update timestamps in active connections */
        priv->timestamp_update_id = g_timeout_add_seconds (300, (GSourceFunc) periodic_update_active_connection_timestamps, manager);

in nm_manager_init(). Note from the strace output that this does a fsync() before the close() which is a little bit brutal. Is this data so critical that we need to force a fsync?

tags: added: battery-power-consumption
Revision history for this message
Tony Espy (awe) wrote :

On my system, I only see the singe "timestamps" file in /var/lib/NetworkManager. Do you have any active systems connections or VPNs active at the same time? That would explain the multiple timestamps files?

From a cursory glance, these timestamps record an active connection's last-used time so that if a disconnect occurs, NetworkManager will automatically re-connect to the right network.

Re: the fsync, my guess is removing it at worse case would cause NetworkManager to hiccup and try to connect to the wrong network if the last-used timestamp didn't actually hit the disk and the system was put to sleep/rebooted...

Revision history for this message
Colin Ian King (colin-king) wrote :

So, I only see a single timestamps file too, the timestamps.096F6V filename is probably a short lived temp filename. As for the configuration, it was a clean install and connected via wireless (and possibly ethernet).

Revision history for this message
Mathieu Trudel-Lapierre (cyphermox) wrote :

This is simple enough, I think we can drop the periodic updates fairly safely, since the timestamps still get updated when connections go down, etc. The main goal is that the latest connection should have the highest timestamp, but I think we already achieve that.

Martin Pitt (pitti)
Changed in network-manager (Ubuntu):
assignee: nobody → Mathieu Trudel-Lapierre (mathieu-tl)
importance: Undecided → Low
status: New → Triaged
Changed in network-manager (Ubuntu):
status: Triaged → In Progress
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package network-manager - 0.9.2.0+git201112151936.6b31828-0ubuntu3

---------------
network-manager (0.9.2.0+git201112151936.6b31828-0ubuntu3) precise; urgency=low

  * debian/patches/avoid-periodic-disk-wakeups.patch: avoid waking up disks to
    write a timestamp every 5 minutes; we already update the timestamp when
    connections are established, and it's enough to get a decent snapshot of
    connection activations. For VPN, also update on disconnect. (LP: #913856)
 -- Mathieu Trudel-Lapierre <email address hidden> Tue, 10 Jan 2012 14:14:45 +0100

Changed in network-manager (Ubuntu):
status: In Progress → Fix Released
Revision history for this message
hankwang (hknienhuys) wrote :

I encountered the same problem, but used a different solution: make /var/lib/NetworkManager a symlink to /var/run/NetworkManager (and create the corresponding directory).

/var/run is a tmpfs filesystem, so it won't generate hard disk wake-ups.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.