xref: /freebsd/sys/contrib/openzfs/tests/zfs-tests/tests/functional/mmap/mmap_sync_001_pos.ksh (revision 61145dc2b94f12f6a47344fb9aac702321880e43)
1#!/bin/ksh -p
2# SPDX-License-Identifier: CDDL-1.0
3
4#
5# This file and its contents are supplied under the terms of the
6# Common Development and Distribution License ("CDDL"), version 1.0.
7# You may only use this file in accordance with the terms of version
8# 1.0 of the CDDL.
9#
10# A full copy of the text of the CDDL should have accompanied this
11# source.  A copy of the CDDL is also available via the Internet at
12# http://www.illumos.org/license/CDDL.
13#
14
15#
16# Copyright (c) 2015, 2016 by Delphix. All rights reserved.
17#
18
19. $STF_SUITE/include/libtest.shlib
20
21#
22# DESCRIPTION:
23# msync()s of mmap()'ed file should complete quickly during
24# background dirty page writebacks by the kernel.
25#
26
27function cleanup
28{
29	log_must eval "echo $saved_vm_dirty_expire_centisecs > /proc/sys/vm/dirty_expire_centisecs"
30	log_must eval "echo $saved_vm_dirty_background_ratio > /proc/sys/vm/dirty_background_ratio"
31	log_must eval "echo $saved_vm_dirty_writeback_centisecs > /proc/sys/vm/dirty_writeback_centisecs"
32
33	# revert to some sensible defaults if the values we saved
34	# were incorrect due to a previous run being interrupted
35	if [ $(</proc/sys/vm/dirty_expire_centisecs) -eq 1 ]; then
36		log_must eval "echo 3000 > /proc/sys/vm/dirty_expire_centisecs"
37	fi
38
39	if [ $(</proc/sys/vm/dirty_background_ratio) -eq 0 ]; then
40		log_must eval "echo 10 > /proc/sys/vm/dirty_background_ratio"
41	fi
42
43	if [ $(</proc/sys/vm/dirty_writeback_centisecs) -eq 1 ]; then
44		log_must eval "echo 500 > /proc/sys/vm/dirty_writeback_centisecs"
45	fi
46}
47
48if ! is_linux; then
49	log_unsupported "Only supported on Linux, requires /proc/sys/vm/ tunables"
50fi
51
52log_onexit cleanup
53log_assert "Run the tests for mmap_sync"
54
55read -r saved_vm_dirty_expire_centisecs < /proc/sys/vm/dirty_expire_centisecs
56read -r saved_vm_dirty_background_ratio < /proc/sys/vm/dirty_background_ratio
57read -r saved_vm_dirty_writeback_centisecs < /proc/sys/vm/dirty_writeback_centisecs
58
59log_must eval "echo 1 > /proc/sys/vm/dirty_expire_centisecs"
60log_must eval "echo 1 > /proc/sys/vm/dirty_background_bytes"
61log_must eval "echo 1 > /proc/sys/vm/dirty_writeback_centisecs"
62
63log_must mmap_sync
64log_pass "mmap_sync tests passed."
65