Received: by 2002:a05:6358:489b:b0:bb:da1:e618 with SMTP id x27csp842013rwn; Thu, 8 Sep 2022 09:28:23 -0700 (PDT) X-Google-Smtp-Source: AA6agR7anfBUD9eNJ75XGzB5M7Pud/D6kDjBw8UMEC7UBd1xqlEQ+Qv1LI+5nXySQ/BhBBap4gib X-Received: by 2002:a2e:8058:0:b0:26a:d0be:ada6 with SMTP id p24-20020a2e8058000000b0026ad0beada6mr2084435ljg.43.1662654503134; Thu, 08 Sep 2022 09:28:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662654503; cv=none; d=google.com; s=arc-20160816; b=PzDMCz7AnY6pRaQd1GbghJmUSL/G16huNpxtTU3ZqlE47wZhNhzMfZMHFLEBYG2QJB 3K/ZU7LaX7MwjgBQfdPfcxRPtN/aJP18Lk5I2l2MCEEsISPvHSCAn9M4/4de8P2JRcn4 3xpYyXbZH5zrXN+2QHpwKsp8PWPQcl77+OMMFO5pDNR29elMh2y+93CxpR6cYo1orlWf xywr4JbIlmRpO76PH6ixNiqSDkThR78nlZ6+bQnQcgTirDTFJa1+xanLJzrq2Kxm2zO2 G1Ni83Qa0N6alGmKjnprO/pAQl6O4A6KYlzdL4trr4OmQK/bgSx9G56fyNwzAczhVmZd 7/rg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=yEDDEp517YYzNNn7UeuJgnNhI2BekeSZAYp6JE4DnUk=; b=HoI1qvbLlj6uWdJ2A024cwgu366sUe5tBycZDHd23w5GbKWJubusJjoctolX2Na5oJ LNWKkzm50L0SkA2utzdvkGr4nhVbdHELEBlJizNsyDkRqY59B+DoXa1aGJXgueqozMz5 1Z/Fmu2qi9Qj0SlUBrSkLrwd6Ncis6a53vREj4cad9itd4OzhNbSYk+TdYi0Gg19fROV LS+2aqzdkPnfAx9zn1nBAidRKJKHx0ISR7JNb/qdcyiyrQyfgZ7lkKrD9Cre5m2Pvwu5 RRwxZ8tBRdJYUTYhXbIoeHcwtzLvo15wUuNIplE17yfdv6Xq4DKqfQ5UP45d/8j1QuYk y4+w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=VNj8EE9T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h7-20020a05651c124700b00261c71b26bfsi8189363ljh.554.2022.09.08.09.27.48; Thu, 08 Sep 2022 09:28:23 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=korg header.b=VNj8EE9T; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230425AbiIHPjH (ORCPT + 99 others); Thu, 8 Sep 2022 11:39:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229902AbiIHPjC (ORCPT ); Thu, 8 Sep 2022 11:39:02 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DAAD3AE869 for ; Thu, 8 Sep 2022 08:39:01 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 777E061D67 for ; Thu, 8 Sep 2022 15:39:01 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3B900C433D7; Thu, 8 Sep 2022 15:39:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1662651540; bh=zZ/SyZ5uIrt8M1sN+XQtWuDHRLfUcWLVoooJIAPUxWc=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=VNj8EE9Tsz+k+9CeVk3OH0tXqA2Bek+2sVutF1nf5+f3H6uQsmbmuIpt2w3+Oa4gN 5tIzImAjWGJsCo7KdraKE/T3mvvwGbieq+imtYEDiG1WLvGDyvP2iO1H7VCFBa6jNm cCz9UIj4TRuhegDcTp3YHsRqbQobf2QswLBu+AZk= Date: Thu, 8 Sep 2022 08:38:59 -0700 From: Andrew Morton To: "Sun, Jiebin" Cc: Tim Chen , vasily.averin@linux.dev, shakeelb@google.com, dennis@kernel.org, tj@kernel.org, cl@linux.com, ebiederm@xmission.com, legion@kernel.org, manfred@colorfullife.com, alexander.mikhalitsyn@virtuozzo.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, tim.c.chen@intel.com, feng.tang@intel.com, ying.huang@intel.com, tianyou.li@intel.com, wangyang.guo@intel.com Subject: Re: [PATCH v4] ipc/msg: mitigate the lock contention with percpu counter Message-Id: <20220908083859.24c989f08d62ddbd031005de@linux-foundation.org> In-Reply-To: References: <20220907172516.1210842-1-jiebin.sun@intel.com> <20220907143427.0ce54bbf096943ffca197fee@linux-foundation.org> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-10.3 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, 8 Sep 2022 16:25:47 +0800 "Sun, Jiebin" wrote: > In our case, if the local > percpu counter is near to INT_MAX and there comes a big msgsz, the > overflow issue could happen. percpu_counter_add_batch() handles this - your big message won't overflow an s64. Lookng at percpu_counter_add_batch(), is this tweak right? - don't need to update *fbc->counters inside the lock - that __this_cpu_sub() is an obscure way of zeroing the thing --- a/lib/percpu_counter.c~a +++ a/lib/percpu_counter.c @@ -89,8 +89,8 @@ void percpu_counter_add_batch(struct per unsigned long flags; raw_spin_lock_irqsave(&fbc->lock, flags); fbc->count += count; - __this_cpu_sub(*fbc->counters, count - amount); raw_spin_unlock_irqrestore(&fbc->lock, flags); + __this_cpu_write(*fbc->counters, 0); } else { this_cpu_add(*fbc->counters, amount); } _