summaryrefslogtreecommitdiff
path: root/checkpoint_gc
diff options
context:
space:
mode:
authorDaniel Rosenberg <drosen@google.com>2019-02-13 16:24:25 -0800
committerDaniel Rosenberg <drosen@google.com>2019-02-28 18:27:22 -0800
commit987de58738e3c3d48af9c68c7fb7b0b4e505183b (patch)
tree27dd9be4872f240a570ae2347484a51c9d32732d /checkpoint_gc
parentac80c040c19219aa802ee7560de5f8546bb7d1e0 (diff)
downloadextras-987de58738e3c3d48af9c68c7fb7b0b4e505183b.tar.gz
Add a postinstall script for GC on F2FS
This script is intended to run on F2FS checkpointing devices. It triggers garbage collection for a period of time to make mounting with checkpoint=disable smoother. Test: Set this script as a postinstall script on vendor Bug: 123367711 Change-Id: I87e143a2004da5852654688c3c8773510b7073ae
Diffstat (limited to 'checkpoint_gc')
-rw-r--r--checkpoint_gc/Android.bp6
-rw-r--r--checkpoint_gc/checkpoint_gc.sh58
2 files changed, 64 insertions, 0 deletions
diff --git a/checkpoint_gc/Android.bp b/checkpoint_gc/Android.bp
new file mode 100644
index 00000000..fac9c6a8
--- /dev/null
+++ b/checkpoint_gc/Android.bp
@@ -0,0 +1,6 @@
+// Checkpointing GC script
+sh_binary {
+ name: "checkpoint_gc",
+ src: "checkpoint_gc.sh",
+ vendor: true,
+}
diff --git a/checkpoint_gc/checkpoint_gc.sh b/checkpoint_gc/checkpoint_gc.sh
new file mode 100644
index 00000000..bf86e214
--- /dev/null
+++ b/checkpoint_gc/checkpoint_gc.sh
@@ -0,0 +1,58 @@
+#!/system/bin/sh
+
+#
+# Copyright (C) 2019 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+
+# This script will run as an pre-checkpointing cleanup for mounting f2fs
+# with checkpoint=disable, so that the first mount after the reboot will
+# be faster. It is unnecessary to run if the device does not use userdata
+# checkpointing on F2FS.
+
+# TARGET_SLOT="${1}"
+STATUS_FD="${2}"
+GC_TIME=120
+DIRTY_SEGMENTS_THRESHOLD=100
+
+NAME=`while read dev dir type opt; do
+ if [ /data = ${dir} -a f2fs = ${type} ]; then
+ echo ${dev##*/}
+ break
+ fi
+done < /proc/mounts`
+if [ -z "${NAME}" ]; then
+ exit 0
+fi
+log -pi -t checkpoint_gc Turning on GC for ${NAME}
+echo 1 > /sys/fs/f2fs/${NAME}/gc_urgent || exit 1
+
+COUNT=0
+STEP=5
+while [ ${COUNT} -lt ${GC_TIME} ]; do
+ print -u${STATUS_FD} "global_progress `echo $COUNT/$GC_TIME|bc -l`"
+ read DIRTY_SEGMENTS < /sys/fs/f2fs/${NAME}/dirty_segments
+ if [ ${DIRTY_SEGMENTS} -le ${DIRTY_SEGMENTS_THRESHOLD} ]; then
+ break
+ fi
+ sleep ${STEP}
+ COUNT=$((${COUNT}+${STEP}))
+done
+
+log -pi -t checkpoint_gc Turning off GC for ${NAME}
+echo 0 > /sys/fs/f2fs/${NAME}/gc_urgent
+sync
+
+print -u${STATUS_FD} "global_progress 1.0"
+exit 0