Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RLMException mmap() failed #4868

Closed
chucktee opened this issue Apr 17, 2017 · 5 comments
Closed

RLMException mmap() failed #4868

chucktee opened this issue Apr 17, 2017 · 5 comments
Labels

Comments

@chucktee
Copy link

I did find the others on this issue, however I am still seeing it.

Xcode 8.3.1 / iOS 10.3.1
Realm Objective-C 2.5.1 / Pods

I am getting random crashes with:

Fatal Exception: RLMException
mmap() failed: Cannot allocate memory size: [some number] offset: 0

Curious is the large numbers I'm seeing. For example, I had one this morning with:
Cannot allocate memory size: 1610612736 offset: 0

When I get these, I have a piece of code that will send in a copy of the Realm with:
RLMRealm *realm = [RLMRealm defaultRealm];
NSURL *urlCopy = [NSURL fileURLWithPath:[self tempCopyPath]];
write to a file, zip and email etc. etc.

When I open the file from the device, it's 1.4MB.

I may be confused on the flow, but it looks like Realm trying for a gig+ for a 1.4MB file?

Happens in 2.4.4-2.5.1 (at least)

I'm *speculating if the on device file is growing due to lots of writes and deletes that aren't recovered, and the file I pull down (since it's a copy) has the deleted space compacted by the write.

Is there something I need to do on the device to compact and recover deleted space? Or is that a red herring-

Thanks in advance for your time.

@chucktee
Copy link
Author

NM- I've RTFM'd a little more and decided to compress by making a copy at startup.
Hopefully that works.

@jpsim jpsim added the T-Help label Apr 17, 2017
@jpsim
Copy link
Contributor

jpsim commented Apr 17, 2017

Take a look at our radar from several years ago about this: rdar://17119975. The best way to resolve this is to remind Apple of this issue. We believe there's no technical basis for the limitation.

Also, please see #4755 which will expose a block to safely compact the Realm on first access, something which is difficult to do safely using Realm's existing public interface at the moment.

@chucktee
Copy link
Author

Thanks as always @jpsim. I grabbed your code from #3513 and dropped a size test in front of it so I'm only compacting when it hits ~200MB on the assumption that some free space is OK and used.

I appreciate your help.

@jpsim
Copy link
Contributor

jpsim commented Apr 17, 2017

There are a few issues with that approach that you should be aware of, that #4755 aims to improve on:

  1. It'll attempt to compact the file even if no space will be reclaimed. For example, if the 200MB is all data, with no free space, you'll essentially rewrite the file as-is on every launch, without any savings. This is very wasteful.
  2. It assumes that you're taking care of all resource locking yourself. No other threads or processes may access the Realm while you're compacting it. The sample from my GitHub comment is prone to race conditions unless you take very special care to avoid cases that could lead to a race.

@chucktee
Copy link
Author

Our Realms don't go over 6-10MB (which is why I think I haven't seen this until recently-) so I think I'm safe on the 200MB re-write of just data.

I will re-double the watch for a race, but I'm doing this at a place where no one is trying to use the Realm yet. Hopefully.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 15, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants