lkl / linux

Linux kernel source tree
https://lkl.github.io/
Other
819 stars 137 forks source link

win32: Leak of TimerQueueTimers #170

Open Rondom opened 8 years ago

Rondom commented 8 years ago

On Windows, everytime a new TimerQueueTimers is scheduled by nt-host.c:timer_set_oneshot, a HANDLE is allocated for that timer.

Currently those timer-handles are only freed when the whole TimerQueue is freed using DeleteTimerQueueEx in nt-host.c:timer_free. This is problematic because we will accumulate those handles over the runtime of the process and crash on Win32-x86 when the process size has reached 2 GB ;-)

These handles can already be freed beforehand, by calling DeleteTimerQueueTimer. I implemented a quick (hacky) fix by freeing the previously scheduled timer using DeleteTimerQueueTimer in timer_set_oneshot, but I do not think this is a good solution and might even be prone to race conditions.

Before I waste a lot of time on this I am wondering how to fix this "properly". Allocating (and with the fix also freeing ;-) ) the handles is quite some overhead. Would it be possible to set up a periodic timer instead? Or could we somehow reuse handles using ChangeTimerQueueTimer?

I am still learning, and I would love to hear your thoughts :-)

ghost commented 8 years ago

Unfortunately we can't use a periodic timer because the Linux timer tick is dynamic when entering idle.

I think the fix with freeing the previously scheduled timer its good. We can't have race conditions since the LKL is single threaded at the moment and the only calls to timer_set_oneshot comes from LKL threads.