Skip to content

Fixed CORE-5611 - Higher memory consumption for prepared statements.#114

Merged
asfernandes merged 11 commits intomasterfrom
work/nodes-memory-core-5611
Nov 26, 2017
Merged

Fixed CORE-5611 - Higher memory consumption for prepared statements.#114
asfernandes merged 11 commits intomasterfrom
work/nodes-memory-core-5611

Conversation

@asfernandes
Copy link
Copy Markdown
Member

  • Remove some fields from nodes, including the pool reference and list of children nodes
  • Organize some fields for better alignment and possible reduction on node size
  • Delete DSQL scratch pool for DML statements

@asfernandes asfernandes changed the title Fixed CORE-5611 - Higher memory consumption for prepared statements in FB3. Fixed CORE-5611 - Higher memory consumption for prepared statements. Oct 3, 2017
@asfernandes
Copy link
Copy Markdown
Member Author

Can someone please review?

@asfernandes
Copy link
Copy Markdown
Member Author

Anyone to review? @dyemanov should all these changes later be backported to 3.0?

The commit fa82181 is an one that should be rewriten from scratch to backport.

@dyemanov
Copy link
Copy Markdown
Member

I'm reviewing it right now.

Comment thread src/dsql/dsql.cpp
Parser* parser = FB_NEW_POOL(*scratchPool) Parser(tdbb, *scratchPool, scratch, clientDialect,
scratch->getAttachment()->dbb_db_SQL_dialect, text, textLength,
tdbb->getAttachment()->att_charset);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What is the point in allocating the parser instance dynamically?

Comment thread src/jrd/Attachment.cpp
att_pools.add(pool);
return pool;
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is the parent-based new pool not accounted in att_pools? It's still a proper pool and must be destroyed via deletePool() in ~Attachment() if not deleted explicitly.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

When the scratch pool is manually deleted (DML statement compiled without error) the thing works with or without registering it in att_pools, as deletePool will be called and remove it.

But for the non-DML case or DML with exception in compilation, that means only the statement pool is explicitly destroyed (scratch is child of statement). In this case, it will try to destroy an already deallocated pool in detach.

Is there any real problem in deleting a child pool via its parent?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

After some tests I see that current usage (let child pool die with parent) does not decrement child pool's memory statistics when parent dies.

I think parent pools should maintain a list of its active children and when parent is destroyed it should decrement statistics from children.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@asfernandes Does child pool unmap memory got from OS when parent is destroyed? As far as I remember we always used to explicitly destroy child pools before parent.

Copy link
Copy Markdown
Member

@dyemanov dyemanov Oct 19, 2017

Choose a reason for hiding this comment

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

Is there any real problem in deleting a child pool via its parent?

AFAIK, it just never happened in our code, so I cannot answer for sure. "Parent" concept was used to redirect allocations up to some amount, but the child pool may have its own memory blocks that the parent is not aware of (and thus cannot deallocate).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

In other words, "delete by pool" concept does not apply to child pools. And I'm not sure it should - it would complicate things without any real gain.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Then how should you prefer? Making the scratch pool independent (not as child of statement) or use parent-child implementing some logic related to att_pools to never delete child after parent?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

When a child pool is going to allocate large amounts of memory, are these blocks requested from parent or are mapped directly with the OS?

They are mapped directly from OS.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'd prefer to make the scratch pool independent but please ensure that it dies when necessary (prepare failure?).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@dyemanov is it ok to merge in master now?

@asfernandes
Copy link
Copy Markdown
Member Author

@dyemanov is it ok to merge in master now?

@dyemanov
Copy link
Copy Markdown
Member

I don't have other complaints, so it can be merged. Let's wait a bit before considering a backport into v3 though.

To make it work, change MAKE_parameter to allocate parameters in the message pool (statement pool).
Children lists will be created and destroyed on demand.
Added a scope block to delete it before the scratch pool is destroyed in DsqlDmlRequest::dsqlPass.
CORE-5646 - Parse error when compiling a statement causes memory leak until attachment is disconnected.
@asfernandes asfernandes force-pushed the work/nodes-memory-core-5611 branch from 513580f to 5f5a869 Compare November 26, 2017 21:17
@asfernandes asfernandes merged commit 9f834ab into master Nov 26, 2017
@asfernandes asfernandes deleted the work/nodes-memory-core-5611 branch November 26, 2017 22:20
@dyemanov
Copy link
Copy Markdown
Member

@asfernandes , can we get back to this issue and backport into v3?

@asfernandes
Copy link
Copy Markdown
Member Author

@asfernandes , can we get back to this issue and backport into v3?

I'm rebasing and completing the old patch.

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