All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joel Fernandes <joel@joelfernandes.org>
To: Steven Rostedt <rostedt@goodmis.org>
Cc: linux-trace-devel@vger.kernel.org, rostedt@google.com,
	vineethrp@google.com, Tzvetomir Stoyanov <tz.stoyanov@gmail.com>
Subject: Re: [PATCH] trace-cmd: Try alternate path for message cache
Date: Sun, 3 Apr 2022 15:24:33 +0000	[thread overview]
Message-ID: <Ykm8MfLnjrcRf/64@google.com> (raw)
In-Reply-To: <Ykm1jBpdD0+NjsTW@google.com>

On Sun, Apr 03, 2022 at 02:56:12PM +0000, Joel Fernandes wrote:
> On Fri, Apr 01, 2022 at 07:06:29PM -0400, Steven Rostedt wrote:
> > On Fri, 1 Apr 2022 15:50:10 -0400
> > Joel Fernandes <joel@joelfernandes.org> wrote:
> > 
> > > export TRACECMD_TEMPDIR="/data"
> > > 
> > > That’s fair. What about using memfd for this, do you feel that’s
> > > reasonable? I have not yet measured how big this file gets but if it’s
> > > small enough that might work too.
> > 
> > Is this a separate question? That is, do you mean using the above
> > environment variable *and* then use memfd?
> > 
> > I believe that the cache is used for passing the compressed data from the
> > guest to the host. I don't think it will be more than one compressed chunk.
> > 
> > But Tzvetomir would know better.
> 
> Hey Steve,
> No its the same question. Instead of temp file, I was proposing in-memory
> file using memfd_create(2), that way no hassle as long as the file is not too
> huge.
> 
> Also looks like my patch is incomplete anyway, I need to change
> tracecmd_msg_handle_cache() as well.
> 
> I'll try to write up a patch with memfd unless you guys disagree.

Something like the following seems to work, and the file grows to only 4KB.
Note with memfd, the file name does not have to be unique and the fd entry
in the process denotes the file's uniqueness.

I'll roll it into a patch, let me know if you disagree:

---8<---

diff --git a/lib/trace-cmd/include/private/trace-cmd-private.h b/lib/trace-cmd/include/private/trace-cmd-private.h
index 6934376..3aee139 100644
--- a/lib/trace-cmd/include/private/trace-cmd-private.h
+++ b/lib/trace-cmd/include/private/trace-cmd-private.h
@@ -377,7 +377,6 @@ enum tracecmd_msg_flags {
 };
 
 /* for both client and server */
-#define MSG_CACHE_FILE "/tmp/trace_msg_cacheXXXXXX"
 struct tracecmd_msg_handle {
 	int			fd;
 	short			cpu_count;
@@ -386,7 +385,6 @@ struct tracecmd_msg_handle {
 	bool			done;
 	bool			cache;
 	int			cfd;
-	char			cfile[sizeof(MSG_CACHE_FILE)];
 };
 
 struct tracecmd_tsync_protos {
diff --git a/lib/trace-cmd/trace-msg.c b/lib/trace-cmd/trace-msg.c
index 03b853e..1472f20 100644
--- a/lib/trace-cmd/trace-msg.c
+++ b/lib/trace-cmd/trace-msg.c
@@ -593,11 +593,9 @@ tracecmd_msg_handle_alloc(int fd, unsigned long flags)
 int tracecmd_msg_handle_cache(struct tracecmd_msg_handle *msg_handle)
 {
 	if (msg_handle->cfd < 0) {
-		strcpy(msg_handle->cfile, MSG_CACHE_FILE);
-		msg_handle->cfd = mkstemp(msg_handle->cfile);
+		msg_handle->cfd = memfd_create("trace_msg_cache", 0);
 		if (msg_handle->cfd < 0)
 			return -1;
-		unlink(msg_handle->cfile);
 	}
 	msg_handle->cache = true;
 	return 0;

  reply	other threads:[~2022-04-03 15:24 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-29 19:18 [PATCH] trace-cmd: Try alternate path for message cache Joel Fernandes
2022-04-01 19:37 ` Steven Rostedt
     [not found]   ` <CAEXW_YQxPgaKOMhDy8kVdaT9esvY8ctP1Mfw3RZXwkJkTYhh0w@mail.gmail.com>
2022-04-01 23:06     ` Steven Rostedt
2022-04-03 14:56       ` Joel Fernandes
2022-04-03 15:24         ` Joel Fernandes [this message]
2022-04-03 17:35           ` Steven Rostedt
2022-04-04  4:41         ` Tzvetomir Stoyanov
2022-04-04  5:02           ` Tzvetomir Stoyanov
2022-04-04 13:21             ` Joel Fernandes
2022-04-04 13:48               ` Tzvetomir Stoyanov
2022-04-04 14:11                 ` Joel Fernandes
2022-04-04 14:35                 ` Steven Rostedt
2022-04-04 14:48                   ` Tzvetomir Stoyanov
2022-04-04 15:04                     ` Steven Rostedt
2022-04-04 15:15                       ` Tzvetomir Stoyanov
2022-04-04 15:27                         ` Steven Rostedt
2022-04-04 15:32                           ` Steven Rostedt
2022-04-04 15:40                             ` Joel Fernandes
2022-04-04 15:41                               ` Joel Fernandes
2022-04-04 15:47                                 ` Steven Rostedt
2022-04-04 17:20                                   ` Joel Fernandes

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=Ykm8MfLnjrcRf/64@google.com \
    --to=joel@joelfernandes.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=rostedt@goodmis.org \
    --cc=rostedt@google.com \
    --cc=tz.stoyanov@gmail.com \
    --cc=vineethrp@google.com \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.