linux-numa.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Petr Holasek <pholasek@redhat.com>
To: linux-numa@vger.kernel.org, Andi Kleen <andi@firstfloor.org>
Cc: Filipe Brandenburger <filbranden@google.com>,
	Cliff Wickman <cpw@sgi.com>, Petr Holasek <pholasek@redhat.com>
Subject: [PATCH] libnuma: don't cache node cpumasks older than 1 second
Date: Thu, 18 Jun 2015 15:48:41 +0200	[thread overview]
Message-ID: <1434635321-25209-1-git-send-email-pholasek@redhat.com> (raw)
In-Reply-To: <20150616144805.GZ19417@two.firstfloor.org>

To preserve useful caching feature and minimize the risk of getting outdated
node cpumask after cpu hotplugging, numactl refreshes cache for every call
delayed more as one second from previous one. This is compromise between
outdated static cache and node cpumask parsing during every call of
numa_node_to_cpus which would be very inefficient.

Signed-off-by: Petr Holasek <pholasek@redhat.com>
---
 libnuma.c | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/libnuma.c b/libnuma.c
index 3717d5b..30d4ac8 100644
--- a/libnuma.c
+++ b/libnuma.c
@@ -30,6 +30,7 @@
 
 #include <sys/mman.h>
 #include <limits.h>
+#include <time.h>
 
 #include "config.h"
 #include "numa.h"
@@ -76,6 +77,7 @@ static int numprocnode = -1;
 static int numproccpu = -1;
 static int nodemask_sz = 0;
 static int cpumask_sz = 0;
+static time_t last_tstamp = 0;
 
 int numa_exit_on_error = 0;
 int numa_exit_on_warn = 0;
@@ -1328,6 +1330,7 @@ numa_node_to_cpus_v2(int node, struct bitmask *buffer)
 	FILE *f; 
 	size_t len = 0; 
 	struct bitmask *mask;
+	time_t curr_tstamp;
 
 	if (!node_cpu_mask_v2)
 		init_node_cpu_mask_v2();
@@ -1338,7 +1341,9 @@ numa_node_to_cpus_v2(int node, struct bitmask *buffer)
 	}
 	numa_bitmask_clearall(buffer);
 
-	if (node_cpu_mask_v2[node]) {
+	curr_tstamp = time(NULL);
+
+	if (node_cpu_mask_v2[node] && curr_tstamp == last_tstamp) {
 		/* have already constructed a mask for this node */
 		if (buffer->size < node_cpu_mask_v2[node]->size) {
 			numa_error("map size mismatch; abort\n");
@@ -1388,6 +1393,9 @@ numa_node_to_cpus_v2(int node, struct bitmask *buffer)
 		else
 			numa_bitmask_free(mask);
 	}
+
+	last_tstamp = curr_tstamp;
+
 	return err; 
 }
 __asm__(".symver numa_node_to_cpus_v2,numa_node_to_cpus@@libnuma_1.2");
-- 
2.4.3

      reply	other threads:[~2015-06-18 13:48 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-06-12 15:16 [PATCH] libnuma: disable caching of node cpusmasks Petr Holasek
2015-06-12 15:30 ` Andi Kleen
2015-06-16 14:40   ` Petr Holasek
2015-06-16 14:48     ` Andi Kleen
2015-06-18 13:48       ` Petr Holasek [this message]

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=1434635321-25209-1-git-send-email-pholasek@redhat.com \
    --to=pholasek@redhat.com \
    --cc=andi@firstfloor.org \
    --cc=cpw@sgi.com \
    --cc=filbranden@google.com \
    --cc=linux-numa@vger.kernel.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;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).