Commit Graph

57 Commits

Author SHA1 Message Date
John Cupitt 976db37f84
Revised threading system (#3105)
* reimplement threadpool

just a set of threads that get recycled

"ninja test" passes and dzsave seems to work, though pytest fails for
some reason

* clean up threading code a bit

move base stuff into thread.c, so we have a simple

	thread -> threadset -> threadpool

layering

* start trying to revert g_threadpool

based on the original commit

* working!

nice low systime again

still need to repply cnages to threadpool.c since 80e0cc3d1

* reapply fixes from master

so threadpool.c is now up to date

* rename VipsThread as VipsWorker

a bit less confusing

* use a semaphore to count workers in a pool

* tidy up

* formatting

* dynamic threadpool sizing

based on counting the number of blocked threads in each pool

it works, but the improvement is not great :(

* add "concurrency" metadata item

so operators can hint threadpool size (dzsave especially)

* don't use thinstrip for small images

* add RGB mode to openslide

since flatten was taking 20% of CPU time for dzsave

* fix up rgb mode

now actually works

* make the tile buffer per thread

in the new openslideload rgb mode

* fix dynamic pool downsize

* mild refactoring

* fix the buffer system

oops, turned it off by mistake

* all done!

* revise changelog

* Update libvips/iofuncs/threadset.c

Co-authored-by: Kleis Auke Wolthuizen <github@kleisauke.nl>

* Update libvips/iofuncs/threadset.c

Co-authored-by: Kleis Auke Wolthuizen <github@kleisauke.nl>

* LSan: add libMagickCore to suppression file

* Revert "Remove mutex lock for VipsThreadStartFn"

This reverts commit 41440491.

* add VIPS_MAX_THREADS

to set a hard limit on the threadset size

* Revert "Revert "Remove mutex lock for VipsThreadStartFn""

This reverts commit 77e8520966ba79194fff3b4e648bbd295cd5c260.

* remove sslock from sink.c

* move fixed threadpool build to init

not first use

* add some doc comments

* revert test suite threshold change

* add a test for MAX_THREADS

and move the test tmp/ area into the builddir

* limit VIPS_MAX_THREADS to sane values

* use tabs rather than spaces

Co-authored-by: Kleis Auke Wolthuizen <github@kleisauke.nl>
2022-10-26 15:25:19 +01:00
Kleis Auke Wolthuizen 0337c09700
Cleanup gettext handling (#2695)
Use GLib's i18n support instead of copying and pasting that
logic into its own header. This deprecates the vips/intl.h
header in favour of glib/gi18n.h.
2022-02-27 15:27:28 +00:00
Kleis Auke Wolthuizen 060ab7c7a2 Free the calculated pixel buffer cache early
Since threads can be reused, we need to free the
calculated pixel buffer cache early (i.e. during
vips_thread_shutdown).

This (partially) reverts commit 1a915db.
2021-05-03 13:21:45 +02:00
Lovell Fuller 117dbd888a Set minimum glib dependency version of 2.40 (March 2014) 2021-02-24 21:59:21 +00:00
Kleis Auke Wolthuizen 9246094033 Fix function pointer cast issues
It is undefined behavior in C and C++ to cast a function pointer
to another type and call it that way. This does work in most native
platforms, however, despite it being UB, but in WASM it can fail.

See:
https://emscripten.org/docs/porting/guidelines/function_pointer_issues.html
2020-06-30 13:35:41 +02:00
John Cupitt cf938280d0 fix a few small things
found with clang static analyzer
2017-03-25 17:55:08 +00:00
John Cupitt 87928d4eba oops, failed merge 2016-10-28 17:26:13 +01:00
John Cupitt e715c62e27 Merge branch '8.4' 2016-10-28 16:51:43 +01:00
John Cupitt a7edd235c4 improve compat with ancient glibs
and fix a tiny threading leak
2016-10-28 16:25:31 +01:00
John Cupitt 1a915db678 no longer need to clean up main buffers
thread-private buffers are now only on workers, no need to to start them
up or free them on the main thread
2016-10-19 09:58:13 +01:00
John Cupitt ded6f17fa8 fix up new buffer.c
and make getpoint() use the threading system
2016-10-14 09:00:21 +01:00
John Cupitt b4d6d6c590 compiles, but untested 2016-10-13 14:57:18 +01:00
John Cupitt 105c396de5 argh revert that
seem to all work now, but buffer.c is getting ugly ... revise for 8.5
2016-10-12 16:40:06 +01:00
John Cupitt cf98b92dbf more tiny buffer fixups 2016-10-12 12:46:27 +01:00
John Cupitt 463d2e885f a bit more debugging code in buffer.c
watch global buffercache
2016-10-12 12:07:09 +01:00
John Cupitt 7883e30d68 group all non-worker buffers
have a single place to keep all non-worker buffers, and guard it with a
lock
2016-10-11 10:47:01 +01:00
John Cupitt ccfe4cb215 seems to work?
needs stress testing still

see https://github.com/jcupitt/libvips/issues/535
2016-10-10 15:12:12 +01:00
John Cupitt b90145ca31 free pixel buffers on image close
We were freeing pixel buffers on thread exit. This was convenient, but
meant that main thread buffers were not freed until program exit. As a
result, long-running programs which created main thread buffers would
slowly fill the operation cache with useless junk, forcing everything else out.

This change also frees pixel buffers on image close. This makes the
cache work much better in long-running programs, and can substantially
reduce memory use.

See https://github.com/jcupitt/libvips/issues/466
2016-06-06 13:50:25 +01:00
John Cupitt 37131e5834 not working tests 2016-06-06 11:03:31 +01:00
John Cupitt 15878bffca Revert "free main-thread pixel buffers"
This reverts commit 2a77301033.
2016-06-06 06:38:18 +01:00
John Cupitt 2a77301033 free main-thread pixel buffers
threads keep pixel buffers in thread-private storage, and free these
buffers on thread exit ... this means buffers created by the main thread will
only be freed on program exit!

if your program creates any main-thread buffers, these buffers will
eventually fill the operation cache and force everything else out,
making the cache useless

this patch explicitly frees main-thread pixel buffers on image close
2016-06-05 16:59:07 +01:00
John Cupitt af34f8f3ef more robust vips file read 2016-05-17 19:43:47 +01:00
John Cupitt e6cbdbb516 add a stub for compat
see https://github.com/jcupitt/libvips/issues/361
2016-01-01 10:58:53 +00:00
John Cupitt 3d163bb4e5 oops, DEBUG was left on in buffer.c
argh, this was burning a lot of CPU for no reason

added a thing to warn if this is left on again
2015-12-14 14:06:16 +00:00
John Cupitt cad052544c try to make vips_thread_shutdown() optional
see

https://github.com/jcupitt/ruby-vips/issues/55

it's still better to call vips_thread_shutdown(), but not calling it
should no longer leak memory
2014-09-30 11:28:24 +01:00
John Cupitt 2e8217338b docs work 2014-08-09 10:25:34 +01:00
John Cupitt 0bb8a218bb exit() in fewer cases
we now only exit() when we know the stack has been trashed, just warn in
other cases
2014-07-29 15:23:27 +01:00
John Cupitt 9cb152596c bg render thread quits on shutdown
fixes a small memleak
2014-01-29 09:07:58 +00:00
John Cupitt 33b9563170 fix a warning 2014-01-26 10:54:31 +00:00
John Cupitt bbd5cbfb44 add vips_thread_shutdown()
You now need to call vips_thread_shutdown() from all threads you create
yourself just before they exit. This gives vips a chance to free any
thread-private memory and to write out profiling data. libvips will
complain noisily if you fail to do this. You can harmlessly call
vips_thread_shutdown() more than once if you wish.

libvips will call vips_thread_shutdown for you automatically for the main
thread (the one that calls vips_shutdown()) and for threads it creates
directly itself.
2014-01-15 14:07:13 +00:00
John Cupitt 68a816f104 try again on the buffer cache assert 2014-01-09 16:56:44 +00:00
John Cupitt cc8e06db0b fix a race in buffer.c 2014-01-07 21:31:00 +00:00
John Cupitt 9c30242745 fix erroneous leak report from vipsprofile 2013-12-18 12:50:22 +00:00
John Cupitt 2c5ee332f0 make the buffer recycle list per image
so now recycle lists are short, scale with pipeline complexity, and
buffers are always appropriately sized for the image instead of being
slowly sized up to the max size for the pipeline

before:

$ vips sharpen k2.jpg x.jpg --radius 20
memory: high-water mark 38.99 MB

after:

$ vips sharpen k2.jpg x.jpg --radius 20
memory: high-water mark 29.46 MB
2013-12-18 09:54:26 +00:00
John Cupitt 0d79221853 memuse improvements
- conv is now SMALLTILE
- more instrumentation
- better buffer recycling
- quicker buf freeing
2013-12-17 15:21:21 +00:00
John Cupitt a9fd318712 run over memuse for sharpen 2013-12-16 09:22:05 +00:00
John Cupitt bfcd50acf2 works!
reusing work, though memuse seems high?
2013-12-13 16:51:01 +00:00
John Cupitt 82df44f9d6 clean up buffer recycle fix 2013-12-13 14:05:10 +00:00
John Cupitt c782150a6d fix sharing detection (again) 2013-12-13 12:20:05 +00:00
John Cupitt 6ae1888ab3 delay region resource unref to reduce malloc churn
we were unreffing windows and buffers attached to regions on
vips_region_region() etc.

when these regions were reinitialised later, fresh buffers were
allocated causing a lot of churn
2013-12-07 11:38:32 +00:00
Benjamin Gilbert 8cc76a6ba3 Update address for Free Software Foundation
Also update LGPLv2.1 license text from the copy currently on the GNU
website.
2013-03-07 00:40:19 -05:00
John Cupitt c6478c811b update use of GPrivate 2012-10-23 13:57:38 +01:00
John Cupitt fad78f8555 rework gthread usage
glib-2.32 deprecated g_mutex_new() ... use a compat function to hide
this change

also remove the --without-threads configure flag, gthread is now
compulsory, so there was no longer any point
2012-10-22 22:08:53 +01:00
John Cupitt ae8faf6597 remove dmalloc support
we never used it and valgrind etc. is better anyway
2011-09-23 17:12:47 +01:00
John Cupitt 5462d5d6b2 switch buffer allocation to tracked
buffer allocs and image memory allocs go to the tracked pool
2011-09-21 18:00:03 +01:00
John Cupitt 4120f7b296 cleanup util
just a few little things left, yay
2011-03-28 16:03:31 +01:00
John Cupitt 842d2e1b16 more more stuff to vips_
window, memory, buffer, b64 all moved to the vips_ namespace
2011-03-25 14:01:12 +00:00
John Cupitt ac801dd1fc rename Rect as VipsRect
move Rect to the new Vips namespace, add gtkdoc comments, add back
compat stuff
2011-03-17 13:05:46 +00:00
John Cupitt c49db35cfa all compiles and links cleanly
or mostly, anyway, try running next
2011-03-05 12:07:18 +00:00
John Cupitt ab427d906b iofuncs compiles
except for a reset thing we need argh
2011-03-03 17:54:08 +00:00