Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge tag 'memblock-v6.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock

Pull memblock updates from Mike Rapoport:
"Small optimizations:

- fix off-by-one in the check whether memblock_add_range() should
reallocate memory to accommodate newly inserted range

- check only for relevant regions in memblock_merge_regions() rather
than swipe over the entire array"

* tag 'memblock-v6.3-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/rppt/memblock:
memblock: Avoid useless checks in memblock_merge_regions().
memblock: Make a boundary tighter in memblock_add_range().

+27 -14
+27 -14
mm/memblock.c
··· 500 500 /** 501 501 * memblock_merge_regions - merge neighboring compatible regions 502 502 * @type: memblock type to scan 503 - * 504 - * Scan @type and merge neighboring compatible regions. 503 + * @start_rgn: start scanning from (@start_rgn - 1) 504 + * @end_rgn: end scanning at (@end_rgn - 1) 505 + * Scan @type and merge neighboring compatible regions in [@start_rgn - 1, @end_rgn) 505 506 */ 506 - static void __init_memblock memblock_merge_regions(struct memblock_type *type) 507 + static void __init_memblock memblock_merge_regions(struct memblock_type *type, 508 + unsigned long start_rgn, 509 + unsigned long end_rgn) 507 510 { 508 511 int i = 0; 509 - 510 - /* cnt never goes below 1 */ 511 - while (i < type->cnt - 1) { 512 + if (start_rgn) 513 + i = start_rgn - 1; 514 + end_rgn = min(end_rgn, type->cnt - 1); 515 + while (i < end_rgn) { 512 516 struct memblock_region *this = &type->regions[i]; 513 517 struct memblock_region *next = &type->regions[i + 1]; 514 518 ··· 529 525 /* move forward from next + 1, index of which is i + 2 */ 530 526 memmove(next, next + 1, (type->cnt - (i + 2)) * sizeof(*next)); 531 527 type->cnt--; 528 + end_rgn--; 532 529 } 533 530 } 534 531 ··· 586 581 bool insert = false; 587 582 phys_addr_t obase = base; 588 583 phys_addr_t end = base + memblock_cap_size(base, &size); 589 - int idx, nr_new; 584 + int idx, nr_new, start_rgn = -1, end_rgn; 590 585 struct memblock_region *rgn; 591 586 592 587 if (!size) ··· 606 601 /* 607 602 * The worst case is when new range overlaps all existing regions, 608 603 * then we'll need type->cnt + 1 empty regions in @type. So if 609 - * type->cnt * 2 + 1 is less than type->max, we know 604 + * type->cnt * 2 + 1 is less than or equal to type->max, we know 610 605 * that there is enough empty regions in @type, and we can insert 611 606 * regions directly. 612 607 */ 613 - if (type->cnt * 2 + 1 < type->max) 608 + if (type->cnt * 2 + 1 <= type->max) 614 609 insert = true; 615 610 616 611 repeat: ··· 640 635 #endif 641 636 WARN_ON(flags != rgn->flags); 642 637 nr_new++; 643 - if (insert) 638 + if (insert) { 639 + if (start_rgn == -1) 640 + start_rgn = idx; 641 + end_rgn = idx + 1; 644 642 memblock_insert_region(type, idx++, base, 645 643 rbase - base, nid, 646 644 flags); 645 + } 647 646 } 648 647 /* area below @rend is dealt with, forget about it */ 649 648 base = min(rend, end); ··· 656 647 /* insert the remaining portion */ 657 648 if (base < end) { 658 649 nr_new++; 659 - if (insert) 650 + if (insert) { 651 + if (start_rgn == -1) 652 + start_rgn = idx; 653 + end_rgn = idx + 1; 660 654 memblock_insert_region(type, idx, base, end - base, 661 655 nid, flags); 656 + } 662 657 } 663 658 664 659 if (!nr_new) ··· 679 666 insert = true; 680 667 goto repeat; 681 668 } else { 682 - memblock_merge_regions(type); 669 + memblock_merge_regions(type, start_rgn, end_rgn); 683 670 return 0; 684 671 } 685 672 } ··· 915 902 r->flags &= ~flag; 916 903 } 917 904 918 - memblock_merge_regions(type); 905 + memblock_merge_regions(type, start_rgn, end_rgn); 919 906 return 0; 920 907 } 921 908 ··· 1288 1275 for (i = start_rgn; i < end_rgn; i++) 1289 1276 memblock_set_region_node(&type->regions[i], nid); 1290 1277 1291 - memblock_merge_regions(type); 1278 + memblock_merge_regions(type, start_rgn, end_rgn); 1292 1279 #endif 1293 1280 return 0; 1294 1281 }