From: Tvrtko Ursulin <tvrtko.ursulin@linux.intel.com>
To: Chris Wilson <chris@chris-wilson.co.uk>, igt-dev@lists.freedesktop.org
Cc: intel-gfx@lists.freedesktop.org
Subject: Re: [igt-dev] [PATCH i-g-t 01/17] lib: Report file cache as available system memory
Date: Mon, 2 Jul 2018 12:54:18 +0100 [thread overview]
Message-ID: <49308e65-3bb0-443a-32a1-33bb85a3c834@linux.intel.com> (raw)
In-Reply-To: <20180702090727.7721-1-chris@chris-wilson.co.uk>
On 02/07/2018 10:07, Chris Wilson wrote:
> sysinfo() doesn't include all reclaimable memory. In particular it
> excludes the majority of global_node_page_state(NR_FILE_PAGES),
> reclaimable pages that are a copy of on-disk files It seems the only way
> to obtain this counter is by parsing /proc/meminfo. For comparison,
> check vm_enough_memory() which includes NR_FILE_PAGES as available
> (sadly there's no way to call vm_enough_memory() directly either!)
>
> v2: Pay attention to what one writes.
>
> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
> ---
> lib/intel_os.c | 36 +++++++++++++++++++++++++++++++-----
> 1 file changed, 31 insertions(+), 5 deletions(-)
>
> diff --git a/lib/intel_os.c b/lib/intel_os.c
> index 885ffdcec..5bd18fc52 100644
> --- a/lib/intel_os.c
> +++ b/lib/intel_os.c
> @@ -84,6 +84,18 @@ intel_get_total_ram_mb(void)
> return retval / (1024*1024);
> }
>
> +static uint64_t get_meminfo(const char *info, const char *tag)
> +{
> + const char *str;
> + unsigned long val;
> +
> + str = strstr(info, tag);
> + if (str && sscanf(str + strlen(tag), " %lu", &val) == 1)
> + return (uint64_t)val << 10;
> +
> + return 0;
Might be safer to assert format was as expected and keywords we expect
are there, rather than silently return zero.
> +}
> +
> /**
> * intel_get_avail_ram_mb:
> *
> @@ -96,17 +108,31 @@ intel_get_avail_ram_mb(void)
> uint64_t retval;
>
> #ifdef HAVE_STRUCT_SYSINFO_TOTALRAM /* Linux */
> - struct sysinfo sysinf;
> + char *info;
> int fd;
>
> fd = drm_open_driver(DRIVER_INTEL);
> intel_purge_vm_caches(fd);
> close(fd);
>
> - igt_assert(sysinfo(&sysinf) == 0);
> - retval = sysinf.freeram;
> - retval += min(sysinf.freeswap, sysinf.bufferram);
> - retval *= sysinf.mem_unit;
> + fd = open("/proc", O_RDONLY);
> + info = igt_sysfs_get(fd, "meminfo");
> + close(fd);
> +
> + if (info) {
> + retval = get_meminfo(info, "MemAvailable: ");
> + retval += get_meminfo(info, "Buffers: ");
> + retval += get_meminfo(info, "Cached: ");
> + retval += get_meminfo(info, "SwapCached: ");
I think it would be more robust to have no trailing space in tag strings.
> + free(info);
> + } else {
> + struct sysinfo sysinf;
> +
> + igt_assert(sysinfo(&sysinf) == 0);
> + retval = sysinf.freeram;
> + retval += min(sysinf.freeswap, sysinf.bufferram);
> + retval *= sysinf.mem_unit;
> + }
Not sure it is worth keeping this path - will we ever not have
/proc/meminfo?
> #elif defined(_SC_PAGESIZE) && defined(_SC_AVPHYS_PAGES) /* Solaris */
> long pagesize, npages;
>
>
Google agrees with you that sysinfo indeed has this limitation. So in
general no complaints.
One tiny detail might be that this would now return a too large value -
doesn't count that it should not swap out itself when thinking about
free memory. But I don't think that is for this level of API to concern
with - it is definitely way more correct to report page cache.
Regards,
Tvrtko
_______________________________________________
igt-dev mailing list
igt-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/igt-dev
next prev parent reply other threads:[~2018-07-02 11:54 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-07-02 9:07 [Intel-gfx] [PATCH i-g-t 01/17] lib: Report file cache as available system memory Chris Wilson
2018-07-02 9:07 ` [igt-dev] [PATCH i-g-t 02/17] igt/gem_tiled_partial_pwrite_pread: Check for known swizzling Chris Wilson
2018-07-02 12:00 ` Tvrtko Ursulin
2018-07-05 11:14 ` [Intel-gfx] " Chris Wilson
2018-07-05 12:30 ` Tvrtko Ursulin
2018-07-05 12:35 ` Chris Wilson
2018-07-05 15:26 ` Tvrtko Ursulin
2018-07-05 15:55 ` Chris Wilson
2018-07-02 9:07 ` [Intel-gfx] [PATCH i-g-t 03/17] igt/gem_set_tiling_vs_pwrite: Show the erroneous value Chris Wilson
2018-07-02 12:00 ` [igt-dev] " Tvrtko Ursulin
2018-07-02 9:07 ` [igt-dev] [PATCH i-g-t 04/17] lib: Convert spin batch constructor to a factory Chris Wilson
2018-07-02 15:34 ` Tvrtko Ursulin
2018-07-02 9:07 ` [igt-dev] [PATCH i-g-t 05/17] lib: Spin fast, retire early Chris Wilson
2018-07-02 15:36 ` [Intel-gfx] " Tvrtko Ursulin
2018-07-05 11:23 ` [igt-dev] " Chris Wilson
2018-07-05 12:33 ` Tvrtko Ursulin
2018-07-05 12:42 ` [igt-dev] " Chris Wilson
2018-07-05 15:29 ` Tvrtko Ursulin
2018-07-05 15:52 ` Chris Wilson
2018-07-02 9:07 ` [Intel-gfx] [PATCH i-g-t 06/17] igt/gem_sync: Alternate stress for nop+sync Chris Wilson
2018-07-02 9:07 ` [igt-dev] [PATCH i-g-t 07/17] igt/gem_sync: Double the wakeups, twice the pain Chris Wilson
2018-07-02 9:07 ` [igt-dev] [PATCH i-g-t 08/17] igt/gem_sync: Show the baseline poll latency for wakeups Chris Wilson
2018-07-02 9:07 ` [igt-dev] [PATCH i-g-t 09/17] igt/gem_userptr: Check read-only mappings Chris Wilson
2018-07-02 9:07 ` [Intel-gfx] [PATCH i-g-t 10/17] igt: Exercise creating context with shared GTT Chris Wilson
2018-07-02 9:07 ` [Intel-gfx] [PATCH i-g-t 11/17] igt/gem_ctx_switch: Exercise queues Chris Wilson
2018-07-02 9:07 ` [igt-dev] [PATCH i-g-t 12/17] igt/gem_exec_whisper: Fork all-engine tests one-per-engine Chris Wilson
2018-07-02 9:07 ` [igt-dev] [PATCH i-g-t 13/17] igt: Add gem_ctx_engines Chris Wilson
2018-07-02 9:07 ` [igt-dev] [PATCH i-g-t 14/17] igt: Add gem_exec_balancer Chris Wilson
2018-07-02 9:07 ` [igt-dev] [PATCH i-g-t 15/17] benchmarks/wsim: Simulate and interpret .wsim Chris Wilson
2018-07-02 9:07 ` [igt-dev] [PATCH i-g-t 16/17] tools: capture execution pathways Chris Wilson
2018-07-02 9:07 ` [igt-dev] [PATCH i-g-t 17/17] igt/gem_exec_latency: Robustify measurements Chris Wilson
2018-07-02 11:54 ` Tvrtko Ursulin [this message]
2018-07-02 12:08 ` [igt-dev] [PATCH i-g-t 01/17] lib: Report file cache as available system memory Chris Wilson
2018-07-02 13:09 ` [igt-dev] ✓ Fi.CI.BAT: success for series starting with [i-g-t,01/17] " Patchwork
2018-07-02 14:16 ` [igt-dev] ✓ Fi.CI.IGT: " Patchwork
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=49308e65-3bb0-443a-32a1-33bb85a3c834@linux.intel.com \
--to=tvrtko.ursulin@linux.intel.com \
--cc=chris@chris-wilson.co.uk \
--cc=igt-dev@lists.freedesktop.org \
--cc=intel-gfx@lists.freedesktop.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox