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

List types memory tracking is inaccurate #3800

Closed
chakaz opened this issue Sep 26, 2024 · 10 comments · Fixed by #4226
Closed

List types memory tracking is inaccurate #3800

chakaz opened this issue Sep 26, 2024 · 10 comments · Fixed by #4226
Assignees
Labels
bug Something isn't working important higher priority than the usual ongoing development tasks

Comments

@chakaz
Copy link
Collaborator

chakaz commented Sep 26, 2024

Create a list with 1,000,000 entries, consuming 1,000 bytes each:

debug populate 1 l 1000 RAND TYPE list ELEMENTS 100000

Then inspect it:

127.0.0.1:6379> memory usage l:0
(integer) 21000048

(this means each element in the list takes 21 bytes)

This is also shown in:

127.0.0.1:6379> info memory
[...]
type_used_memory_list:21000048
[...]
@chakaz chakaz added the bug Something isn't working label Sep 26, 2024
@kostasrim
Copy link
Contributor

Same for strings, this is a duplicate. One sec

@kostasrim
Copy link
Contributor

duplicate of #3723

@romange
Copy link
Collaborator

romange commented Sep 26, 2024

I think this bug is better defined than #3723 because it clearly shows how to reproduce it. In fact, even an external contributor can try fixing it.

@romange romange reopened this Sep 26, 2024
@kostasrim
Copy link
Contributor

kostasrim commented Sep 26, 2024

because it clearly shows how to reproduce it.

It reproduces in the test I added as well 😄 Sure let's keep it though

@romange romange added the important higher priority than the usual ongoing development tasks label Oct 2, 2024
@romange
Copy link
Collaborator

romange commented Oct 2, 2024

It could be nice if we could account for memory usage for lists in O(1) time.
I suggest introducing a __thread ssize_t cur_list_sz variable in quick_list.c. Before any operation on the list we will copy RobjWrapper::sz_ into it, then do the operation and quicklist code will update it with the size changes.
Once the operation completes we will copy cur_list_sz back into RobjWrapper::sz_ that will hold the total memory size of quicklist->entry data

romange added a commit that referenced this issue Oct 2, 2024
Also remove unused quicklist function.
Relates to #3800

Signed-off-by: Roman Gershman <[email protected]>
@romange
Copy link
Collaborator

romange commented Oct 2, 2024

Seems that quicklistNodeUpdateSz and __quicklistCompress are places where we should update cur_list_sz

romange added a commit that referenced this issue Oct 2, 2024
Also remove unused quicklist function.
Relates to #3800

Signed-off-by: Roman Gershman <[email protected]>
@andydunstall
Copy link
Contributor

Discussed with roman and agreed this will require bigger changes than expected, so unassigning myself

@andydunstall andydunstall removed their assignment Oct 15, 2024
@chakaz
Copy link
Collaborator Author

chakaz commented Nov 10, 2024

@andydunstall / @romange, can you please elaborate on what you've learned that make this bigger than originally expected? Is it not enough to add accounting in quick_list.c? What else is needed?

@romange
Copy link
Collaborator

romange commented Nov 10, 2024

It is enough but I did not feel comfortable to do intrusive changes to quicklist.cc
There are also other reasons why I preferred to move the code ownership under Dragonfly and then develop the code according to our needs.

@romange romange assigned romange and unassigned chakaz Nov 10, 2024
@romange
Copy link
Collaborator

romange commented Nov 10, 2024

@adiholden I am assigning to myself since I am doing changes in that area.

romange added a commit that referenced this issue Nov 29, 2024
After running `debug POPULATE 100 list 100 rand type list elements 10000`
with `--list_experimental_v2=false`:

```
type_used_memory_list:16512800
used_memory:105573120
```

When running with `--list_experimental_v2=true`:

```
used_memory:105573120
type_used_memory_list:103601700
```

Fixes #3800

Signed-off-by: Roman Gershman <[email protected]>
romange added a commit that referenced this issue Nov 29, 2024
After running `debug POPULATE 100 list 100 rand type list elements 10000`
with `--list_experimental_v2=false`:

```
type_used_memory_list:16512800
used_memory:105573120
```

When running with `--list_experimental_v2=true`:

```
used_memory:105573120
type_used_memory_list:103601700
```

TODO: does not yet handle compressed entries correctly but we do not enable compression by default.

Fixes #3800

Signed-off-by: Roman Gershman <[email protected]>
romange added a commit that referenced this issue Nov 29, 2024
After running `debug POPULATE 100 list 100 rand type list elements 10000`
with `--list_experimental_v2=false`:

```
type_used_memory_list:16512800
used_memory:105573120
```

When running with `--list_experimental_v2=true`:

```
used_memory:105573120
type_used_memory_list:103601700
```

TODO: does not yet handle compressed entries correctly but we do not enable compression by default.

Fixes #3800

Signed-off-by: Roman Gershman <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working important higher priority than the usual ongoing development tasks
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants