Skip to content

Tear down FS to free memory for old storage wrappers - #25286

Closed
butonic wants to merge 2 commits into
stable9from
fixmemleakonsyncjob
Closed

butonic wants to merge 2 commits into
stable9from
fixmemleakonsyncjob

Conversation

@butonic

@butonic butonic commented Jun 28, 2016

Copy link
Copy Markdown
Contributor

With a lot of users the carddav SyncJob will run out of memory because it fetches an avatar, causing the filesystem for every user to be initialized.

The workaround introduced to not create the skeleton when fetching an avatar can be further uglified by tearing down the filesystem so that all old storage wrappers are cleaned up. I did not want to tear down the filesystem in a different place to minimize the impact on other code paths.

@PVince81 @DeepDiver1975 @icewind1991 can you comment if the approach makes sense until we find a better solution as tracked in #22414?

This is how memory developed before this PR:

  1. at 2800 users
    1-2800users
  2. at 3900 users
    2-3900users

This is after the patch:

  1. 4600 users
    3-4600users-patched
  2. 6200 users
    4-6200users-patched

While there is still a memory increase the whole encryption wrapper and filesystem mounts stuff is now freed. There are three classes still growing:

  • \OC\User\Manager,
  • \OC\AllConfig::getUserValues() and
  • \OC\Group\Manager::getUserIdGroups()

When these three use a capped cache the biggest loosers are removed.

  • Additional memory profiling should be resceduled before the next release?

@mention-bot

Copy link
Copy Markdown

By analyzing the blame information on this pull request, we identified @rullzer, @blizzz and @icewind1991 to be potential reviewers

@butonic

butonic commented Jun 28, 2016

Copy link
Copy Markdown
Contributor Author

at 11300 users, patched
5-11300users-patched

@PVince81

Copy link
Copy Markdown
Contributor

@rullzer @icewind1991 please comment as this can have impact on the FS and also avatar logic

@DeepDiver1975

Copy link
Copy Markdown
Contributor

hmmm ... I understand the intention of the fix - but it looks like this is tearing down too much of the fs logic.

Looks like we need call teardown explicitly for the users after accessing the avatar images.

Maybe we even can get rid of initializing the filesystem for each user?
We might want to think about storing the avatar independent of the user home e.g. in a more global location. What a mess ....

@butonic

butonic commented Jun 28, 2016 •

Copy link
Copy Markdown
Contributor Author

hm ... the CardDav SyncJob is executed daily. When it runs out of memory, the job will be executed with the next cron job ... probably blocking other jobs ... and what not ...

* Basically we do not want to copy the skeleton folder
*/
\OC\Files\Filesystem::tearDown();
\OC\Files\Filesystem::initMountPoints($userId);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you do a teardown you need to follow it up by a full setup instead of only adding the mounts for a user

@butonic butonic added this to the 9.0.4-next-maintenance milestone Jun 29, 2016
/*
* Resetup FS to free memory of old storage wrappers
*/
\OC_Util::tearDownFS();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we can use setupFS here. I remember that @rullzer explicitly had to avoid setupFS due to other problems and had to resort to use initMountPoints only, which is a sub-operation of setupFS

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original issue was about skeleton copy that got triggered for every user whenever the avatar is queried: #22119
and PR here #22410

@rullzer can you remind us why you chose to use initMountPoints instead of setupFS ? I can't seem to find the reason in the PR

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need a tearDownMountPoints($user) ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rullzer tried to avoid the skeleton creation which is triggered when using \OC::$server->getUserFolder($userId); I don't see where setupFS triggers the user skeleton generation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

waiting for smashbox? the rest is green. ..

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@butonic $userId is not guaranteed to be the currently logged in user. There are cases where you are logged in as user A but request the avatar of user B.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yuck ... well ... hmmm ... but requesting an avatar image hopefully only happens when requesting it via ajax. And in this from job ... in any case, this is only a proposed workaround. We shoul focus on solving this correctly and store the avatars in a user agnostic storage that does not require doing a user specific filesystem setup. See linked issue above.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hopefully

Experience tells that we're usually unlucky on that side...

Even when requesting over ajax, the currently logged in user might still not be the one from the avatar that is fetched, for example in the share dropdown or in the users page. Last time we touched this code it was because the users page was auto-creating the skeleton files while listing the users, due to avatar fetching. This means that the users page already fetches avatars for a user who is not the same as the avatar (the fetching user being admin).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree to focus on moving the avatars to a better location, however such change will not be backportable. So depending on the goal for the fix, we might or might not want to continue finding a backportable fix in the meantime.

@PVince81 PVince81 modified the milestones: 9.0.5, 9.0.4 Jul 18, 2016
@PVince81

Copy link
Copy Markdown
Contributor

Moving this quickfix to 9.0.5.
Do we still want to spend time on this quickfix or rather invest it in the proper solution ?

@PVince81

Copy link
Copy Markdown
Contributor

....proper solution being the one that changes the location of avatars permanently, which won't be backportable.

@PVince81

Copy link
Copy Markdown
Contributor

Further ideas:

  • chunk the carddav job
  • more precise teardownFS for the user in avatarmanager but with a check if it's ok to tear down here. To check if ok check if the above initMountPoints is indeed the one that set them up, not another one

@PVince81

Copy link
Copy Markdown
Contributor

I'll have a try with the second approach.
Basically here I assume that the problem is that the avatar manager sets up the FS for many users and nevers frees it, and that the FS of other users are only ever needed by the avatar manager when running carddav jobs.

@PVince81

Copy link
Copy Markdown
Contributor

Argh, nooooo... we can't tear down that user's FS because the Avatar object that is returned still needs the mount to exist to be able to access the avatars on demand...

@PVince81

Copy link
Copy Markdown
Contributor

Even worse: I just noticed while testing something that tearDown doesn't only tear down the user's stuff, it tears down everything include the root mount "/".. And it seems setupFS with no arguments doesn't resetup the root. So your PR would likely have broken much more.

That FS part could really use a good redesign and rewrite...

@PVince81

Copy link
Copy Markdown
Contributor

Oh, looks like there's \OC\Util::tearDownFS() and \OC\Files\Filesystem:tearDown() that don't do the same thing

/me bangs head against the wall

@PVince81
PVince81 deleted the fixmemleakonsyncjob branch January 12, 2017 08:52
@lock

lock Bot commented Aug 4, 2019

Copy link
Copy Markdown

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@lock lock Bot locked as resolved and limited conversation to collaborators Aug 4, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants