devicemodel/core/hugetlb.c
/* try to release larger free page */
try to release larger free page
try to release larger free page
static bool release_larger_freepage(int level_limit)
{
	int level;
	int total_pages, orig_pages, cur_pages;
	char cmd_buf[MAX_PATH_LEN];
	FILE *fp;
	for (level = hugetlb_lv_max - 1; level >= level_limit; level--) {
		if (hugetlb_priv[level].pages_delta >= 0)
			continue;
		orig_pages = read_sys_info(hugetlb_priv[level].nr_pages_path);
		total_pages = orig_pages - 1;
		snprintf(cmd_buf, MAX_PATH_LEN, "echo %d > %s",
			total_pages, hugetlb_priv[level].nr_pages_path);
		fp = popen(cmd_buf, "r");
		if (fp == NULL) {
			pr_err("cmd to free mem: %s failed!\n", cmd_buf);
			return false;
		}
		pclose(fp);
		cur_pages = read_sys_info(hugetlb_priv[level].nr_pages_path);
		if (cur_pages < orig_pages) {
			hugetlb_priv[level].pages_delta++;
			break;
		}
	}
	if (level < level_limit)
		return false;
	return true;
}
static bool release_larger_freepage ( int level_limit ) { int level ; int total_pages , orig_pages , cur_pages ; char cmd_buf [ MAX_PATH_LEN ] ; FILE * fp ; for ( level = hugetlb_lv_max - 1 ; level >= level_limit ; level -- ) { if ( hugetlb_priv [ level ] . pages_delta >= 0 ) continue ; orig_pages = read_sys_info ( hugetlb_priv [ level ] . nr_pages_path ) ; total_pages = orig_pages - 1 ; snprintf ( cmd_buf , MAX_PATH_LEN , " " , total_pages , hugetlb_priv [ level ] . nr_pages_path ) ; fp = popen ( cmd_buf , " " ) ; if ( fp == NULL ) { pr_err ( " \n " , cmd_buf ) ; return false ; } pclose ( fp ) ; cur_pages = read_sys_info ( hugetlb_priv [ level ] . nr_pages_path ) ; if ( cur_pages < orig_pages ) { hugetlb_priv [ level ] . pages_delta ++ ; break ; } } if ( level < level_limit ) return false ; return true ; }
try to release larger free page
try to release larger free page
/* free one unsed larger page */ /* release page successfully */