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

Replace fixed size blocks with linked list #176

Merged
merged 1 commit into from
Jan 16, 2025

Conversation

ChAoSUnItY
Copy link
Collaborator

This PR adjusts size of blocks array based on demand instead of using a constant, to prevent potential insufficient allocation issues in the future work, also reduces memory usage when compiling small programs.

I use /usr/bin/time -v ./out/shecc tests/hello.c to benchmark the usage of memory:

Before:

Command being timed: "./out/shecc tests/hello.c"
        User time (seconds): 0.00
        System time (seconds): 0.06
        Percent of CPU this job got: 93%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.07
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 224528
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 11436
        Voluntary context switches: 2
        Involuntary context switches: 0
        Swaps: 0
        File system inputs: 16
        File system outputs: 32
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0

After:

Command being timed: "./out/shecc tests/hello.c"
        User time (seconds): 0.00
        System time (seconds): 0.02
        Percent of CPU this job got: 100%
        Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.02
        Average shared text size (kbytes): 0
        Average unshared data size (kbytes): 0
        Average stack size (kbytes): 0
        Average total size (kbytes): 0
        Maximum resident set size (kbytes): 51852
        Average resident set size (kbytes): 0
        Major (requiring I/O) page faults: 0
        Minor (reclaiming a frame) page faults: 12204
        Voluntary context switches: 1
        Involuntary context switches: 1
        Swaps: 0
        File system inputs: 0
        File system outputs: 32
        Socket messages sent: 0
        Socket messages received: 0
        Signals delivered: 0
        Page size (bytes): 4096
        Exit status: 0

@jserv jserv requested a review from vacantron January 15, 2025 23:18
@jserv jserv changed the title Reimplement fixed size blocks array with linked list Replace fixed size blocks with linked list Jan 15, 2025
src/globals.c Outdated Show resolved Hide resolved
Copy link
Collaborator

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Improve git commit messages.

@ChAoSUnItY ChAoSUnItY force-pushed the refactor/reduce-blocks-alloc branch 2 times, most recently from 907682e to 4fbe2ee Compare January 16, 2025 07:42
src/defs.h Outdated Show resolved Hide resolved
src/globals.c Outdated Show resolved Hide resolved
Copy link
Collaborator

@jserv jserv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This adjustment enables compilation to use as much blocks as the
compilation  needs instead of allocating huge fixed-size array for
block structures to store, not only saves memory when compiling small
programs, but also prevents potential insufficient allocation issues
in the future work.

This improves significantly while compiling small programs. For example,
compiling "tests/hello.c" previously takes roughly 224.528 mb, while
this patch reduces to roughly 51.852 mb.
@ChAoSUnItY ChAoSUnItY force-pushed the refactor/reduce-blocks-alloc branch from 4fbe2ee to e22f595 Compare January 16, 2025 15:10
@jserv jserv merged commit cfcc553 into sysprog21:master Jan 16, 2025
6 checks passed
@jserv
Copy link
Collaborator

jserv commented Jan 16, 2025

Thank @ChAoSUnItY for contributing!

@ChAoSUnItY ChAoSUnItY deleted the refactor/reduce-blocks-alloc branch January 17, 2025 07:23
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.

3 participants