From bcc600db9feb6aa50e0880422a071d0e39ae74aa Mon Sep 17 00:00:00 2001 From: "Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com)" Date: Mon, 30 Aug 2021 16:08:05 +0100 Subject: current_process_memory_usage: Better document what happens with inaccurate commit charge calculation on older Linux kernels. --- include/llfio/revision.hpp | 6 +++--- include/llfio/v2.0/detail/impl/posix/utils.ipp | 13 +++++++++++-- include/llfio/v2.0/utils.hpp | 8 ++++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/include/llfio/revision.hpp b/include/llfio/revision.hpp index 9d544a02..08851c80 100644 --- a/include/llfio/revision.hpp +++ b/include/llfio/revision.hpp @@ -1,4 +1,4 @@ // Note the second line of this file must ALWAYS be the git SHA, third line ALWAYS the git SHA update time -#define LLFIO_PREVIOUS_COMMIT_REF 46f0760e7ed2b80c46acd91bacc130049620bee6 -#define LLFIO_PREVIOUS_COMMIT_DATE "2021-08-21 13:31:38 +00:00" -#define LLFIO_PREVIOUS_COMMIT_UNIQUE 46f0760e +#define LLFIO_PREVIOUS_COMMIT_REF 8cec4ff8fcd601b774c0ed882fe869e73d23d136 +#define LLFIO_PREVIOUS_COMMIT_DATE "2021-08-30 14:53:35 +00:00" +#define LLFIO_PREVIOUS_COMMIT_UNIQUE 8cec4ff8 diff --git a/include/llfio/v2.0/detail/impl/posix/utils.ipp b/include/llfio/v2.0/detail/impl/posix/utils.ipp index c043ca44..15fe1a5a 100644 --- a/include/llfio/v2.0/detail/impl/posix/utils.ipp +++ b/include/llfio/v2.0/detail/impl/posix/utils.ipp @@ -333,7 +333,7 @@ namespace utils (values are in pages) - /proc/[pid]/smaps_rollup: + /proc/[pid]/smaps_rollup (Linux 3.16 onwards only): total_address_space_in_use = ??? MISSING total_address_space_paged_in = ??? MISSING @@ -363,7 +363,16 @@ namespace utils if(want & process_memory_usage::want::private_committed) { std::vector smaps_rollup(256), maps(65536); - OUTCOME_TRY(fill_buffer(smaps_rollup, "/proc/self/smaps_rollup")); + auto r = fill_buffer(smaps_rollup, "/proc/self/smaps_rollup"); + if(!r) + { + if(r.error() == errc::no_such_file_or_directory) + { + // Linux kernel is too old + return errc::operation_not_supported; + } + return std::move(r).error(); + } OUTCOME_TRY(fill_buffer(maps, "/proc/self/maps")); uint64_t lazyfree = 0; { diff --git a/include/llfio/v2.0/utils.hpp b/include/llfio/v2.0/utils.hpp index 1877d43a..147dfc7b 100644 --- a/include/llfio/v2.0/utils.hpp +++ b/include/llfio/v2.0/utils.hpp @@ -236,6 +236,14 @@ namespace utils cannot distinguish between regions with the accounted flag enabled or disabled. By default, this fast path is enabled. + \note `/proc/pid/smaps_rollup` was added in Linux kernel 3.16, so the default specifying + `process_memory_usage::want::private_committed_inaccurate` will always fail on Linux + kernels preceding that with an error code comparing equal to `errc::operation_not_supported`. + As one would assume users would prefer this operation to fail on older kernels rather than + silently go slowly in complex memory spaces, it is left opt-in to request + the accurate implementation which works on older Linux kernels. Or, just don't request + `private_committed` at all, and pretend `private_paged_in` means the same thing. + \note Mac OS provides no way of reading how much memory a process has committed. We therefore supply as `private_committed` the same value as `private_paged_in`. */ -- cgit v1.2.3