Windows - MMAP Memory Workspace not releasing the resource to the underlying file
See original GitHub issueHello,
First of all - sorry for reporting so many MMAP related issues lately. I hit few roadblockers with my initial implementation of PCA using MMAPs and I’m working under a bit of pressure. Not something which concerns you but just wanted to say - sorry 😉
Issue Description
It looks like on Windows the MMAP resources used within the TRY-WITH-RESOURCE block are not released on a timely manner, which causes attempts of removing the oldmap file to fail. Best illustrated with this sample:
@Test
public void testDeletion()
throws IOException
{
final Path mmapFile = Paths.get("D://test.mmap");
WorkspaceConfiguration mmap = WorkspaceConfiguration.builder()
.initialSize(100 * 1024L * 1024L) // 100 mb
.policyLocation(LocationPolicy.MMAP)
.tempFilePath(mmapFile.toAbsolutePath().toString())
.build();
try (MemoryWorkspace ws = Nd4j.getWorkspaceManager().getAndActivateWorkspace(mmap, "M2")) {
Nd4j.ones(100);
}
Files.delete(mmapFile);
}
This fails immediately with
java.nio.file.FileSystemException: D:\test.mmap: The process cannot access the file because it is being used by another process.
I had a look at your tests and found the DL4JFileUtils
and that you are using deleteOnExit()
to cleanup the resources in your tests, but so happens that this piece of code also runs in a bigger test of ours which deletes the entire folder @After
each test. This obviously is causing that one to fail, because it cannot do that due to blocked resource.
Deletion works fine on Linux.
Version Information
- ND4J 1.0.0-beta6, CPU backend
- Windows (not working), tested on Linux (working)
Issue Analytics
- State:
- Created 3 years ago
- Comments:11 (6 by maintainers)
Both issues were addressed. Thanks for highlighting them 😃
Awesome! Thank you! Due to some internal conflicts with other javacpp, javacv, opencv versions it may take some time before I get to use ND4J snapshots, but I will definitely give it a go once I can. Thanks!