-
Notifications
You must be signed in to change notification settings - Fork 76
Add the utility function to clear page cache #741
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
Changes from 8 commits
606b233
b8ca03d
54c51bc
f9c4d17
1416bb1
25e82fa
0082e52
7051979
4b3017f
d84a329
e22ea53
763d7bd
f1fc66b
cb6e730
bb68d17
0bb9b69
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,10 @@ | |
#include <sys/mman.h> | ||
#include <sys/stat.h> | ||
#include <unistd.h> | ||
|
||
#include <sstream> | ||
#include <stdexcept> | ||
#include <string> | ||
#include <system_error> | ||
#include <utility> | ||
#include <vector> | ||
|
@@ -209,4 +212,16 @@ std::pair<std::size_t, std::size_t> get_page_cache_info(int fd) | |
SYSCALL_CHECK(munmap(addr, file_size)); | ||
return {num_pages_in_page_cache, num_pages}; | ||
} | ||
|
||
bool clear_page_cache(bool reclaim_dentries_and_inodes, bool clear_dirty_pages) | ||
{ | ||
KVIKIO_NVTX_FUNC_RANGE(); | ||
if (clear_dirty_pages) { sync(); } | ||
std::string param = reclaim_dentries_and_inodes ? "3" : "1"; | ||
std::stringstream ss; | ||
ss << "echo " << param << " | sudo tee /proc/sys/vm/drop_caches 1>/dev/null"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we also try without sudo? Some like: https://github.com/rapidsai/cudf/blob/6bc515d8219538b104861b48f2b8822a53be841f/cpp/benchmarks/io/cuio_common.cpp#L230 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think cuDF's implementation still relies on sudo or superuser privilege. The logic is:
Consequently:
So this PR simplifies 1 and 2 to a single PS: I actually had another implementation earlier that does not use PSS: I also had an experimental snippet that does something like below, with the hope that I can achieve temporary privilege elevation for non-superusers:
But I scratched this idea too, because it still requires users to run the process with elevated privilege, and as a result the code prior to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @vuule explained that the non-sudo command is used on specially configured machines where unprivileged users have no access to |
||
auto ret = system(ss.str().c_str()); | ||
SYSCALL_CHECK(ret); | ||
return ret == 0; | ||
} | ||
} // namespace kvikio |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,14 +14,15 @@ | |
|
||
from kvikio._lib.defaults import CompatMode # noqa: F401 | ||
from kvikio._version import __git_commit__, __version__ | ||
from kvikio.cufile import CuFile, get_page_cache_info | ||
from kvikio.cufile import CuFile, clear_page_cache, get_page_cache_info | ||
from kvikio.remote_file import RemoteFile, is_remote_file_available | ||
|
||
__all__ = [ | ||
"__git_commit__", | ||
"__version__", | ||
"CuFile", | ||
"get_page_cache_info", | ||
"clear_page_cache", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typically we try to keep There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks. Sorted. |
||
"RemoteFile", | ||
"is_remote_file_available", | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when would we want to call this without clearing the dirty pages?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd say these options are for curious minds who wonder the respective effect on page cache 😃