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 83605C7618D for ; Mon, 20 Mar 2023 11:20:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2610E6B0074; Mon, 20 Mar 2023 07:20:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1EAEA6B0075; Mon, 20 Mar 2023 07:20:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 064946B0078; Mon, 20 Mar 2023 07:20:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E0E8D6B0074 for ; Mon, 20 Mar 2023 07:20:10 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id B9D8CA0251 for ; Mon, 20 Mar 2023 11:20:10 +0000 (UTC) X-FDA: 80589032580.10.656DC10 Received: from mail-lf1-f46.google.com (mail-lf1-f46.google.com [209.85.167.46]) by imf23.hostedemail.com (Postfix) with ESMTP id BDCA5140019 for ; Mon, 20 Mar 2023 11:20:08 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=OIKR1gpz; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.46 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=1679311208; 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=j2UL4IhRczrMrkP5475LvCds4xNJEhrT8X1HycL9bCM=; b=tRAoJTta2EAs56Dim+oEdvoVeCFqzzFIt6fIiZ/2JUaqm2CqmK0YqlYmPdmSeoRSCXIdgS WRZAq6nv2dCW5xNWe9Sfvs163sXURJWS39mGoo1QVI+KUYLvSaucLF8jkwq+JhR/wV/Irl 2pdYP+kLibxJSrKUlX84P16SuKO6zm0= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=OIKR1gpz; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf23.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.46 as permitted sender) smtp.mailfrom=urezki@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679311208; a=rsa-sha256; cv=none; b=21gh+x3qYi/+vZIKVGJYattRXRWy8NAr9mTT1m2oDZT7vwZ2lOAaRK5TNgBrPQ6WGf6lhz oSIWpgpO8DBYWnUeKBbGVLFau8aP+zoGzp+tTLaoT2WN8pMFCoVGfxxjkBeTfsuHaBCIld aKesDEQR10nr0clbjWqXF94qBc21kJg= Received: by mail-lf1-f46.google.com with SMTP id k37so1471236lfv.0 for ; Mon, 20 Mar 2023 04:20:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1679311207; 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=j2UL4IhRczrMrkP5475LvCds4xNJEhrT8X1HycL9bCM=; b=OIKR1gpz9fxP9kEKYvLpG9gFyqB6Ac9wXlzlWqKCzh7tCkMxxd/gjXqirHd1XftHuG pl6B14hklTrpuU2MTnq3CG8+AEHgBWss70azrqAcmCjWhsh8hK9RalzOMx+oMOLjV+Kh fGEDHO3Cx9qtTbqPt3ksSHa5DMp6dIFFr0PUx7l+Ve4vnJodgdc6Dfon1M8Yv0KZuw8C RPU49u3y5rsXo2yToa13w5igQ0YqWyorKvmL35yiO0wAEdmymh5nbOZiIiazFSuXmfdY QQzWNqEfPfcLZnU2SACtJd+qUrhDZsRaz48aFt7l9nIkT7/P7dRcnhKu1JPl01ANuHdy Wxrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679311207; 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=j2UL4IhRczrMrkP5475LvCds4xNJEhrT8X1HycL9bCM=; b=QRas3fY54GGE69d6VcAlKIgVfnUjVzZO4IgT8Ao1vijUL18SXAVQGgO6veNHF/6bw3 HB+iVASnbhIFwEJc3nvWwRqcjrmbf0YuytKnOu7qjo+u+4KkusBM0LHvAkY5SNIxUCMC E79Jh5iNdbUJfd57Ny8fwtOmShtFQKeMEyNcu4rLYgLNK9PCX4WBgNsBswrBTiIycow6 OAmgKS7bmF1Ciwzu2ZQmPDYJMjgqxXfxyvsx/v7WrEX4mLs/hrGqKw8mhvieHT8/hk8E 9zvUfvlSlW0M89oT0XIjrEWu9bXUlGWekDMxb5oLj1AH3xqFqWnstCDA9wSqr6b0212s jIkA== X-Gm-Message-State: AO0yUKUDv6DhGJbKGQdb5bdEXCtERvksxtMSqaJudpyTCnLIZ950PlnH steo35FcXyJrsEKQPpoP+i8= X-Google-Smtp-Source: AK7set9iwMt81SiNTCxVYLtVATbXkAzHAgYDh2+QIEnKRGF458BQJo4CdD5b5KOJsAPUaO9n19BDDQ== X-Received: by 2002:ac2:494b:0:b0:4b5:b06d:4300 with SMTP id o11-20020ac2494b000000b004b5b06d4300mr5770655lfi.29.1679311206757; Mon, 20 Mar 2023 04:20:06 -0700 (PDT) Received: from pc636 (host-90-235-3-187.mobileonline.telia.com. [90.235.3.187]) by smtp.gmail.com with ESMTPSA id u1-20020ac248a1000000b004db51387ad6sm1653571lfg.129.2023.03.20.04.20.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Mar 2023 04:20:06 -0700 (PDT) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Mon, 20 Mar 2023 12:20:02 +0100 To: Lorenzo Stoakes Cc: Uladzislau Rezki , 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: BDCA5140019 X-Stat-Signature: tefd34r5mqja4bsqydyx7nst6a1gham4 X-HE-Tag: 1679311208-789726 X-HE-Meta: U2FsdGVkX19kacmTSwLDHj4yEae3nI+Yk6CmmC99snlpVtntSBhBfdNfm/uFv5PtSV8+LsDGjPB6pSSlm1/s+skLkQ1xIoOR2PEKXKT2zWWG3WHORlTTFb9EoP/0OSSbjzRGDiWPPO049ZEnRNxyjmB+4lNEsnBRz5gn1RnFogv5U/hN+dASfNbQJzSIpIV8QekQSx51T8IrZplpvEtuC+JxAk7yXd5kkmAP2yXmlDqFLxzUjWEXn9r50q/uu1rqU9jIjV2QdNnR3n6qZX+EPAfKz9ZJYDc80to0Rg2y7MMrKuXzX7/kngk7b+0P3LgV2Xz4AeM+krH6r/Bapeg0Vr+13P+A5Eu3mk9y0lTYXOxuRtyk5271u/QTXIk2HSbkgBBqd57a3E9b3x9SOs7tIn4gqrsCvBaQiGRo99JLlRz+xxFBAc654mwwe3a5hV8Sfyh4o63VLXhyxicpq8BJSfCaUgXMXYcotq37/OdfOWENccGC1RHz0H1SklW0qnG4vIUv1wOWrFUIhmiES2qutjhEbL1cxtBzUPfQuzvqv5VfRO9LQtj0WeARW+SARSnKpzV+FJuM2Id0RSSYpeLwHV2K7NYqoIvAH2QPJiygXrC3NUN7JoXf/G/jBmuVVLT4uUEpHnqEzIPsoREoYUWJKdpTMU8zHAlfx/8DcsJtjBD27eMdx4NxedWRCvlueaC6FQ41ZKJt9TX3oSYb5re0RWoO0NOLOqY1TqbkK67VachNdS9I6xx7sV+bAYbg9VH6xOoGbigSTLPd4UvPTq3rmVsLKC6F3fvbiSKEW8Om3sF9ktK2wR3BMrqgqOvhYTIvvlw+1txIR/JA7MP3CtCu0WtCtQoC/Djk23VIZqipxEFwrikATpJsl5fDNp7tkwx8wh28UKcBEM42RoZtyO0zPxcRXCl5HGK2dAMjPPbKaDJgQHV1IjVGkCURN0ewsYZNu+duvZLEr7w83CXPV9z qJxhkRap E77HF80mwij5YCp2a3LrAaRvvT3ItxhyYvA831sGKf3ygJYWNOjON0zwewTNdfrQo5EA3FRA2u5v/9M2/veDAuVNOuLQxxUINspAaJtL2x6OTmZbjUFItdL5E9hsnJ++dfc473EMhcoKaaueFUlVglZ1+g9upLEKQV2JVqVP0U7GN/6ESNVpmAlwsM/az7cvRjnKbdzNZ72FCY7KU0ObL8PqF9WNU8sJClJv0tRopnJhZmkWY8x49EIE+u4EgNP65yCjbnl+RZ6NP82X04O2LJtHKCDRQ2t5Er+lAcgD44CUD77HwEr6HVEVE47GRnZ6VADF4DXBl8fxo3oc2gYuC6BWciMToPdVSlsrXDeRscHf6EVVQSkpmqFQZ23z09M9vDoTViOZKkKeK6F7mIidp35PEJW41aZyBHl7JUo29U2HDfCDTP/hI3js0s019ivoReKNuJ+lZMwoo1KQNeejcOnhTyxpr1T+N73IBGeKmsfVfWxTqmSCtT52v2g== 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 08:35:11AM +0000, Lorenzo Stoakes wrote: > 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. > Totally agree :) -- Uladzislau Rezki