| # Copyright 2016 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 "Run ureadahead for ARC++" |
| author "chromium-os-dev@chromium.org" |
| |
| # Run this job in parallel with arc_setup_wrapper.sh run_oci hook. The job |
| # shouldn't be started until 'ureadahead' (which may be in tracing mode) |
| # is stopped, otherwise ureadahead may corrupt the $PACK file. Depending |
| # on start-arc-instance ensures that. |
| start on start-arc-instance |
| |
| script |
| PACK=/var/lib/ureadahead/opt.google.containers.android.rootfs.root.pack |
| |
| { |
| ANDROID_ROOTFS_DIR=/opt/google/containers/android/rootfs/root |
| SYSTEM_IMAGE=/opt/google/containers/android/system.raw.img |
| |
| echo "Start arc-ureadahead" |
| set -x |
| |
| # Read-ahead files in the image. |
| if [ -f "${PACK}" ] && [ ! -L "${PACK}" ]; then |
| # The pack file size is usually 90-100KB. Remove the file if the size is |
| # <= 60KB. |
| MINSIZE=60k |
| FILE=$(find "${PACK}" -newer "${SYSTEM_IMAGE}" -size +"${MINSIZE}") |
| if [ -n "${FILE}" ]; then |
| # Run ureadahead. If it fails, probably because the pack file is too old |
| # (>30 days) or is corrupted, remove it. |
| # Note: when ureadahead is executed with a mount point argument, it does |
| # not automatically switch into tracing mode even when the pack file is |
| # not valid. |
| ureadahead "${ANDROID_ROOTFS_DIR}" || rm -f "${PACK}" |
| else |
| # Remove the pack file if it exists but is older than the image. |
| rm -f "${PACK}" |
| fi |
| else |
| # In case it's a weird path, nuke it. |
| rm -rf "${PACK}" |
| fi |
| } 2>&1 | logger -t "${UPSTART_JOB}" |
| |
| # The pack file is not available or corrupted. Fall back to arc-setup's |
| # read-ahead to minimize the performance impact. |
| if [ ! -e "${PACK}" ]; then |
| exec /usr/sbin/arc-setup --mode=read-ahead "--log_tag=${UPSTART_JOB}" |
| fi |
| end script |