Commit 208578e
committed
cgroup2: fix event loss and resource issues in EventChan
Fix multiple issues in EventChan that caused event loss and inefficient
resource usage when monitoring cgroup memory events.
1. Use non-blocking I/O for efficient event monitoring
EventChan previously used blocking file descriptors to watch
memory.events, causing goroutines to block indefinitely when no
events occurred. This wasted system resources by holding threads
without doing useful work.
Switch to non-blocking I/O to allow goroutines to efficiently wait
for events without consuming blocked threads.
2. Fix race condition causing missed OOM kill events
A race condition could cause OOM kill events to be missed when they
occurred between reading memory.events and checking if the cgroup
was empty:
- T1: Receive modified event for memory.events
- T2: Read memory.events (no oom_kill event present yet)
- T3: Process in cgroup is OOM-killed
- T4: No running processes remain in cgroup
- T5: isCgroupEmpty() returns true
- T6: EventChan exits, missing the OOM kill event
Fix by checking isCgroupEmpty() before reading memory.events to
ensure events are not lost.
3. Initialize inotify watch before returning
Ensure inotify watches are fully initialized before EventChan
returns to prevent races where events could be missed during
initialization.
Signed-off-by: Wei Fu <[email protected]>1 parent 751ce28 commit 208578e
2 files changed
+120
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
764 | 764 | | |
765 | 765 | | |
766 | 766 | | |
767 | | - | |
768 | | - | |
769 | | - | |
770 | | - | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
771 | 772 | | |
772 | | - | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
773 | 796 | | |
774 | 797 | | |
775 | | - | |
776 | | - | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
777 | 801 | | |
778 | | - | |
| 802 | + | |
779 | 803 | | |
780 | 804 | | |
781 | | - | |
| 805 | + | |
782 | 806 | | |
783 | | - | |
784 | 807 | | |
785 | | - | |
786 | | - | |
787 | | - | |
788 | | - | |
789 | | - | |
790 | | - | |
791 | | - | |
792 | | - | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
793 | 830 | | |
794 | 831 | | |
795 | 832 | | |
| |||
798 | 835 | | |
799 | 836 | | |
800 | 837 | | |
| 838 | + | |
801 | 839 | | |
802 | 840 | | |
803 | 841 | | |
804 | 842 | | |
805 | 843 | | |
806 | 844 | | |
807 | 845 | | |
808 | | - | |
| 846 | + | |
| 847 | + | |
809 | 848 | | |
810 | 849 | | |
811 | 850 | | |
812 | | - | |
| 851 | + | |
| 852 | + | |
813 | 853 | | |
814 | 854 | | |
815 | 855 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
121 | 177 | | |
122 | 178 | | |
123 | 179 | | |
| |||
406 | 462 | | |
407 | 463 | | |
408 | 464 | | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
0 commit comments