• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3  * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
4  * Author(s): Xiao Yang <yangx.jy@cn.fujitsu.com>
5  */
6 
7 #define TST_NO_DEFAULT_MAIN
8 
9 #include <unistd.h>
10 #include "tst_test.h"
11 #include "ksm_helper.h"
12 
wait_ksmd_full_scan(void)13 void wait_ksmd_full_scan(void)
14 {
15 	unsigned long full_scans, at_least_one_full_scan;
16 	int count = 0;
17 
18 	SAFE_FILE_SCANF(PATH_KSM "full_scans", "%lu", &full_scans);
19 	/*
20 	 * The current scan is already in progress so we can't guarantee that
21 	 * the get_user_pages() is called on every existing rmap_item if we
22 	 * only waited for the remaining part of the scan.
23 	 *
24 	 * The actual merging happens after the unstable tree has been built so
25 	 * we need to wait at least two full scans to guarantee merging, hence
26 	 * wait full_scans to increment by 3 so that at least two full scans
27 	 * will run.
28 	 */
29 	at_least_one_full_scan = full_scans + 3;
30 	while (full_scans < at_least_one_full_scan) {
31 		sleep(1);
32 		count++;
33 		SAFE_FILE_SCANF(PATH_KSM "full_scans", "%lu", &full_scans);
34 	}
35 
36 	tst_res(TINFO, "ksm daemon takes %ds to run two full scans", count);
37 }
38