/etc/cron.daily/apt is holding memory while "sleep"

Bug #1178943 reported by Jérôme on 2013-05-11
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
APT
Fix Released
Unknown
apt (Ubuntu)
Undecided
Unassigned

Bug Description

The "random_sleep" function is calling "sleep". Thus the memory used by anacron, the /etc/cron.daily/apt script is frozen for minutes when the "random_sleep" blocks until the "sleep" program completes.

Maybe an implementation of a delayed system call back would save memory. For example the script could register a call-back with "at" utility instead of using sleep.

I think this problem is important, especially during a few minutes after the system startup. The desktop has to be responsive while many desktop tasks are temporarily using more memory for initialization during the first hour.

ProblemType: Bug
DistroRelease: Ubuntu 12.04
Package: apt 0.8.16~exp12ubuntu10.10
ProcVersionSignature: Ubuntu 3.2.0-41.66-generic 3.2.42
Uname: Linux 3.2.0-41-generic i686
ApportVersion: 2.0.1-0ubuntu17.2
Architecture: i386
Date: Sat May 11 11:00:38 2013
InstallationMedia: Xubuntu 12.04.2 LTS "Precise Pangolin" - Release i386 (20130213)
MarkForUpload: True
ProcEnviron:
 LANGUAGE=fr:en
 TERM=xterm
 PATH=(custom, no user)
 LANG=fr_FR.UTF-8
 SHELL=/bin/bash
SourcePackage: apt
UpgradeStatus: No upgrade log present (probably fresh install)

Jérôme (jerome-bouat) wrote :

On 11 May 2013 17:18, Jérôme <email address hidden> wrote:
> Public bug reported:
>
> The "random_sleep" function is calling "sleep". Thus the memory used by
> anacron, the /etc/cron.daily/apt script is frozen for minutes when the
> "random_sleep" blocks until the "sleep" program completes.

> I think this problem is important,

Provide some figures to back up this claim. How much resources are
consumed when this script sleeps?

 status incomplete

Changed in apt (Ubuntu):
status: New → Incomplete
Jérôme (jerome-bouat) wrote :

Below is the output of ps :
---
j@lt:~$ ps axlf
F UID PID PPID PRI NI VSZ RSS WCHAN STAT TTY TIME COMMAND
(...)
1 0 812 1 20 0 2392 840 rt_sig Ss ? 0:00 anacron -s
0 0 1615 812 20 0 2232 520 wait S ? 0:00 \_ /bin/sh -c nice run-parts --report /etc/cron.daily
0 0 1616 1615 30 10 2140 520 poll_s SN ? 0:00 \_ run-parts --report /etc/cron.daily
0 0 1622 1616 30 10 2232 560 wait SN ? 0:00 \_ /bin/sh /etc/cron.daily/apt
0 0 1672 1622 30 10 2148 280 hrtime SN ? 0:00 \_ sleep 1307
(...)
---

This makes 11 MB of virtual memory and 3 MB of physical memory.

Changed in apt (Ubuntu):
status: Incomplete → New
Julian Andres Klode (juliank) wrote :

I don't think 11 MB are a problem on systems with at least 1 GB of RAM (that's 1% on those; and most systems have more memory).

Jérôme (jerome-bouat) wrote :

This script contributes to swapping on my system which has only 256 MB of memory . Anyway this script is consuming a lot of memory during up to 30 minutes.

Jérôme (jerome-bouat) wrote :

11 MB is 4% of my physical memory.

Anyway, 11 MB just for sleeping during 30 minutes is too much. What would occur if each application had the same behaviour ?

On 12 May 2013 02:37, Jérôme <email address hidden> wrote:
> Below is the output of ps :
> ---
> j@lt:~$ ps axlf
> F UID PID PPID PRI NI VSZ RSS WCHAN STAT TTY TIME COMMAND
> (...)
> 1 0 812 1 20 0 2392 840 rt_sig Ss ? 0:00 anacron -s
> 0 0 1615 812 20 0 2232 520 wait S ? 0:00 \_ /bin/sh -c nice run-parts --report /etc/cron.daily
> 0 0 1616 1615 30 10 2140 520 poll_s SN ? 0:00 \_ run-parts --report /etc/cron.daily
> 0 0 1622 1616 30 10 2232 560 wait SN ? 0:00 \_ /bin/sh /etc/cron.daily/apt
> 0 0 1672 1622 30 10 2148 280 hrtime SN ? 0:00 \_ sleep 1307
> (...)
> ---
>
> This makes 11 MB of virtual memory and 3 MB of physical memory.
>
>

Virtual size (VSZ) and Resident Set Size (RSS) are not accurate
measures of the _unique_ memory consumed by a process. Processes
share memory e.g. for the executable image. Use a tool such as the
mem_usage script at
<http://www.elinux.org/Runtime_Memory_Measurement>. See also
<http://lwn.net/Articles/230975/>.

The unique memory size of that process tree is more on the order of
1–2 MB, and a system has any number of /bin/sh processes and all
sharing the same executable image. Further, a sleeping and nice
process is never a significant contributor to swapping, whose data is
swapped out and rarely in.

If this is causing measurable harm on your system you have many more
problems than one tiny, sleeping process. Submit a patch or dont, I
would not waste my time.

 status invalid

Changed in apt (Ubuntu):
status: New → Invalid
Jérôme (jerome-bouat) wrote :

I propose the attached patch.

In short :
- /etc/cron.daily/apt is moved to /usr/lib/apt/maintenance.sh and I removed the random_sleep function
- /etc/cron.daily/apt request to "at" to launch /usr/lib/apt/maintenance.sh after a random delay

There is another benefit : we are checking for battery operation only once.

The package will require a dependency to "at".

Changed in apt (Ubuntu):
status: Invalid → New

The attachment "changes in /etc/cron.daily/apt and new /usr/lib/apt/maintenance.sh" seems to be a patch. If it isn't, please remove the "patch" flag from the attachment, remove the "patch" tag, and if you are a member of the ~ubuntu-reviewers, unsubscribe the team.

[This is an automated message performed by a Launchpad user owned by ~brian-murray, for any issues please contact him.]

tags: added: patch
Rajiv Shah (compukid) on 2013-05-24
Changed in apt (Ubuntu):
status: New → Confirmed
Changed in apt:
status: Unknown → New
Jérôme (jerome-bouat) wrote :

Will this patch be accepted ?

Changed in apt:
status: New → Fix Committed
Changed in apt:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers

Remote bug watches

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