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

Add adaptive replacement cache #118

Merged
merged 2 commits into from
Mar 13, 2023
Merged

Conversation

qwe661234
Copy link
Collaborator

Current basic block management consumes a significant amount of memory, which leads to unnecessary waste due to frequent map allocation and release. Adaptive Replacement Cache (ARC) is a page replacement algorithm with better performance than least recently used (LRU). After the translated blocks are handled by ARC, better memory usage and hit rates can be achieved by keeping track of frequently used and recently used pages, as well as a recent eviction history for both.

According to the cache information obtained while running CoreMark, the cache hit rate of ARC can reach over 99%.

see #105

src/cache.c Fixed Show fixed Hide fixed
src/list.h Fixed Show fixed Hide fixed
src/list.h Fixed Show fixed Hide fixed
src/cache.h Fixed Show fixed Hide fixed
Makefile Outdated Show resolved Hide resolved
src/cache.c Outdated Show resolved Hide resolved
src/cache.c Outdated Show resolved Hide resolved
src/cache.h Outdated Show resolved Hide resolved
src/cache.h Outdated Show resolved Hide resolved
src/cache.h Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
Makefile Outdated Show resolved Hide resolved
src/cache.c Outdated Show resolved Hide resolved
src/cache.c Outdated Show resolved Hide resolved
src/cache.h Outdated Show resolved Hide resolved
src/cache.h Outdated Show resolved Hide resolved
src/emulate.c Outdated Show resolved Hide resolved
src/cache.h Outdated Show resolved Hide resolved
src/list.h Outdated Show resolved Hide resolved
@jserv
Copy link
Contributor

jserv commented Mar 3, 2023

Check the build system of linux-list for building test programs.

@qwe661234
Copy link
Collaborator Author

qwe661234 commented Mar 3, 2023

Check the build system of linux-list for building test programs.

Does the test programs here means new test case for testing cache?

@jserv
Copy link
Contributor

jserv commented Mar 3, 2023

Does the test programs here means new test case for testing cache?

Exactly. These test programs should be built and verified before we integrate ARC into rv32emu core.

@qwe661234 qwe661234 force-pushed the wip/add_ARC branch 3 times, most recently from 810c16d to 18bfefa Compare March 5, 2023 17:04
@qwe661234 qwe661234 requested a review from jserv March 5, 2023 17:10
Copy link
Contributor

@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.

  1. All test cases should be built from top-level Makefile.
  2. Test specific file should be placed in tests directory, and there are no file names in upper case.
  3. Show report of test cases and integrate into GitHub Actions.

src/cache.c Outdated Show resolved Hide resolved
src/cache.h Outdated Show resolved Hide resolved
src/cache.h Outdated Show resolved Hide resolved
src/list.h Outdated Show resolved Hide resolved
mk/cache-test.mk Outdated Show resolved Hide resolved
src/cache.c Outdated Show resolved Hide resolved
src/cache.c Outdated Show resolved Hide resolved
.github/workflows/main.yml Outdated Show resolved Hide resolved
@qwe661234 qwe661234 force-pushed the wip/add_ARC branch 2 times, most recently from ea22aad to f835ab1 Compare March 12, 2023 12:54
mk/tests.mk Outdated
$(VECHO) " CC\t$@\n"
$(Q)$(CC) $^ -o $(CACHE_BUILD_DIR)/$(TARGET)

$(CACHE_BUILD_DIR)/cache.o: src/cache.c
Copy link
Contributor

Choose a reason for hiding this comment

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

You can unify the rules by the following:

$(CACHE_BUILD_DIR)/%.o: $(CACHE_TEST_DIR)/%.c

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The directory of cache.c is src, but the directory of test_cache.c is tests/cache. So I cannot nuify the rules to this.

Copy link
Contributor

Choose a reason for hiding this comment

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

No, you don't have to build $(CACHE_BUILD_DIR)/cache.o. Instead, only $(CACHE_BUILD_DIR)/test_cache.o should be built here. The test oriented rules always depend on the generation of $(OBJS).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I see, cache.o would be built by make all

Copy link
Collaborator Author

@qwe661234 qwe661234 Mar 12, 2023

Choose a reason for hiding this comment

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

However, the GitHub Action fails now, because we don't integrate the cache and it does not build cache.o.

Copy link
Contributor

Choose a reason for hiding this comment

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

The appropriate sequence would be

make
make tests

Alternatively, you can extend item check to perform make tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

By the way, the next tests would be associated with #94 .

src/cache.h Outdated Show resolved Hide resolved
mk/tests.mk Outdated Show resolved Hide resolved
@qwe661234 qwe661234 force-pushed the wip/add_ARC branch 2 times, most recently from 8e1e19f to 14f79c3 Compare March 12, 2023 13:28
src/cache.c Outdated Show resolved Hide resolved
src/cache.c Outdated Show resolved Hide resolved
src/cache.c Show resolved Hide resolved
src/cache.c Outdated Show resolved Hide resolved
src/cache.c Outdated Show resolved Hide resolved
Copy link
Contributor

@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.

For the consistency, file name would use dash (-) rather than underscores (_). One exception is to emphasize the items you want to validate. e.g., test-cache_t. In this pull request, we can safely enforce the replacement for all underscores.

.github/workflows/main.yml Outdated Show resolved Hide resolved
Copy link
Contributor

@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.

Resolve CI pipeline failure.

Current basic block management consumes a significant amount of memory,
which leads to unnecessary waste due to frequent map allocation and
release. Adaptive Replacement Cache (ARC) is a page replacement
algorithm with better performance than least recently used (LRU). After
the translated blocks are handled by ARC, better memory usage and hit
rates can be achieved by keeping track of frequently used and recently
used pages, as well as a recent eviction history for both.

According to the cache information obtained while running CoreMark, the
cache hit rate of ARC can reach over 99%.
tests/cache/test-cache.c Outdated Show resolved Hide resolved
@jserv jserv merged commit 452b325 into sysprog21:master Mar 13, 2023
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