elm image: Fix async open to avoid multiple mmap
authorJean-Philippe Andre <jp.andre@samsung.com>
Fri, 15 Sep 2017 05:39:14 +0000 (14:39 +0900)
committerJean-Philippe Andre <jp.andre@samsung.com>
Mon, 18 Sep 2017 02:58:53 +0000 (11:58 +0900)
Reported by @jiin.moon:

In case of async_open for an elm_image, we try and open a file in a
thread, then map it and populate a bit, as this may take some time
(blocking I/O). This creates a mmap with eina_file_map_new. But later
evas image loaders will (usually) try and map the entire file with
eina_file_map_all() which creates another mmap. Since the size is
different (32Kb first then all) the returned map might be different
(it's up to the kernel to decide at this point).

So, in order to avoid having multiple maps on the same file, and try to
reduce the peak memory usage, we should prefer using the same map all
the time, i.e. the global one returned by eina_file_map_all().

This patch relies on the previous patch in eina_file which fixes
eina_file_map_populate() for the global map.

@fix

src/lib/elementary/efl_ui_image.c

index b8f0486241ecb3b826cea7c8388d2243b19b02cd..093e79bff2684545570c9ac6a97df8a2b5aef22f 100644 (file)
@@ -323,7 +323,8 @@ _efl_ui_image_async_open_do(void *data, Ecore_Thread *thread)
    // blindly load in here to let's say 32KB (Should be enough to get
    // image headers without getting to much data from the hard drive).
    size = size > 32 * 1024 ? 32 * 1024 : size;
-   map = eina_file_map_new(f, EINA_FILE_POPULATE, 0, size);
+   map = eina_file_map_all(f, EINA_FILE_SEQUENTIAL);
+   eina_file_map_populate(f, EINA_FILE_POPULATE, map, 0, size);
 
    if (ecore_thread_check(thread))
      {