@@ -670,10 +670,11 @@ func (p *policy) compareScores(request Request, pools []Node, scores map[int]Sco
670670 //
671671 // - insufficient isolated, reserved or shared capacity loses
672672 // - if we have affinity, the higher affinity score wins
673- // - if only one node matches the memory type request, it wins
674673 // - if we have topology hints
675674 // * better hint score wins
676675 // * for a tie, prefer the lower node then the smaller id
676+ // - if we have a better matching or tighter fitting memory offer, it wins
677+ // - if only one node matches the memory type request, it wins
677678 // - for low-prio and high-prio CPU preference, if only one node has such CPUs, it wins
678679 // - if a node is lower in the tree it wins
679680 // - for reserved allocations
@@ -722,6 +723,55 @@ func (p *policy) compareScores(request Request, pools []Node, scores map[int]Sco
722723
723724 log .Debug (" - affinity is a TIE" )
724725
726+ // better topology hint score wins
727+ hScores1 := score1 .HintScores ()
728+ if len (hScores1 ) > 0 {
729+ hScores2 := score2 .HintScores ()
730+ hs1 , nz1 := combineHintScores (hScores1 )
731+ hs2 , nz2 := combineHintScores (hScores2 )
732+
733+ if hs1 > hs2 {
734+ log .Debug (" => %s WINS on hints" , node1 .Name ())
735+ return true
736+ }
737+ if hs2 > hs1 {
738+ log .Debug (" => %s WINS on hints" , node2 .Name ())
739+ return false
740+ }
741+
742+ log .Debug (" - hints are a TIE" )
743+
744+ if hs1 == 0 {
745+ if nz1 > nz2 {
746+ log .Debug (" => %s WINS on non-zero hints" , node1 .Name ())
747+ return true
748+ }
749+ if nz2 > nz1 {
750+ log .Debug (" => %s WINS on non-zero hints" , node2 .Name ())
751+ return false
752+ }
753+
754+ log .Debug (" - non-zero hints are a TIE" )
755+ }
756+
757+ // for a tie, prefer lower nodes and smaller ids
758+ if hs1 == hs2 && nz1 == nz2 && (hs1 != 0 || nz1 != 0 ) {
759+ if depth1 > depth2 {
760+ log .Debug (" => %s WINS as it is lower" , node1 .Name ())
761+ return true
762+ }
763+ if depth1 < depth2 {
764+ log .Debug (" => %s WINS as it is lower" , node2 .Name ())
765+ return false
766+ }
767+
768+ log .Debug (" => %s WINS based on equal hint socres, lower id" ,
769+ map [bool ]string {true : node1 .Name (), false : node2 .Name ()}[id1 < id2 ])
770+
771+ return id1 < id2
772+ }
773+ }
774+
725775 // better matching or tighter memory offer wins
726776 switch {
727777 case o1 != nil && o2 == nil :
@@ -789,55 +839,6 @@ func (p *policy) compareScores(request Request, pools []Node, scores map[int]Sco
789839 log .Debug (" - memory type is a TIE" )
790840 }
791841
792- // better topology hint score wins
793- hScores1 := score1 .HintScores ()
794- if len (hScores1 ) > 0 {
795- hScores2 := score2 .HintScores ()
796- hs1 , nz1 := combineHintScores (hScores1 )
797- hs2 , nz2 := combineHintScores (hScores2 )
798-
799- if hs1 > hs2 {
800- log .Debug (" => %s WINS on hints" , node1 .Name ())
801- return true
802- }
803- if hs2 > hs1 {
804- log .Debug (" => %s WINS on hints" , node2 .Name ())
805- return false
806- }
807-
808- log .Debug (" - hints are a TIE" )
809-
810- if hs1 == 0 {
811- if nz1 > nz2 {
812- log .Debug (" => %s WINS on non-zero hints" , node1 .Name ())
813- return true
814- }
815- if nz2 > nz1 {
816- log .Debug (" => %s WINS on non-zero hints" , node2 .Name ())
817- return false
818- }
819-
820- log .Debug (" - non-zero hints are a TIE" )
821- }
822-
823- // for a tie, prefer lower nodes and smaller ids
824- if hs1 == hs2 && nz1 == nz2 && (hs1 != 0 || nz1 != 0 ) {
825- if depth1 > depth2 {
826- log .Debug (" => %s WINS as it is lower" , node1 .Name ())
827- return true
828- }
829- if depth1 < depth2 {
830- log .Debug (" => %s WINS as it is lower" , node2 .Name ())
831- return false
832- }
833-
834- log .Debug (" => %s WINS based on equal hint socres, lower id" ,
835- map [bool ]string {true : node1 .Name (), false : node2 .Name ()}[id1 < id2 ])
836-
837- return id1 < id2
838- }
839- }
840-
841842 // for low-prio and high-prio CPU preference, the only fulfilling node wins
842843 log .Debug (" - preferred CPU priority is %s" , request .CPUPrio ())
843844 switch request .CPUPrio () {
0 commit comments