Received: by 2002:a05:6a10:c7d3:0:0:0:0 with SMTP id h19csp864587pxy; Sun, 15 Aug 2021 02:48:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzf+kOrC8SZG7+G54VJJ4NZd8Y7mEAUc3KZNb1P5YACjLBnd7b7avgV8+Af9/eO/Eqxa17h X-Received: by 2002:a02:cbb0:: with SMTP id v16mr2183033jap.114.1629020926580; Sun, 15 Aug 2021 02:48:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629020926; cv=none; d=google.com; s=arc-20160816; b=NuIjt6hjW/6edIzGzqgB/ww+sn63h8vOkCaFy359WDKF4zSfjRw1ioIblDD+AeLVcC yCv37vZ/h/tpjtLcGUCH0d7yVAhbxEa9hvw9dZ9xKmab3Jo0zilRwmsMx/cRWVwEOQkF EAKpoyAw6wn2poWTHH1yE9Ks2ezoM8YQVEGgfWlzqb/tr+D4qnpayc7pGPh37sS2xjJp XfhJhOCshlz+bgE30DrF6uWURZkM/LeP5+94NRHrGVdHZMerNKXvSXYM0Ip8/yS3vhJT WMCI2QIfytDTg/y6GUYsxukrSRsgmdebOGdOxBNKtvu6hRGvvP8VgS8/FCmprT0irKfd Lokg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:organization :from:references:cc:to:subject:dkim-signature; bh=qwyay/dEQEEK6waiS0XNV4Vw4UtAbQ2ptEmOpQd9FII=; b=nlSUDEnKwl95S0kLAygp4Dv7u1Vq76OYA8g3tcTEWJ4ExegCcd4xjZLXnC7g4C+KZL p5vSDhqNuU2jQPKNyGnTFZic8Jxtuc6urPxT82L+FVUG/hcFr5c4eLWA2knplI+rV24y bq6s0F4SILgxNXpCPTiMGINKiIN/be4FeACp+bLOrbK+9HmKk9CdT4697MAF7yE8M24p vz/YLmRJz/PWW5go4u6w00DSK5BU7k+W4NJHOCPox8wdOHqdKNq7aW5Ty5122Lmxh+UV cLce/jru4MtIJhSnuEoE1l9oetu1VwQ0oRXbLanF1hFJlgY66SWWqhGm6avbxfKgbft+ jusg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=EVNtqTvJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f7si8040360jav.38.2021.08.15.02.48.34; Sun, 15 Aug 2021 02:48:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@canonical.com header.s=20210705 header.b=EVNtqTvJ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=canonical.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236843AbhHOJsU (ORCPT + 99 others); Sun, 15 Aug 2021 05:48:20 -0400 Received: from smtp-relay-canonical-0.canonical.com ([185.125.188.120]:58790 "EHLO smtp-relay-canonical-0.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232507AbhHOJsT (ORCPT ); Sun, 15 Aug 2021 05:48:19 -0400 Received: from [192.168.192.153] (unknown [50.45.173.99]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-canonical-0.canonical.com (Postfix) with ESMTPSA id D9C833F0AB; Sun, 15 Aug 2021 09:47:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=canonical.com; s=20210705; t=1629020867; bh=qwyay/dEQEEK6waiS0XNV4Vw4UtAbQ2ptEmOpQd9FII=; h=Subject:To:Cc:References:From:Message-ID:Date:MIME-Version: In-Reply-To:Content-Type; b=EVNtqTvJvPfxiARjevKAO52t9iDlan3/hRGljK0qOOyLh7lB6PE6U02wvHcFmu/UX y5HLKeRHg8LHcMzgE6h5xwVJCDtt0DcyvYV8I+M4g7IQkkQsvgUmJHOMiYIxsbASKQ DHvm2VIQPRW00EX4R1AkQADqcn6b0pMsYWyZh1g2UPrieXufBnba9Gc2OXGLnhPGN+ HZFpM3r6sGeFcEJtZn2QFPQei8e5ckam80fP4WWGcHPNbWp2m8Zpo6kf1mGV7J1G2R tFXM/MpHrJnao5arvYF8AjuLEuKd5kpxoLVLk1R8EoMAHfE2FsB2spucfTMyNZ4Lsu 2vrwMXqHow3xw== Subject: Re: apparmor: global buffers spin lock may get contended To: Sergey Senozhatsky , Sebastian Andrzej Siewior Cc: Peter Zijlstra , Tomasz Figa , linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org References: From: John Johansen Organization: Canonical Message-ID: Date: Sun, 15 Aug 2021 02:47:28 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.11.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/13/21 6:19 AM, Sergey Senozhatsky wrote: > Hi, > > We've notices that apparmor has switched from using per-CPU buffer pool > and per-CPU spin_lock to a global spin_lock in df323337e507a0009d3db1ea. > > This seems to be causing some contention on our build machines (with > quite a bit of cores). Because that global spin lock is a part of the > stat() sys call (and perhaps some other) > > E.g. > > - 9.29% 0.00% clang++ [kernel.vmlinux] > - 9.28% entry_SYSCALL_64_after_hwframe > - 8.98% do_syscall_64 > - 7.43% __do_sys_newlstat > - 7.43% vfs_statx > - 7.18% security_inode_getattr > - 7.15% apparmor_inode_getattr > - aa_path_perm > - 3.53% aa_get_buffer > - 3.47% _raw_spin_lock > 3.44% native_queued_spin_lock_slowpath > - 3.49% aa_put_buffer.part.0 > - 3.45% _raw_spin_lock > 3.43% native_queued_spin_lock_slowpath > > Can we fix this contention? > sorry this got filtered to a wrong mailbox. Yes this is something that can be improved, and was a concern when the switch was made from per-CPU buffers to the global pool. We can look into doing a hybrid approach where we can per cpu cache a buffer from the global pool. The trick will be coming up with when the cached buffer can be returned so we don't run into the problems that lead to df323337e507a0009d3db1ea