<commit_before>package voldemort.store.readonly.io;

import java.io.Closeable;
import java.io.File;
import java.io.FileDescriptor;
import java.io.IOException;

import org.apache.log4j.Logger;

import voldemort.store.readonly.io.jna.mman;

import com.sun.jna.Pointer;

public class MemLock implements Closeable {

    private static final Logger logger = Logger.getLogger(MemLock.class);

    private Pointer pa;
    private long length;
    private File file;
    private FileDescriptor descriptor;

    /**
     * Call mmap a file descriptor, then lock the pages using mlock(). This
     * will then prevent the pages from being swapped out due to VFS cache
     * pressure.
     * 
     * @param descriptor The file we should mmap and mlock
     * @param offset
     * @param length
     * @see #close()
     * @throws IOException
     */
    public MemLock(File file, FileDescriptor descriptor, long offset, long length)
                                                                                  throws IOException {
        if(logger.isDebugEnabled())
            logger.debug("mlocking " + file + " with length " + length);

        this.setFile(file);
        this.setDescriptor(descriptor);
        this.length = length;
	pa = null;

        int fd = voldemort.store.readonly.io.Native.getFd(descriptor);

        pa = mman.mmap(length, mman.PROT_READ, mman.MAP_SHARED, fd, offset);

	/* note, any failure in the mlock() system call is ignored,
	 * because it's normal behavior in an unprivileged process is to
	 * fail due system rlimits.
	 */
	mman.mlock(pa, length);

    }

    /**
     * Release this lock so that the memory can be returned to the OS if it
     * wants to us it.
     */
    @Override
    public void close() throws IOException {

        if(logger.isDebugEnabled())
            logger.debug("munlocking " + file + " with length " + length);

	if(pa != null) {
	    /* note: any failure in the munlock() system call is ignored too */
	    Pointer xpa = pa;
	    pa = null;
	    mman.munlock(xpa, length);
	    mman.munmap(xpa, length);
	}
    }

    public File getFile() {
        return file;
    }

    public void setFile(File file) {
        this.file = file;
    }

    public FileDescriptor getDescriptor() {
        return descriptor;
    }

    public void setDescriptor(FileDescriptor descriptor) {
        this.descriptor = descriptor;
    }

}<commit_msg>Remove unused members and methods from MemLock<commit_after>package voldemort.store.readonly.io;

import java.io.Closeable;
import java.io.File;
import java.io.FileDescriptor;
import java.io.IOException;

import org.apache.log4j.Logger;

import voldemort.store.readonly.io.jna.mman;

import com.sun.jna.Pointer;

public class MemLock implements Closeable {

    private static final Logger logger = Logger.getLogger(MemLock.class);

    private Pointer pa;
    private long length;
    private File file;

    /**
     * Call mmap a file descriptor, then lock the pages using mlock(). This
     * will then prevent the pages from being swapped out due to VFS cache
     * pressure.
     * 
     * @param descriptor The file we should mmap and mlock
     * @param offset
     * @param length
     * @see #close()
     * @throws IOException
     */
    public MemLock(File file, FileDescriptor descriptor, long offset, long length)
                                                                                  throws IOException {
        if(logger.isDebugEnabled())
            logger.debug("mlocking " + file + " with length " + length);

        this.file = file;
        this.length = length;
	pa = null;

        int fd = voldemort.store.readonly.io.Native.getFd(descriptor);

        pa = mman.mmap(length, mman.PROT_READ, mman.MAP_SHARED, fd, offset);

	/* note, any failure in the mlock() system call is ignored,
	 * because it's normal behavior in an unprivileged process is to
	 * fail due system rlimits.
	 */
	mman.mlock(pa, length);

    }

    /**
     * Release this lock so that the memory can be returned to the OS if it
     * wants to us it.
     */
    @Override
    public void close() throws IOException {

        if(logger.isDebugEnabled())
            logger.debug("munlocking " + file + " with length " + length);

	if(pa != null) {
	    /* note: any failure in the munlock() system call is ignored too */
	    Pointer xpa = pa;
	    pa = null;
	    mman.munlock(xpa, length);
	    mman.munmap(xpa, length);
	}
    }

    public File getFile() {
        return file;
    }

}
{'fraction_non_alphanumeric': 0.09431868619618286, 'fraction_numerical': 0.0004438526409232135, 'mean_word_length': 2.2994143484626646, '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': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2488573', 'n_tokens_mistral': 1330, 'n_tokens_neox': 1271, 'n_words': 416}