@@ -657,15 +657,24 @@ def _set_rt(self, pid, sched, prio):
657
657
def _is_kthread (self , process ):
658
658
return process ["stat" ]["flags" ] & procfs .pidstat .PF_KTHREAD != 0
659
659
660
+ def _process_in_blacklisted_cgroup (self , process ):
661
+ if self ._cgroup_ps_blacklist_re == "" :
662
+ return False
663
+ return re .search (self ._cgroup_ps_blacklist_re , self ._get_stat_cgroup (process )) is not None
664
+
660
665
# Returns True if we can ignore a failed affinity change of
661
666
# a process with the given PID and therefore not report it as an error.
662
- def _ignore_set_affinity_error (self , pid ):
667
+ def _ignore_set_affinity_error (self , process ):
668
+ pid = process .pid
663
669
try :
664
- process = procfs .process (pid )
665
670
if process ["stat" ]["state" ] == "Z" :
666
671
log .debug ("Affinity of zombie task with PID %d could not be changed."
667
672
% pid )
668
673
return True
674
+ if self ._process_in_blacklisted_cgroup (process ):
675
+ log .debug ("Affinity of task with PID %d could not be changed, the task was moved into a blacklisted cgroup."
676
+ % pid )
677
+ return True
669
678
if process ["stat" ].is_bound_to_cpu ():
670
679
if self ._is_kthread (process ):
671
680
log .debug ("Affinity of kernel thread with PID %d cannot be changed, the task's affinity mask is fixed."
@@ -674,6 +683,9 @@ def _ignore_set_affinity_error(self, pid):
674
683
log .warning ("Affinity of task with PID %d cannot be changed, the task's affinity mask is fixed."
675
684
% pid )
676
685
return True
686
+ log .info ("Task %d cmdline: %s" % (pid , self ._get_cmdline (process )))
687
+ log .info ("Task %d cgroup: %s" % (pid , self ._get_stat_cgroup (process )))
688
+ log .info ("Task %d affinity: %s" % (pid , list (self ._scheduler_utils .get_affinity (pid ))))
677
689
except (OSError , IOError ) as e :
678
690
if e .errno == errno .ENOENT or e .errno == errno .ESRCH :
679
691
log .debug ("Failed to get task info for PID %d, the task vanished."
@@ -1181,13 +1193,17 @@ def _get_affinity(self, pid):
1181
1193
return res
1182
1194
1183
1195
def _set_affinity (self , pid , affinity ):
1196
+ process = procfs .process (pid )
1197
+ if self ._process_in_blacklisted_cgroup (process ):
1198
+ log .debug ("Not setting CPU affinity of PID %d, the task belongs to a blacklisted cgroup." % pid )
1199
+ return
1184
1200
log .debug ("Setting CPU affinity of PID %d to '%s'." % (pid , affinity ))
1185
1201
try :
1186
1202
self ._scheduler_utils .set_affinity (pid , affinity )
1187
1203
# Workaround for old python-schedutils (pre-0.4) which
1188
1204
# incorrectly raised SystemError instead of OSError
1189
1205
except (SystemError , OSError ) as e :
1190
- if not self ._ignore_set_affinity_error (pid ):
1206
+ if not self ._ignore_set_affinity_error (process ):
1191
1207
log .error ("Failed to set affinity of PID %d to '%s': %s"
1192
1208
% (pid , affinity , e ))
1193
1209
@@ -1204,9 +1220,6 @@ def _set_all_obj_affinity(self, objs, affinity, threads = False):
1204
1220
if self ._ps_blacklist != "" :
1205
1221
psl = [v for v in psl if re .search (self ._ps_blacklist ,
1206
1222
self ._get_stat_comm (v )) is None ]
1207
- if self ._cgroup_ps_blacklist_re != "" :
1208
- psl = [v for v in psl if re .search (self ._cgroup_ps_blacklist_re ,
1209
- self ._get_stat_cgroup (v )) is None ]
1210
1223
psd = dict ([(v .pid , v ) for v in psl ])
1211
1224
for pid in psd :
1212
1225
try :
0 commit comments