Skip to content

runtime: add used_memory() implementation for FreeBSD#24909

Merged
spytheman merged 5 commits into
vlang:masterfrom
kimshrier:add-freebsd-used-memory
Jul 17, 2025
Merged

runtime: add used_memory() implementation for FreeBSD#24909
spytheman merged 5 commits into
vlang:masterfrom
kimshrier:add-freebsd-used-memory

Conversation

@kimshrier

@kimshrier kimshrier commented Jul 15, 2025

Copy link
Copy Markdown
Contributor

Adding a FreeBSD implementation of used_memory() so that the vlib/runtime/used_memory_test.v passes.

@huly-for-github

Copy link
Copy Markdown

Connected to Huly®: V_0.6-23378

@spytheman

Copy link
Copy Markdown
Contributor

I propose using getrusage/2 and the ru_maxrss field, for tcc on freebsd.

It is not ideal (since it does not shrink, when memory is freed), but it is still better than returning 0 or error, and will probably compile fine.

Comment thread vlib/runtime/used_memory_freebsd.c.v Outdated
@kimshrier

Copy link
Copy Markdown
Contributor Author

I initially used getrusage but it didn't look like it was working properly. I'll give it another try.

@spytheman

spytheman commented Jul 16, 2025

Copy link
Copy Markdown
Contributor

I have a version that does produce this:

image

getrusage behaves weirdly indeed - it sometimes returns 0 in ru_maxrss, and sometimes the reported size does not grow, even after allocation and writing was done 🤔

edit: forgot the link to the change - spytheman@43e1fb9

@kimshrier

Copy link
Copy Markdown
Contributor Author

It's rather late and I have a ton of work to do tomorrow at my day job. I'll look into what is going on with getrusage after I finish work tomorrow.

@spytheman

Copy link
Copy Markdown
Contributor

I can push the tcc fix and merge the PR, to make the test pass on freebsd if you want, for now?

@kimshrier

Copy link
Copy Markdown
Contributor Author

Go ahead and apply your fix.

@spytheman spytheman merged commit c3dfe62 into vlang:master Jul 17, 2025
76 of 78 checks passed
spytheman added a commit to spytheman/v that referenced this pull request Jul 17, 2025
* master: (22 commits)
  runtime: add used_memory() implementation for FreeBSD (vlang#24909)
  decoder2: fix checking and decoding of escape characters (fix vlang#24834) (vlang#24915)
  runtime: add note for the availability of the used_memory implementation (vlang#24913)
  compress,compress.gzip: add decompress_with_callback API (vlang#24904)
  markused: remove `@[markused]` from option and result fns (vlang#24900)
  ast: fix arch loongarch64 comptime support (fix vlang#24906) (vlang#24907)
  cgen: use alias `next` method if defined in `for x in iterator {` (vlang#24905)
  ci: cleanup produced executables after manually running `v ci/linux_ci.vsh` (vlang#24902)
  ci: skip checking vlib/datatypes/lockfree/ringbuffer_test.v on the gcc-windows job for now
  runtime: reduce allocations done in runtime.used_memory/0 on linux (vlang#24901)
  os: fix windows get_error_msg() leak (vlang#24899)
  runtime: add used_memory() (vlang#24897)
  ci: add `-prealloc` self compilation checks on more platforms (vlang#24891)
  cgen: allow alias types to be iterated if parent type has `next` method (fix vlang#24890) (vlang#24894)
  markused: whitelist `_option_none` too (fix vlang#24862) (vlang#24885)
  markused: fix mark for array init from sumtype (fix vlang#24887) (vlang#24889)
  cgen: add a `__closure_init` call for sokol/gg programs on android as well (vlang#24892)
  builtin,cgen,markused: add struct @[aligned] support for structs allocated on the heap too (vlang#24886)
  math.big: fix toom-cook 3-way multiplication (vlang#24888)
  x.json2.decoder2: fix option decode (fix vlang#24861) (vlang#24881)
  ...
@kimshrier kimshrier deleted the add-freebsd-used-memory branch April 28, 2026 02:05
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.

2 participants