Fix memory accounting (#9739)
1. `localAllocated` is not set to 0 when resetting the memory context, which makes the statistics data incorrect. 2. Size is an unsigned integer, and `MEMORY_ACCOUNT_UPDATE_ALLOCATED` uses the opposite value for subtraction. Since they have the same bit width and the same bit results. We'd avoid using it in this way. 3. Fix memory accounting when setting a new parent. The accounting parent must be one of the ancestors of the child. Re-setting the parent might break the rule, see below: If we set the new parent to the sibling or the ancestor of the old parent, all children's accounting parent may have to change, because the old accountingParent may not be the ancestor of the children's AllocSet. We must have a loop to find it. For example: root <- A <- B <- H <- C <- D \ <-E root <- A <- B <- H \ <-E <- C <- D We want to change the parent of C to E, and both C and D have the B to be the accountingParent. After we set the new parent of C to E, the accountingParent has to update. But if the new parent of C is B, it still satisfies the above rule. So, we don't have to update the accountingParent. The issue 1 is fixed in PR(https://github.com/greenplum-db/gpdb/pull/10106). Reviewed-by: NNing Yu <nyu@pivotal.io>
Showing
想要评论请 注册 或 登录