You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: balancer.go
    path of file: ./repos/tidb/pkg/disttask/framework/scheduler
    
    the code of the file until where you have to start completion: // Copyright 2023 PingCAP, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     htt
    
func (b *balancer) balance(ctx context.Context, sm *Manager) {
	// we will use currUsedSlots to calculate adjusted eligible nodes during balance,
	// it's initial value depends on the managed nodes, to have a consistent view,
	// DO NOT call getManagedNodes twice during 1 balance.
	managedNodes := b.nodeMgr.getManagedNodes()
	b.currUsedSlots = make(map[string]int, len(managedNodes))
	for _, n := range managedNodes {
		b.currUsedSlots[n] = 0
	}

	schedulers := sm.getSchedulers()
	for _, sch := range schedulers {
		if err := b.balanceSubtasks(ctx, sch, managedNodes); err != nil {
			b.logger.Warn("failed to balance subtasks",
				zap.Int64("task-id", sch.GetTask().ID), llog.ShortError(err))
			return
		}
	}
}