#Program increasingly uses 1MB of ram every 2 seconds

126 messages · Page 1 of 1 (latest)

lime bough
#

find the source here: https://www.codeberg.org/saianonymous/gl-l1

I am monitoring via btop and the runme executable started from 150 MB of RAM and is now sitting at 300MB and has no sign of stopping

i have used -fsanitize=address and make sure there are no leaks please help

knotty pulsarBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

lime bough
#

Program increasingly uses 1MB of ram every 2 seconds

lucid flare
#

Bad link

lime bough
#

oke lemme fix

lucid flare
#

No, I mean it sends me to a 404

lime bough
#

now fixed sorry

#

typo

lime bough
prime iron
#

No one's going to do a code review on a code base, you're supposed to isolate an issue to a small snippet and ask a question. Also, you're misusing version control. You have backup files, fonts, build artifacts, etc. in there. That makes absolutely no sense.

#

Git isn't a way for you to share a directory with other people.

#

What the hell. Your header files are full of code.

#

This must be some of the worst C I've seen in a while.

#

The naming conventions too. vao_attribute returns nothing and binds the VAO/VBO. That's insane.

#

You're manually unrolling loops when the compiler will do that for you (and even take advantage of things like SSE).

#

A bunch of if (a) { ... } if (!a) { ... } which is just dumb.

#

Most .c files are just a #include statement for the code that is in their associated header file and it feels like you used static in a willy-nilly way to get away from compilation errors while essentially duplicating all the code (not even inlining it).

#

Even if I wanted to review this code it's not reasonable given how unreadable it is.

#

Even the makefiles are poorly written.

#

(Break reasonable assumptions such as the user providing various macro values, such as for CFLAGS, they don't handle dependencies, etc.)

#

Using this will only lead to incremental build problems.

#

No clear separation of concerns in the code, modularity is an afterthought, declarations are randomly intermixed with code.

#

Randomly using standard include guards here and GCC-specific include guards there.

#

So this is my honest advice and don't consider it discouragement: the code is trash and it's not because you're stupid it's because you don't know C or how to use any of the other tools for that matter (git, make). So it's exactly what you'd expect, you're not the first or last person in this situation. Scrap it, learn C (maybe start with K&R and then get up-to-date since that's C89), play around with it on some less ambitious projects, ask for help when you hit a wall, learn how to use git/make effectively, and only then come back to this project which you should 100% start from scratch. This isn't me being mean, I promise that you won't get anywhere if you keep this up. People who write proper code struggle with maintainability once code bases grow and you've used quicksand as a foundation, it will blow up in your face. Trust me, you'll have a much better time if you follow this advice. Learning stuff is maybe not as fun as tinkering but it's a prerequisite and we all had to do it. Maybe keep this around just so you see how far you've come and realize why this is so very bad.

#

And don't fall into the common pitfall of not seeing the forest from the trees. Some people react by saying "I just wanted this know how to fix this current issue, I don't want to be lectured, I'll figure it out later." without realizing they'll hit wall after wall when others can see it clearly. It's a bit like trying to make soup not being sure how to turn on the oven to boil the water, asking about it, and someone pointing out "I could tell you but what you're doing won't result in soup; you have an unopened can inside the pot of water, you're using a plastic knife to stir, and there's a gas leak".

lime bough
#

@prime iron i really appreciate you going out of your way and telling me this and i will take your word for it.... and I do understand that having someone else look at a codebase with very unreadable code is insane... at the very least i gave it a shot thanks again... i will leave this open for a week until some miracle happens and a madlad sees whats going wrong

prime iron
#

Take that time to study C, again, I would recommend by reading K&R. It's what got most people started even if it's a bit dated at this point.

#

The principles it talks about are sound.

lime bough
prime iron
#

Tinkering is more fun after learning more though 🙂

knotty pulsarBOT
#

@lime bough Has your question been resolved? If so, type !solved :)

lime bough
#

RAM consumtion on integrated GPU:

#

before

#

RAM consumtion on dedicated GPU:

#

before

#

after 10min

#

@prime iron any idea of why this is happening?

lime bough
#

is it caching ? could that possibly be it? should i let it run for a while and check if it hits a wall?

subtle crescent
#

address catches memory bugs

patent flame
# subtle crescent address catches memory bugs

ASAN enables LSAN by default. you can call __lsan_do_leak_check at any point to run LSAN before the default atexit hook, though (source)

lime bough
subtle crescent
#

do you have valgrind?

lime bough
#

Yes valgrind also says no leaks

#

I'll send the full valgrind output in a while

lime bough
#

it says ASan cannot proced correctly

lime bough
lime bough
#

so now i have used LD_PRELOAD=/usr/lib/gcc/x86_64-linux-gnu/14/libasan.so make -f Makefile.linux

lime bough
icy sphinx
#

Maybe you didn't compile codes as a debug mode?

#

I think that lacks of stacktraces

#

You added a -g3 flag 🤔

#

Did you make the libs yourself?

#

Try building those in a debug mode if you didn't

lime bough
#

assimp, stb_image, cglm, glfw and such...

#

not asan and others

lime bough
icy sphinx
#

Now that I think about it, wouldn't the link fail if some libaries were built in a debug mode and some were not

icy sphinx
lime bough
icy sphinx
#

I don't know what ggdb is

lime bough
#

is makes debug info for gdb

icy sphinx
#

I know what gdb is but never used ggdb

lime bough
#

oh no

icy sphinx
lime bough
#

it is gdb itself, just the flag looks like that

icy sphinx
#

Then try building thoese libraries with -g or -ggdb whatever

lime bough
#

i built those as instructed by readme for respective libraries

lime bough
icy sphinx
#

I'm not sure but I think the valgrind is not showing full stacktraces

lime bough
#

ah okay

#

also why is leak in libasan affecting my program if it isnt using it at all?

icy sphinx
#

It probably replaces normal memory allocators for the memory leak detection purpose

lime bough
#

libasan leaks

#

nope wait

#

im wrong

#

no matter the compiler... still libasan leaks

icy sphinx
#

I mean I don't think the libasan itself leaks

lime bough
#

SUMMARY: AddressSanitizer: 2174371 byte(s) leaked in 4910 allocation(s). clang: error: linker command failed with exit code 1 (use -v to see invocation)

icy sphinx
#

There're probably some higher codes which are not seen in stacktraces which valgrind provides

lime bough
#

im not using valgrind for this right now

icy sphinx
#

What are you using now then

lime bough
#

LD_PRELOAD=/usr/lib/gcc/x86_64-linux-gnu/14/libasan.so make -f Makefile.linux

#

make throws leak error -fsanitize=address throws error

#

if i build it without LD_PRELOAD it compiles successfully

#

you would run valgrind like this right>: valgrind ./RUNME

icy sphinx
#

yeah

lime bough
#

but it says this: if i build without LD_PRELOAD

icy sphinx
#

How told you to use LD_PRELOAD by the way

lime bough
#

shadow memory range interleaves with an existing memory mapping. ASan cannot proceed correctly. ABORTING. ==97139==ASan shadow was supposed to be located in the [0x00007fff7000-0x10007fff7fff] range. ==97139==This might be related to ELF_ET_DYN_BASE change in Linux 4.12. ==97139==See https://github.com/google/sanitizers/issues/856 for possible workarounds.

icy sphinx
#

So that's one of the workarounds?

lime bough
#
==94115== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==94115== Using Valgrind-3.22.0 and LibVEX; rerun with -h for copyright info
==94115== Command: ./RUNME
==94115== 
==94115==ASan runtime does not come first in initial library list; you should either link runtime to your application or manually preload it with LD_PRELOAD.
==94115== 
==94115== HEAP SUMMARY:
==94115==     in use at exit: 0 bytes in 0 blocks
==94115==   total heap usage: 0 allocs, 0 frees, 0 bytes allocated
==94115== 
==94115== All heap blocks were freed -- no leaks are possible
==94115== 
==94115== For lists of detected and suppressed errors, rerun with: -s
==94115== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)```
lime bough
icy sphinx
#

Oh ok maybe I just forgot about it

icy sphinx
#

This should be the correct output

#

see asam there?

#

asan itself is not leaking memory, codes which call malloc (which is replaced by asam malloc) cause memory leaks

#

So you're probably seeing wrong stacktraces and misjudging based on those

lime bough
#

i do have stacktraces

icy sphinx
#

I don't think so

lime bough
#

oh yeah i am wrong in saying libasan is leaking

#

my bad

icy sphinx
#

That's the reason why I told you to try building libraries in a debug mode though I'm not sure this will solve the issue

lime bough
#

sample:

    #0 0x7f0ca80fd9c7 in malloc ../../../../src/libsanitizer/asan/asan_malloc_linux.cpp:69
    #1 0x7f0ca7f0d536 in bfd_elf_get_elf_syms (/lib/x86_64-linux-gnu/libbfd-2.42-system.so+0x76536) (BuildId: 697bbe8a7d1d7f6ce3ccf7ce4f833c0de725d5d9)
    #2 0x7f0ca7f3ac7a  (/lib/x86_64-linux-gnu/libbfd-2.42-system.so+0xa3c7a) (BuildId: 697bbe8a7d1d7f6ce3ccf7ce4f833c0de725d5d9)
    #3 0x7f0ca7f3cde5  (/lib/x86_64-linux-gnu/libbfd-2.42-system.so+0xa5de5) (BuildId: 697bbe8a7d1d7f6ce3ccf7ce4f833c0de725d5d9)
    #4 0x7f0ca7f4a18d in bfd_elf_discard_info (/lib/x86_64-linux-gnu/libbfd-2.42-system.so+0xb318d) (BuildId: 697bbe8a7d1d7f6ce3ccf7ce4f833c0de725d5d9)
    #5 0x5bc4f2242dda  (/usr/bin/x86_64-linux-gnu-ld.bfd+0x4edda) (BuildId: 5a2a4743db96f42167dd1cdafe22203ea1e2f95b)
    #6 0x5bc4f2232f5d  (/usr/bin/x86_64-linux-gnu-ld.bfd+0x3ef5d) (BuildId: 5a2a4743db96f42167dd1cdafe22203ea1e2f95b)
    #7 0x5bc4f223aea2  (/usr/bin/x86_64-linux-gnu-ld.bfd+0x46ea2) (BuildId: 5a2a4743db96f42167dd1cdafe22203ea1e2f95b)
    #8 0x7f0ca7c2a1c9 in __libc_start_call_main ../sysdeps/nptl/libc_start_call_main.h:58
    #9 0x7f0ca7c2a28a in __libc_start_main_impl ../csu/libc-start.c:360
    #10 0x5bc4f223a1c4  (/usr/bin/x86_64-linux-gnu-ld.bfd+0x461c4) (BuildId: 5a2a4743db96f42167dd1cdafe22203ea1e2f95b)
lime bough
icy sphinx
#

Sorry but I'm not skilled enough

lime bough
#

thanks for reaching out though

icy sphinx
#

Your welcome

knotty pulsarBOT
#

@lime bough Has your question been resolved? If so, type !solved :)

dawn shard
lime bough
#

it seems this is only happen when used with iGPU seems there's no helping it

#

!solved