blob: deebcb6a4d31eb7c5e378332fe2e0edd1e438d30 [file] [log] [blame]
# Copyright 2015 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
description "Schedule SSD trim"
author "chromium-os-dev@chromium.org"
start on started system-services
stop on stopping system-services
pre-start script
. /usr/share/cros/disk_utils.sh
. /usr/share/cros/trim_utils.sh
mkdir -p "${CHROMEOS_TRIM_DIR}"
ts="$(cat "${CHROMEOS_TRIM_STATE}" 2> /dev/null || : )"
case "${ts}" in
"${TRIM_NOT_SUPPORTED}")
stop
;;
"${TRIM_SUPPORTED}" | \
"${TRIM_COMPLETED}" | \
"${TRIM_FAILED}" | \
"${TRIM_IN_PROGRESS}" )
;;
*)
ts="${TRIM_SUPPORTED}"
# Use a length larger than the discard granularity.
if ! fstrim --length 16K "${STATEFUL}" 2>/dev/null; then
ts="${TRIM_NOT_SUPPORTED}"
fi
echo "${ts}" > "${CHROMEOS_TRIM_STATE}"
if [ "${ts}" = "${TRIM_NOT_SUPPORTED}" ]; then
stop
fi
;;
esac
end script
exec periodic_scheduler --period=21600 --timeout=3600 --task_name=trim \
-- chromeos-trim