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 C6DCAC7618A for ; Mon, 20 Mar 2023 08:35:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 5EA056B0074; Mon, 20 Mar 2023 04:35:16 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 59A8C6B007B; Mon, 20 Mar 2023 04:35:16 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 43B926B007E; Mon, 20 Mar 2023 04:35:16 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 33EE96B0074 for ; Mon, 20 Mar 2023 04:35:16 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 03787160A1E for ; Mon, 20 Mar 2023 08:35:15 +0000 (UTC) X-FDA: 80588617032.22.9F9F7CF Received: from mail-wr1-f50.google.com (mail-wr1-f50.google.com [209.85.221.50]) by imf24.hostedemail.com (Postfix) with ESMTP id 29195180011 for ; Mon, 20 Mar 2023 08:35:13 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=MuqoYtE2; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf24.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.50 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679301314; 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=Mw6JA2zY0YivE6nJVSYT9uoTL/7utmSek4bJmSKErlA=; b=fKBxXMMtdxmCKd6OCui9+rS3LbLy42OmrDO8xcP/vLoH+Hb3phWt/QfJ2mhTp8R7gaDz9V buPEP6uMIkB51lJSWq0zPgjEZFMH/oUroUXRLnqd9ncQD2Mo4672fUuRav4YgB310PTXlX lTfC6ldRFFhKMoXv1NRMv+uarG++lrs= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=MuqoYtE2; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf24.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.50 as permitted sender) smtp.mailfrom=lstoakes@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679301314; a=rsa-sha256; cv=none; b=7ZnJrDrS88hiGOYWa9A2d880bCfbcHPnljqjMFHnWksJXqOog4KzYunp6WVyMCmH3rCw6g HG73yhXoOV5Es92djjx2qhCzPO8cBYCEBsvQ/0fVTwHq3P80VFGGrhf4Yc60YHT1GWLnvy SyNVyvomzbRnfqG/8orpGjjfi6OUY1U= Received: by mail-wr1-f50.google.com with SMTP id l27so1160934wrb.2 for ; Mon, 20 Mar 2023 01:35:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679301313; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Mw6JA2zY0YivE6nJVSYT9uoTL/7utmSek4bJmSKErlA=; b=MuqoYtE2A+FbAxOcuJ0LCjSECiXJedG/YWDzZ7ct3SmzvH3SKQQrga/OgBkOZx379n PWzmdELer0aISPFvHWVEkbck/cPSJD0vIUov3TyFJ1aRufsqpa4N3F5YuJg0CXiHtiao /g3aPrRkHmdSuZsbGgfwE4LKoK9Oq+2B2lqKL7RWR5a0JJPJbfzafJty8hTFnZtUdXd5 sBvEOPkKA34Os6P4fCBuHcNzNnA5HL6Br28lk/TEN+tAOrSj/rHDyaNNrenz1ptSsfDr o1BfF2+RdxRtZcHKjohX4TZG0S1SNwAH8zCJ8pqoD40xWcSkO8p5Nl4wj+XD6R4TVUdN 4SFQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679301313; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Mw6JA2zY0YivE6nJVSYT9uoTL/7utmSek4bJmSKErlA=; b=4s/KxL8bzNftPxZ9+s3CHpvHEo0G4jKmQiVPOHlvRcqrIf0cjaJ4aZ/8vVfIDDk9G6 cDta4eonKJEpaFLq1qtX8r1cnrSZGG7JTrel5+Bm4K8k/pW4GNQ7mdq6YaFEYoN+k6RJ 1ucBA9BA6Z5DcoFwaU4sA21l7KKj6zabG5gTRSkx0t+3/aGQYXdwlR9eLjFRqOJ0h/+k 35JVh+wKE6kwSEhia0+fQpMjXIQA04tCZL119t0mZKcrQrVaDrTX9GUCibJgQSwExXWu bG+fVs4nV24rKI+Sk/Td4rmBSlY/H/ygjasf1LVx5j9HK0TPDVyZOh/Kek2slbt07t6l Sluw== X-Gm-Message-State: AO0yUKXCcogCF36CbZAgXf9LuF557tGlJY6mQEz7blidlzbcIRkNiFFD zdRNfGiSk1OY8uNBYtsz/fE= X-Google-Smtp-Source: AK7set9ID3EMrd5i5Zd++UKkLOmJpQYqUv4XbWXkslFicxah1hD9HjPt06aCYaEbotmTX9SH+EYFNg== X-Received: by 2002:adf:e88a:0:b0:2d3:33d4:1cfb with SMTP id d10-20020adfe88a000000b002d333d41cfbmr8150741wrm.36.1679301312658; Mon, 20 Mar 2023 01:35:12 -0700 (PDT) Received: from localhost (host86-146-209-214.range86-146.btcentralplus.com. [86.146.209.214]) by smtp.gmail.com with ESMTPSA id u4-20020a5d4344000000b002c5526234d2sm8405427wrr.8.2023.03.20.01.35.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Mar 2023 01:35:12 -0700 (PDT) Date: Mon, 20 Mar 2023 08:35:11 +0000 From: Lorenzo Stoakes To: Uladzislau Rezki Cc: 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> <413e0dfe-5a68-4cd9-9036-bed741e4cd22@lucifer.local> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 29195180011 X-Stat-Signature: siy377tx6q4zt554irta7pin1u4hw6if X-HE-Tag: 1679301313-442879 X-HE-Meta: U2FsdGVkX18KgdVqxUDqpep9hQ45NMWxQEVrui19CN+sMGHNk5AijGtLODzHOrYoIyMCEOQC5d9r1kyLzg4+6bm2sJx760lRbX9HjxIZBCfMxsGldvzo7OONXdTlw05cpyfue+bWnRGk7l30HeXeL2I/q6KZ3VjRNnjUba3zi3nXNcTk9PaTOt3EkMJ5K/qt0YLungJkI6lYEzOxm/zp2Acwu7YFIRUlejtwSYvQnVDFAF5cSoLz+tfKlqfEdS4QHrX8EKS3UCvx+l046gBf7RjIymqKF7llgQnWR0GdeQS3PHjRIZIhkOYEzzdAV3Y8Hwo08pg7glD1jSGXr9jVHBS3Qu33Si+XDUpGw7dXjWRkiQj+2wbjFYf6rbS5TEn7wjvfp+IcWriv+oPOHeiIUVAqIyrRsKCde6O3q/I7oXZ+8iNIoHZDcePDGw3aZw32OAhmbxztj06YNRTzi0G2k6Cw1e1tLndJVAfIJnRW4rIuO3+UDfoI+uPc4IfRoRsOdhapgfwiixYxsN/NriRVtp9uunE0rqWZRJ1F8c9HuKZbA09j97NaSlCGzK+r03x4APEDLVMjErrBp4OulS69jd61wqwPWK0miTYsToPvJ/YDCHIFSTlxCTp1g82QRobyD7iB715zt2dDXKN722tvvQd+qO7qepkoJEzqHYSQTlAISl0apqo++Nkugjsd9zEcC9v6zZ+1rHekQZlgCu16UMcA2LEoU9YUSYUPr2dDpY/r1YINrKQlFhWPQsp/Mmx4I5gbrj1J4/jxEL9L7gHgBP2UcOZOkbIhcqz5eHBNzoCdLIxTH6EjZ1KbLUpoOFytWC/hwu9ChntLxfpNzN8ZOiCWl+aam40N9LvuZ85rV8++VaroEn091Aef/f12eEqJsBSJ3kW1ENWw/P+kbvHSOO2u05cDa0qkZSkCp3DpWUfEwSfyP4sz0A8wB0CeztV0STBa4CXMn18p/HQjP/i 2Je+O7i1 tF4SDsbvoGCH8mHQBS62WmpebpRfsy1QQ344kJIIJ+2QS9cvE+oM8v97bpOwYJoCDjsQdFHjUbWBaHFV8aUSQC75uK7Nm9si3dVsW/+Nczc6BLy94nvC8gYaCAukomn36HBalLf5TuzeARyXpV4H5xMD0Vz/HPWe76vfIdpJummIrcxdoaV2z9wYdm/QMPBVXS+a1DQfD1+RhtbAig7zIM8JAnV06W3NL1IlYVgmknQRb1bikMg82L4mUKQrnDdWenCLNN1T+jeALP9JfousSxVXGQOjdTtGKpSJy3Myw+thjzRbqitK+okFvYq0VtgV9en/6CNTVgCc0aFOSCDrcQf+UrFeS6/yPuGl7lFU+EwqkdN83B2u9xluiOsoRe9t9DYgegPHkfNBoNnlLuroUmxz213ICGHz9gWMm9yTQQo7/2fWLdzM3wHhHMtO1xOuiPw7enTYNqFlRBvo= 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 Mon, Mar 20, 2023 at 09:32:06AM +0100, Uladzislau Rezki wrote: > On Mon, Mar 20, 2023 at 08:25:32AM +0000, Lorenzo Stoakes wrote: > > On Mon, Mar 20, 2023 at 08:54:33AM +0100, Uladzislau Rezki 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. > > > > > > > How important to have many simultaneous users of vread()? I do not see a > > > big reason to switch into mutexes due to performance impact and making it > > > less atomic. > > > > It's less about simultaneous users of vread() and more about being able to write > > direct to user memory rather than via a bounce buffer and not hold a spinlock > > over possible page faults. > > > > The performance impact is barely above noise (I got fairly widely varying > > results), so I don't think it's really much of a cost at all. I can't imagine > > there are many users critically dependent on a sub-single digit % reduction in > > speed in vmalloc() allocation. > > > > As I was saying to Willy, the code is already not atomic, or rather needs rework > > to become atomic-safe (there are a smattering of might_sleep()'s throughout) > > > > However, given your objection alongside Willy's, let me examine Willy's > > suggestion that we instead of doing this, prefault the user memory in advance of > > the vread call. > > > Just a quick perf tests shows regression around 6%. 10 workers test_mask is 31: > > # default > [ 140.349731] All test took worker0=485061693537 cycles > [ 140.386065] All test took worker1=486504572954 cycles > [ 140.418452] All test took worker2=467204082542 cycles > [ 140.435895] All test took worker3=512591010219 cycles > [ 140.458316] All test took worker4=448583324125 cycles > [ 140.494244] All test took worker5=501018129647 cycles > [ 140.518144] All test took worker6=516224787767 cycles > [ 140.535472] All test took worker7=442025617137 cycles > [ 140.558249] All test took worker8=503337286539 cycles > [ 140.590571] All test took worker9=494369561574 cycles > > # patch > [ 144.464916] All test took worker0=530373399067 cycles > [ 144.492904] All test took worker1=522641540924 cycles > [ 144.528999] All test took worker2=529711158267 cycles > [ 144.552963] All test took worker3=527389011775 cycles > [ 144.592951] All test took worker4=529583252449 cycles > [ 144.610286] All test took worker5=523605706016 cycles > [ 144.627690] All test took worker6=531494777011 cycles > [ 144.653046] All test took worker7=527150114726 cycles > [ 144.669818] All test took worker8=526599712235 cycles > [ 144.693428] All test took worker9=526057490851 cycles > OK ouch, that's worse than I observed! Let me try this prefault approach and then we can revert back to spinlocks. > > > > > > So, how important for you to have this change? > > > > > > > Personally, always very important :) > > > This is good. Personal opinion always wins :) > The heart always wins ;) well, an adaption here can make everybody's hearts happy I think. > -- > Uladzislau Rezki