From: Andrei Vagin <avagin@virtuozzo.com>
To: Andrew Morton <akpm@linux-foundation.org>
Cc: Andrei Vagin <avagin@openvz.org>,
linux-fsdevel@vger.kernel.org,
Alexey Dobriyan <adobriyan@gmail.com>,
KAMEZAWA Hiroyuki <kamezawa.hiroyu@jp.fujitsu.com>
Subject: Re: [PATCH 1/2] procfs: add seq_put_hex_ll to speed up /proc/pid/maps
Date: Sun, 14 Jan 2018 23:04:41 -0800 [thread overview]
Message-ID: <20180115070440.GA23941@outlook.office365.com> (raw)
In-Reply-To: <20180112153304.f4a7dfbae2942e3fdd93eab9@linux-foundation.org>
On Fri, Jan 12, 2018 at 03:33:04PM -0800, Andrew Morton wrote:
> On Fri, 12 Jan 2018 10:58:11 -0800 Andrei Vagin <avagin@openvz.org> wrote:
>
> > seq_put_hex_ll() prints a number in hexadecimal notation and works
> > faster than seq_printf().
> >
> > ...
> >
> > --- a/fs/seq_file.c
> > +++ b/fs/seq_file.c
> > @@ -670,6 +670,26 @@ void seq_puts(struct seq_file *m, const char *s)
> > }
> > EXPORT_SYMBOL(seq_puts);
> >
> > +static inline void seq_put_delimeter(struct seq_file *m, const char *delimiter)
> > +{
> > + int len;
> > +
> > + if (!delimiter || !delimiter[0])
> > + return;
> > +
> > + if (delimiter[1] == 0)
> > + return seq_putc(m, delimiter[0]);
> > +
> > + len = strlen(delimiter);
> > + if (m->count + len >= m->size) {
> > + seq_set_overflow(m);
> > + return;
> > + }
> > +
> > + memcpy(m->buf + m->count, delimiter, len);
> > + m->count += len;
> > +}
>
> Can we please have a nice comment describing this function's role and
> behaviour?
seq_put_decimal_* and seq_put_hex_ll prints a string before printing a
number. Originaly it was just one symbol, it is probably a reason why it
is called delimeter.
I added an optimization for a case when delimiter is one symbol, and
found that it sinificantly affect perfomance (about 13% for
/proc/pid/maps):
Without this optimization:
[root@fc24 ~]# time python test.py
real 0m9.105s
user 0m2.200s
sys 0m6.901s
With this optimization:
[root@fc24 ~]# time python test.py
real 0m8.097s
user 0m1.994s
sys 0m6.102s
If inline is replaced by noinline
[root@fc24 ~]# time python test.py
real 0m8.263s
user 0m2.058s
sys 0m6.200s
[root@fc24 ~]# cat test.py
#!/usr/bin/env python2
num = 0
with open("/proc/1/maps") as f:
for x in xrange(100000):
data = f.read()
f.seek(0, 0)
Andrew, thank you for the review, I will send a fixed patch soon.
>
> I don't think the `inline' is needed or desirable - gcc can figure that
> out, and with three callsites a `noinline' would be more justified!
>
> That `return seq_putc(...)' will generate a warning in some situations
> - seq_putc() returns void. Let's split it into 'seq_putc(...);
> return;' please.
>
> > +/**
> > + * seq_put_hex_ll - put a number in hexadecimal notation
> > + * @m: seq_file identifying the buffer to which data should be written
> > + * @delimiter: a string which is printed before the number
> > + * @v: the number
> > + * @width: a minimum field width
> > + *
> > + * seq_put_hex_ll(m, "", v, 8) is equal to seq_printf(m, "0x08llx", v)
> > + *
> > + * This routine is very quick when you show lots of numbers.
> > + * In usual cases, it will be better to use seq_printf(). It's easier to read.
> > + */
> > +void seq_put_hex_ll(struct seq_file *m, const char *delimiter,
> > + unsigned long long v, int width)
> > +{
> > + int i, len;
> > +
> > + seq_put_delimeter(m, delimiter);
> > +
> > + len = (sizeof(v) * 8 - __builtin_clzll(v) + 3) / 4;
> > +
> > + if (unlikely(len == 0))
> > + len = 1;
> > +
> > + if (len < width)
> > + len = width;
> > +
> > + if (m->count + len > m->size)
> > + goto overflow;
> > +
> > + for (i = len - 1; i >= 0; i--) {
> > + m->buf[m->count + i] = hex_asc[0xf & v];
> > + v = v >> 4;
> > + }
> > + m->count += len;
> > + return;
> > +overflow:
> > + seq_set_overflow(m);
> > +}
>
> I don't think we need the goto. Just do "seq_set_overflow(m); return;".
>
next prev parent reply other threads:[~2018-01-15 7:05 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-01-12 18:58 [PATCH 1/2] procfs: add seq_put_hex_ll to speed up /proc/pid/maps Andrei Vagin
2018-01-12 18:58 ` [PATCH 2/2] procfs: optimize seq_pad() " Andrei Vagin
2018-01-12 23:33 ` [PATCH 1/2] procfs: add seq_put_hex_ll " Andrew Morton
2018-01-15 7:04 ` Andrei Vagin [this message]
2018-01-17 8:20 ` [PATCH v2] " Andrei Vagin
2018-02-09 13:48 ` Alexey Dobriyan
2018-02-10 7:50 ` Andrei Vagin
2018-02-12 22:15 ` Alexey Dobriyan
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=20180115070440.GA23941@outlook.office365.com \
--to=avagin@virtuozzo.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=avagin@openvz.org \
--cc=kamezawa.hiroyu@jp.fujitsu.com \
--cc=linux-fsdevel@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 NNTP newsgroup(s).