From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D16EAC433F5 for ; Fri, 15 Oct 2021 10:37:23 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7976661053 for ; Fri, 15 Oct 2021 10:37:23 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 7976661053 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id EF42C94000E; Fri, 15 Oct 2021 06:37:22 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EA427940009; Fri, 15 Oct 2021 06:37:22 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D941394000E; Fri, 15 Oct 2021 06:37:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0037.hostedemail.com [216.40.44.37]) by kanga.kvack.org (Postfix) with ESMTP id CBB32940009 for ; Fri, 15 Oct 2021 06:37:22 -0400 (EDT) Received: from smtpin01.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 7D2BE2C5BD for ; Fri, 15 Oct 2021 10:37:22 +0000 (UTC) X-FDA: 78698319924.01.2D28B3E Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf04.hostedemail.com (Postfix) with ESMTP id 32FF850000AD for ; Fri, 15 Oct 2021 10:37:21 +0000 (UTC) Received: from relay2.suse.de (relay2.suse.de [149.44.160.134]) by smtp-out2.suse.de (Postfix) with ESMTP id D9C931F770; Fri, 15 Oct 2021 10:37:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1634294240; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=FgFCS8iC20BumOM77ygbLsc59VX0YyLRTPNYnxLgQBY=; b=H57LBK8GF9w4rqelv+HYOL+3MtzUU+wA9dX7askK9NTOPiFpoPfehWa0qdtc8xvXsRBX9A /UH40nQS3hiQHE8P7aunTFXy+akjRf3CIv4EJsWQV00e03PPwOVj3XcoCtCE99BfpsqGHa O63rGwq89PU4eWzNV8G2cMS0qRjZWJ0= Received: from suse.cz (unknown [10.100.224.162]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by relay2.suse.de (Postfix) with ESMTPS id BCC33A3B87; Fri, 15 Oct 2021 10:37:20 +0000 (UTC) Date: Fri, 15 Oct 2021 12:37:17 +0200 From: Petr Mladek To: Rasmus Villemoes Cc: Yafang Shao , "Matthew Wilcox (Oracle)" , Sergey Senozhatsky , Linux MM , Vlastimil Babka Subject: Re: [PATCH 4/5] test_printf: Append '|' more efficiently Message-ID: References: <20211012182647.1605095-1-willy@infradead.org> <20211012182647.1605095-5-willy@infradead.org> <18622fb5-c4cd-7e4c-b295-e06837261fc5@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <18622fb5-c4cd-7e4c-b295-e06837261fc5@rasmusvillemoes.dk> X-Rspamd-Queue-Id: 32FF850000AD X-Stat-Signature: 77w9wyrig56sdxxq8mz4ye9rfjjyduei Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=H57LBK8G; dmarc=pass (policy=quarantine) header.from=suse.com; spf=pass (imf04.hostedemail.com: domain of pmladek@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=pmladek@suse.com X-Rspamd-Server: rspam02 X-HE-Tag: 1634294241-602737 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed 2021-10-13 11:59:38, Rasmus Villemoes wrote: > On 13/10/2021 07.22, Yafang Shao wrote: > > On Wed, Oct 13, 2021 at 2:33 AM Matthew Wilcox (Oracle) > > wrote: > >> > >> Instead of calling snprintf(), just append '|' by hand. > >> > >> Signed-off-by: Matthew Wilcox (Oracle) > >> --- > >> lib/test_printf.c | 6 +++--- > >> 1 file changed, 3 insertions(+), 3 deletions(-) > >> > >> diff --git a/lib/test_printf.c b/lib/test_printf.c > >> index 60cdf4ba991e..662c3785aa57 100644 > >> --- a/lib/test_printf.c > >> +++ b/lib/test_printf.c > >> @@ -623,9 +623,9 @@ page_flags_test(int section, int node, int zone, int last_cpupid, > >> if (!pft[i].width) > >> continue; > >> > >> - if (append) { > >> - snprintf(cmp_buf + size, BUF_SIZE - size, "|"); > >> - size = strlen(cmp_buf); > >> + if (append && size < BUF_SIZE) { > > > > Should it be: > > if (append && size < BUF_SIZE - 1) > > Perhaps, but the whole thing screams "don't do it like this". We have > seq_buf to abstract a "buffer with known length you can do a bunch of > snprintfs to". That's what should be used. Then the test can also error > out if seq_buf_has_overflowed(), because that's a bug in the test. Interesting idea. > Alternatively, the right pattern is "size += scnprintf(cmp_buf + size, > BUF_SIZE - size)", since that will eventually saturate size at BUF_SIZE-1. Yup, this is well known pattern so that it is much easier to make it correctly and review. The performance is not important here. Best Regards, Petr