From patchwork Mon Feb 12 07:49:31 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrey Vagin X-Patchwork-Id: 10211939 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 7D26160153 for ; Mon, 12 Feb 2018 07:49:46 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6FF24288F1 for ; Mon, 12 Feb 2018 07:49:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6480428C03; Mon, 12 Feb 2018 07:49:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 04041288F1 for ; Mon, 12 Feb 2018 07:49:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932858AbeBLHtl (ORCPT ); Mon, 12 Feb 2018 02:49:41 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:46123 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750980AbeBLHti (ORCPT ); Mon, 12 Feb 2018 02:49:38 -0500 Received: by mail-pg0-f65.google.com with SMTP id a11so7000141pgu.13 for ; Sun, 11 Feb 2018 23:49:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references; bh=REkwUoXb9hG3CFjaHF/PJ/w5/raOcf3I7vzS6Meq/Tg=; b=NfUSUyaHCLfpFkWS+MFBe3aYH5IgCnT32KQv4N/bw9ZLRpjDsXfHD+MQb+7azWqewM cd6/ndGaKzT6alP/PrK259Tia/oaoEUV7MJ9dEqyvjvURSbFeldzxT6FCfOJlzFJ1jHg +Zgzu6Tk4NGKJkzkmby0VpYGy4ef/iHSInBwf+grkpTpV9mCsFgJV6Mk8xP+zm8JV/Pl QmrQXJrUflxe7FbDBsTMv7UkPfrwDA/kpW4rLhTQRYDGP8Canu+QfXctI6HaSG2p7Vim XZSr+JBFLXShr3XqZdvieAzlNJwlF0wXXrKDskUQ74cjIV3ukWE8EoDXfKM1oHpTirmQ RBcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references; bh=REkwUoXb9hG3CFjaHF/PJ/w5/raOcf3I7vzS6Meq/Tg=; b=WPzLlbysR/xfcrrhak7+4XdWDMfbDXcHP0Lu2VziJYMcXwWM/Mf2CyEjOTZ+0oehh6 JVCdOESt8gwYki+8x9YABLJDjPypqAZjF06J+NTnJmJdnJ2+jxhP7C20A8EXEzBIpr7+ EpnR6aWzyWc4IHdtM5s8uV8uObZTvNuvGGGj0rPkj2hmtnNCimaSSonnafr1Iuu5jovP GwKdsnUAlA9tYKkuyPdtX9fmKey+a6mtFbX9y7n1lJAQ6W/zdioO3A3MEvZbFojk0qNW jE+55cf+wkXgUR0H8/Lub0CNHylCd61qbtM0LLrTAQ/+9F7vKXkgpiu8KNvGvDA8nnPG ZDvw== X-Gm-Message-State: APf1xPBwSH1IAWHirDcftr4fJ2C9+mghPj5DPYbqjyEWMyW+IiWZf9el mC9SbY5puRYOsltKaHnJXy1ss73a X-Google-Smtp-Source: AH8x2253ry93x6QINHgvufcqOdCyGEQL3mUMcVVixfUnK3r+2WKhpqEWoqQQX0+Wn4HfhmAgc0R1hg== X-Received: by 10.99.176.15 with SMTP id h15mr8824403pgf.374.1518421777983; Sun, 11 Feb 2018 23:49:37 -0800 (PST) Received: from localhost.localdomain (c-73-140-212-29.hsd1.wa.comcast.net. [73.140.212.29]) by smtp.gmail.com with ESMTPSA id x71sm26623102pfe.182.2018.02.11.23.49.37 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 11 Feb 2018 23:49:37 -0800 (PST) From: Andrei Vagin To: linux-fsdevel@vger.kernel.org, Andrew Morton Cc: Alexey Dobriyan , Andrei Vagin Subject: [PATCH 4/4] proc: replace seq_printf by seq_put_smth to speed up /proc/pid/status Date: Sun, 11 Feb 2018 23:49:31 -0800 Message-Id: <20180212074931.7227-4-avagin@openvz.org> X-Mailer: git-send-email 2.13.6 In-Reply-To: <20180212074931.7227-1-avagin@openvz.org> References: <20180212074931.7227-1-avagin@openvz.org> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP seq_printf() works slower than seq_puts, seq_puts, etc. == test_proc.c int main(int argc, char **argv) { int n, i, fd; char buf[16384]; n = atoi(argv[1]); for (i = 0; i < n; i++) { fd = open(argv[2], O_RDONLY); if (fd < 0) return 1; if (read(fd, buf, sizeof(buf)) <= 0) return 1; close(fd); } return 0; } == $ time ./test_proc 1000000 /proc/1/status == Before path == real 0m5.171s user 0m0.328s sys 0m4.783s == After patch == real 0m4.761s user 0m0.334s sys 0m4.366s Signed-off-by: Andrei Vagin --- fs/proc/array.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/fs/proc/array.c b/fs/proc/array.c index 598803576e4c..0a61affe1356 100644 --- a/fs/proc/array.c +++ b/fs/proc/array.c @@ -187,7 +187,8 @@ static inline void task_state(struct seq_file *m, struct pid_namespace *ns, task_unlock(p); rcu_read_unlock(); - seq_printf(m, "State:\t%s", get_task_state(p)); + seq_puts(m, "State:\t"); + seq_puts(m, get_task_state(p)); seq_put_decimal_ull(m, "\nTgid:\t", tgid); seq_put_decimal_ull(m, "\nNgid:\t", ngid); @@ -313,8 +314,8 @@ static void render_cap_t(struct seq_file *m, const char *header, seq_puts(m, header); CAP_FOR_EACH_U32(__capi) { - seq_printf(m, "%08x", - a->cap[CAP_LAST_U32 - __capi]); + seq_put_hex_ll(m, NULL, + a->cap[CAP_LAST_U32 - __capi], 8); } seq_putc(m, '\n'); } @@ -368,7 +369,8 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task) static inline void task_core_dumping(struct seq_file *m, struct mm_struct *mm) { - seq_printf(m, "CoreDumping:\t%d\n", !!mm->core_state); + seq_put_decimal_ull(m, "CoreDumping:\t", !!mm->core_state); + seq_putc(m, '\n'); } int proc_pid_status(struct seq_file *m, struct pid_namespace *ns, @@ -504,7 +506,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns, /* convert nsec -> ticks */ start_time = nsec_to_clock_t(task->real_start_time); - seq_printf(m, "%d (%s) %c", pid_nr_ns(pid, ns), tcomm, state); + seq_put_decimal_ull(m, "", pid_nr_ns(pid, ns)); + seq_puts(m, " ("); + seq_puts(m, tcomm); + seq_puts(m, ") "); + seq_putc(m, state); seq_put_decimal_ll(m, " ", ppid); seq_put_decimal_ll(m, " ", pgid); seq_put_decimal_ll(m, " ", sid);