1 /*
2 * Copyright (c) 2018 FUJITSU LIMITED. All rights reserved.
3 * Author(s): Xiao Yang <yangx.jy@cn.fujitsu.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program, if not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #define TST_NO_DEFAULT_MAIN
20
21 #include <unistd.h>
22 #include "tst_test.h"
23 #include "ksm_helper.h"
24
wait_ksmd_full_scan(void)25 void wait_ksmd_full_scan(void)
26 {
27 unsigned long full_scans, at_least_one_full_scan;
28 int count = 0;
29
30 SAFE_FILE_SCANF(PATH_KSM "full_scans", "%lu", &full_scans);
31 /*
32 * The current scan is already in progress so we can't guarantee that
33 * the get_user_pages() is called on every existing rmap_item if we
34 * only waited for the remaining part of the scan.
35 *
36 * The actual merging happens after the unstable tree has been built so
37 * we need to wait at least two full scans to guarantee merging, hence
38 * wait full_scans to increment by 3 so that at least two full scans
39 * will run.
40 */
41 at_least_one_full_scan = full_scans + 3;
42 while (full_scans < at_least_one_full_scan) {
43 sleep(1);
44 count++;
45 SAFE_FILE_SCANF(PATH_KSM "full_scans", "%lu", &full_scans);
46 }
47
48 tst_res(TINFO, "ksm daemon takes %ds to run two full scans", count);
49 }
50