Skip to content

Commit f975841

Browse files
authored
Merge pull request #693 from yadzhang/feat/tmo-optimize-rebase-release
feat(tmo): block config support kcc and optimize target size calc
2 parents 47cc1fc + 8170d9d commit f975841

File tree

7 files changed

+384
-28
lines changed

7 files changed

+384
-28
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ require (
1818
github.com/google/uuid v1.3.0
1919
github.com/h2non/gock v1.2.0
2020
github.com/klauspost/cpuid/v2 v2.2.6
21-
github.com/kubewharf/katalyst-api v0.5.1-0.20240820031712-7c1239991078
21+
github.com/kubewharf/katalyst-api v0.5.1-0.20240911051124-d5c09c115a19
2222
github.com/montanaflynn/stats v0.7.1
2323
github.com/opencontainers/runc v1.1.6
2424
github.com/opencontainers/selinux v1.10.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,8 +568,8 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
568568
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
569569
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
570570
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
571-
github.com/kubewharf/katalyst-api v0.5.1-0.20240820031712-7c1239991078 h1:CSBXQOe0AzlWcGaww8uqOUDu+/4bL3hVNBz86oziOis=
572-
github.com/kubewharf/katalyst-api v0.5.1-0.20240820031712-7c1239991078/go.mod h1:Y2IeIorxQamF2a3oa0+URztl5QCSty6Jj3zD83R8J9k=
571+
github.com/kubewharf/katalyst-api v0.5.1-0.20240911051124-d5c09c115a19 h1:5kz2u+tLNzW94ByL9yfsfkvE4N8n/r6C1TKDiFWK8rw=
572+
github.com/kubewharf/katalyst-api v0.5.1-0.20240911051124-d5c09c115a19/go.mod h1:Y2IeIorxQamF2a3oa0+URztl5QCSty6Jj3zD83R8J9k=
573573
github.com/kubewharf/kubelet v1.24.6-kubewharf.9 h1:jOTYZt7h/J7I8xQMKMUcJjKf5UFBv37jHWvNp5VRFGc=
574574
github.com/kubewharf/kubelet v1.24.6-kubewharf.9/go.mod h1:MxbSZUx3wXztFneeelwWWlX7NAAStJ6expqq7gY2J3c=
575575
github.com/kyoh86/exportloopref v0.1.7/go.mod h1:h1rDl2Kdj97+Kwh4gdz3ujE7XHmH51Q0lUiZ1z4NLj8=

pkg/agent/sysadvisor/plugin/qosaware/resource/memory/advisor_test.go

Lines changed: 248 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -816,6 +816,11 @@ func TestUpdate(t *testing.T) {
816816
0: machine.MustParse("1"),
817817
1: machine.MustParse("25"),
818818
}, 200<<30),
819+
makeContainerInfo("uid4", "default", "pod4", "c4", consts.PodAnnotationQoSLevelReclaimedCores, nil,
820+
map[int]machine.CPUSet{
821+
0: machine.MustParse("1"),
822+
1: machine.MustParse("25"),
823+
}, 200<<30),
819824
},
820825
pods: []*v1.Pod{
821826
{
@@ -874,6 +879,62 @@ func TestUpdate(t *testing.T) {
874879
},
875880
},
876881
},
882+
{
883+
ObjectMeta: metav1.ObjectMeta{
884+
Name: "pod3",
885+
Namespace: "default",
886+
UID: "uid3",
887+
Annotations: map[string]string{
888+
consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
889+
},
890+
Labels: map[string]string{
891+
consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelSharedCores,
892+
},
893+
},
894+
Spec: v1.PodSpec{
895+
Containers: []v1.Container{
896+
{
897+
Name: "c3",
898+
},
899+
},
900+
},
901+
Status: v1.PodStatus{
902+
ContainerStatuses: []v1.ContainerStatus{
903+
{
904+
Name: "c3",
905+
ContainerID: "containerd://c3",
906+
},
907+
},
908+
},
909+
},
910+
{
911+
ObjectMeta: metav1.ObjectMeta{
912+
Name: "pod4",
913+
Namespace: "default",
914+
UID: "uid4",
915+
Annotations: map[string]string{
916+
consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
917+
},
918+
Labels: map[string]string{
919+
consts.PodAnnotationQoSLevelKey: consts.PodAnnotationQoSLevelReclaimedCores,
920+
},
921+
},
922+
Spec: v1.PodSpec{
923+
Containers: []v1.Container{
924+
{
925+
Name: "c4",
926+
},
927+
},
928+
},
929+
Status: v1.PodStatus{
930+
ContainerStatuses: []v1.ContainerStatus{
931+
{
932+
Name: "c4",
933+
ContainerID: "containerd://c4",
934+
},
935+
},
936+
},
937+
},
877938
},
878939
wantHeadroom: *resource.NewQuantity(996<<30, resource.DecimalSI),
879940
nodeMetrics: defaultNodeMetrics,
@@ -891,6 +952,18 @@ func TestUpdate(t *testing.T) {
891952
podUID: "uid1",
892953
containerName: "c1",
893954
},
955+
{
956+
metricName: coreconsts.MetricMemCacheContainer,
957+
metricValue: metricutil.MetricData{Value: 5 << 30},
958+
podUID: "uid1",
959+
containerName: "c1",
960+
},
961+
{
962+
metricName: coreconsts.MetricMemMappedContainer,
963+
metricValue: metricutil.MetricData{Value: 2 << 30},
964+
podUID: "uid1",
965+
containerName: "c1",
966+
},
894967
{
895968
metricName: coreconsts.MetricMemInactiveAnonContainer,
896969
metricValue: metricutil.MetricData{Value: 1 << 30},
@@ -939,9 +1012,21 @@ func TestUpdate(t *testing.T) {
9391012
podUID: "uid2",
9401013
containerName: "c2",
9411014
},
1015+
{
1016+
metricName: coreconsts.MetricMemCacheContainer,
1017+
metricValue: metricutil.MetricData{Value: 3 << 30},
1018+
podUID: "uid2",
1019+
containerName: "c2",
1020+
},
1021+
{
1022+
metricName: coreconsts.MetricMemMappedContainer,
1023+
metricValue: metricutil.MetricData{Value: 2 << 30},
1024+
podUID: "uid2",
1025+
containerName: "c2",
1026+
},
9421027
{
9431028
metricName: coreconsts.MetricMemInactiveAnonContainer,
944-
metricValue: metricutil.MetricData{Value: 1 << 30},
1029+
metricValue: metricutil.MetricData{Value: 2 << 30},
9451030
podUID: "uid2",
9461031
containerName: "c2",
9471032
},
@@ -975,6 +1060,126 @@ func TestUpdate(t *testing.T) {
9751060
podUID: "uid2",
9761061
containerName: "c2",
9771062
},
1063+
{
1064+
metricName: coreconsts.MetricMemPsiAvg60Container,
1065+
metricValue: metricutil.MetricData{Value: 0.01},
1066+
podUID: "uid3",
1067+
containerName: "c3",
1068+
},
1069+
{
1070+
metricName: coreconsts.MetricMemUsageContainer,
1071+
metricValue: metricutil.MetricData{Value: 10 << 30},
1072+
podUID: "uid3",
1073+
containerName: "c3",
1074+
},
1075+
{
1076+
metricName: coreconsts.MetricMemCacheContainer,
1077+
metricValue: metricutil.MetricData{Value: 3 << 30},
1078+
podUID: "uid3",
1079+
containerName: "c3",
1080+
},
1081+
{
1082+
metricName: coreconsts.MetricMemMappedContainer,
1083+
metricValue: metricutil.MetricData{Value: 2 << 30},
1084+
podUID: "uid3",
1085+
containerName: "c3",
1086+
},
1087+
{
1088+
metricName: coreconsts.MetricMemInactiveAnonContainer,
1089+
metricValue: metricutil.MetricData{Value: 2 << 30},
1090+
podUID: "uid3",
1091+
containerName: "c3",
1092+
},
1093+
{
1094+
metricName: coreconsts.MetricMemInactiveFileContainer,
1095+
metricValue: metricutil.MetricData{Value: 1 << 30},
1096+
podUID: "uid3",
1097+
containerName: "c3",
1098+
},
1099+
{
1100+
metricName: coreconsts.MetricMemPgscanContainer,
1101+
metricValue: metricutil.MetricData{Value: 15000},
1102+
podUID: "uid3",
1103+
containerName: "c3",
1104+
},
1105+
{
1106+
metricName: coreconsts.MetricMemPgstealContainer,
1107+
metricValue: metricutil.MetricData{Value: 10000},
1108+
podUID: "uid3",
1109+
containerName: "c3",
1110+
},
1111+
{
1112+
metricName: coreconsts.MetricMemWorkingsetRefaultContainer,
1113+
metricValue: metricutil.MetricData{Value: 1000},
1114+
podUID: "uid3",
1115+
containerName: "c3",
1116+
},
1117+
{
1118+
metricName: coreconsts.MetricMemWorkingsetActivateContainer,
1119+
metricValue: metricutil.MetricData{Value: 1000},
1120+
podUID: "uid3",
1121+
containerName: "c3",
1122+
},
1123+
{
1124+
metricName: coreconsts.MetricMemPsiAvg60Container,
1125+
metricValue: metricutil.MetricData{Value: 0.01},
1126+
podUID: "uid4",
1127+
containerName: "c4",
1128+
},
1129+
{
1130+
metricName: coreconsts.MetricMemUsageContainer,
1131+
metricValue: metricutil.MetricData{Value: 10 << 30},
1132+
podUID: "uid4",
1133+
containerName: "c4",
1134+
},
1135+
{
1136+
metricName: coreconsts.MetricMemCacheContainer,
1137+
metricValue: metricutil.MetricData{Value: 2 << 30},
1138+
podUID: "uid4",
1139+
containerName: "c4",
1140+
},
1141+
{
1142+
metricName: coreconsts.MetricMemMappedContainer,
1143+
metricValue: metricutil.MetricData{Value: 2 << 30},
1144+
podUID: "uid4",
1145+
containerName: "c4",
1146+
},
1147+
{
1148+
metricName: coreconsts.MetricMemInactiveAnonContainer,
1149+
metricValue: metricutil.MetricData{Value: 1 << 30},
1150+
podUID: "uid4",
1151+
containerName: "c4",
1152+
},
1153+
{
1154+
metricName: coreconsts.MetricMemInactiveFileContainer,
1155+
metricValue: metricutil.MetricData{Value: 1 << 30},
1156+
podUID: "uid4",
1157+
containerName: "c4",
1158+
},
1159+
{
1160+
metricName: coreconsts.MetricMemPgscanContainer,
1161+
metricValue: metricutil.MetricData{Value: 15000},
1162+
podUID: "uid4",
1163+
containerName: "c4",
1164+
},
1165+
{
1166+
metricName: coreconsts.MetricMemPgstealContainer,
1167+
metricValue: metricutil.MetricData{Value: 10000},
1168+
podUID: "uid4",
1169+
containerName: "c4",
1170+
},
1171+
{
1172+
metricName: coreconsts.MetricMemWorkingsetRefaultContainer,
1173+
metricValue: metricutil.MetricData{Value: 1000},
1174+
podUID: "uid4",
1175+
containerName: "c4",
1176+
},
1177+
{
1178+
metricName: coreconsts.MetricMemWorkingsetActivateContainer,
1179+
metricValue: metricutil.MetricData{Value: 1000},
1180+
podUID: "uid4",
1181+
containerName: "c4",
1182+
},
9781183
},
9791184
cgroupMetrics: []cgroupMetric{
9801185
{
@@ -1007,6 +1212,16 @@ func TestUpdate(t *testing.T) {
10071212
metricValue: metricutil.MetricData{Value: 4 << 30},
10081213
cgroupPath: "/hdfs",
10091214
},
1215+
{
1216+
metricName: coreconsts.MetricMemCacheCgroup,
1217+
metricValue: metricutil.MetricData{Value: 3 << 30},
1218+
cgroupPath: "/hdfs",
1219+
},
1220+
{
1221+
metricName: coreconsts.MetricMemMappedCgroup,
1222+
metricValue: metricutil.MetricData{Value: 1 << 30},
1223+
cgroupPath: "/hdfs",
1224+
},
10101225
{
10111226
metricName: coreconsts.MetricMemInactiveAnonCgroup,
10121227
metricValue: metricutil.MetricData{Value: 1 << 30},
@@ -1024,19 +1239,37 @@ func TestUpdate(t *testing.T) {
10241239
{
10251240
CgroupPath: "/hdfs",
10261241
Values: map[string]string{
1027-
string(memoryadvisor.ControlKnobKeySwapMax): coreconsts.ControlKnobON,
1242+
string(memoryadvisor.ControlKnobKeySwapMax): coreconsts.ControlKnobOFF,
10281243
string(memoryadvisor.ControlKnowKeyMemoryOffloading): "38654705",
10291244
},
10301245
},
10311246
},
1032-
ContainerEntries: []types.ContainerMemoryAdvices{{
1033-
PodUID: "uid1",
1034-
ContainerName: "c1",
1035-
Values: map[string]string{
1036-
string(memoryadvisor.ControlKnobKeySwapMax): coreconsts.ControlKnobON,
1037-
string(memoryadvisor.ControlKnowKeyMemoryOffloading): "96636764",
1247+
ContainerEntries: []types.ContainerMemoryAdvices{
1248+
{
1249+
PodUID: "uid1",
1250+
ContainerName: "c1",
1251+
Values: map[string]string{
1252+
string(memoryadvisor.ControlKnobKeySwapMax): coreconsts.ControlKnobOFF,
1253+
string(memoryadvisor.ControlKnowKeyMemoryOffloading): "96636764",
1254+
},
10381255
},
1039-
}},
1256+
{
1257+
PodUID: "uid3",
1258+
ContainerName: "c3",
1259+
Values: map[string]string{
1260+
string(memoryadvisor.ControlKnobKeySwapMax): coreconsts.ControlKnobON,
1261+
string(memoryadvisor.ControlKnowKeyMemoryOffloading): "96636764",
1262+
},
1263+
},
1264+
//{
1265+
// PodUID: "uid4",
1266+
// ContainerName: "c4",
1267+
// Values: map[string]string{
1268+
// string(memoryadvisor.ControlKnobKeySwapMax): coreconsts.ControlKnobOFF,
1269+
// string(memoryadvisor.ControlKnowKeyMemoryOffloading): "96636764",
1270+
// },
1271+
//},
1272+
},
10401273
},
10411274
},
10421275
{
@@ -2226,12 +2459,15 @@ func TestUpdate(t *testing.T) {
22262459
transparentMemoryOffloadingConfiguration := tmo.NewTransparentMemoryOffloadingConfiguration()
22272460
transparentMemoryOffloadingConfiguration.QoSLevelConfigs[consts.QoSLevelReclaimedCores] = tmo.NewTMOConfigDetail(transparentMemoryOffloadingConfiguration.DefaultConfigurations)
22282461
transparentMemoryOffloadingConfiguration.QoSLevelConfigs[consts.QoSLevelReclaimedCores].EnableTMO = true
2229-
transparentMemoryOffloadingConfiguration.QoSLevelConfigs[consts.QoSLevelReclaimedCores].EnableSwap = true
2462+
transparentMemoryOffloadingConfiguration.QoSLevelConfigs[consts.QoSLevelReclaimedCores].EnableSwap = false
2463+
transparentMemoryOffloadingConfiguration.QoSLevelConfigs[consts.QoSLevelSharedCores] = tmo.NewTMOConfigDetail(transparentMemoryOffloadingConfiguration.DefaultConfigurations)
2464+
transparentMemoryOffloadingConfiguration.QoSLevelConfigs[consts.QoSLevelSharedCores].EnableTMO = true
2465+
transparentMemoryOffloadingConfiguration.QoSLevelConfigs[consts.QoSLevelSharedCores].EnableSwap = true
22302466

22312467
// cgroup level
22322468
transparentMemoryOffloadingConfiguration.CgroupConfigs["/sys/fs/cgroup/hdfs"] = tmo.NewTMOConfigDetail(transparentMemoryOffloadingConfiguration.DefaultConfigurations)
22332469
transparentMemoryOffloadingConfiguration.CgroupConfigs["/sys/fs/cgroup/hdfs"].EnableTMO = true
2234-
transparentMemoryOffloadingConfiguration.CgroupConfigs["/sys/fs/cgroup/hdfs"].EnableSwap = true
2470+
transparentMemoryOffloadingConfiguration.CgroupConfigs["/sys/fs/cgroup/hdfs"].EnableSwap = false
22352471

22362472
advisor.conf.GetDynamicConfiguration().TransparentMemoryOffloadingConfiguration = transparentMemoryOffloadingConfiguration
22372473
_, advisorRecvChInterface := advisor.GetChannels()
@@ -2256,7 +2492,7 @@ func TestUpdate(t *testing.T) {
22562492
ctx, cancel := context.WithCancel(context.Background())
22572493
advisor.Run(ctx)
22582494

2259-
time.Sleep(10 * time.Millisecond) // Wait some time because no signal will be sent to channel
2495+
time.Sleep(100 * time.Millisecond) // Wait some time because no signal will be sent to channel
22602496
if tt.needRecvAdvices {
22612497
result := <-recvCh
22622498

0 commit comments

Comments
 (0)