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

Interop broken on Linux? #11

Open
guregu opened this issue Jul 19, 2023 · 3 comments
Open

Interop broken on Linux? #11

guregu opened this issue Jul 19, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@guregu
Copy link
Collaborator

guregu commented Jul 19, 2023

$ WASMTIME_BACKTRACE_DETAILS=1 go test -v ./trealla   
=== RUN   TestInterop/custom_function
2023/07/19 18:29:51 query: interop_test(X).
2023/07/19 18:29:51 query: X is 1 + 1.
=== NAME  TestInterop
    interop_test.go:34: trealla: query error: error while executing at wasm backtrace:
            0: <unknown>!pl_query
            1: 0x1fe1db - fn_sys_host_call_2
                            at /Users/guregu/code/trealla/fork/src/predicates.c:7692:12
            2: 0x234bc6 - start
                            at /Users/guregu/code/trealla/fork/src/query.c:1611:14
            3: 0x23b115 - execute
                            at /Users/guregu/code/trealla/fork/src/query.c:1823:9
            4: 0xf8327 - run
                            at /Users/guregu/code/trealla/fork/src/parser.c:3630:3
            5: 0x223e56 - pl_query
                            at /Users/guregu/code/trealla/fork/src/prolog.c:162:12
        
        Caused by:
            wasm trap: call stack exhausted

Works ok on macOS+arm64 so probably something weird going on. This is running in a VM though.

@guregu guregu added the bug Something isn't working label Jul 19, 2023
@guregu
Copy link
Collaborator Author

guregu commented Jul 19, 2023

Hmm, looks like there's a 1MB (maybe 2MB?) stack size limit by default: bytecodealliance/wasmtime#900
This would explain a lot... the Trealla wasm build uses a 8MB stack.
There's no way to set this size yet for wasmtime-go so I will add it then fix this.
Pretty surprising it doesn't read the stack size from the binary.

@guregu
Copy link
Collaborator Author

guregu commented Jul 19, 2023

This should take care of it: bytecodealliance/wasmtime-go#180

@guregu
Copy link
Collaborator Author

guregu commented Aug 26, 2023

Hmm... it looks like it's more complex than I thought.
wasmtime divides the stack space every time a guest -> host -> guest (reentrant?) call happens
Even with the larger stack, if there's more than 2 or so reentrant queries happening the stack just becomes too small.
This can be worked around by calling Clone() on the instance passed to the native predicate, but incurs an overhead.
It might be possible to avoid this with a more complex locking system but probably not worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant