<commit_before>#!/bin/bash
set -e

if [ ! -d "/opt/skiff" ]; then
  echo "Non-skiff system detected, bailing out!"
  exit 1
fi

PERSIST_MNT=/mnt/persist

if mountpoint -q $PERSIST_MNT; then
  echo "Found persist drive at $PERSIST_MNT"
else
  echo "Cannot find persist mount point, bailing."
  exit 1
fi

SWAPFILE_PATH=$PERSIST_MNT/primary.swap
# in mb
SWAPFILE_SIZE=2000
if [ -f /etc/skiff-swap.env ]; then
    source /etc/skiff-swap.env
fi

if swapon -s | grep -q "${SWAPFILE_PATH}" ; then
    echo "$SWAPFILE_PATH is already initialized."
    exit 0
fi

# Allocate swap file if it doesn't exist
if [ ! -f $SWAPFILE_PATH ]; then
  echo "Allocating swapfile at $SWAPFILE_PATH of size $SWAPFILE_SIZE"
  if ! fallocate -l ${SWAPFILE_SIZE}Mb $SWAPFILE_PATH ; then
      echo "Failed to use fallocate, trying dd..."
      dd if=/dev/zero of=$SWAPFILE_PATH bs=1M count=${SWAPFILE_SIZE}
  fi
fi
chmod 600 $SWAPFILE_PATH
mkswap $SWAPFILE_PATH

swapon $SWAPFILE_PATH<commit_msg>skiff/systemd: avoid swapon error: swapfile has holes<commit_after>#!/bin/bash
set -e

# TODO: switch to systemd.swap utility

if [ ! -d "/opt/skiff" ]; then
  echo "Non-skiff system detected, bailing out!"
  exit 1
fi

PERSIST_MNT=/mnt/persist

if mountpoint -q $PERSIST_MNT; then
  echo "Found persist drive at $PERSIST_MNT"
else
  echo "Cannot find persist mount point, bailing."
  exit 1
fi

SWAPFILE_PATH=$PERSIST_MNT/primary.swap
# in mb
SWAPFILE_SIZE=2000
if [ -f /etc/skiff-swap.env ]; then
    source /etc/skiff-swap.env
fi

if swapon -s | grep -q "${SWAPFILE_PATH}" ; then
    echo "$SWAPFILE_PATH is already initialized."
    exit 0
fi

# Allocate swap file if it doesn't exist
if [ ! -f $SWAPFILE_PATH ]; then
  echo "Allocating swapfile at $SWAPFILE_PATH of size $SWAPFILE_SIZE"
  # fallocate: does not work against ext4, due to "swapfile has holes"
  # fallocate -l ${SWAPFILE_SIZE}Mb $SWAPFILE_PATH 
  dd if=/dev/zero of=$SWAPFILE_PATH bs=1M count=${SWAPFILE_SIZE}
  echo "Done allocating swapfile."
fi
chmod 600 $SWAPFILE_PATH
mkswap $SWAPFILE_PATH
swapon $SWAPFILE_PATH

{'fraction_non_alphanumeric': 0.10452114730189596, 'fraction_numerical': 0.01118133203694701, 'mean_word_length': 3.923444976076555, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6889618', 'n_tokens_mistral': 815, 'n_tokens_neox': 776, 'n_words': 239}