Skip to content

DAOS-17823 client: implement LRU cache in shared memory - #16785

Merged
mchaarawi merged 18 commits into
feature/dfs_dcachefrom
lei/DAOS-17823
Sep 29, 2025
Merged

mchaarawi merged 18 commits into
feature/dfs_dcachefrom
lei/DAOS-17823

Conversation

@wiliamhuang

@wiliamhuang wiliamhuang commented Aug 29, 2025 •

Copy link
Copy Markdown
Contributor

Least Recently Used (LRU) cache designed for shared memory is implemented. It has a fixed capacity. Fine-grained lock is used by dividing cache into many smaller sub-caches to achieve better performance in high concurrency.

Steps for the author:

  • Commit message follows the guidelines.
  • Appropriate Features or Test-tag pragmas were used.
  • Appropriate Functional Test Stages were run.
  • At least two positive code reviews including at least one code owner from each category referenced in the PR.
  • Testing is complete. If necessary, forced-landing label added and a reason added in a comment.

After all prior steps are complete:

  • Gatekeeper requested (daos-gatekeeper added as a reviewer).

fix the padding issue in hash table insertion

Signed-off-by: Lei Huang <lei.huang@hpe.com>
@github-actions

Copy link
Copy Markdown

Ticket title is 'To implement LRU cache based on shm'
Status is 'In Review'
https://daosio.atlassian.net/browse/DAOS-17823

Signed-off-by: Lei Huang <lei.huang@hpe.com>
Signed-off-by: Lei Huang <lei.huang@hpe.com>
Signed-off-by: Lei Huang <lei.huang@hpe.com>
@daos-stack daos-stack deleted a comment from daosbuild3 Aug 29, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Aug 29, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Aug 29, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Aug 29, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Aug 29, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Aug 29, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Aug 29, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Aug 29, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Aug 29, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Aug 29, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Aug 29, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Aug 29, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Aug 29, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Aug 29, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Aug 29, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Aug 29, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Aug 29, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Aug 29, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Aug 29, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Aug 29, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Aug 29, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Aug 29, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Aug 29, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Aug 29, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Aug 29, 2025
Test put()/get() concurrently.

Allow-unstable-test: true

Signed-off-by: Lei Huang <lei.huang@hpe.com>
Allow-unstable-test: true

Signed-off-by: Lei Huang <lei.huang@hpe.com>

@knard38 knard38 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I will continue the review tomorrow, but if my understanding is correct some points needs to be fixed.

Comment thread src/gurt/shm_lru.c Outdated
Comment thread src/gurt/shm_lru.c Outdated
Comment thread src/gurt/shm_lru.c Outdated
Comment thread src/gurt/shm_lru.c
Comment thread src/gurt/shm_lru.c
Comment thread src/gurt/shm_internal.h Outdated
Comment thread src/gurt/shm_lru.c
Comment thread src/gurt/shm_lru.c Outdated
Comment thread src/gurt/shm_lru.c Outdated
@daos-stack daos-stack deleted a comment from daosbuild3 Sep 24, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Sep 24, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Sep 24, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Sep 24, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Sep 24, 2025
@daos-stack daos-stack deleted a comment from daosbuild3 Sep 24, 2025
set cache pointer in test_lrucache and decrease the number of repeat times
simplify the rule for dynamic allocation of key and data in LRU cache

Allow-unstable-test: true

Signed-off-by: Lei Huang <lei.huang@hpe.com>
@wiliamhuang
wiliamhuang requested review from a team as code owners September 24, 2025 18:02
Allow-unstable-test: true

Signed-off-by: Lei Huang <lei.huang@hpe.com>
Allow-unstable-test: true

Signed-off-by: Lei Huang <lei.huang@hpe.com>
Comment thread src/gurt/shm_alloc.c Outdated
int depth;

/* Allocate, initialize, and perform topology detection */
hwloc_topology_init(&topology);

@knard38 knard38 Sep 25, 2025 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

My apologies to not have done it in the example, but the return code of the function calls to hwloc_topology_init() and hwloc_topology_load() should be checked.
From my understanding, the call to hwloc_topology_destroy() have to be done only if hwloc_topology_init() succeed.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you very much! Fixed as you suggested.

@wiliamhuang
wiliamhuang requested a review from knard38 September 25, 2025 12:19
Allow-unstable-test: true

Signed-off-by: Lei Huang <lei.huang@hpe.com>

@knard38 knard38 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@daosbuild3

Copy link
Copy Markdown
Collaborator

Test stage Functional Hardware Medium MD on SSD completed with status FAILURE. https://jenkins-3.daos.hpc.amslabs.hpecorp.net//job/daos-stack/job/daos/view/change-requests/job/PR-16785/21/execution/node/1554/log

Comment thread src/gurt/shm_lru.c
*new_node = NULL;

/* make sure LRU is not full */
if (subcache->first_av < 0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I do not understand how an LRU can be full. by definition it should kick the oldest element out.
did i misunderstand this here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes. That's true for regular LRU cache.
In current implementation, data copy is not done in-place and the reference count is increased by 1 after we call shm_lru_get(). The caller gets the pointer of cache entry data. The reference count is decrease once user gets all needed data from the cache entry. This allows multiple consumers to read the same cache entry concurrently.
The entry with non-zero reference count cannot be evicted. When we search an entry starting from the tail for eviction, we skip such entries since users may be reading data from them.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i see.. we probably should do some dynamic solution there.
meanwhile the put should document that on EBUSY one needs to retry or just disregard putting the element as this is not fatal.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you! I will add the document as you suggested in another PR.
Regarding "some dynamic solution", could you please provide more information if there is any suggestion in your mind? Thank you!

Comment thread src/gurt/shm_lru.c
memcpy(buf_key, key, key_size);
} else {
/* use preallocated buffer for key */
node->off_key = subcache->off_keylist + idx_node * (long int)cache->key_size;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we ever grow the lru size anywhere or it is always fixed?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

LRU size is fixed.

@wiliamhuang
wiliamhuang requested a review from a team September 29, 2025 13:45
@wiliamhuang wiliamhuang added the forced-landing The PR has known failures or has intentionally reduced testing, but should still be landed. label Sep 29, 2025
@wiliamhuang

Copy link
Copy Markdown
Contributor Author

@mchaarawi The failure in Functional Hardware Medium MD on SSD / FTEST_io.IoConsistency.1-./io/io_consistency.py is not related. Can we force land this PR? Thank you very much!

@mchaarawi

Copy link
Copy Markdown
Contributor

please add a description for landing..

@wiliamhuang

Copy link
Copy Markdown
Contributor Author

please add a description for landing..

Done as you suggested. Thank you!

@mchaarawi
mchaarawi merged commit eeb28d3 into feature/dfs_dcache Sep 29, 2025
42 of 45 checks passed
@mchaarawi
mchaarawi deleted the lei/DAOS-17823 branch September 29, 2025 14:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

forced-landing The PR has known failures or has intentionally reduced testing, but should still be landed.

Development

Successfully merging this pull request may close these issues.

4 participants