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 94B5DEB64D7 for ; Mon, 26 Jun 2023 14:28:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1414F8D0005; Mon, 26 Jun 2023 10:28:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0F21F8D0001; Mon, 26 Jun 2023 10:28:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ED4148D0005; Mon, 26 Jun 2023 10:28:03 -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 DF5F68D0001 for ; Mon, 26 Jun 2023 10:28:03 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 965771A06FA for ; Mon, 26 Jun 2023 14:28:03 +0000 (UTC) X-FDA: 80945128446.17.E5A8FA9 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf08.hostedemail.com (Postfix) with ESMTP id 00024160004 for ; Mon, 26 Jun 2023 14:27:59 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SghG27CW; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of dakr@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dakr@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687789681; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=YoyWyxXX7ShezkxwEtGhHhAWKCuXh2pj0Y+G9zY6kLU=; b=7wcuyE5D/HmCvuy5mf0GfyJQcwDxw4f7yTLte8uhHlzcB5bL2yYFJOb2PDWM2J4zvFTfsx Z0TJS+zMgO5ARbi3P/bHMqbKIggIk7ZVTLnyjERDgS/Vj0ckOsrYO6KoOHPFQY8WIcwY/h h9qIietO07XrGLS/eXhd/hDVn4Ubc60= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=SghG27CW; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf08.hostedemail.com: domain of dakr@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=dakr@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687789681; a=rsa-sha256; cv=none; b=DVcAgba/P5xGEe9b7YNbxioTK3isd4lG4oDeOLbJSHKCkAPpW2FUAEsD8CE1F5/QpqT3I6 UCepNZ46GvaV9QlGjg9RozNcCHD8skauyWJksK6BaWSHE/SO5WdbvJ33yvywxltaM4lG/B jUcGwjmfVgnL3eKq1pRXelx5virgGgk= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1687789679; h=from:from: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:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=YoyWyxXX7ShezkxwEtGhHhAWKCuXh2pj0Y+G9zY6kLU=; b=SghG27CWqztyUSuk7mipBvcUDjpEcQTMCyH9dHfEvTrl+8FTzmJ7Fk6Qw7wj/w5Znb91IH M3HhCEXRgu7G9AC2aIBaKBT5uAa3AtQOZsi2y+tIyiuRyVCu6mFGoRUzyOXwdFv1U0068p SPyZQuGM2WoTDGa2hq7Oyqc8RNdRBSs= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-96-iaJ2US5ROsyE0pfTvq7Wfw-1; Mon, 26 Jun 2023 10:27:58 -0400 X-MC-Unique: iaJ2US5ROsyE0pfTvq7Wfw-1 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-3fa871e1eaaso33245405e9.3 for ; Mon, 26 Jun 2023 07:27:57 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687789677; x=1690381677; h=content-transfer-encoding:in-reply-to:organization:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=YoyWyxXX7ShezkxwEtGhHhAWKCuXh2pj0Y+G9zY6kLU=; b=epfQOofAXbGphbw7hDcENbwEIgRKcDrqWMwp9Jqh9wVgxxbcDViQdTjPxOna0FfahB lMsVGvKusvCpWQTEB/FeTQisQSCvuqOaCOPSHx42M5NrvlyJyrJE2gf1bOePiQXH+f6N Vmpg9NZCjCSliPflxNK2iC3ZG0kohhJp2YTOQy70raQpoKWGn1JLniBQ0J0m2SAByhjC 9YeJXzkUGUSotIHMUIwVoSjsc3cZfM6j+0xgZMd3JJ5Mvvo1YudWR9Wfzs46F9N3j/sF 5xP8JACpmdR2O61rrKicAgGLlCeIzrxbFFpyZe1Ka1Lhmmxo1iNmDJ0C429zhkOfCJGb 4Cdg== X-Gm-Message-State: AC+VfDzPaxwE/LPTnvrFsbbwvyANu/stOJnimWpuR+irOwgQQtbXGu3+ ebpnp9bLK85RoQbH0+bUUkgnVRjGHvWjFM+07HAX2BiHs7CC3Jpc0hN1bR59RJqC52eapbW50qK swFY/mFCvHp8= X-Received: by 2002:a05:600c:2284:b0:3fa:8219:9163 with SMTP id 4-20020a05600c228400b003fa82199163mr10267673wmf.21.1687789676707; Mon, 26 Jun 2023 07:27:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ7K552SJ/lZjinu84fOMgSD+Rx2qEd1aQy6B7PJIPCKHf1jhpcjAX6S6KSzOQjPctTzvRro+w== X-Received: by 2002:a05:600c:2284:b0:3fa:8219:9163 with SMTP id 4-20020a05600c228400b003fa82199163mr10267658wmf.21.1687789676389; Mon, 26 Jun 2023 07:27:56 -0700 (PDT) Received: from ?IPV6:2a02:810d:4b3f:de9c:642:1aff:fe31:a15c? ([2a02:810d:4b3f:de9c:642:1aff:fe31:a15c]) by smtp.gmail.com with ESMTPSA id u3-20020a05600c00c300b003faa6ce54b2sm1933871wmm.2.2023.06.26.07.27.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 26 Jun 2023 07:27:56 -0700 (PDT) Message-ID: <57527c36-57a1-6699-b6f0-373ba895014c@redhat.com> Date: Mon, 26 Jun 2023 16:27:54 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.10.0 Subject: Re: [PATCH v2 14/16] maple_tree: Refine mas_preallocate() node calculations To: Matthew Wilcox Cc: Peng Zhang , maple-tree@lists.infradead.org, linux-mm@kvack.org, Andrew Morton , "Liam R. Howlett" , linux-kernel@vger.kernel.org, Peng Zhang , David Airlie , Boris Brezillon References: <20230612203953.2093911-1-Liam.Howlett@oracle.com> <20230612203953.2093911-15-Liam.Howlett@oracle.com> <26d8fbcf-d34f-0a79-9d91-8c60e66f7341@redhat.com> <43ce08db-210a-fec8-51b4-351625b3cdfb@redhat.com> From: Danilo Krummrich Organization: RedHat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 00024160004 X-Stat-Signature: xnkazw43bgt15w3esjptbne6cufzsm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4t8Q5heBVQW0Vo+2P+j29Ejn/TfmDiY1aV5FCIKk+asat9bKNeosFo6Z9KNY5KbY2GiSRE+KQBuZ5P9PUl/j2RNJCx4Fba+OqT2BqfBnsD0eSQmP/d354XethnUWp2M0tXV4pIms4ltfuNWkhLHOn0uNji5nph+Z75qYJVRV6XjQWFFyCcM1A/iqr3xuPuIujfxmKc7uId4mbq0zAnvgVroAhRew7dMaRHKvJ+8U6QY9t1gSJcsjBKROWHlrBtLpR5IGbKQBXH4jn8Cy51onRljQsYDTzS7JtYc18RS7j/ZswHOAAYTVV5k3SRNFsnpHCPx+7lXtXfcD11blXv05H5xBm5shUXbSQiXrLL+4CLCzg2sgO0Ysha6UWdkzhisBBR6VY24txO8mSd9qHNO743hgIWttxU= 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 6/26/23 15:19, Matthew Wilcox wrote: > On Mon, Jun 26, 2023 at 02:38:06AM +0200, Danilo Krummrich wrote: >> On the other hand, unless I miss something (and if so, please let me know), >> something is bogus with the API then. >> >> While the documentation of the Advanced API of the maple tree explicitly >> claims that the user of the API is responsible for locking, this should be >> limited to the bounds set by the maple tree implementation. Which means, the >> user must decide for either the internal (spin-) lock or an external lock >> (which possibly goes away in the future) and acquire and release it >> according to the rules maple tree enforces through lockdep checks. >> >> Let's say one picks the internal lock. How is one supposed to ensure the >> tree isn't modified using the internal lock with mas_preallocate()? >> >> Besides that, I think the documentation should definitely mention this >> limitation and give some guidance for the locking. >> >> Currently, from an API perspective, I can't see how anyone not familiar with >> the implementation details would be able to recognize this limitation. >> >> In terms of the GPUVA manager, unfortunately, it seems like I need to drop >> the maple tree and go back to using a rb-tree, since it seems there is no >> sane way doing a worst-case pre-allocation that does not suffer from this >> limitation. > > I haven't been paying much attention here (too many other things going > on), but something's wrong. > > First, you shouldn't need to preallocate. Preallocation is only there Unfortunately, I think we really have a case where we have to. Typically GPU mappings are created in a dma-fence signalling critical path and that is where such mappings need to be added to the maple tree. Hence, we can't do any sleeping allocations there. > for really gnarly cases. The way this is *supposed* to work is that > the store walks down to the leaf, attempts to insert into that leaf > and tries to allocate new nodes with __GFP_NOWAIT. If that fails, > it drops the spinlock, allocates with the gfp flags you've specified, > then rewalks the tree to retry the store, this time with allocated > nodes in its back pocket so that the store will succeed. You are talking about mas_store_gfp() here, right? And I guess, if the tree has changed while the spinlock was dropped and even more nodes are needed it just retries until it succeeds? But what about mas_preallocate()? What happens if the tree changed in between mas_preallocate() and mas_store_prealloc()? Does the latter one fall back to __GFP_NOWAIT in such a case? I guess not, since mas_store_prealloc() has a void return type, and __GFP_NOWAIT could fail as well. So, how to use the internal spinlock for mas_preallocate() and mas_store_prealloc() to ensure the tree can't change?