When the number of sub-channels offered by Hyper-V is >= the number of CPUs in the VM, calculate the correct number of sub-channels. The current code produces one too many. This scenario arises only when the number of CPUs is artificially restricted (for example, with maxcpus=<n> on the kernel boot line), because Hyper-V normally offers a sub-channel count < number of CPUs. While the current code doesn't break, the extra sub-channel is unbalanced across the CPUs (for example, a total of 5 channels on a VM with 4 CPUs).
Unified · Split
| @@ -668,13 +668,22 @@ static void handle_multichannel_storage(struct hv_device *device, int max_chns) · 667 unmodified lines | |||
| 668 | { | 668 | { |
| 669 | struct device *dev = &device->device; | 669 | struct device *dev = &device->device; |
| 670 | struct storvsc_device *stor_device; | 670 | struct storvsc_device *stor_device; |
| 671 | int num_cpus = num_online_cpus(); | ||
| 672 | int num_sc; | 671 | int num_sc; |
| 673 | struct storvsc_cmd_request *request; | 672 | struct storvsc_cmd_request *request; |
| 674 | struct vstor_packet *vstor_packet; | 673 | struct vstor_packet *vstor_packet; |
| 675 | int ret, t; | 674 | int ret, t; |
| 676 | 675 | ||
| 677 | num_sc = ((max_chns > num_cpus) ? num_cpus : max_chns); | 676 | /* |
| 677 | * If the number of CPUs is artificially restricted, such as | ||
| 678 | * with maxcpus=1 on the kernel boot line, Hyper-V could offer | ||
| 679 | * sub-channels >= the number of CPUs. These sub-channels | ||
| 680 | * should not be created. The primary channel is already created | ||
| 681 | * and assigned to one CPU, so check against # CPUs - 1. | ||
| 682 | */ | ||
| 683 | num_sc = min((int)(num_online_cpus() - 1), max_chns); | ||
| 684 | if (!num_sc) | ||
| 685 | return; | ||
| 686 | |||
| 678 | stor_device = get_out_stor_device(device); | 687 | stor_device = get_out_stor_device(device); |
| 679 | if (!stor_device) | 688 | if (!stor_device) |
| 680 | return; | 689 | return; |