balloon: stop inflate balloon after oom notification
Subsystems (2)
PATCH 1/1 balloon: stop inflate balloon after oom notification
From: Konstantin Neumoin <[email protected]>
At this moment oom notification in balloon does not work as expected. After virtballoon_oom_notify there is an infinitive loop:
- virtballoon_oom_notify was called and balloon was deflated
- balloon get notification that config was changed, compare target and actual and try to reach target again.
This patch adds global variable fail_counter which indicates that oom has been happened. We check that fail_counter was changed between calls update_balloon_size_func. In this case we should not try to inflate balloon even if actual != target.
--- drivers/virtio/virtio_balloon.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
drivers/virtio/virtio_balloon.c +15 -0
@@ -50,6 +50,8 @@ MODULE_PARM_DESC(oom_pages, "pages to free on OOM");static struct vfsmount *balloon_mnt;#endif +static unsigned long fail_count; +struct virtio_balloon {struct virtio_device *vdev;struct virtqueue *inflate_vq, *deflate_vq, *stats_vq;
@@ -361,6 +363,8 @@ static int virtballoon_oom_notify(struct notifier_block *self,unsigned long *freed;unsigned num_freed_pages; + fail_count++; + vb = container_of(self, struct virtio_balloon, nb);if (!virtio_has_feature (vb->vdev,VIRTIO_BALLOON_F_DEFLATE_ON_OOM ))return NOTIFY_OK ;
@@ -386,11 +390,22 @@ static void update_balloon_size_func(struct work_struct *work) {struct virtio_balloon *vb;s64 diff; +static unsigned long fc; + +if (fc ==0 ) + fc = fail_count; vb = container_of(work, struct virtio_balloon, update_balloon_size_work); diff =towards_target (vb); +if (fc != fail_count) { + fc = fail_count; +/* Don't inflate balloon after oom notification */ +if (diff >0 ) +return ; + } +if (diff >0 ) diff -=fill_balloon (vb, diff);else if (diff <0 )
Signature · 1 line
2.7.4
Michael S. Tsirkin
maintainerQuoted 8 lines · Denis V. Lunev
From: Konstantin Neumoin <[email protected]>
At this moment oom notification in balloon does not work as expected. After
virtballoon_oom_notifythere is an infinitive loop:
-virtballoon_oom_notifywas called and balloon was deflated
- balloon get notification that config was changed, compare target and actual and try to reach target again.
Quoted 4 lines
This patch adds global variable
fail_counterwhich indicates that oom has been happened. We check thatfail_counterwas changed between callsupdate_balloon_size_func. In this case we should not try to inflate balloon even if actual != target.
Doesn't look right to me. What if it triggered an hour ago?
We really need mm core to expose an oom_in_progress flag that we can test.
More implementation comments below.
Quoted 22 lines
Signed-off-by Konstantin Neumoin <[email protected]>Signed-off-by Denis V. Lunev <[email protected]>CC Michael S. Tsirkin <[email protected]>--- drivers/virtio/virtio_balloon.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+)drivers/virtio/virtio_balloon.c +2
-0@@ -50,6 +50,8 @@ MODULE_PARM_DESC(oom_pages, "pages to free on OOM");static struct vfsmount *balloon_mnt;#endif +static unsigned long fail_count; +struct virtio_balloon {struct virtio_device *vdev;struct virtqueue *inflate_vq, *deflate_vq, *stats_vq;
drivers/virtio/virtio_balloon.c static int virtballoon_oom_notify(struct notifier_block *self, · line 370
Quoted 8 lines
drivers/virtio/virtio_balloon.c +2
-0@@ -361,6 +363,8 @@ static int virtballoon_oom_notify(struct notifier_block *self,unsigned long *freed;unsigned num_freed_pages; + fail_count++; + vb = container_of(self, struct virtio_balloon, nb);if (!virtio_has_feature (vb->vdev,VIRTIO_BALLOON_F_DEFLATE_ON_OOM ))return NOTIFY_OK ;
OOM should not interfere with ballooning unless VIRTIO_BALLOON_F_DEFLATE_ON_OOM has been negotiated.
drivers/virtio/virtio_balloon.c static void update_balloon_size_func(struct work_struct *work) · line 396
Quoted 8 lines
drivers/virtio/virtio_balloon.c +4
-0@@ -386,11 +390,22 @@ static void update_balloon_size_func(struct work_struct *work) {struct virtio_balloon *vb;s64 diff; +static unsigned long fc; + +if (fc ==0 ) + fc = fail_count;
Why?
drivers/virtio/virtio_balloon.c static void update_balloon_size_func(struct work_struct *work) · line 403
Quoted 7 lines
drivers/virtio/virtio_balloon.c +2
-0vb = container_of(work, struct virtio_balloon, update_balloon_size_work); diff =towards_target (vb); +if (fc != fail_count) { + fc = fail_count;
Unlikely to work correctly if there are multiple balloon devices.
drivers/virtio/virtio_balloon.c static void update_balloon_size_func(struct work_struct *work) · line 411
Quoted 8 lines
drivers/virtio/virtio_balloon.c +5
-0+/* Don't inflate balloon after oom notification */ +if (diff >0 ) +return ; + } +if (diff >0 ) diff -=fill_balloon (vb, diff);else if (diff <0 )
I'd rather make it per-device.
Absence of memory ordering primitives of any kind also looks suspicious.
Quoted 2 lines
Signature · 1 line
2.7.4