HADOOP-10815. Implement Windows equivalent of mlock. Contributed by Chris Nauroth.
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1609588 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
50be8561a7
commit
520e458d4f
|
@ -393,6 +393,8 @@ Release 2.6.0 - UNRELEASED
|
|||
|
||||
HADOOP-10808. Remove unused native code for munlock. (cnauroth)
|
||||
|
||||
HADOOP-10815. Implement Windows equivalent of mlock. (cnauroth)
|
||||
|
||||
OPTIMIZATIONS
|
||||
|
||||
BUG FIXES
|
||||
|
|
|
@ -551,6 +551,19 @@ public class NativeIO {
|
|||
return access0(path, desiredAccess.accessRight());
|
||||
}
|
||||
|
||||
/**
|
||||
* Extends both the minimum and maximum working set size of the current
|
||||
* process. This method gets the current minimum and maximum working set
|
||||
* size, adds the requested amount to each and then sets the minimum and
|
||||
* maximum working set size to the new values. Controlling the working set
|
||||
* size of the process also controls the amount of memory it can lock.
|
||||
*
|
||||
* @param delta amount to increment minimum and maximum working set size
|
||||
* @throws IOException for any error
|
||||
* @see POSIX#mlock(ByteBuffer, long)
|
||||
*/
|
||||
public static native void extendWorkingSetSize(long delta) throws IOException;
|
||||
|
||||
static {
|
||||
if (NativeCodeLoader.isNativeCodeLoaded()) {
|
||||
try {
|
||||
|
|
|
@ -388,10 +388,10 @@ Java_org_apache_hadoop_io_nativeio_NativeIO_00024POSIX_mlock_1native(
|
|||
JNIEnv *env, jclass clazz,
|
||||
jobject buffer, jlong len)
|
||||
{
|
||||
#ifdef UNIX
|
||||
void* buf = (void*)(*env)->GetDirectBufferAddress(env, buffer);
|
||||
PASS_EXCEPTIONS(env);
|
||||
|
||||
#ifdef UNIX
|
||||
if (mlock(buf, len)) {
|
||||
CHECK_DIRECT_BUFFER_ADDRESS(buf);
|
||||
throw_ioe(env, errno);
|
||||
|
@ -399,8 +399,10 @@ Java_org_apache_hadoop_io_nativeio_NativeIO_00024POSIX_mlock_1native(
|
|||
#endif
|
||||
|
||||
#ifdef WINDOWS
|
||||
THROW(env, "java/io/IOException",
|
||||
"The function POSIX.mlock_native() is not supported on Windows");
|
||||
if (!VirtualLock(buf, len)) {
|
||||
CHECK_DIRECT_BUFFER_ADDRESS(buf);
|
||||
throw_ioe(env, GetLastError());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -980,6 +982,40 @@ cleanup:
|
|||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Class: org_apache_hadoop_io_nativeio_NativeIO_Windows
|
||||
* Method: extendWorkingSetSize
|
||||
* Signature: (J)V
|
||||
*
|
||||
* The "00024" in the function name is an artifact of how JNI encodes
|
||||
* special characters. U+0024 is '$'.
|
||||
*/
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_apache_hadoop_io_nativeio_NativeIO_00024Windows_extendWorkingSetSize(
|
||||
JNIEnv *env, jclass clazz, jlong delta)
|
||||
{
|
||||
#ifdef UNIX
|
||||
THROW(env, "java/io/IOException",
|
||||
"The function extendWorkingSetSize(delta) is not supported on Unix");
|
||||
#endif
|
||||
|
||||
#ifdef WINDOWS
|
||||
SIZE_T min, max;
|
||||
HANDLE hProcess = GetCurrentProcess();
|
||||
if (!GetProcessWorkingSetSize(hProcess, &min, &max)) {
|
||||
throw_ioe(env, GetLastError());
|
||||
return;
|
||||
}
|
||||
if (!SetProcessWorkingSetSizeEx(hProcess, min + delta, max + delta,
|
||||
QUOTA_LIMITS_HARDWS_MIN_DISABLE | QUOTA_LIMITS_HARDWS_MAX_DISABLE)) {
|
||||
throw_ioe(env, GetLastError());
|
||||
return;
|
||||
}
|
||||
// There is no need to call CloseHandle on the pseudo-handle returned from
|
||||
// GetCurrentProcess.
|
||||
#endif
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL
|
||||
Java_org_apache_hadoop_io_nativeio_NativeIO_renameTo0(JNIEnv *env,
|
||||
jclass clazz, jstring jsrc, jstring jdst)
|
||||
|
|
|
@ -49,7 +49,6 @@ import org.apache.hadoop.fs.Path;
|
|||
import org.apache.hadoop.fs.permission.FsPermission;
|
||||
import org.apache.hadoop.security.UserGroupInformation;
|
||||
import org.apache.hadoop.util.NativeCodeLoader;
|
||||
import org.apache.hadoop.util.Shell;
|
||||
import org.apache.hadoop.util.Time;
|
||||
|
||||
public class TestNativeIO {
|
||||
|
@ -572,7 +571,6 @@ public class TestNativeIO {
|
|||
@Test(timeout=10000)
|
||||
public void testMlock() throws Exception {
|
||||
assumeTrue(NativeIO.isAvailable());
|
||||
assumeTrue(Shell.LINUX);
|
||||
final File TEST_FILE = new File(new File(
|
||||
System.getProperty("test.build.data","build/test/data")),
|
||||
"testMlockFile");
|
||||
|
|
Loading…
Reference in New Issue