Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

Re^4: IPC::Shareable sometimes leaks memory segments

by stevieb (Canon)
on Jul 09, 2019 at 15:07 UTC ( #11102602=note: print w/replies, xml ) Need Help??

in reply to Re^3: IPC::Shareable sometimes leaks memory segments
in thread IPC::Shareable sometimes leaks memory segments

I've been pouring over the code in the distribution over the last day, and am putting together the code paths quite nicely, and I've learned a LOT about the shared memory subsystem in general. Also, I've never delved into tie'd variables before, so I went down that rabbit hole so I understood what's going on there.

I've copied the code into a new repository, and will get this sorted out for sure (as to why cleanup isn't working properly especially). Now that I know how the overall thing hangs together, I now know what part of my problem was...

In the case that was causing me the most grief, was having two separate processes running (ie. completely unrelated, two separate scripts/process stacks). When the first one went out of scope, it would remove all segments (and semaphores), thereby destroying the shared data in the process. When the other, still running proc next attempted to access the shared data, it would die because the underlying memory was gone.

That's why I couldn't use destroy, but because the cleanup routines don't reliably work, I was left with leaks.

So, I'm currently trying to figure out a) why the cleanup routines don't work in all cases and how to fix it, and b) the most logical way to ensure at least one segment stays alive until *all* processes (unrelated or not) go out of scope.

Because I'm still figuring it all out, I'm unsure how to do that yet, but one attempt will be trying to add a reference to the tied variable within the shared memory itself, and then pulling it in from there into each separate object that accesses it. Whether that's a valid approach, I'm unsure at this time.

There are quite a few things within the code already I see I'm going to want to modify/remove/add, but everything completely hinges on me getting the clean routines working precisely. I'm even weighing the possibility of ditching the tied var entirely, and going more along the lines of IPC::ShareLite, and adding in my own serialization routine. That's thinking too far ahead yet though; I still need more knowledge on the "keeping the data shared, while keeping the memory segments/semaphores in check" stuff.

I'll definitely be writing a blog post about this entire learning process once I've got an exceptionally good grasp of things. This isn't something I thought I'd get so distracted by, but I've found that it's a very interesting topic, and I can already see future uses for some of my projects (even stuff that the Shareable modules don't yet currently do).

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11102602]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (7)
As of 2019-11-22 17:54 GMT
Find Nodes?
    Voting Booth?
    Strict and warnings: which comes first?

    Results (113 votes). Check out past polls.