Skip to content

Add FadvDontNeed option to avoid double pagecache consumption#2095

Merged
ktock merged 1 commit intocontainerd:mainfrom
wswsmao:main
Jul 29, 2025
Merged

Add FadvDontNeed option to avoid double pagecache consumption#2095
ktock merged 1 commit intocontainerd:mainfrom
wswsmao:main

Conversation

@wswsmao
Copy link
Copy Markdown
Contributor

@wswsmao wswsmao commented Jul 28, 2025

Fixes #2093

@wswsmao wswsmao changed the title fix double pagecache consumption Fix double pagecache consumption Jul 28, 2025
@wswsmao wswsmao changed the title Fix double pagecache consumption addFadvDontNeed Fix double pagecache consumption Jul 28, 2025
@wswsmao wswsmao changed the title addFadvDontNeed Fix double pagecache consumption Add FadvDontNeed option to avoid double pagecache consumption Jul 28, 2025
cache/cache.go Outdated
#include <unistd.h>
#include <errno.h>
*/
import "C"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

stargz snapshotter is imported from other projects as well so cgo should be avoided.

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.

done

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.

use unix instead

Direct bool `toml:"direct" default:"true" json:"direct"`

// FadvDontNeed forcefully clean fscache pagecache for saving memory. Default is false.
FadvDontNeed bool `toml:"fadv_dontneed" json:"fadv_dontneed"`
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

performance numbers?

Copy link
Copy Markdown
Contributor Author

@wswsmao wswsmao Jul 29, 2025

Choose a reason for hiding this comment

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

performance numbers?

Could you please clarify if you would like me to provide additional performance metrics or if you're suggesting that I should include a note on potential performance impacts in the documentation? Forgive me, I'm not entirely sure I understood this comment.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry for the unclear comment, I meant, how big can we expect the memory saving improvement from this change in the actual workloads?

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.

Sorry for the unclear comment, I meant, how big can we expect the memory saving improvement from this change in the actual workloads?

In theory, this approach can save up to 50% of memory.
I created a test image containing a 1GB file. The container under test runs a sha512sum operation on this file:

nerdctl run --rm -it --snapshotter stargz $REGISTRY_NAME/$IMAGE_NAME:alpine-1G-esgz sha512sum /bigfile

Meanwhile, in another terminal, I monitored the system's memory information:

watch -n 1 'cat /proc/meminfo | grep -E "Cached"'

Here are the test results, showing a reduction close to 50%:

fadv_dontneed before after Cached
disable 852,368 3,074,640 2,222,272
enable 852,060 2,022,852 1,170,792

Copy link
Copy Markdown
Member

@ktock ktock left a comment

Choose a reason for hiding this comment

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

Thanks

@ktock ktock merged commit 19a5bd5 into containerd:main Jul 29, 2025
81 of 85 checks passed
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.

Double pagecache consumption and solution

2 participants