In tvheadend, each channel can have more services which are usually on different tuners (called adapters).
Each recording or live stream for such a channel tries to create a so called subscription to a service by iterating over all available services, which are mapped to the channel. This subscription has a weight assigned, which is calculated for example from the recording priority.
If there is already a service for the desired channel running, of course this service is choosen. Otherwise, by iterating over the available services in a first run, tvheadend tries to create a subscription with lowest priority. This means, it tries to find an available mux respectively a free adapter where it can hang on to without disturbing existing subscriptions.
If this is not possible, then in a second run, going over the mapped services, the maximum weight for existing subscriptions is calculated and compared with the new to be created subscription. Does the new subscription have the highest weight, the adapter is retuned.
HTH,
Martin