private static int initializeSoftBlockSize(String fileOrDir) {

        int fsBlockSize = -1;

        if (binit) {
            // get file system block size for use with workingDir
            // see "man 3 posix_memalign" for why we do this
            fsBlockSize = pathconf(fileOrDir, PC_REC_XFER_ALIGN);
            /* conservative for version >= 2.6
             * "man 2 open":
             *
             * Under Linux 2.6, alignment
             * to 512-byte boundaries suffices.
             */

            // Since O_DIRECT requires pages to be memory aligned with the file system block size,
            // we will do this too in case the page size and the block size are different for
            // whatever reason. By taking the least common multiple, everything should be happy:
            int pageSize = getpagesize();
            fsBlockSize = lcm(fsBlockSize, pageSize);

            // just being completely paranoid:
            // (512 is the rule for 2.6+ kernels as mentioned before)
            fsBlockSize = lcm(fsBlockSize, 512);

            // lastly, a sanity check
            if (fsBlockSize <= 0 || ((fsBlockSize & (fsBlockSize - 1)) != 0)) {
                LOGGER.warn("file system block size should be a power of two, was found to be " + fsBlockSize);
                LOGGER.warn("Disabling O_DIRECT support");
                return -1;
            }
        }

        return fsBlockSize;
    }
Finds a block size for use with O_DIRECT. Choose it in the most paranoid
way possible to maximize probability that things work.

@param fileOrDir A file or directory within which O_DIRECT access will be performed.
s3stream/src/main/java/com/automq/stream/thirdparty/moe/cnkirito/kdio/DirectIOLib.java