Reduce memory usage

Bug #525441 reported by Michael Nagel
32
This bug affects 6 people
Affects Status Importance Assigned to Milestone
Simple Scan
Confirmed
Low
Unassigned
simple-scan (Ubuntu)
Confirmed
Undecided
Unassigned

Bug Description

i just scanned a multipage document (something like 15 pages) using simple-scan. everything went like a charm and i really like the application and it's concept a lot! thanks so much, robert!
and probably thanks to canonical, i think there is some money involved (?) :)

however it used an impressive 750 MB of memory doing so! this was not actually a problem, but this clearly does not scale and for other hardware it would have been problematic already.

i suppose all raw image data is kept in memory until the complete batch is finished, the file saved and closed, but i did not really investigate in detail.

solution: memory usage should be optimized.

best regards!

nailor@nailworks:~° simple-scan --debug [1001]
** (simple-scan:19246): DEBUG: Starting Simple Scan 0.9.5, PID=19246
** (simple-scan:19246): DEBUG: Restoring window to 1062x707 pixels
** (simple-scan:19246): DEBUG: Restoring window to maximized
** (simple-scan:19246): DEBUG: sane_init () -> SANE_STATUS_GOOD
** (simple-scan:19246): DEBUG: SANE version 1.0.20
** (simple-scan:19246): DEBUG: Requesting redetection of scan devices
** (simple-scan:19246): DEBUG: Processing request
** (simple-scan:19246): DEBUG: Stopping scan thread
WARNING: Unhandled message: interface=org.freedesktop.DBus.Introspectable, path=/, member=Introspect
** (simple-scan:19246): DEBUG: sane_get_devices () -> SANE_STATUS_GOOD
** (simple-scan:19246): DEBUG: Device: name="hpaio:/usb/Deskjet_F4100_series?serial=CN7CO6V2MP04TJ" vendor="Hewlett-Packard" model="Deskjet_F4100_series" type="all-in-one"
** (simple-scan:19246): DEBUG: Processing request
** (simple-scan:19246): DEBUG: sane_exit ()

summary: - simple-scan uses massive amounts of memory
+ Reduce memory usage
Changed in simple-scan:
status: New → Triaged
importance: Undecided → Low
Revision history for this message
Robert Ancell (robert-ancell) wrote :

Closing as the memory usage in 2.31.90.1 is much reduced. Please re-open if it appears unreasonable!

Changed in simple-scan:
status: Triaged → Fix Released
Revision history for this message
bojo42 (bojo42) wrote :

Memory usage is still a concern. On 2.32 the app crashed on scanning about 80 pages due to too low memory:

GLib-ERROR **: /build/buildd/glib2.0-2.24.1/glib/gmem.c:137: failed to allocate 26779794 bytes
aborting...
Aborted

I did it on a machine with 1 GB RAM, before starting Simple Scan memory usage was 290 MB and did not start something else during scanning. After revaluating it on a machine with 4 GB i noticed that the saving process to PDF will always take another bunch of MB on the RAM, but it won't free it after finishing! This means that every saving will increase that amount of RAM usage and you can't get rid of without restarting Simple Scan. How comes that?

The main problem with high memory usage is that users will loose all there scans when no free RAM is left (as my case shows it's not too hard to reach that point). There should be some sort of checking on the amount of free RAM and when it get's too low users should get a warning, so that they can save there scans before crashing. Of course this means that there need to be enough RAM for the saving process.

Revision history for this message
bojo42 (bojo42) wrote :

oops somehow i am not able to reopen it for simple-scan as a project.

Michael Nagel (nailor)
Changed in simple-scan (Ubuntu):
status: New → Fix Released
Revision history for this message
Jose Gómez (adler-dreamcoder) wrote :

Actually, I don't think this bug is fixed at all.

When scanning text documents (at 300 dpi), around 15 pages consumes about 500 to 900 MB of memory. If I continue scanning, eventually the program will run out of memory, and crash, therefore all the work will be lost.

Furthermore, sometimes the crash happens while saving, which is the point when the memory usage peaks, getting an increase of some hundred MBs. So, saving frequently does not eases the problem.

Finally, neither deleting pages, nor clicking on the button "Start a new document" free any memory. That memory is also not reused. The only way of being able to scan more pages, is closing the program and opening a new instance.

Therefore, this is just a huge memory leak.

My workaround for the time being is just to scan documents in batches of 15 pages, saving into different pdf files, closing the program and opening it again, and then merge the different files with pdftk:

    pdftk inputfile1.pdf inputfile2.pdf inputfilen.pdf cat ouput outputfile.pdf

Revision history for this message
bojo42 (bojo42) wrote :

@Micheal: just before i go trough the rather long testing procedure (scanning many pages with a slow scanner takes rather hours than minutes) i want to ask you:

What change did fix this bug and are you really certain it is fixed at least by the version currently in precise?

Revision history for this message
Michael Nagel (nailor) wrote :

In comment #1 Robert said he fixed it in 2.31.90.1

------------------
Closing as the memory usage in 2.31.90.1 is much reduced. Please re-open if it appears unreasonable!
------------------

I changed the status for Ubuntu when that version hit the archives.
Probably the situation just improved somewhat, but the issue was not fixed thoroughly.

Feel free to reopen!

Revision history for this message
bojo42 (bojo42) wrote :

Then i need to reopen, as i already confirmed it with a later version then 2.31.90.1. Back then it was relative easy to crash Simple Scan but just keep on scanning.

Unfortunaly i am not able to reset the status to confirmed or triaged , could someone help out?

Michael Nagel (nailor)
Changed in simple-scan (Ubuntu):
status: Fix Released → Confirmed
Changed in simple-scan:
status: Fix Released → Confirmed
Revision history for this message
Ali Shtarbanov (ametedinov) wrote :

I monitored my memory usage during a scanning job (60+ pages) and I observed the following:

On the machine where the scan was performed I have 1GB of RAM. Each new scanned page (in color at 300ppi) increased my RAM usage by ~30MB. This process continued until my memory usage reached ~850MB. After this point, each new scanned page added caused my SWAP usage to increase by ~30MB.

From the aforementioned explanation the following beneficial conclusion/workaround can be stated:
If worried that you will run out of free memory make your swap partition as large as necessary. When the used memory reaches 85%, the raw scanned images are kept on the swap partition.

Revision history for this message
Maurits Lamers (mauritslamers) wrote :

This issue is still not fixed on 3.14.0-ubuntu1. When scanning I see the same behaviour as ametedinov describes in #8

Revision history for this message
JJ (bjustjones) wrote :

If simple-scan is unable to load the cached data it should give the user the option to abandon the cached auto-save data on successive attempts. Currently it just tries and crashes repeatedly due to lack of memory.
At a minimum: Console output indicating an attempt to load the cache and its location would've been helpful in solving the issue.

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

Duplicates of this bug

Other bug subscribers

Related questions

Remote bug watches

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