Skip to content

gc_cdatanum is counted improperly #5820

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

Closed
Buristan opened this issue Feb 16, 2021 · 1 comment
Closed

gc_cdatanum is counted improperly #5820

Buristan opened this issue Feb 16, 2021 · 1 comment
Assignees
Labels
bug Something isn't working luajit
Milestone

Comments

@Buristan
Copy link
Collaborator

Some kinds of cdata are counted improperly (i.e. are not counted).

How to reproduce:
Assume we have a file named <cdatanum.lua> with the following code:

local ffi = require "ffi"

local function collected() print"collected" end

collectgarbage()
print("before", misc.getmetrics().gc_cdatanum)
ffi.gc(ffi.cast("void *", 0), collected)
collectgarbage()
collectgarbage()
print("after", misc.getmetrics().gc_cdatanum)

Output:

$ src/luajit cdatanum.lua
before  0
collected
after   -1
@Buristan Buristan added bug Something isn't working luajit teamL labels Feb 16, 2021
@Buristan Buristan self-assigned this Feb 16, 2021
Buristan added a commit to tarantool/luajit that referenced this issue Feb 16, 2021
When cdata has custom finalizer (and so LJ_GC_CDATA_FIN flag) it is not
collected immediately, when lj_cdata_free() is called. Instead, it is
resurrected and marked finalized, so it is collected at the next GC
cycle. The reason of the bug is that gc_cdatanum is decremented when
cdata is resurrected too (i.e. twice).

This patch excludes cdata decrementing from resurrection branch and
adds corresponding tests.

Follows up tarantool/tarantool#5187
Closes tarantool/tarantool#5820
Buristan added a commit to tarantool/luajit that referenced this issue Feb 16, 2021
When cdata has custom finalizer (and so LJ_GC_CDATA_FIN flag) it is not
collected immediately, when lj_cdata_free() is called. Instead, it is
resurrected and marked finalized, so it is collected at the next GC
cycle. The reason of the bug is that gc_cdatanum is decremented when
cdata is resurrected too (i.e. twice).

This patch excludes cdata decrementing from resurrection branch and
adds corresponding tests.

Relates to tarantool/tarantool#5820
Follows up tarantool/tarantool#5187
Buristan added a commit to tarantool/luajit that referenced this issue Feb 16, 2021
When cdata has custom finalizer (and so LJ_GC_CDATA_FIN flag) it is not
collected immediately, when lj_cdata_free() is called. Instead, it is
resurrected and marked finalized, so it is collected at the next GC
cycle. The reason of the bug is that gc_cdatanum is decremented when
cdata is resurrected too (i.e. twice).

This patch excludes cdata decrementing from resurrection branch and
adds corresponding tests.

Resolves tarantool/tarantool#5820
Follows up tarantool/tarantool#5187
@Buristan Buristan added the 1sp label Feb 16, 2021
@kyukhin kyukhin added this to the 1.10.10 milestone Feb 19, 2021
@sergos sergos modified the milestones: 1.10.10, 2.6.3 Feb 20, 2021
Buristan added a commit to tarantool/luajit that referenced this issue Mar 4, 2021
When cdata has custom finalizer (and so LJ_GC_CDATA_FIN flag) it is not
collected immediately, when lj_cdata_free() is called. Instead, it is
resurrected and marked finalized, so it is collected at the next GC
cycle. The reason of the bug is that gc_cdatanum is decremented when
cdata is resurrected too (i.e. twice).

This patch excludes cdata decrementing from resurrection branch and
adds corresponding tests.

Resolves tarantool/tarantool#5820
Follows up tarantool/tarantool#5187

Reviewed-by: Igor Munkin <[email protected]>
Reviewed-by: Sergey Ostanevich <[email protected]>
igormunkin pushed a commit to tarantool/luajit that referenced this issue Mar 4, 2021
When cdata has custom finalizer (and so LJ_GC_CDATA_FIN flag) it is not
collected immediately, when lj_cdata_free() is called. Instead, it is
resurrected and marked finalized, so it is collected at the next GC
cycle. The reason of the bug is that gc_cdatanum is decremented when
cdata is resurrected too (i.e. twice).

This patch excludes cdata decrementing from resurrection branch and
adds corresponding tests.

Resolves tarantool/tarantool#5820
Follows up tarantool/tarantool#5187

Reviewed-by: Igor Munkin <[email protected]>
Reviewed-by: Sergey Ostanevich <[email protected]>
Signed-off-by: Igor Munkin <[email protected]>
(cherry picked from commit 82932be)
igormunkin pushed a commit to tarantool/luajit that referenced this issue Mar 4, 2021
When cdata has custom finalizer (and so LJ_GC_CDATA_FIN flag) it is not
collected immediately, when lj_cdata_free() is called. Instead, it is
resurrected and marked finalized, so it is collected at the next GC
cycle. The reason of the bug is that gc_cdatanum is decremented when
cdata is resurrected too (i.e. twice).

This patch excludes cdata decrementing from resurrection branch and
adds corresponding tests.

Resolves tarantool/tarantool#5820
Follows up tarantool/tarantool#5187

Reviewed-by: Igor Munkin <[email protected]>
Reviewed-by: Sergey Ostanevich <[email protected]>
Signed-off-by: Igor Munkin <[email protected]>
(cherry picked from commit 82932be)
igormunkin added a commit that referenced this issue Mar 4, 2021
* core: fix cdata decrementing

Closes #5820
Follows up #5187
igormunkin added a commit that referenced this issue Mar 4, 2021
* core: fix cdata decrementing

Closes #5820
Follows up #5187
igormunkin added a commit that referenced this issue Mar 4, 2021
* core: fix cdata decrementing

Closes #5820
Follows up #5187
@igormunkin
Copy link
Collaborator

The issue is resolved in scope of tarantool/luajit@82932be. The submodule was updated in tarantool in 2.8.0-103-g3fe840b02 (3fe840b), 2.7.1-94-g755dfe2d5 (755dfe2), 2.6.2-91-g05ad06d14 (05ad06d).

@Buristan Buristan removed the memprof label Apr 19, 2021
igormunkin pushed a commit to tarantool/luajit that referenced this issue Jun 16, 2022
When cdata has custom finalizer (and so LJ_GC_CDATA_FIN flag) it is not
collected immediately, when lj_cdata_free() is called. Instead, it is
resurrected and marked finalized, so it is collected at the next GC
cycle. The reason of the bug is that gc_cdatanum is decremented when
cdata is resurrected too (i.e. twice).

This patch excludes cdata decrementing from resurrection branch and
adds corresponding tests.

Resolves tarantool/tarantool#5820
Follows up tarantool/tarantool#5187

Reviewed-by: Igor Munkin <[email protected]>
Reviewed-by: Sergey Ostanevich <[email protected]>
Signed-off-by: Igor Munkin <[email protected]>
igormunkin pushed a commit to tarantool/luajit that referenced this issue Jun 16, 2022
When cdata has custom finalizer (and so LJ_GC_CDATA_FIN flag) it is not
collected immediately, when lj_cdata_free() is called. Instead, it is
resurrected and marked finalized, so it is collected at the next GC
cycle. The reason of the bug is that gc_cdatanum is decremented when
cdata is resurrected too (i.e. twice).

This patch excludes cdata decrementing from resurrection branch and
adds corresponding tests.

Resolves tarantool/tarantool#5820
Follows up tarantool/tarantool#5187

Reviewed-by: Igor Munkin <[email protected]>
Reviewed-by: Sergey Ostanevich <[email protected]>
Signed-off-by: Igor Munkin <[email protected]>
@igormunkin igormunkin removed the teamL label Oct 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working luajit
Projects
None yet
Development

No branches or pull requests

4 participants