From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm0-f51.google.com ([74.125.82.51]:35310 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752233AbeBINsw (ORCPT ); Fri, 9 Feb 2018 08:48:52 -0500 Received: by mail-wm0-f51.google.com with SMTP id r78so16437463wme.0 for ; Fri, 09 Feb 2018 05:48:52 -0800 (PST) Date: Fri, 9 Feb 2018 16:48:47 +0300 From: Alexey Dobriyan To: Andrei Vagin Cc: linux-fsdevel@vger.kernel.org, Andrew Morton , KAMEZAWA Hiroyuki Subject: Re: [PATCH v2] procfs: add seq_put_hex_ll to speed up /proc/pid/maps Message-ID: <20180209134847.GA6916@avx2> References: <20180112153304.f4a7dfbae2942e3fdd93eab9@linux-foundation.org> <20180117082050.25406-1-avagin@openvz.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180117082050.25406-1-avagin@openvz.org> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: On Wed, Jan 17, 2018 at 12:20:50AM -0800, Andrei Vagin wrote: > + * seq_put_hex_ll(m, "", v, 8) is equal to seq_printf(m, "0x08llx", v) No, it is not. Scratch "0x". > +void seq_put_hex_ll(struct seq_file *m, const char *delimiter, > + unsigned long long v, int width) I understand that "unsigned long long" mimics decimal counterpart, but in thie case everything is "unsigned long" including ->vm_pgoff. Also, width should be unsigned for the common case of %08lx (and "len" too) > +{ > + int i, len; > + > + if (delimiter && delimiter[0]) { > + if (delimiter[1] == 0) > + seq_putc(m, delimiter[0]); > + else > + seq_puts(m, delimiter); > + } > + > + /* If x is 0, the result of __builtin_clzll is undefined */ > + if (v == 0) > + len = 1; > + else > + len = (sizeof(v) * 8 - __builtin_clzll(v) + 3) / 4; > + > + if (len < width) > + len = width; > + > + if (m->count + len > m->size) { > + seq_set_overflow(m); > + return; > + } > + > + for (i = len - 1; i >= 0; i--) { > + m->buf[m->count + i] = hex_asc[0xf & v]; > + v = v >> 4; > + } > + m->count += len; > +}