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 181CDC74A5B for ; Tue, 21 Mar 2023 08:54:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8F82F6B0075; Tue, 21 Mar 2023 04:54:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8A7F96B0078; Tue, 21 Mar 2023 04:54:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 748D86B007B; Tue, 21 Mar 2023 04:54:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 63BED6B0075 for ; Tue, 21 Mar 2023 04:54:34 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 323321A147A for ; Tue, 21 Mar 2023 08:54:34 +0000 (UTC) X-FDA: 80592294468.23.843F138 Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) by imf19.hostedemail.com (Postfix) with ESMTP id 3B35D1A0014 for ; Tue, 21 Mar 2023 08:54:30 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=PUeizF7d; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf19.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.50 as permitted sender) smtp.mailfrom=urezki@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679388871; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ihWLb6YDeUm4LyXoGDvnXvPNh5dZmfkRW4mzY5FPdhM=; b=628yppJnHh3CG6dhCA17dYFyIyp1980+CGLhQXqgbL84Lo7KCwHinvqepP87ntY/bFMZdI YMrv5lmnobvw79gB+q17yJksZ0Cj7pwAloe0HDDd0klbiLAPwsGZ/5rKde92P/V1vohW7p kT3baPMe8FACae2J/b+KC+y1PCs7cAU= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=PUeizF7d; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf19.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.50 as permitted sender) smtp.mailfrom=urezki@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679388871; a=rsa-sha256; cv=none; b=sDhHDwU7MOgjcABoJ4yVRFCdthtC7VOopOplpSImb08FeGHDnbUZEO88+8Jfir22wyCMtH Z46WiT3b3mRfbbvS3epTf10DlDcatcRvePAwN30SBKsMv3fZXF3tcKD+3vsYIiia7jf5BI E5CVwkGbgF6ZIwpC42a8ba+Bu3yq7TI= Received: by mail-lf1-f50.google.com with SMTP id g17so18181617lfv.4 for ; Tue, 21 Mar 2023 01:54:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679388869; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc:subject:date:message-id:reply-to; bh=ihWLb6YDeUm4LyXoGDvnXvPNh5dZmfkRW4mzY5FPdhM=; b=PUeizF7dzLAZJmmyz4Qbzek28PUiJv9e9blTv2pw/0T3CuhF3KprL7LCtEIm9Jbwme eIkhw77b4qrg8nCvBEJebTu6itTSeuurkArgaVZ1YEkPcyI41jLz43/Vh7vBqquQ8i8U kOx+jzUiRR6h37OW8uI+XYmgIwVnsmTugrhGPhmTmoPmHgPBJyXhBKWg8ayzUhlumy4k bFRdCdg4RWqrwp8zDPG3ryeKWj1ZQnN87by6Y6axKqfevqW3Szk7O42xikCQtp3BpKYk s5e1ElpL/7HIKEX69eQWOzjC5ha2nWhlxFcURYkt8JMO8SSVt3/trvKLrIpSd/krX5YS xniQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679388869; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ihWLb6YDeUm4LyXoGDvnXvPNh5dZmfkRW4mzY5FPdhM=; b=EQQ20nxQVoLUz9doM5ZV9QJQbN6sAdCUvWn2abXKrn1OypeEjEhE7gdtasjeZEoLc2 thRLvvgH9VokrfqBmnphY8UgYAgYn9na8l3ShceOlMV0UAdgdnp8tcKBANz5rqnjoVR3 2H2JOhKcSeB1rZ5EVruqRMyGittN3Fwl1cTkxoIzCC1aw5bxtQ/lwQ4JBqMHa4X8XdXy 0bRrnSF4v0KT3x5mpImI4pqMpAH7uDSrIDCbCnby6ImxhVvwVeYtAlusr8Tf3CrKjLi+ bApqihTIl1LBmphZN1ZCpQkvM3UKqA4mtzHQL0hzGZVFi2WiAZY1LbwUyqRauEag5tAB PeQw== X-Gm-Message-State: AO0yUKVeVm64w2PsCrEbwpY9+baUhr5uquWS0teumKz1WwVYUDwIDCGi GwmmARAfQ6seH46ABF5u4Aw= X-Google-Smtp-Source: AK7set+HyqoO+eZz5C//84EZqAvcFQ7KS7XwqX9sdZR0jNq+5OaFBZIEVgNAuP9hR3nhr0Nv+lsEZA== X-Received: by 2002:ac2:5a1a:0:b0:4d5:a689:7580 with SMTP id q26-20020ac25a1a000000b004d5a6897580mr582688lfn.47.1679388869163; Tue, 21 Mar 2023 01:54:29 -0700 (PDT) Received: from pc636 (host-90-233-209-15.mobileonline.telia.com. [90.233.209.15]) by smtp.gmail.com with ESMTPSA id h11-20020ac250cb000000b004db3d57c3a8sm2079989lfm.96.2023.03.21.01.54.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 21 Mar 2023 01:54:28 -0700 (PDT) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Tue, 21 Mar 2023 09:54:26 +0100 To: Lorenzo Stoakes Cc: Uladzislau Rezki , Dave Chinner , linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Andrew Morton , Baoquan He , Matthew Wilcox , David Hildenbrand , Liu Shixin , Jiri Olsa Subject: Re: [PATCH v2 2/4] mm: vmalloc: use rwsem, mutex for vmap_area_lock and vmap_block->lock Message-ID: References: <6c7f1ac0aeb55faaa46a09108d3999e4595870d9.1679209395.git.lstoakes@gmail.com> <8cd31bcd-dad4-44e3-920f-299a656aea98@lucifer.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8cd31bcd-dad4-44e3-920f-299a656aea98@lucifer.local> X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 3B35D1A0014 X-Stat-Signature: othaadkdg9q1zt5dh7pte8jhfsr8u6nt X-HE-Tag: 1679388870-489124 X-HE-Meta: U2FsdGVkX19VF9eIqAh6zpQ33uEza5irg9EeUrpmbi96+GEO8IhKO0VObXaaYB/u40UJb2or4sjdbcwWghONIk5E9Xsw1FQ8fMkgeeV+xRP7lgT4SsjeZ8n5McWx5l8Vte97aaRh7Ha6P9Wv8/4a34Y+fsPPcT4shRsCcHKUaA8fxBK5M+OEEMf9VVWzJkEawvnv60b4TmMZR2MAXI0o7mkQ2cc2vwF4L2vK0wtMhQqq+S86aOISA3yVThJmyctcsiK68eNvCpJQ++lVH3CtWEihCweU/Sjiw/WxcB9l7A3kz4c1dCkwA5r3RShaWhblgkcqSDUIUoVTrcZ9P9Xk+bAKIK/n3goblKCQ0+WtuFDRmOGh0us9ILeD/kMgEBWJ88IfWW1OpAdhnixlqSxhawpeKUMC647yTZcTwT0YCz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pCbru4W2a2KckUQlNgt7tYpoOl7foJak3ueJZ2yQqMPBL/ww3M+MDoSSkus= 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 Tue, Mar 21, 2023 at 07:45:56AM +0000, Lorenzo Stoakes wrote: > On Tue, Mar 21, 2023 at 06:23:39AM +0100, Uladzislau Rezki wrote: > > On Tue, Mar 21, 2023 at 12:09:12PM +1100, Dave Chinner wrote: > > > On Sun, Mar 19, 2023 at 07:09:31AM +0000, Lorenzo Stoakes wrote: > > > > vmalloc() is, by design, not permitted to be used in atomic context and > > > > already contains components which may sleep, so avoiding spin locks is not > > > > a problem from the perspective of atomic context. > > > > > > > > The global vmap_area_lock is held when the red/black tree rooted in > > > > vmap_are_root is accessed and thus is rather long-held and under > > > > potentially high contention. It is likely to be under contention for reads > > > > rather than write, so replace it with a rwsem. > > > > > > > > Each individual vmap_block->lock is likely to be held for less time but > > > > under low contention, so a mutex is not an outrageous choice here. > > > > > > > > A subset of test_vmalloc.sh performance results:- > > > > > > > > fix_size_alloc_test 0.40% > > > > full_fit_alloc_test 2.08% > > > > long_busy_list_alloc_test 0.34% > > > > random_size_alloc_test -0.25% > > > > random_size_align_alloc_test 0.06% > > > > ... > > > > all tests cycles 0.2% > > > > > > > > This represents a tiny reduction in performance that sits barely above > > > > noise. > > > > > > I'm travelling right now, but give me a few days and I'll test this > > > against the XFS workloads that hammer the global vmalloc spin lock > > > really, really badly. XFS can use vm_map_ram and vmalloc really > > > heavily for metadata buffers and hit the global spin lock from every > > > CPU in the system at the same time (i.e. highly concurrent > > > workloads). vmalloc is also heavily used in the hottest path > > > throught the journal where we process and calculate delta changes to > > > several million items every second, again spread across every CPU in > > > the system at the same time. > > > > > > We really need the global spinlock to go away completely, but in the > > > mean time a shared read lock should help a little bit.... > > > > > Hugely appreciated Dave, however I must disappoint on the rwsem as I have now > reworked my patch set to use the original locks in order to satisfy Willy's > desire to make vmalloc atomic in future, and Uladzislau's desire to not have a > ~6% performance hit - > https://lore.kernel.org/all/cover.1679354384.git.lstoakes@gmail.com/ > > > I am working on it. I submitted a proposal how to eliminate it: > > > > > > > > Hello, LSF. > > > > Title: Introduce a per-cpu-vmap-cache to eliminate a vmap lock contention > > > > Description: > > Currently the vmap code is not scaled to number of CPU cores in a system > > because a global vmap space is protected by a single spinlock. Such approach > > has a clear bottleneck if many CPUs simultaneously access to one resource. > > > > In this talk i would like to describe a drawback, show some data related > > to contentions and places where those occur in a code. Apart of that i > > would like to share ideas how to eliminate it providing a few approaches > > and compare them. > > > > Requirements: > > * It should be a per-cpu approach; > > * Search of freed ptrs should not interfere with other freeing(as much as we can); > > * - offload allocated areas(buzy ones) per-cpu; > > * Cache ready sized objects or merge them into one big per-cpu-space(split on demand); > > * Lazily-freed areas either drained per-cpu individually or by one CPU for all; > > * Prefetch a fixed size in front and allocate per-cpu > > > > Goals: > > * Implement a per-cpu way of allocation to eliminate a contention. > > > > Thanks! > > > > > > -- > > Uladzislau Rezki > > > > That's really awesome! I will come to that talk at LSF/MM :) being able to > sustain the lock in atomic context seems to be an aspect that is important going > forward also. > Uhh... So i need to prepare then :))) -- Uladzislau Rezki