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

implement interpreter pool to reduce memory usage for threaded mode #17

Open
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

frett
Copy link
Contributor

@frett frett commented Oct 5, 2013

FUSE treats threads as light-weight objects and creates/deletes them
frequently. This leads to a new perl interpreter being created for all new
threads, but never being reclaimed/reused when a thread goes away. So, a long
running threaded mount continues to leak memory as new perl interpreters are
continuously created.

To address that issue, this pull request implements an interpreter pool to satisfy requests when running in threaded mode. Threaded callbacks will attempt to use an inactive interpreter from the pool, or create a new one if none are available.

This pull request has been tested on the following versions of perl (all running on Fedora Core):
5.8.8
5.10.0
5.14.4
5.16.3

frett added 9 commits October 3, 2013 14:10
…from being freed in the new interpreter"

This reverts commit 929a32d.

This was a temporary work around until correct refcnting could be added
also reversed test to make it clear the else is the default behavior
FUSE treats threads as light-weight objects and creates/deletes them
frequently. This leads to a new perl interpreter being created for all new
threads, but never being reclaimed/reused when a thread goes away. So, a long
running threaded mount continues to leak memory as new perl interpreters are
continuously created.

This commit is a first-pass at an alternate interpreter/thread usage pattern.
When a thread does not have an interpreter associated with it, it searches for
a currently inactive interpreter to utilize before it attempts to create one.
Accessing MY_CXT on perl < 5.10.0 fetches the object out of a global hash. All
perl data-structure accesses are not thread-safe due to refcounting. This means
that MY_CXT is not a safe place to store anything that controls access to a
specific interpreter.
@frett
Copy link
Contributor Author

frett commented Oct 5, 2013

Because this is a threaded design change, I would ask that this pull request is tested on other architectures before it gets merged in to make sure I didn't overlook something.

@demonfoo
Copy link
Collaborator

demonfoo commented Oct 5, 2013

That's my plan. I'll probably test it over the next few days; NetBSD and Mac OS X, I think, are the only non-Linux UN*X-like OSes I can think of that ship a threaded Perl interpreter. I'll probably have to dick around with FreeBSD for awhile to get a threaded build up without breaking my VM. Not sure if that's even possible with OpenBSD, since it's part of the base system. I'll see what I can figure out.

@demonfoo
Copy link
Collaborator

demonfoo commented Oct 7, 2013

So far 'make test' seems to work fine on MacOS X 10.6 and NetBSD 6.0.2; is there anything in particular that should be done to beat on it?

@frett
Copy link
Contributor Author

frett commented Oct 8, 2013

I would try some simultaneous operations (such as multiple processes reading files at the same time) to exercise the interpreter pool and actually get it potentially swapping the active interpreters for threads. For my testing I usually spawn this command on multiple shells and then copy a file while it's going:

while true; do ls -alR lib; done;

@frett
Copy link
Contributor Author

frett commented Oct 25, 2013

I've now been running a couple mounts using this patch for 2 and a half weeks without having to remount them. They are currently using less memory than they were after a couple hours without this patch, and we haven't had any issues with using the mounts.

I'm satisfied that the code is stable on Fedora Core, not sure if you ever got around to trying any stress testing on other *nix flavors.

@disaster123
Copy link

This one also fixes some deadlocks i had while using the threaded mode. THX!
Any chance to get this upstream?

@disaster123
Copy link

ping?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants