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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2AA75C433FE for ; Sun, 30 Jan 2022 20:57:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9DB586B0071; Sun, 30 Jan 2022 15:57:30 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 998AC6B0073; Sun, 30 Jan 2022 15:57:30 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 8514C6B0074; Sun, 30 Jan 2022 15:57:30 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0061.hostedemail.com [216.40.44.61]) by kanga.kvack.org (Postfix) with ESMTP id 730D56B0071 for ; Sun, 30 Jan 2022 15:57:30 -0500 (EST) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 3309B91AD1 for ; Sun, 30 Jan 2022 20:57:30 +0000 (UTC) X-FDA: 79088164260.23.07A1E1E Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf02.hostedemail.com (Postfix) with ESMTP id A4EF480003 for ; Sun, 30 Jan 2022 20:57:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1643576249; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=CYWsjFfFSt2RF45PXlVv4n8PSHaq7o1llJS6PLtLhlI=; b=C/wvZzVHsS3LeZ454S2lk0oX1sR68jb3xkU8zWbSpeSPmD3sqhyaDbM0eGAADj7wVkAbVF XC+esCVyWn1QwV4NQENB7Gzoa25FCNMaKB6p6pfIoOBTVbMNKyJvWmnDdu5rQ8EERAyP/I ZWJQc/nlLiDK49EXSSLS8BOOuSwWBVY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-134-YyS5BFIUMLe47zlp5ij9Jw-1; Sun, 30 Jan 2022 15:57:23 -0500 X-MC-Unique: YyS5BFIUMLe47zlp5ij9Jw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id D37BE814245; Sun, 30 Jan 2022 20:57:20 +0000 (UTC) Received: from [10.22.16.114] (unknown [10.22.16.114]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7BD4B56F6F; Sun, 30 Jan 2022 20:57:15 +0000 (UTC) Message-ID: <53f74ef1-e097-ea2a-84ef-2d34367e60eb@redhat.com> Date: Sun, 30 Jan 2022 15:57:14 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.4.0 Subject: Re: [PATCH v2 1/3] lib/vsprintf: Avoid redundant work with 0 size Content-Language: en-US To: David Rientjes Cc: Johannes Weiner , Michal Hocko , Vladimir Davydov , Andrew Morton , Petr Mladek , Steven Rostedt , Sergey Senozhatsky , Andy Shevchenko , Rasmus Villemoes , linux-kernel@vger.kernel.org, cgroups@vger.kernel.org, linux-mm@kvack.org, Ira Weiny , Rafael Aquini References: <20220129205315.478628-1-longman@redhat.com> <20220129205315.478628-2-longman@redhat.com> From: Waiman Long In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: A4EF480003 X-Stat-Signature: os9iiw567bjns4srbzo7to7banh7azxd X-Rspam-User: nil Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="C/wvZzVH"; spf=none (imf02.hostedemail.com: domain of longman@redhat.com has no SPF policy when checking 170.10.133.124) smtp.mailfrom=longman@redhat.com; dmarc=pass (policy=none) header.from=redhat.com X-HE-Tag: 1643576249-639916 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 1/30/22 15:49, David Rientjes wrote: > On Sat, 29 Jan 2022, Waiman Long wrote: > >> For *scnprintf(), vsnprintf() is always called even if the input size is >> 0. That is a waste of time, so just return 0 in this case. >> >> Signed-off-by: Waiman Long >> --- >> lib/vsprintf.c | 8 +++++--- >> 1 file changed, 5 insertions(+), 3 deletions(-) >> >> diff --git a/lib/vsprintf.c b/lib/vsprintf.c >> index 3b8129dd374c..a65df546fb06 100644 >> --- a/lib/vsprintf.c >> +++ b/lib/vsprintf.c >> @@ -2895,13 +2895,15 @@ int vscnprintf(char *buf, size_t size, const char *fmt, va_list args) >> { >> int i; >> >> + if (!size) >> + return 0; > Nit: any reason this shouldn't be unlikely()? If the conditional for > i < size is likely(), this seems assumed already? Good suggestion. Will make the change in the next version. Cheers, Longman