question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Windows - MMAP Memory Workspace not releasing the resource to the underlying file

See original GitHub issue

Hello,

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:closed
  • Created 3 years ago
  • Comments:11 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
raver119commented, Apr 23, 2020

Both issues were addressed. Thanks for highlighting them 😃

0reactions
lukaszbachmancommented, Apr 23, 2020

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

MMAP Memory Workspace not releasing the resource to the ...
java.nio.file.FileSystemException: D:\test.mmap: The process cannot access the file because it is being used by another process.
Read more >
What happens to the contents of a memory-mapped file when ...
Page out clean: The page is about to be removed from memory. The application has not written to the page since it was...
Read more >
Are You Sure You Want to Use MMAP in Your Database ...
ABSTRACT. Memory-mapped (mmap) file I/O is an OS-provided feature that maps the contents of a file on secondary storage into a program's.
Read more >
OCMA: Fast, Memory-Efficient Factorization of Prohibitively ...
By integrating memory mapping (mmap) and the latest matrix factorization libraries, ... methods to big genomics data using lightweight computing resources.
Read more >
- mmap(), mmap64()
Don't update the underlying file. Note: If the same region in a file is mapped twice, once with MAP_NOSYNCFILE and once without, the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found