Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp1327814rwb; Sat, 3 Sep 2022 13:11:35 -0700 (PDT) X-Google-Smtp-Source: AA6agR44OzFdIAAfSBElgR990JlZhCWXeMxxrnWiolMbvhLknbYPzRi1n7+4qUzeHEuS5PJ8kND/ X-Received: by 2002:a05:6a00:8d0:b0:53b:2cbd:fab6 with SMTP id s16-20020a056a0008d000b0053b2cbdfab6mr11251970pfu.3.1662235895417; Sat, 03 Sep 2022 13:11:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662235895; cv=none; d=google.com; s=arc-20160816; b=iQiK3j2LPCpJFYck+M1FOMZUMOu79mxtJeSgCa9y6QMCXXVBfkvLO06SgBEzr5iJwx t6LUwjBRl2kjCg9lQtjb1fE+RKRTvhXOc5LOdHbxvzelpzoFGA8YXoazbxyJuIHWeXdc IVRqaF9qaOj8b1npaFgVfZmsHjasZy+jpCCzGU7hx+YwEC+njJtlLvgyJCMjI82HiRw+ Bgb/dmULMEMsd9IzVC97Bf1Q6G8F46RQ7wyCU2BzLGTrTa+5EEQjhTrOv/cRT9+vxAv5 ewIc5Op4q/P1Lpd1s3O3iu+8H6dexbVmMpCcwyQwSl0t1Mq9cx75F9c0mSMatWL5Bch0 mPvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=SZHgv5PGtCOBVjWnaY9l+4AtXRMYbHOX4QK5lq24Xw8=; b=lgEDdcMbESSVj5cRKeZr1hP9Jf2zHN7UYBWZoJBKbPEbHtG5NCD8quziQLgfPRQV9d hVtDNNYzO5saLb3OxyqQO+elmlTwCH3W8IQs4uvUzxy9fjJgZD8wNAw/nrCb9tcp7XWn Rsy6kY9eKpw/lhqJhQOTVXq2K53Jh6cdAO+0IafIAypzbxQbAt0Ckxe93TwxAC1uRtQC ZKIeHXyCcxb2BjtHbgdcUNq6yV6xlbWrKMQGE5rAInDGE4NcKmUNXcqlXY4BmnAFKNX8 VUQwrQpuy3oZvmCoJ1MGc6p5id1S1JRSWPmml23botNRyhxm4Zy2SEELUTG3BSc5DQ68 JaBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@colorfullife-com.20210112.gappssmtp.com header.s=20210112 header.b=aw2e7015; 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 t11-20020a170902bc4b00b001769ba6946fsi600519plz.548.2022.09.03.13.11.23; Sat, 03 Sep 2022 13:11:35 -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=@colorfullife-com.20210112.gappssmtp.com header.s=20210112 header.b=aw2e7015; 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 S231435AbiICTfT (ORCPT + 99 others); Sat, 3 Sep 2022 15:35:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233284AbiICTfQ (ORCPT ); Sat, 3 Sep 2022 15:35:16 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5C09A2B627 for ; Sat, 3 Sep 2022 12:35:15 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id b16so6747905edd.4 for ; Sat, 03 Sep 2022 12:35:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=colorfullife-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date; bh=SZHgv5PGtCOBVjWnaY9l+4AtXRMYbHOX4QK5lq24Xw8=; b=aw2e70151gm0RXhKYCpGiSN/b/Y9kL3kKAnQ6GeIPbheh9RyeJtsymmdTFXBzYIFJN eLpaxD5GDU81Kb16mLqlGun90ktfMKNHcgWAMVAXicC55KNq/rtAaNbPqh976P5fplZE k0i96oHIDjhDl1nQWgpbtTIhmy6jP3QhLmRFVe2wsXIwHiRfgWIq2Qj/1/ChgenWiAjE UeP8yD0+NlPun/hI5obF0Tm3unP0fVdUxrakYhsW6lAatiVHVtz+zSXdiCbludVUGuZn LYzUrVj4k/9e20thps26T4Z9mZWZvH7KrAQ+cQVFD+B+E6pf/wjNuWul4X3U4mtImkhP +iBA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date; bh=SZHgv5PGtCOBVjWnaY9l+4AtXRMYbHOX4QK5lq24Xw8=; b=lnUSyRtD1DSGyWL5xl/uQWnu9Ltf2L3eLfWUWF1RACpx/bs52K5lHEYykBIFPVHDZK Xdh3F8Rt8yNbZlNQseISOZTRZuQYakJ4nluOAPTlsSaoopOxqO03XtTMalx7W5nLu7xP 9s3Ij226nhjPllUVUYjupuXr4bTvlKPiLk8hNIjrt4mSLMsVZArMMrWpA7UL3hGmzjXG toaoIuzLtAmqRMAdOkWhUuh77CVG8PbuwtDPNhhi6EnI3Oif4gj2ChITQ0vkLW00ls6r 2VGIZU/+ss4NJ6c/MeDZzbPkzVfmSN3NVOKVuAMtjIN9mBU15IrZrIRKxSMnD0m+c4NM G5JA== X-Gm-Message-State: ACgBeo1wKE6gBwAxghBW8JPegejRU8ENmbq0PvkkfuKuF/lgZQkbceGd +H7UMUYg1YJ3LD85UZwu9ya4aA== X-Received: by 2002:aa7:db0a:0:b0:44e:5868:f489 with SMTP id t10-20020aa7db0a000000b0044e5868f489mr522344eds.299.1662233713881; Sat, 03 Sep 2022 12:35:13 -0700 (PDT) Received: from ?IPV6:2003:d9:9740:fc00:bf68:310a:7021:7923? (p200300d99740fc00bf68310a70217923.dip0.t-ipconnect.de. [2003:d9:9740:fc00:bf68:310a:7021:7923]) by smtp.googlemail.com with ESMTPSA id p23-20020a056402045700b0044792480994sm3611258edw.68.2022.09.03.12.35.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 03 Sep 2022 12:35:13 -0700 (PDT) Message-ID: Date: Sat, 3 Sep 2022 21:35:11 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.0 Subject: Re: [PATCH] ipc/msg.c: mitigate the lock contention with percpu counter To: Jiebin Sun , akpm@linux-foundation.org, vasily.averin@linux.dev, shakeelb@google.com, dennis@kernel.org, tj@kernel.org, cl@linux.com, ebiederm@xmission.com, legion@kernel.org, alexander.mikhalitsyn@virtuozzo.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Cc: tim.c.chen@intel.com, feng.tang@intel.com, ying.huang@intel.com, tianyou.li@intel.com, wangyang.guo@intel.com References: <20220902152243.479592-1-jiebin.sun@intel.com> Content-Language: en-US From: Manfred Spraul In-Reply-To: <20220902152243.479592-1-jiebin.sun@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,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 Hi Jiebin, On 9/2/22 17:22, Jiebin Sun wrote: > The msg_bytes and msg_hdrs atomic counters are frequently > updated when IPC msg queue is in heavy use, causing heavy > cache bounce and overhead. Change them to percpu_counters > greatly improve the performance. Since there is one unique > ipc namespace, additional memory cost is minimal. With ipc namespaces, there is one struct per namespace, correct? The cost is probably still ok, but the change log should be correct. > @@ -1303,14 +1305,16 @@ void msg_init_ns(struct ipc_namespace *ns) > ns->msg_ctlmnb = MSGMNB; > ns->msg_ctlmni = MSGMNI; > > - atomic_set(&ns->msg_bytes, 0); > - atomic_set(&ns->msg_hdrs, 0); > + percpu_counter_init(&ns->percpu_msg_bytes, 0, GFP_KERNEL); > + percpu_counter_init(&ns->percpu_msg_hdrs, 0, GFP_KERNEL); > ipc_init_ids(&ns->ids[IPC_MSG_IDS]); These calls can fail. You must add error handling. --     Manfred