1 @@ -50,6 +50,7 @@ 2 struct list_head *a, struct list_head *b) 3 { 4 struct list_head *tail = head; 5 + u8 count = 0; 6 7 for (;;) { 8 /* if equal, take 'a' -- important for sort stability */ 9 @@ -75,6 +76,15 @@ 10 /* Finish linking remainder of list b on to tail */ 11 tail->next = b; 12 do { 13 + /* 14 + * If the merge is highly unbalanced (e.g. the input is 15 + * already sorted), this loop may run many iterations. 16 + * Continue callbacks to the client even though no 17 + * element comparison is needed, so the client's cmp() 18 + * routine can invoke cond_resched() periodically. 19 + */ 20 + if (unlikely(!++count)) 21 + cmp(priv, b, b); 22 b->prev = tail; 23 tail = b; 24 b = b->next; 25