From: Dmitry Safonov <dima@arista.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: linux-kernel@vger.kernel.org,
Dmitry Safonov <0x7f454c46@gmail.com>,
Hua Zhong <hzhong@arista.com>, Shuah Khan <shuah@kernel.org>,
Stuart Ritchie <sritchie@arista.com>,
linux-kselftest@vger.kernel.org
Subject: Re: [PATCH] mm/selftest: Add MAP_POPULATE test
Date: Thu, 02 Aug 2018 01:29:06 +0100 [thread overview]
Message-ID: <1533169746.2679.130.camel@arista.com> (raw)
In-Reply-To: <20180801171224.562aa07efc6b1612d6d6b23f@linux-foundation.org>
On Wed, 2018-08-01 at 17:12 -0700, Andrew Morton wrote:
> On Thu, 2 Aug 2018 00:36:36 +0100 Dmitry Safonov <dima@arista.com>
> wrote:
>
> > As many other projects, we use some shmalloc allocator.
> > At some point we need to make a part of allocated pages back
> > private to
> > process. And it should be populated straight away.
> > Check that (MAP_PRIVATE | MAP_POPULATE) actually copies the private
> > page.
> >
> > ...
> >
> > --- /dev/null
> > +++ b/tools/testing/selftests/vm/map_populate.c
> >
> > ...
> >
> > +#define BUG_ON(condition, description)
> > \
> > + do {
> > \
> > + if (condition) {
> > \
> > + fprintf(stderr, "[FAIL]\t%s:%d\t%s:%s\n",
> > __func__, \
> > + __LINE__, (description),
> > strerror(errno)); \
> > + exit(1);
> > \
> > + }
> > \
> > + } while (0)
>
> This is userspace. Why not use assert()?
I wanted to print errno too. Of cause it's possible to get it from
coredump - but I think it's easier if you get buildbot reply to see
what the error is from the log.
>
> >
> > ...
> >
> > +int main(int argc, char **argv)
> > +{
> > + int sock[2], child, ret;
> > + FILE *ftmp;
> > + unsigned long *smap;
> > +
> > + ftmp = tmpfile();
>
> Seems odd to putz around with stdio when you just want the fd.
> mkstemp(), maybe?
It needs a template and unlink() call.. I can do it.
I initially thought about memfd_create(), can change it that way.
The only downside is that it will be syscall(NR_memfd_create,...)
>
> > + BUG_ON(ftmp == 0, "tmpfile()");
> > +
> > + ret = ftruncate(fileno(ftmp), MMAP_SZ);
> > + BUG_ON(ret, "ftruncate()");
> > +
> > + smap = mmap(0, MMAP_SZ, PROT_READ | PROT_WRITE,
> > + MAP_SHARED, fileno(ftmp), 0);
> > + BUG_ON(smap == MAP_FAILED, "mmap()");
> > +
> > + *smap = 0xdeadbabe;
> > + /* Probably unnecessary, but let it be. */
> > + ret = msync(smap, MMAP_SZ, MS_SYNC);
> > + BUG_ON(ret, "msync()");
> > +
> > + ret = socketpair(PF_LOCAL, SOCK_SEQPACKET, 0, sock);
> > + BUG_ON(ret, "socketpair()");
> > +
> > + child = fork();
> > + BUG_ON(child == -1, "fork()");
> > +
> > + if (child) {
> > + ret = close(sock[0]);
> > + BUG_ON(ret, "close()");
> > +
> > + return parent_f(sock[1], smap, child);
> > + }
> > +
> > + ret = close(sock[1]);
> > + BUG_ON(ret, "close()");
> > +
> > + return child_f(sock[0], smap, fileno(ftmp));
> > +}
> >
> > ...
> >
prev parent reply other threads:[~2018-08-02 0:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-08-01 23:36 [PATCH] mm/selftest: Add MAP_POPULATE test Dmitry Safonov
2018-08-02 0:02 ` Shuah Khan
2018-08-02 0:24 ` Dmitry Safonov
2018-08-02 0:12 ` Andrew Morton
2018-08-02 0:29 ` Dmitry Safonov [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=1533169746.2679.130.camel@arista.com \
--to=dima@arista.com \
--cc=0x7f454c46@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=hzhong@arista.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-kselftest@vger.kernel.org \
--cc=shuah@kernel.org \
--cc=sritchie@arista.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox