Bug 756493

Summary: Yast2 System Backup causes Xorg to use much CPU
Product: [openSUSE] openSUSE 12.1 Reporter: Greg Holmberg <holmberg2066>
Component: YaST2Assignee: Lukas Ocilka <locilka>
Status: RESOLVED FIXED QA Contact: Jiri Srain <jsrain>
Severity: Normal    
Priority: P3 - Medium    
Version: Final   
Target Milestone: ---   
Hardware: x86-64   
OS: openSUSE 12.1   
Whiteboard: maint:running:49405:low maint:released:sle11-sp2:49406
Found By: --- Services Priority:
Business Priority: Blocker: ---
Marketing QA Status: --- IT Deployment: ---
Attachments: Y2Logs from the System Backup tool
Proposed patch
Another (additional) patch
Last patch for "Searching in Package: ..."

Description Greg Holmberg 2012-04-10 20:41:54 UTC
User-Agent:       Opera/9.80 (X11; Linux x86_64; U; en) Presto/2.10.229 Version/11.61

Running the GTK GUI for System Backup, I notice that of the CPU being used on my system, half is by the y2base process and half is by Xorg.

I assume this is due to the high rate that the Backup GUI is updating the number of packages found (the number changes so fast I can't read the right-most digits).

You could cut in half the CPU load on the system that is due to running System Backup by simply updating the GUI much less often.

Note: Perhaps the rate at which System Backup finds packages on my system is unusually high since the system is installed on a vary fast solid-state drive.

Reproducible: Always

Steps to Reproduce:
1. Run top or htop, observe the CPU load on the system, especially the Xorg process, which should be at nearly zero CPU usage.
2. Start the System Backup GUI.
3. Click the "Create Backup" button.
4. Observe the "Modified Files" and "Total Size" fields update their values very fast (too fast to read).
5. Back in top, observe the Xorg process using nearly as much CPU as the "y2base backup gtk" process.
6. When the backup finishes, observe the CPU usage of Xorg return to nearly zero.  So, whatever was causing Xorg to use so much CPU, was clearly related to the System Backup GUI.
Actual Results:  
CPU usage on my dual-core system is nearly 100%.

Expected Results:  
I expected CPU usage to only be about 50% (one core, not two).  At least until the "Create package archives" phase starts (running bzip).

Suggested change: update the "Modified Files" and "Total Size" values in the GUI much less often.

System is installed on a solid-state drive, so Yast discovers packages at a very high rate during backup.
Comment 1 Kun Kun Zhang 2012-04-11 06:37:37 UTC
Hi,thank you for your report.could you please help to provide y2logs according to the following URL?Thank you.
http://en.opensuse.org/openSUSE:Bugreport_YaST
Comment 2 Greg Holmberg 2012-04-11 17:59:39 UTC
Created attachment 485688 [details]
Y2Logs from the System Backup tool

OK, here are the logs.  I'm not sure how log files help you implement an enhancement, but OK.
Comment 3 Lukas Ocilka 2012-04-13 13:18:00 UTC
YaST logs were obviously not needed, the bug is well-reported
and clear.
Comment 4 Lukas Ocilka 2012-04-16 10:56:27 UTC
Created attachment 486230 [details]
Proposed patch

How to apply the patch:

  cd /usr/share/YaST2/include/backup/
  patch -p0 < /path/to/yast-backup.diff
Comment 5 Lukas Ocilka 2012-04-16 10:59:55 UTC
Please, retest with patch from comment #4.
Comment 6 Greg Holmberg 2012-04-16 18:25:00 UTC
Hi Lukas--

I applied the patch and tested.  However, I still saw very fast updates to the numbers on the screen, and I got the same CPU usage from Xorg.

Looking at the code, I think I see why.  In this line

    if (ui_time_now > ui_last_refresh) {

the condition is always true.

I think ui_time_now needs to be at least a certain amount of time > 0 after ui_last_refresh.  For example:

    if (ui_time_now > ui_last_refresh + 10) {

However, I tested this and again, there was no effect.  In addition to 10, I also tried 100 and 1000.

To verify that I was modifying the right file, I renamed the ui.ycp file, and restarted.  Sure enough, the GUI couldn't start, so I'm definitely editing the right file.

I can't explain why none of this has an effect on Xorg's CPU usage.  It seems like it should.

Greg
Comment 7 Lukas Ocilka 2012-04-17 10:20:39 UTC
From my POV, "if (ui_time_now > ui_last_refresh) {" is correct because
time() returns integer with seconds from 1.1.1970, see 
http://doc.opensuse.org/projects/YaST/SLES11/tdg/time.html

Considering that, ui_time_now should stay the same for one second and
thus updating the UI sometimes skipped.

There must be something else, I'll try to debug that issue a bit more.
Comment 8 Lukas Ocilka 2012-04-17 11:28:57 UTC
Created attachment 486423 [details]
Another (additional) patch

ui_last_refresh was always set to 0
Comment 9 Lukas Ocilka 2012-04-17 11:29:22 UTC
Retest, please.
Comment 10 Greg Holmberg 2012-04-17 23:09:33 UTC
Ahh.  time() returns seconds.  OK, that works.  I had assumed milliseconds.

I tested the latest patch, and it works.  CPU utilization by Xorg was 12% to 18% of one core (normally running 0% to 2%).  Which is a great improvement over 100% of one core.

One last improvement you could make would be to do the same thing with the "Searching in Package" widget.  It's still updating many times per second, and I would guess this is the cause of that last 12% to 18% CPU utilization by Xorg.

Actually, looking at the code, it appears to me that you've already tried to do that.  Perhaps it has the same bug (i.e. dir_last_refresh is always zero)?
Comment 11 Lukas Ocilka 2012-05-03 13:59:01 UTC
Created attachment 489391 [details]
Last patch for "Searching in Package: ..."
Comment 12 Lukas Ocilka 2012-05-03 13:59:48 UTC
Please retest with the latest additional patch for
"Searching in Package: ..." dialog.
Comment 13 Greg Holmberg 2012-05-05 00:44:32 UTC
Well, that had the right effect on CPU usage.  Xorg used only 0% to 1% CPU while system backup was searching for modified files.

Unfortunately, it only rarely updated the "Searching in Package" widget.  Approximately 5 to 7 seconds between updates.
Comment 14 Lukas Ocilka 2012-05-16 13:16:33 UTC
I've checked that on my system and UI is refreshed every single second
(if applicable), the rest is skipped.

You can find an updated package in openSUSE:Factory repository, the
version is yast2-backup-2.22.2
Comment 15 Swamp Workflow Management 2012-10-13 00:02:34 UTC
Update released for: yast2-backup
Products:
SLE-DESKTOP 11-SP2 (i386, x86_64)
SLE-SERVER 11-SP2 (i386, ia64, ppc64, s390x, x86_64)
SLES4VMWARE 11-SP2 (i386, x86_64)