devicemodel/core/hugetlb.c
/* reserve more free huge pages as different levels.
 * it need handle following cases:
 * A.no enough free memory to reserve gap pages, just fails.
 * B enough free memory to reserve each level gap pages
 *.C.enough free memory, but it can't reserve enough higher level gap pages,
 *    so lower level need handle that, to reserve more free pages.
 *.D.enough higher level free pages, but not enough free memory for
 *    lower level gap pages, so release some higher level free pages for that.
 * other info:
 *.   even enough free memory, it is eaiser to reserve smaller pages than
 * lager ones, for example:2MB easier than 1GB. One flow of current solution:
 *.it could leave Service VM very small free memory.
 *.return value: true: success; false: failure
 */
reserve more free huge pages as different levels.
it need handle following cases:
A.no enough free memory to reserve gap pages, just fails.
B enough free memory to reserve each level gap pages
.C.enough free memory, but it can't reserve enough higher level gap pages,
so lower level need handle that, to reserve more free pages.
.D.enough higher level free pages, but not enough free memory for
lower level gap pages, so release some higher level free pages for that.
other info:
.   even enough free memory, it is eaiser to reserve smaller pages than
lager ones, for example:2MB easier than 1GB. One flow of current solution:
.it could leave Service VM very small free memory.
.return value: true: success; false: failure
reserve more free huge pages as different levels . it need handle following cases : A . no enough free memory to reserve gap pages just fails . B enough free memory to reserve each level gap pages . C . enough free memory but it can ' t reserve enough higher level gap pages so lower level need handle that to reserve more free pages . . D . enough higher level free pages but not enough free memory for lower level gap pages so release some higher level free pages for that . other info : . even enough free memory it is eaiser to reserve smaller pages than lager ones for example : 2MB easier than 1GB . One flow of current solution : . it could leave Service VM very small free memory . . return value : true : success ; false : failure
static bool hugetlb_reserve_pages(void)
{
	int left_gap = 0, pg_size;
	int level;
	pr_info("to reserve more free pages:\n");
	for (level = hugetlb_lv_max - 1; level >= HUGETLB_LV1; level--) {
		if (hugetlb_priv[level].pages_delta <= 0)
			continue;
		reserve_more_pages(level);
		if (hugetlb_priv[level].pages_delta <= 0)
			continue;
		if (level > HUGETLB_LV1) {
			left_gap = hugetlb_priv[level].pages_delta;
			pg_size = hugetlb_priv[level].pg_size;
			hugetlb_priv[level - 1].pages_delta += (size_t)left_gap
				* (pg_size / hugetlb_priv[level - 1].pg_size);
			continue;
		}
		if (release_larger_freepage(level + 1))
			level++;
		else
			break;
	}
	if (level >= HUGETLB_LV1) {
		pr_err("level %d pages gap: %d failed to reserve!\n",
			level, left_gap);
		return false;
	}
	pr_info("now enough free pages are reserved!\n");
	return true;
}
static bool hugetlb_reserve_pages ( void ) { int left_gap = 0 , pg_size ; int level ; pr_info ( " \n " ) ; for ( level = hugetlb_lv_max - 1 ; level >= HUGETLB_LV1 ; level -- ) { if ( hugetlb_priv [ level ] . pages_delta <= 0 ) continue ; reserve_more_pages ( level ) ; if ( hugetlb_priv [ level ] . pages_delta <= 0 ) continue ; if ( level > HUGETLB_LV1 ) { left_gap = hugetlb_priv [ level ] . pages_delta ; pg_size = hugetlb_priv [ level ] . pg_size ; hugetlb_priv [ level - 1 ] . pages_delta += ( size_t ) left_gap * ( pg_size / hugetlb_priv [ level - 1 ] . pg_size ) ; continue ; } if ( release_larger_freepage ( level + 1 ) ) level ++ ; else break ; } if ( level >= HUGETLB_LV1 ) { pr_err ( " \n " , level , left_gap ) ; return false ; } pr_info ( " \n " ) ; return true ; }
reserve more free huge pages as different levels.
reserve more free huge pages as different levels .
/* if gaps, try to reserve more pages */ /* check if reserved enough pages */ /* probably system allocates fewer pages than needed
		 * especially for larger page like 1GB, even there is enough
		 * free memory, it stil can fail to allocate 1GB huge page.
		 * so if that,it needs the next level to handle it.
		 */ /* now for level == HUGETLB_LV1 it still can't alloc enough
		 * pages, go back to larger pages, to check if it can
		 *.release some unused free pages, if release success,
		 * let it go LV1 again
		 */