private void compact() {
    lock(true);
    compactInProgress = true;
    try {
      try {
        ifRAF.close();
      } catch (IOException ignore) {
      }
      // rename the old file to tmpFile
      File tmpFile = getTempFile();
      if (ifFile.renameTo(tmpFile)) {
        boolean success = false;
        try {
          // create the new file
          openRAF();
          // fill the new file with data
          writeLiveData();
          success = true;

          // delete the old file
          if (!tmpFile.delete()) {
            throw new DiskAccessException("could not delete temporary file " + tmpFile,
                parent);
          }
        } catch (DiskAccessException e) {
          if (logger.isDebugEnabled()) {
            logger.debug("Exception compacting init file {}", this, e);
          }
        } finally {
          if (!success) {
            // if we failed
            // close the new one and delete it
            try {
              ifRAF.close();
            } catch (IOException ignore2) {
            }
            if (!ifFile.delete()) {
              throw new DiskAccessException("could not delete file " + ifFile, parent);
            }
            if (!tmpFile.renameTo(ifFile)) {
              throw new DiskAccessException(
                  "could not rename file " + tmpFile + " to " + ifFile, parent);
            }
            // reopen the old file since we couldn't write the new one
            openRAF();
            // reset the counts to 0 so we will try a compaction again
            // in the future but not right away.
            ifLiveRecordCount = 0;
            ifTotalRecordCount = 0;
          }
        }
      } else {
        // reopen the old file since we couldn't rename it
        openRAF();
        // reset the counts to 0 so we will try a compaction again
        // in the future but not right away.
        ifLiveRecordCount = 0;
        ifTotalRecordCount = 0;
      }
    } finally {
      compactInProgress = false;
      unlock(true);
    }
  }
If the ratio of live vs. dead is not less than this constant then no need to compact.
geode-core/src/main/java/org/apache/geode/internal/cache/DiskInitFile.java