1 // SPDX-License-Identifier: GPL-2.0-or-later
3 #include <linux/memblock.h>
6 #define EXPECTED_MEMBLOCK_REGIONS 128
7 #define FUNC_ADD "memblock_add"
8 #define FUNC_RESERVE "memblock_reserve"
9 #define FUNC_REMOVE "memblock_remove"
10 #define FUNC_FREE "memblock_free"
11 #define FUNC_TRIM "memblock_trim_memory"
13 static int memblock_initialization_check(void)
17 ASSERT_NE(memblock.memory.regions, NULL);
18 ASSERT_EQ(memblock.memory.cnt, 1);
19 ASSERT_EQ(memblock.memory.max, EXPECTED_MEMBLOCK_REGIONS);
20 ASSERT_EQ(strcmp(memblock.memory.name, "memory"), 0);
22 ASSERT_NE(memblock.reserved.regions, NULL);
23 ASSERT_EQ(memblock.reserved.cnt, 1);
24 ASSERT_EQ(memblock.memory.max, EXPECTED_MEMBLOCK_REGIONS);
25 ASSERT_EQ(strcmp(memblock.reserved.name, "reserved"), 0);
27 ASSERT_EQ(memblock.bottom_up, false);
28 ASSERT_EQ(memblock.current_limit, MEMBLOCK_ALLOC_ANYWHERE);
36 * A simple test that adds a memory block of a specified base address
37 * and size to the collection of available memory regions (memblock.memory).
38 * Expect to create a new entry. The region counter and total memory get
41 static int memblock_add_simple_check(void)
43 struct memblock_region *rgn;
45 rgn = &memblock.memory.regions[0];
54 reset_memblock_regions();
55 memblock_add(r.base, r.size);
57 ASSERT_EQ(rgn->base, r.base);
58 ASSERT_EQ(rgn->size, r.size);
60 ASSERT_EQ(memblock.memory.cnt, 1);
61 ASSERT_EQ(memblock.memory.total_size, r.size);
69 * A simple test that adds a memory block of a specified base address, size,
70 * NUMA node and memory flags to the collection of available memory regions.
71 * Expect to create a new entry. The region counter and total memory get
74 static int memblock_add_node_simple_check(void)
76 struct memblock_region *rgn;
78 rgn = &memblock.memory.regions[0];
87 reset_memblock_regions();
88 memblock_add_node(r.base, r.size, 1, MEMBLOCK_HOTPLUG);
90 ASSERT_EQ(rgn->base, r.base);
91 ASSERT_EQ(rgn->size, r.size);
93 ASSERT_EQ(rgn->nid, 1);
95 ASSERT_EQ(rgn->flags, MEMBLOCK_HOTPLUG);
97 ASSERT_EQ(memblock.memory.cnt, 1);
98 ASSERT_EQ(memblock.memory.total_size, r.size);
106 * A test that tries to add two memory blocks that don't overlap with one
109 * | +--------+ +--------+ |
111 * +--------+--------+--------+--------+--+
113 * Expect to add two correctly initialized entries to the collection of
114 * available memory regions (memblock.memory). The total size and
115 * region counter fields get updated.
117 static int memblock_add_disjoint_check(void)
119 struct memblock_region *rgn1, *rgn2;
121 rgn1 = &memblock.memory.regions[0];
122 rgn2 = &memblock.memory.regions[1];
129 .base = SZ_1G + SZ_16K,
135 reset_memblock_regions();
136 memblock_add(r1.base, r1.size);
137 memblock_add(r2.base, r2.size);
139 ASSERT_EQ(rgn1->base, r1.base);
140 ASSERT_EQ(rgn1->size, r1.size);
142 ASSERT_EQ(rgn2->base, r2.base);
143 ASSERT_EQ(rgn2->size, r2.size);
145 ASSERT_EQ(memblock.memory.cnt, 2);
146 ASSERT_EQ(memblock.memory.total_size, r1.size + r2.size);
154 * A test that tries to add two memory blocks r1 and r2, where r2 overlaps
155 * with the beginning of r1 (that is r1.base < r2.base + r2.size):
157 * | +----+----+------------+ |
159 * +----+----+----+------------+----------+
166 * Expect to merge the two entries into one region that starts at r2.base
167 * and has size of two regions minus their intersection. The total size of
168 * the available memory is updated, and the region counter stays the same.
170 static int memblock_add_overlap_top_check(void)
172 struct memblock_region *rgn;
173 phys_addr_t total_size;
175 rgn = &memblock.memory.regions[0];
188 total_size = (r1.base - r2.base) + r1.size;
190 reset_memblock_regions();
191 memblock_add(r1.base, r1.size);
192 memblock_add(r2.base, r2.size);
194 ASSERT_EQ(rgn->base, r2.base);
195 ASSERT_EQ(rgn->size, total_size);
197 ASSERT_EQ(memblock.memory.cnt, 1);
198 ASSERT_EQ(memblock.memory.total_size, total_size);
206 * A test that tries to add two memory blocks r1 and r2, where r2 overlaps
207 * with the end of r1 (that is r2.base < r1.base + r1.size):
209 * | +--+------+----------+ |
211 * +--+--+------+----------+--------------+
218 * Expect to merge the two entries into one region that starts at r1.base
219 * and has size of two regions minus their intersection. The total size of
220 * the available memory is updated, and the region counter stays the same.
222 static int memblock_add_overlap_bottom_check(void)
224 struct memblock_region *rgn;
225 phys_addr_t total_size;
227 rgn = &memblock.memory.regions[0];
240 total_size = (r2.base - r1.base) + r2.size;
242 reset_memblock_regions();
243 memblock_add(r1.base, r1.size);
244 memblock_add(r2.base, r2.size);
246 ASSERT_EQ(rgn->base, r1.base);
247 ASSERT_EQ(rgn->size, total_size);
249 ASSERT_EQ(memblock.memory.cnt, 1);
250 ASSERT_EQ(memblock.memory.total_size, total_size);
258 * A test that tries to add two memory blocks r1 and r2, where r2 is
259 * within the range of r1 (that is r1.base < r2.base &&
260 * r2.base + r2.size < r1.base + r1.size):
262 * | +-------+--+-----------------------+
264 * +---+-------+--+-----------------------+
269 * Expect to merge two entries into one region that stays the same.
270 * The counter and total size of available memory are not updated.
272 static int memblock_add_within_check(void)
274 struct memblock_region *rgn;
276 rgn = &memblock.memory.regions[0];
289 reset_memblock_regions();
290 memblock_add(r1.base, r1.size);
291 memblock_add(r2.base, r2.size);
293 ASSERT_EQ(rgn->base, r1.base);
294 ASSERT_EQ(rgn->size, r1.size);
296 ASSERT_EQ(memblock.memory.cnt, 1);
297 ASSERT_EQ(memblock.memory.total_size, r1.size);
305 * A simple test that tries to add the same memory block twice. Expect
306 * the counter and total size of available memory to not be updated.
308 static int memblock_add_twice_check(void)
317 reset_memblock_regions();
319 memblock_add(r.base, r.size);
320 memblock_add(r.base, r.size);
322 ASSERT_EQ(memblock.memory.cnt, 1);
323 ASSERT_EQ(memblock.memory.total_size, r.size);
331 * A test that tries to add two memory blocks that don't overlap with one
332 * another and then add a third memory block in the space between the first two:
334 * | +--------+--------+--------+ |
335 * | | r1 | r3 | r2 | |
336 * +--------+--------+--------+--------+--+
338 * Expect to merge the three entries into one region that starts at r1.base
339 * and has size of r1.size + r2.size + r3.size. The region counter and total
340 * size of the available memory are updated.
342 static int memblock_add_between_check(void)
344 struct memblock_region *rgn;
345 phys_addr_t total_size;
347 rgn = &memblock.memory.regions[0];
354 .base = SZ_1G + SZ_16K,
358 .base = SZ_1G + SZ_8K,
364 total_size = r1.size + r2.size + r3.size;
366 reset_memblock_regions();
367 memblock_add(r1.base, r1.size);
368 memblock_add(r2.base, r2.size);
369 memblock_add(r3.base, r3.size);
371 ASSERT_EQ(rgn->base, r1.base);
372 ASSERT_EQ(rgn->size, total_size);
374 ASSERT_EQ(memblock.memory.cnt, 1);
375 ASSERT_EQ(memblock.memory.total_size, total_size);
383 * A simple test that tries to add a memory block r when r extends past
391 * +----------------------------+----+
393 * Expect to add a memory block of size PHYS_ADDR_MAX - r.base. Expect the
394 * total size of available memory and the counter to be updated.
396 static int memblock_add_near_max_check(void)
398 struct memblock_region *rgn;
399 phys_addr_t total_size;
401 rgn = &memblock.memory.regions[0];
404 .base = PHYS_ADDR_MAX - SZ_1M,
410 total_size = PHYS_ADDR_MAX - r.base;
412 reset_memblock_regions();
413 memblock_add(r.base, r.size);
415 ASSERT_EQ(rgn->base, r.base);
416 ASSERT_EQ(rgn->size, total_size);
418 ASSERT_EQ(memblock.memory.cnt, 1);
419 ASSERT_EQ(memblock.memory.total_size, total_size);
427 * A test that trying to add the 129th memory block.
428 * Expect to trigger memblock_double_array() to double the
429 * memblock.memory.max, find a new valid memory as
432 static int memblock_add_many_check(void)
440 phys_addr_t new_memory_regions_size;
441 phys_addr_t base, size = SZ_64;
442 phys_addr_t gap_size = SZ_64;
446 reset_memblock_regions();
447 memblock_allow_resize();
449 dummy_physical_memory_init();
451 * We allocated enough memory by using dummy_physical_memory_init(), and
452 * split it into small block. First we split a large enough memory block
453 * as the memory region which will be choosed by memblock_double_array().
455 base = PAGE_ALIGN(dummy_physical_memory_base());
456 new_memory_regions_size = PAGE_ALIGN(INIT_MEMBLOCK_REGIONS * 2 *
457 sizeof(struct memblock_region));
458 memblock_add(base, new_memory_regions_size);
460 /* This is the base of small memory block. */
461 base += new_memory_regions_size + gap_size;
463 orig_region = memblock.memory.regions;
465 for (i = 0; i < INIT_MEMBLOCK_REGIONS; i++) {
467 * Add these small block to fulfill the memblock. We keep a
468 * gap between the nearby memory to avoid being merged.
470 memblock_add(base, size);
471 base += size + gap_size;
473 ASSERT_EQ(memblock.memory.cnt, i + 2);
474 ASSERT_EQ(memblock.memory.total_size, new_memory_regions_size +
479 * At there, memblock_double_array() has been succeed, check if it
480 * update the memory.max.
482 ASSERT_EQ(memblock.memory.max, INIT_MEMBLOCK_REGIONS * 2);
484 /* memblock_double_array() will reserve the memory it used. Check it. */
485 ASSERT_EQ(memblock.reserved.cnt, 1);
486 ASSERT_EQ(memblock.reserved.total_size, new_memory_regions_size);
489 * Now memblock_double_array() works fine. Let's check after the
490 * double_array(), the memblock_add() still works as normal.
492 memblock_add(r.base, r.size);
493 ASSERT_EQ(memblock.memory.regions[0].base, r.base);
494 ASSERT_EQ(memblock.memory.regions[0].size, r.size);
496 ASSERT_EQ(memblock.memory.cnt, INIT_MEMBLOCK_REGIONS + 2);
497 ASSERT_EQ(memblock.memory.total_size, INIT_MEMBLOCK_REGIONS * size +
498 new_memory_regions_size +
500 ASSERT_EQ(memblock.memory.max, INIT_MEMBLOCK_REGIONS * 2);
502 dummy_physical_memory_cleanup();
505 * The current memory.regions is occupying a range of memory that
506 * allocated from dummy_physical_memory_init(). After free the memory,
507 * we must not use it. So restore the origin memory region to make sure
508 * the tests can run as normal and not affected by the double array.
510 memblock.memory.regions = orig_region;
511 memblock.memory.cnt = INIT_MEMBLOCK_REGIONS;
518 static int memblock_add_checks(void)
521 prefix_push(FUNC_ADD);
522 test_print("Running %s tests...\n", FUNC_ADD);
524 memblock_add_simple_check();
525 memblock_add_node_simple_check();
526 memblock_add_disjoint_check();
527 memblock_add_overlap_top_check();
528 memblock_add_overlap_bottom_check();
529 memblock_add_within_check();
530 memblock_add_twice_check();
531 memblock_add_between_check();
532 memblock_add_near_max_check();
533 memblock_add_many_check();
541 * A simple test that marks a memory block of a specified base address
542 * and size as reserved and to the collection of reserved memory regions
543 * (memblock.reserved). Expect to create a new entry. The region counter
544 * and total memory size are updated.
546 static int memblock_reserve_simple_check(void)
548 struct memblock_region *rgn;
550 rgn = &memblock.reserved.regions[0];
559 reset_memblock_regions();
560 memblock_reserve(r.base, r.size);
562 ASSERT_EQ(rgn->base, r.base);
563 ASSERT_EQ(rgn->size, r.size);
571 * A test that tries to mark two memory blocks that don't overlap as reserved:
573 * | +--+ +----------------+ |
575 * +--------+--+------+----------------+--+
577 * Expect to add two entries to the collection of reserved memory regions
578 * (memblock.reserved). The total size and region counter for
579 * memblock.reserved are updated.
581 static int memblock_reserve_disjoint_check(void)
583 struct memblock_region *rgn1, *rgn2;
585 rgn1 = &memblock.reserved.regions[0];
586 rgn2 = &memblock.reserved.regions[1];
599 reset_memblock_regions();
600 memblock_reserve(r1.base, r1.size);
601 memblock_reserve(r2.base, r2.size);
603 ASSERT_EQ(rgn1->base, r1.base);
604 ASSERT_EQ(rgn1->size, r1.size);
606 ASSERT_EQ(rgn2->base, r2.base);
607 ASSERT_EQ(rgn2->size, r2.size);
609 ASSERT_EQ(memblock.reserved.cnt, 2);
610 ASSERT_EQ(memblock.reserved.total_size, r1.size + r2.size);
618 * A test that tries to mark two memory blocks r1 and r2 as reserved,
619 * where r2 overlaps with the beginning of r1 (that is
620 * r1.base < r2.base + r2.size):
622 * | +--------------+--+--------------+ |
624 * +--+--------------+--+--------------+--+
631 * Expect to merge two entries into one region that starts at r2.base and
632 * has size of two regions minus their intersection. The total size of the
633 * reserved memory is updated, and the region counter is not updated.
635 static int memblock_reserve_overlap_top_check(void)
637 struct memblock_region *rgn;
638 phys_addr_t total_size;
640 rgn = &memblock.reserved.regions[0];
653 total_size = (r1.base - r2.base) + r1.size;
655 reset_memblock_regions();
656 memblock_reserve(r1.base, r1.size);
657 memblock_reserve(r2.base, r2.size);
659 ASSERT_EQ(rgn->base, r2.base);
660 ASSERT_EQ(rgn->size, total_size);
662 ASSERT_EQ(memblock.reserved.cnt, 1);
663 ASSERT_EQ(memblock.reserved.total_size, total_size);
671 * A test that tries to mark two memory blocks r1 and r2 as reserved,
672 * where r2 overlaps with the end of r1 (that is
673 * r2.base < r1.base + r1.size):
675 * | +--------------+--+--------------+ |
677 * +--+--------------+--+--------------+--+
684 * Expect to merge two entries into one region that starts at r1.base and
685 * has size of two regions minus their intersection. The total size of the
686 * reserved memory is updated, and the region counter is not updated.
688 static int memblock_reserve_overlap_bottom_check(void)
690 struct memblock_region *rgn;
691 phys_addr_t total_size;
693 rgn = &memblock.reserved.regions[0];
706 total_size = (r2.base - r1.base) + r2.size;
708 reset_memblock_regions();
709 memblock_reserve(r1.base, r1.size);
710 memblock_reserve(r2.base, r2.size);
712 ASSERT_EQ(rgn->base, r1.base);
713 ASSERT_EQ(rgn->size, total_size);
715 ASSERT_EQ(memblock.reserved.cnt, 1);
716 ASSERT_EQ(memblock.reserved.total_size, total_size);
724 * A test that tries to mark two memory blocks r1 and r2 as reserved,
725 * where r2 is within the range of r1 (that is
726 * (r1.base < r2.base) && (r2.base + r2.size < r1.base + r1.size)):
728 * | +-----+--+---------------------------|
730 * +-+-----+--+---------------------------+
737 * Expect to merge two entries into one region that stays the same. The
738 * counter and total size of available memory are not updated.
740 static int memblock_reserve_within_check(void)
742 struct memblock_region *rgn;
744 rgn = &memblock.reserved.regions[0];
757 reset_memblock_regions();
758 memblock_reserve(r1.base, r1.size);
759 memblock_reserve(r2.base, r2.size);
761 ASSERT_EQ(rgn->base, r1.base);
762 ASSERT_EQ(rgn->size, r1.size);
764 ASSERT_EQ(memblock.reserved.cnt, 1);
765 ASSERT_EQ(memblock.reserved.total_size, r1.size);
773 * A simple test that tries to reserve the same memory block twice.
774 * Expect the region counter and total size of reserved memory to not
777 static int memblock_reserve_twice_check(void)
786 reset_memblock_regions();
788 memblock_reserve(r.base, r.size);
789 memblock_reserve(r.base, r.size);
791 ASSERT_EQ(memblock.reserved.cnt, 1);
792 ASSERT_EQ(memblock.reserved.total_size, r.size);
800 * A test that tries to mark two memory blocks that don't overlap as reserved
801 * and then reserve a third memory block in the space between the first two:
803 * | +--------+--------+--------+ |
804 * | | r1 | r3 | r2 | |
805 * +--------+--------+--------+--------+--+
807 * Expect to merge the three entries into one reserved region that starts at
808 * r1.base and has size of r1.size + r2.size + r3.size. The region counter and
809 * total for memblock.reserved are updated.
811 static int memblock_reserve_between_check(void)
813 struct memblock_region *rgn;
814 phys_addr_t total_size;
816 rgn = &memblock.reserved.regions[0];
823 .base = SZ_1G + SZ_16K,
827 .base = SZ_1G + SZ_8K,
833 total_size = r1.size + r2.size + r3.size;
835 reset_memblock_regions();
836 memblock_reserve(r1.base, r1.size);
837 memblock_reserve(r2.base, r2.size);
838 memblock_reserve(r3.base, r3.size);
840 ASSERT_EQ(rgn->base, r1.base);
841 ASSERT_EQ(rgn->size, total_size);
843 ASSERT_EQ(memblock.reserved.cnt, 1);
844 ASSERT_EQ(memblock.reserved.total_size, total_size);
852 * A simple test that tries to reserve a memory block r when r extends past
860 * +----------------------------+----+
862 * Expect to reserve a memory block of size PHYS_ADDR_MAX - r.base. Expect the
863 * total size of reserved memory and the counter to be updated.
865 static int memblock_reserve_near_max_check(void)
867 struct memblock_region *rgn;
868 phys_addr_t total_size;
870 rgn = &memblock.reserved.regions[0];
873 .base = PHYS_ADDR_MAX - SZ_1M,
879 total_size = PHYS_ADDR_MAX - r.base;
881 reset_memblock_regions();
882 memblock_reserve(r.base, r.size);
884 ASSERT_EQ(rgn->base, r.base);
885 ASSERT_EQ(rgn->size, total_size);
887 ASSERT_EQ(memblock.reserved.cnt, 1);
888 ASSERT_EQ(memblock.reserved.total_size, total_size);
896 * A test that trying to reserve the 129th memory block.
897 * Expect to trigger memblock_double_array() to double the
898 * memblock.memory.max, find a new valid memory as
901 static int memblock_reserve_many_check(void)
909 phys_addr_t memory_base = SZ_128K;
910 phys_addr_t new_reserved_regions_size;
914 reset_memblock_regions();
915 memblock_allow_resize();
917 /* Add a valid memory region used by double_array(). */
918 dummy_physical_memory_init();
919 memblock_add(dummy_physical_memory_base(), MEM_SIZE);
921 for (i = 0; i < INIT_MEMBLOCK_REGIONS; i++) {
922 /* Reserve some fakes memory region to fulfill the memblock. */
923 memblock_reserve(memory_base, MEM_SIZE);
925 ASSERT_EQ(memblock.reserved.cnt, i + 1);
926 ASSERT_EQ(memblock.reserved.total_size, (i + 1) * MEM_SIZE);
928 /* Keep the gap so these memory region will not be merged. */
929 memory_base += MEM_SIZE * 2;
932 orig_region = memblock.reserved.regions;
934 /* This reserve the 129 memory_region, and makes it double array. */
935 memblock_reserve(memory_base, MEM_SIZE);
938 * This is the memory region size used by the doubled reserved.regions,
939 * and it has been reserved due to it has been used. The size is used to
940 * calculate the total_size that the memblock.reserved have now.
942 new_reserved_regions_size = PAGE_ALIGN((INIT_MEMBLOCK_REGIONS * 2) *
943 sizeof(struct memblock_region));
945 * The double_array() will find a free memory region as the new
946 * reserved.regions, and the used memory region will be reserved, so
947 * there will be one more region exist in the reserved memblock. And the
948 * one more reserved region's size is new_reserved_regions_size.
950 ASSERT_EQ(memblock.reserved.cnt, INIT_MEMBLOCK_REGIONS + 2);
951 ASSERT_EQ(memblock.reserved.total_size, (INIT_MEMBLOCK_REGIONS + 1) * MEM_SIZE +
952 new_reserved_regions_size);
953 ASSERT_EQ(memblock.reserved.max, INIT_MEMBLOCK_REGIONS * 2);
956 * Now memblock_double_array() works fine. Let's check after the
957 * double_array(), the memblock_reserve() still works as normal.
959 memblock_reserve(r.base, r.size);
960 ASSERT_EQ(memblock.reserved.regions[0].base, r.base);
961 ASSERT_EQ(memblock.reserved.regions[0].size, r.size);
963 ASSERT_EQ(memblock.reserved.cnt, INIT_MEMBLOCK_REGIONS + 3);
964 ASSERT_EQ(memblock.reserved.total_size, (INIT_MEMBLOCK_REGIONS + 1) * MEM_SIZE +
965 new_reserved_regions_size +
967 ASSERT_EQ(memblock.reserved.max, INIT_MEMBLOCK_REGIONS * 2);
969 dummy_physical_memory_cleanup();
972 * The current reserved.regions is occupying a range of memory that
973 * allocated from dummy_physical_memory_init(). After free the memory,
974 * we must not use it. So restore the origin memory region to make sure
975 * the tests can run as normal and not affected by the double array.
977 memblock.reserved.regions = orig_region;
978 memblock.reserved.cnt = INIT_MEMBLOCK_RESERVED_REGIONS;
985 static int memblock_reserve_checks(void)
988 prefix_push(FUNC_RESERVE);
989 test_print("Running %s tests...\n", FUNC_RESERVE);
991 memblock_reserve_simple_check();
992 memblock_reserve_disjoint_check();
993 memblock_reserve_overlap_top_check();
994 memblock_reserve_overlap_bottom_check();
995 memblock_reserve_within_check();
996 memblock_reserve_twice_check();
997 memblock_reserve_between_check();
998 memblock_reserve_near_max_check();
999 memblock_reserve_many_check();
1007 * A simple test that tries to remove a region r1 from the array of
1008 * available memory regions. By "removing" a region we mean overwriting it
1009 * with the next region r2 in memblock.memory:
1011 * | ...... +----------------+ |
1013 * +--+----+----------+----------------+--+
1018 * Expect to add two memory blocks r1 and r2 and then remove r1 so that
1019 * r2 is the first available region. The region counter and total size
1022 static int memblock_remove_simple_check(void)
1024 struct memblock_region *rgn;
1026 rgn = &memblock.memory.regions[0];
1028 struct region r1 = {
1032 struct region r2 = {
1039 reset_memblock_regions();
1040 memblock_add(r1.base, r1.size);
1041 memblock_add(r2.base, r2.size);
1042 memblock_remove(r1.base, r1.size);
1044 ASSERT_EQ(rgn->base, r2.base);
1045 ASSERT_EQ(rgn->size, r2.size);
1047 ASSERT_EQ(memblock.memory.cnt, 1);
1048 ASSERT_EQ(memblock.memory.total_size, r2.size);
1056 * A test that tries to remove a region r2 that was not registered as
1057 * available memory (i.e. has no corresponding entry in memblock.memory):
1059 * +----------------+
1061 * +----------------+
1064 * +--+----+------------------------------+
1069 * Expect the array, regions counter and total size to not be modified.
1071 static int memblock_remove_absent_check(void)
1073 struct memblock_region *rgn;
1075 rgn = &memblock.memory.regions[0];
1077 struct region r1 = {
1081 struct region r2 = {
1088 reset_memblock_regions();
1089 memblock_add(r1.base, r1.size);
1090 memblock_remove(r2.base, r2.size);
1092 ASSERT_EQ(rgn->base, r1.base);
1093 ASSERT_EQ(rgn->size, r1.size);
1095 ASSERT_EQ(memblock.memory.cnt, 1);
1096 ASSERT_EQ(memblock.memory.total_size, r1.size);
1104 * A test that tries to remove a region r2 that overlaps with the
1105 * beginning of the already existing entry r1
1106 * (that is r1.base < r2.base + r2.size):
1108 * +-----------------+
1110 * +-----------------+
1111 * | .........+--------+ |
1113 * +-----------------+--------+--------+--+
1119 * Expect that only the intersection of both regions is removed from the
1120 * available memory pool. The regions counter and total size are updated.
1122 static int memblock_remove_overlap_top_check(void)
1124 struct memblock_region *rgn;
1125 phys_addr_t r1_end, r2_end, total_size;
1127 rgn = &memblock.memory.regions[0];
1129 struct region r1 = {
1133 struct region r2 = {
1140 r1_end = r1.base + r1.size;
1141 r2_end = r2.base + r2.size;
1142 total_size = r1_end - r2_end;
1144 reset_memblock_regions();
1145 memblock_add(r1.base, r1.size);
1146 memblock_remove(r2.base, r2.size);
1148 ASSERT_EQ(rgn->base, r1.base + r2.base);
1149 ASSERT_EQ(rgn->size, total_size);
1151 ASSERT_EQ(memblock.memory.cnt, 1);
1152 ASSERT_EQ(memblock.memory.total_size, total_size);
1160 * A test that tries to remove a region r2 that overlaps with the end of
1161 * the already existing region r1 (that is r2.base < r1.base + r1.size):
1163 * +--------------------------------+
1165 * +--------------------------------+
1168 * +-+---+----+---------------------------+
1173 * Expect that only the intersection of both regions is removed from the
1174 * available memory pool. The regions counter and total size are updated.
1176 static int memblock_remove_overlap_bottom_check(void)
1178 struct memblock_region *rgn;
1179 phys_addr_t total_size;
1181 rgn = &memblock.memory.regions[0];
1183 struct region r1 = {
1187 struct region r2 = {
1194 total_size = r2.base - r1.base;
1196 reset_memblock_regions();
1197 memblock_add(r1.base, r1.size);
1198 memblock_remove(r2.base, r2.size);
1200 ASSERT_EQ(rgn->base, r1.base);
1201 ASSERT_EQ(rgn->size, total_size);
1203 ASSERT_EQ(memblock.memory.cnt, 1);
1204 ASSERT_EQ(memblock.memory.total_size, total_size);
1212 * A test that tries to remove a region r2 that is within the range of
1213 * the already existing entry r1 (that is
1214 * (r1.base < r2.base) && (r2.base + r2.size < r1.base + r1.size)):
1219 * | +-------------+....+---------------+ |
1220 * | | rgn1 | r1 | rgn2 | |
1221 * +-+-------------+----+---------------+-+
1226 * Expect that the region is split into two - one that ends at r2.base and
1227 * another that starts at r2.base + r2.size, with appropriate sizes. The
1228 * region counter and total size are updated.
1230 static int memblock_remove_within_check(void)
1232 struct memblock_region *rgn1, *rgn2;
1233 phys_addr_t r1_size, r2_size, total_size;
1235 rgn1 = &memblock.memory.regions[0];
1236 rgn2 = &memblock.memory.regions[1];
1238 struct region r1 = {
1242 struct region r2 = {
1249 r1_size = r2.base - r1.base;
1250 r2_size = (r1.base + r1.size) - (r2.base + r2.size);
1251 total_size = r1_size + r2_size;
1253 reset_memblock_regions();
1254 memblock_add(r1.base, r1.size);
1255 memblock_remove(r2.base, r2.size);
1257 ASSERT_EQ(rgn1->base, r1.base);
1258 ASSERT_EQ(rgn1->size, r1_size);
1260 ASSERT_EQ(rgn2->base, r2.base + r2.size);
1261 ASSERT_EQ(rgn2->size, r2_size);
1263 ASSERT_EQ(memblock.memory.cnt, 2);
1264 ASSERT_EQ(memblock.memory.total_size, total_size);
1272 * A simple test that tries to remove a region r1 from the array of
1273 * available memory regions when r1 is the only available region.
1274 * Expect to add a memory block r1 and then remove r1 so that a dummy
1275 * region is added. The region counter stays the same, and the total size
1278 static int memblock_remove_only_region_check(void)
1280 struct memblock_region *rgn;
1282 rgn = &memblock.memory.regions[0];
1284 struct region r1 = {
1291 reset_memblock_regions();
1292 memblock_add(r1.base, r1.size);
1293 memblock_remove(r1.base, r1.size);
1295 ASSERT_EQ(rgn->base, 0);
1296 ASSERT_EQ(rgn->size, 0);
1298 ASSERT_EQ(memblock.memory.cnt, 1);
1299 ASSERT_EQ(memblock.memory.total_size, 0);
1307 * A simple test that tries remove a region r2 from the array of available
1308 * memory regions when r2 extends past PHYS_ADDR_MAX:
1315 * +------------------------+---+----+
1317 * Expect that only the portion between PHYS_ADDR_MAX and r2.base is removed.
1318 * Expect the total size of available memory to be updated and the counter to
1321 static int memblock_remove_near_max_check(void)
1323 struct memblock_region *rgn;
1324 phys_addr_t total_size;
1326 rgn = &memblock.memory.regions[0];
1328 struct region r1 = {
1329 .base = PHYS_ADDR_MAX - SZ_2M,
1333 struct region r2 = {
1334 .base = PHYS_ADDR_MAX - SZ_1M,
1340 total_size = r1.size - (PHYS_ADDR_MAX - r2.base);
1342 reset_memblock_regions();
1343 memblock_add(r1.base, r1.size);
1344 memblock_remove(r2.base, r2.size);
1346 ASSERT_EQ(rgn->base, r1.base);
1347 ASSERT_EQ(rgn->size, total_size);
1349 ASSERT_EQ(memblock.memory.cnt, 1);
1350 ASSERT_EQ(memblock.memory.total_size, total_size);
1358 * A test that tries to remove a region r3 that overlaps with two existing
1359 * regions r1 and r2:
1361 * +----------------+
1363 * +----------------+
1364 * | +----+..... ........+--------+
1365 * | | |r1 : : |r2 | |
1366 * +----+----+----+---+-------+--------+-----+
1368 * Expect that only the intersections of r1 with r3 and r2 with r3 are removed
1369 * from the available memory pool. Expect the total size of available memory to
1370 * be updated and the counter to not be updated.
1372 static int memblock_remove_overlap_two_check(void)
1374 struct memblock_region *rgn1, *rgn2;
1375 phys_addr_t new_r1_size, new_r2_size, r2_end, r3_end, total_size;
1377 rgn1 = &memblock.memory.regions[0];
1378 rgn2 = &memblock.memory.regions[1];
1380 struct region r1 = {
1384 struct region r2 = {
1388 struct region r3 = {
1395 r2_end = r2.base + r2.size;
1396 r3_end = r3.base + r3.size;
1397 new_r1_size = r3.base - r1.base;
1398 new_r2_size = r2_end - r3_end;
1399 total_size = new_r1_size + new_r2_size;
1401 reset_memblock_regions();
1402 memblock_add(r1.base, r1.size);
1403 memblock_add(r2.base, r2.size);
1404 memblock_remove(r3.base, r3.size);
1406 ASSERT_EQ(rgn1->base, r1.base);
1407 ASSERT_EQ(rgn1->size, new_r1_size);
1409 ASSERT_EQ(rgn2->base, r3_end);
1410 ASSERT_EQ(rgn2->size, new_r2_size);
1412 ASSERT_EQ(memblock.memory.cnt, 2);
1413 ASSERT_EQ(memblock.memory.total_size, total_size);
1420 static int memblock_remove_checks(void)
1423 prefix_push(FUNC_REMOVE);
1424 test_print("Running %s tests...\n", FUNC_REMOVE);
1426 memblock_remove_simple_check();
1427 memblock_remove_absent_check();
1428 memblock_remove_overlap_top_check();
1429 memblock_remove_overlap_bottom_check();
1430 memblock_remove_within_check();
1431 memblock_remove_only_region_check();
1432 memblock_remove_near_max_check();
1433 memblock_remove_overlap_two_check();
1441 * A simple test that tries to free a memory block r1 that was marked
1442 * earlier as reserved. By "freeing" a region we mean overwriting it with
1443 * the next entry r2 in memblock.reserved:
1447 * +--------------+----+-----------+----+-+
1452 * Expect to reserve two memory regions and then erase r1 region with the
1453 * value of r2. The region counter and total size are updated.
1455 static int memblock_free_simple_check(void)
1457 struct memblock_region *rgn;
1459 rgn = &memblock.reserved.regions[0];
1461 struct region r1 = {
1465 struct region r2 = {
1472 reset_memblock_regions();
1473 memblock_reserve(r1.base, r1.size);
1474 memblock_reserve(r2.base, r2.size);
1475 memblock_free((void *)r1.base, r1.size);
1477 ASSERT_EQ(rgn->base, r2.base);
1478 ASSERT_EQ(rgn->size, r2.size);
1480 ASSERT_EQ(memblock.reserved.cnt, 1);
1481 ASSERT_EQ(memblock.reserved.total_size, r2.size);
1489 * A test that tries to free a region r2 that was not marked as reserved
1490 * (i.e. has no corresponding entry in memblock.reserved):
1492 * +----------------+
1494 * +----------------+
1497 * +--+----+------------------------------+
1502 * The array, regions counter and total size are not modified.
1504 static int memblock_free_absent_check(void)
1506 struct memblock_region *rgn;
1508 rgn = &memblock.reserved.regions[0];
1510 struct region r1 = {
1514 struct region r2 = {
1521 reset_memblock_regions();
1522 memblock_reserve(r1.base, r1.size);
1523 memblock_free((void *)r2.base, r2.size);
1525 ASSERT_EQ(rgn->base, r1.base);
1526 ASSERT_EQ(rgn->size, r1.size);
1528 ASSERT_EQ(memblock.reserved.cnt, 1);
1529 ASSERT_EQ(memblock.reserved.total_size, r1.size);
1537 * A test that tries to free a region r2 that overlaps with the beginning
1538 * of the already existing entry r1 (that is r1.base < r2.base + r2.size):
1543 * | ...+--------------+ |
1545 * +----+--+--------------+---------------+
1552 * Expect that only the intersection of both regions is freed. The
1553 * regions counter and total size are updated.
1555 static int memblock_free_overlap_top_check(void)
1557 struct memblock_region *rgn;
1558 phys_addr_t total_size;
1560 rgn = &memblock.reserved.regions[0];
1562 struct region r1 = {
1566 struct region r2 = {
1573 total_size = (r1.size + r1.base) - (r2.base + r2.size);
1575 reset_memblock_regions();
1576 memblock_reserve(r1.base, r1.size);
1577 memblock_free((void *)r2.base, r2.size);
1579 ASSERT_EQ(rgn->base, r2.base + r2.size);
1580 ASSERT_EQ(rgn->size, total_size);
1582 ASSERT_EQ(memblock.reserved.cnt, 1);
1583 ASSERT_EQ(memblock.reserved.total_size, total_size);
1591 * A test that tries to free a region r2 that overlaps with the end of
1592 * the already existing entry r1 (that is r2.base < r1.base + r1.size):
1594 * +----------------+
1596 * +----------------+
1597 * | +-----------+..... |
1599 * +----+-----------+----+----------------+
1601 * Expect that only the intersection of both regions is freed. The
1602 * regions counter and total size are updated.
1604 static int memblock_free_overlap_bottom_check(void)
1606 struct memblock_region *rgn;
1607 phys_addr_t total_size;
1609 rgn = &memblock.reserved.regions[0];
1611 struct region r1 = {
1615 struct region r2 = {
1622 total_size = r2.base - r1.base;
1624 reset_memblock_regions();
1625 memblock_reserve(r1.base, r1.size);
1626 memblock_free((void *)r2.base, r2.size);
1628 ASSERT_EQ(rgn->base, r1.base);
1629 ASSERT_EQ(rgn->size, total_size);
1631 ASSERT_EQ(memblock.reserved.cnt, 1);
1632 ASSERT_EQ(memblock.reserved.total_size, total_size);
1640 * A test that tries to free a region r2 that is within the range of the
1641 * already existing entry r1 (that is
1642 * (r1.base < r2.base) && (r2.base + r2.size < r1.base + r1.size)):
1647 * | +------------+....+---------------+
1648 * | | rgn1 | r1 | rgn2 |
1649 * +----+------------+----+---------------+
1654 * Expect that the region is split into two - one that ends at r2.base and
1655 * another that starts at r2.base + r2.size, with appropriate sizes. The
1656 * region counter and total size fields are updated.
1658 static int memblock_free_within_check(void)
1660 struct memblock_region *rgn1, *rgn2;
1661 phys_addr_t r1_size, r2_size, total_size;
1663 rgn1 = &memblock.reserved.regions[0];
1664 rgn2 = &memblock.reserved.regions[1];
1666 struct region r1 = {
1670 struct region r2 = {
1677 r1_size = r2.base - r1.base;
1678 r2_size = (r1.base + r1.size) - (r2.base + r2.size);
1679 total_size = r1_size + r2_size;
1681 reset_memblock_regions();
1682 memblock_reserve(r1.base, r1.size);
1683 memblock_free((void *)r2.base, r2.size);
1685 ASSERT_EQ(rgn1->base, r1.base);
1686 ASSERT_EQ(rgn1->size, r1_size);
1688 ASSERT_EQ(rgn2->base, r2.base + r2.size);
1689 ASSERT_EQ(rgn2->size, r2_size);
1691 ASSERT_EQ(memblock.reserved.cnt, 2);
1692 ASSERT_EQ(memblock.reserved.total_size, total_size);
1700 * A simple test that tries to free a memory block r1 that was marked
1701 * earlier as reserved when r1 is the only available region.
1702 * Expect to reserve a memory block r1 and then free r1 so that r1 is
1703 * overwritten with a dummy region. The region counter stays the same,
1704 * and the total size is updated.
1706 static int memblock_free_only_region_check(void)
1708 struct memblock_region *rgn;
1710 rgn = &memblock.reserved.regions[0];
1712 struct region r1 = {
1719 reset_memblock_regions();
1720 memblock_reserve(r1.base, r1.size);
1721 memblock_free((void *)r1.base, r1.size);
1723 ASSERT_EQ(rgn->base, 0);
1724 ASSERT_EQ(rgn->size, 0);
1726 ASSERT_EQ(memblock.reserved.cnt, 1);
1727 ASSERT_EQ(memblock.reserved.total_size, 0);
1735 * A simple test that tries free a region r2 when r2 extends past PHYS_ADDR_MAX:
1742 * +------------------------+---+----+
1744 * Expect that only the portion between PHYS_ADDR_MAX and r2.base is freed.
1745 * Expect the total size of reserved memory to be updated and the counter to
1748 static int memblock_free_near_max_check(void)
1750 struct memblock_region *rgn;
1751 phys_addr_t total_size;
1753 rgn = &memblock.reserved.regions[0];
1755 struct region r1 = {
1756 .base = PHYS_ADDR_MAX - SZ_2M,
1760 struct region r2 = {
1761 .base = PHYS_ADDR_MAX - SZ_1M,
1767 total_size = r1.size - (PHYS_ADDR_MAX - r2.base);
1769 reset_memblock_regions();
1770 memblock_reserve(r1.base, r1.size);
1771 memblock_free((void *)r2.base, r2.size);
1773 ASSERT_EQ(rgn->base, r1.base);
1774 ASSERT_EQ(rgn->size, total_size);
1776 ASSERT_EQ(memblock.reserved.cnt, 1);
1777 ASSERT_EQ(memblock.reserved.total_size, total_size);
1785 * A test that tries to free a reserved region r3 that overlaps with two
1786 * existing reserved regions r1 and r2:
1788 * +----------------+
1790 * +----------------+
1791 * | +----+..... ........+--------+
1792 * | | |r1 : : |r2 | |
1793 * +----+----+----+---+-------+--------+-----+
1795 * Expect that only the intersections of r1 with r3 and r2 with r3 are freed
1796 * from the collection of reserved memory. Expect the total size of reserved
1797 * memory to be updated and the counter to not be updated.
1799 static int memblock_free_overlap_two_check(void)
1801 struct memblock_region *rgn1, *rgn2;
1802 phys_addr_t new_r1_size, new_r2_size, r2_end, r3_end, total_size;
1804 rgn1 = &memblock.reserved.regions[0];
1805 rgn2 = &memblock.reserved.regions[1];
1807 struct region r1 = {
1811 struct region r2 = {
1815 struct region r3 = {
1822 r2_end = r2.base + r2.size;
1823 r3_end = r3.base + r3.size;
1824 new_r1_size = r3.base - r1.base;
1825 new_r2_size = r2_end - r3_end;
1826 total_size = new_r1_size + new_r2_size;
1828 reset_memblock_regions();
1829 memblock_reserve(r1.base, r1.size);
1830 memblock_reserve(r2.base, r2.size);
1831 memblock_free((void *)r3.base, r3.size);
1833 ASSERT_EQ(rgn1->base, r1.base);
1834 ASSERT_EQ(rgn1->size, new_r1_size);
1836 ASSERT_EQ(rgn2->base, r3_end);
1837 ASSERT_EQ(rgn2->size, new_r2_size);
1839 ASSERT_EQ(memblock.reserved.cnt, 2);
1840 ASSERT_EQ(memblock.reserved.total_size, total_size);
1847 static int memblock_free_checks(void)
1850 prefix_push(FUNC_FREE);
1851 test_print("Running %s tests...\n", FUNC_FREE);
1853 memblock_free_simple_check();
1854 memblock_free_absent_check();
1855 memblock_free_overlap_top_check();
1856 memblock_free_overlap_bottom_check();
1857 memblock_free_within_check();
1858 memblock_free_only_region_check();
1859 memblock_free_near_max_check();
1860 memblock_free_overlap_two_check();
1867 static int memblock_set_bottom_up_check(void)
1869 prefix_push("memblock_set_bottom_up");
1871 memblock_set_bottom_up(false);
1872 ASSERT_EQ(memblock.bottom_up, false);
1873 memblock_set_bottom_up(true);
1874 ASSERT_EQ(memblock.bottom_up, true);
1876 reset_memblock_attributes();
1882 static int memblock_bottom_up_check(void)
1884 prefix_push("memblock_bottom_up");
1886 memblock_set_bottom_up(false);
1887 ASSERT_EQ(memblock_bottom_up(), memblock.bottom_up);
1888 ASSERT_EQ(memblock_bottom_up(), false);
1889 memblock_set_bottom_up(true);
1890 ASSERT_EQ(memblock_bottom_up(), memblock.bottom_up);
1891 ASSERT_EQ(memblock_bottom_up(), true);
1893 reset_memblock_attributes();
1899 static int memblock_bottom_up_checks(void)
1901 test_print("Running memblock_*bottom_up tests...\n");
1904 memblock_set_bottom_up_check();
1906 memblock_bottom_up_check();
1912 * A test that tries to trim memory when both ends of the memory region are
1913 * aligned. Expect that the memory will not be trimmed. Expect the counter to
1916 static int memblock_trim_memory_aligned_check(void)
1918 struct memblock_region *rgn;
1919 const phys_addr_t alignment = SMP_CACHE_BYTES;
1921 rgn = &memblock.memory.regions[0];
1925 .size = alignment * 4
1930 reset_memblock_regions();
1931 memblock_add(r.base, r.size);
1932 memblock_trim_memory(alignment);
1934 ASSERT_EQ(rgn->base, r.base);
1935 ASSERT_EQ(rgn->size, r.size);
1937 ASSERT_EQ(memblock.memory.cnt, 1);
1945 * A test that tries to trim memory when there are two available regions, r1 and
1946 * r2. Region r1 is aligned on both ends and region r2 is unaligned on one end
1947 * and smaller than the alignment:
1951 * | +-----------------+ +------+ |
1953 * +--------+-----------------+--------+------+---+
1955 * |________|________|________| |
1956 * | Unaligned address
1959 * Expect that r1 will not be trimmed and r2 will be removed. Expect the
1960 * counter to be updated.
1962 static int memblock_trim_memory_too_small_check(void)
1964 struct memblock_region *rgn;
1965 const phys_addr_t alignment = SMP_CACHE_BYTES;
1967 rgn = &memblock.memory.regions[0];
1969 struct region r1 = {
1971 .size = alignment * 2
1973 struct region r2 = {
1974 .base = alignment * 4,
1975 .size = alignment - SZ_2
1980 reset_memblock_regions();
1981 memblock_add(r1.base, r1.size);
1982 memblock_add(r2.base, r2.size);
1983 memblock_trim_memory(alignment);
1985 ASSERT_EQ(rgn->base, r1.base);
1986 ASSERT_EQ(rgn->size, r1.size);
1988 ASSERT_EQ(memblock.memory.cnt, 1);
1996 * A test that tries to trim memory when there are two available regions, r1 and
1997 * r2. Region r1 is aligned on both ends and region r2 is unaligned at the base
1998 * and aligned at the end:
2003 * | +-----------------+ +---------------+ |
2005 * +--------+-----------------+----------+---------------+---+
2007 * |________|________|________|________|________|
2011 * Expect that r1 will not be trimmed and r2 will be trimmed at the base.
2012 * Expect the counter to not be updated.
2014 static int memblock_trim_memory_unaligned_base_check(void)
2016 struct memblock_region *rgn1, *rgn2;
2017 const phys_addr_t alignment = SMP_CACHE_BYTES;
2018 phys_addr_t offset = SZ_2;
2019 phys_addr_t new_r2_base, new_r2_size;
2021 rgn1 = &memblock.memory.regions[0];
2022 rgn2 = &memblock.memory.regions[1];
2024 struct region r1 = {
2026 .size = alignment * 2
2028 struct region r2 = {
2029 .base = alignment * 4 + offset,
2030 .size = alignment * 2 - offset
2035 new_r2_base = r2.base + (alignment - offset);
2036 new_r2_size = r2.size - (alignment - offset);
2038 reset_memblock_regions();
2039 memblock_add(r1.base, r1.size);
2040 memblock_add(r2.base, r2.size);
2041 memblock_trim_memory(alignment);
2043 ASSERT_EQ(rgn1->base, r1.base);
2044 ASSERT_EQ(rgn1->size, r1.size);
2046 ASSERT_EQ(rgn2->base, new_r2_base);
2047 ASSERT_EQ(rgn2->size, new_r2_size);
2049 ASSERT_EQ(memblock.memory.cnt, 2);
2057 * A test that tries to trim memory when there are two available regions, r1 and
2058 * r2. Region r1 is aligned on both ends and region r2 is aligned at the base
2059 * and unaligned at the end:
2064 * | +-----------------+ +---------------+ |
2066 * +--------+-----------------+--------+---------------+---+
2068 * |________|________|________|________|________|
2072 * Expect that r1 will not be trimmed and r2 will be trimmed at the end.
2073 * Expect the counter to not be updated.
2075 static int memblock_trim_memory_unaligned_end_check(void)
2077 struct memblock_region *rgn1, *rgn2;
2078 const phys_addr_t alignment = SMP_CACHE_BYTES;
2079 phys_addr_t offset = SZ_2;
2080 phys_addr_t new_r2_size;
2082 rgn1 = &memblock.memory.regions[0];
2083 rgn2 = &memblock.memory.regions[1];
2085 struct region r1 = {
2087 .size = alignment * 2
2089 struct region r2 = {
2090 .base = alignment * 4,
2091 .size = alignment * 2 - offset
2096 new_r2_size = r2.size - (alignment - offset);
2098 reset_memblock_regions();
2099 memblock_add(r1.base, r1.size);
2100 memblock_add(r2.base, r2.size);
2101 memblock_trim_memory(alignment);
2103 ASSERT_EQ(rgn1->base, r1.base);
2104 ASSERT_EQ(rgn1->size, r1.size);
2106 ASSERT_EQ(rgn2->base, r2.base);
2107 ASSERT_EQ(rgn2->size, new_r2_size);
2109 ASSERT_EQ(memblock.memory.cnt, 2);
2116 static int memblock_trim_memory_checks(void)
2119 prefix_push(FUNC_TRIM);
2120 test_print("Running %s tests...\n", FUNC_TRIM);
2122 memblock_trim_memory_aligned_check();
2123 memblock_trim_memory_too_small_check();
2124 memblock_trim_memory_unaligned_base_check();
2125 memblock_trim_memory_unaligned_end_check();
2132 int memblock_basic_checks(void)
2134 memblock_initialization_check();
2135 memblock_add_checks();
2136 memblock_reserve_checks();
2137 memblock_remove_checks();
2138 memblock_free_checks();
2139 memblock_bottom_up_checks();
2140 memblock_trim_memory_checks();