Re: use of shrinker in virtio balloon free page hinting

From: Wei Wang
Date: Thu Jul 18 2019 - 05:03:12 EST


On 07/18/2019 02:47 PM, Michael S. Tsirkin wrote:
On Thu, Jul 18, 2019 at 02:30:01PM +0800, Wei Wang wrote:
On 07/18/2019 01:58 PM, Michael S. Tsirkin wrote:
what if it does not fail?


Shrinker is called on system memory pressure. On memory pressure
get_free_page_and_send will fail memory allocation, so it stops allocating
more.
Memory pressure could be triggered by an unrelated allocation
e.g. from another driver.
As memory pressure is system-wide (no matter who triggers it), free page
hinting
will fail on memory pressure, same as other drivers.
That would be good. Except instead of failing it can hit a race
condition where it will reallocate memory freed by shrinker. Not good.

OK..I could see this when another module does allocation, which triggers kswapd
to have balloon's shrinker release some memory, which could be eaten by balloon
quickly again before that module takes it, and this could happen repeatedly
in theory.

So add a vb->stop_free_page_report boolean, set it in shrinker_count, and clear it in
virtio_balloon_queue_free_page_work?

Best,
Wei