From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f50.google.com (mail-lf1-f50.google.com [209.85.167.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C6D83A6EF0 for ; Thu, 18 Jun 2026 10:06:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781777173; cv=none; b=P+Z7JqpJ1qUWuR6xIzxfk1soQLbL11JkSVqSyxxIzg1xOKfadMjksBm9WhJCXpLOrd6xtOV1lWoPU+A5F29KJG33pENhwZ3oO22uNJrSHO1K74Q1acd4lVjxzThIuER68oSBhhpvjNufD68ZHouJH6rBfxE8b6u99HryZOcVmoU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781777173; c=relaxed/simple; bh=TitDFJ22rWTu69eIL7namB++1FBWVFkpWQbRoRpbMQk=; h=From:Date:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Vtfr/PIHH5WelhHFri8LtoQ61NtkAU4XnPAOAV67NoxA+EF2WKOClhgm4Y0JvFSy/0fkRLvoDs/HClZ7+7qF4AbZO+jY1rZWalL02t4HvQop6zsDa6GueVLMCVX/RPLSiMVA2hrOGAMIMME+Nm1ANGvOMCQs27hBxQpfAH6WcNk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=oXhOQ4Fj; arc=none smtp.client-ip=209.85.167.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oXhOQ4Fj" Received: by mail-lf1-f50.google.com with SMTP id 2adb3069b0e04-5ad53c8d4dfso167149e87.1 for ; Thu, 18 Jun 2026 03:06:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1781777171; x=1782381971; darn=vger.kernel.org; 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=4ic2yPlu9WxxvvZRxBvrLjmMOjFkWCzZQ9ebOBQNrJ8=; b=oXhOQ4FjZSfjDsuJTMRzE4drYOiraqWt0fpy+F6BxUWd9BwmvBZDEbh0nHZVKJORAR y+tZH0lsBsNWG3dl80PBzbjAqgGdFrUT3uEWNbN/uinanAYfSAtFKVc/Z2+Qa5HonamH yEn/EEYewMNzdjT6uKThPP37snDLGGIJ0ccrs9idlw3QJI7XKYo5nU+u7HG/buQWUPt0 A1yHFh893DnxkgeZuAn3z1dTqlwFsaH/c6kxxZ0RRjJUQvcnIHFs0DM+jykx0Jr3B39k ssQ5Ji16Z1URfskG8qYJJAipfqEqsa/IZfFffypZKO7obH/pVcr+e0KelyxYnDlb8hwI gdig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781777171; x=1782381971; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4ic2yPlu9WxxvvZRxBvrLjmMOjFkWCzZQ9ebOBQNrJ8=; b=P8IkrS2/8EZnwnhZ2AAqiNMwyNiR33DccIRqaSFw948eBWIeTeSjnKn4BgfBXHg9T6 g+/k3KDA74mi7KDV/jE+E1CBiVKi/b3QK7e/Zei7GdqouD49qdJcpUaFV0Veh1KELlkj t0inWDPsbUyEXsmU6n11+MDDek3mYHdqH3vtOxhGMe0V+ziOO/jwDg7pftlidviPHBT3 uVuSsTvsZx8b5X8yEDnFFC77sxdO6/QW7HXN3CDyUurUScG7xsIh59P+2L7KXvPbAQxD 8vGEsRrBAy2uQigiY06PQLAnQsruBOQAk6ojxB+sGPABMgybz9SeJcFLHxvn1avQRbod BhTQ== X-Forwarded-Encrypted: i=1; AFNElJ/2MNSwPnIZ0JWyojz04S7deQ8sWWkZuozyWVW0PlOJfDd0XbHcOb6pIuibqBurGBoIhvaidr8yGeGIFfU=@vger.kernel.org X-Gm-Message-State: AOJu0YwjmrZNbnmrStip3teFnUh9/0zpxIWnE1ckc/tj5ibNz2UYN+a3 rZkOskswQpN+9eVR/G/6pCClNETp76/Ostcw+NGufjVPsgg55Vknm5XV X-Gm-Gg: AfdE7clf3IhDB5L9rkKdiVaG+tjoDNKYAAkS4z1JxU5C4vQC9R5m8Px3vi8xbxIywKt Yaq7yPH0a76f9Z0S5O6XhUNtx4kyvhBzkxCUUxFdyU26Fk7JULLG6rK5BCQ439w2dk9Y4g8CMRG BsiKikmcB8UcOeRL8ti6SbUhHHMoAPHJZHlX8sFUT3OkkX/lOhWeYRvx+5tL2gAQ3Wh4I5Xi3+7 itBzGWCsvw6q90dpSkEoPqRxAvOPfiyC2e+oRmYaMdMbuBNnUInOPO67lE+Vm+QeU9AVGsjY3gM bL1+00bxCnKwDViGoql4kWyKdAxMwX+DpbKJzNI8f9t96Dsohqc1w3ZENbv8UldsHdLR77TzCli U2Wh0fbVUdZqSSoqqqzI2G+C1ItPEwiraOeEOXPUfO2SP7GvQTFs9U8X9ul3706jyBpz+4kTLyE /Y87/Uf1w5dK6Hok43s3TCnOUIRkqOdkOgO2j3+w== X-Received: by 2002:a05:6512:61d8:10b0:5aa:628b:5892 with SMTP id 2adb3069b0e04-5ad4d4577cemr623663e87.5.1781777169449; Thu, 18 Jun 2026 03:06:09 -0700 (PDT) Received: from pc636 (host-95-203-2-134.mobileonline.telia.com. [95.203.2.134]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5ad2e1aea92sm5216940e87.63.2026.06.18.03.06.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jun 2026 03:06:09 -0700 (PDT) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Thu, 18 Jun 2026 12:06:06 +0200 To: Matthew Wilcox Cc: Uladzislau Rezki , Pranjal Arya , Andrew Morton , "Liam R. Howlett" , Alice Ryhl , Andrew Ballance , linux-arm-msm@vger.kernel.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org, Lorenzo Stoakes , Pranjal Shrivastava , Will Deacon , Suzuki K Poulose , Neil Armstrong , Mostafa Saleh , Balbir Singh , Suren Baghdasaryan , Marco Elver , Dmitry Vyukov , Alexander Potapenko , Shuah Khan , Dev Jain , Brendan Jackman , Puranjay Mohan , Santosh Shukla , Wyes Karny , Sudeep Holla Subject: Re: [PATCH RFC 00/12] mm/vmalloc: migrate vmap_area indexing from rb-tree to maple-tree Message-ID: References: <20260613-vmalloc_maple-v1-0-0aa740bb944b@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: On Tue, Jun 16, 2026 at 07:07:57PM +0100, Matthew Wilcox wrote: > On Mon, Jun 15, 2026 at 11:52:22AM +0200, Uladzislau Rezki wrote: > > On Sun, Jun 14, 2026 at 12:15:28AM +0100, Matthew Wilcox wrote: > > > What I don't understand is why you maintain a separate "free" tree. > > > It should not be necessary any more, but maybe you tried removing it > > > already and found a performance problem? > > > > We maintain it in order to split several entities. That prevents > > interfering between allocated data and vmap-free-space manager. > > So in that case one context can easily access allocated data, for > > example vread iterator, etc., whereas another can do an allocation. > > > > So by splitting parts i minimize lock-contention. > > Sure, but there are many ways to reduce lock contention. One is to not > take locks at all; the maple tree is RCU-safe, so you can read the tree > holding only the RCU read lock, as long as you obey the RCU rules. > > Specifically: > - Write side has to RCU-free the objects that are stored in the tree > - Read side has to trylock the objects it finds (and retry the walk > if the trylock fails) > - Read side can see a mixture of objects if the tree is changed while > it is reading, but for any given index in the tree it is guaranteed > to see one of the objects which has been referred to by that index. > That is, if the write side overwrites an index that referred to > object A with object B, the reader will see either object A or B. > It will not see NULL and it will not see any other object. > - If the write side stores both object C and object D in the tree, > the read side may see neither, both, only C or only D. > Some thoughts about it. Having the tree which is RCU safe is good for sure. We can benefit from at least in the: vmallocinfo scanning/dumping, possibly in the vread_iter() when access to /proc/kcore and other places(which i need to check carefully). But this is for read-only traversal. Switching to gap-based approach requires quite a bit of refactoring and it should be a full switch without any hybrid schemes or mixes. I expect that we remove more code then adding because of some parts will become hidden like lookups/reserving range/erase, etc which is good. - replacing free_vmap_area to maple-tree gap based approach; - rewriting pcpu-allocator which lives in the end of vmalloc space; - refactoring per-cpu allocator which is also part of vmalloc space; - vread iterator; - vmalloc dump path; - vmap_node logic(use gap-reserve to minimize contention); - and more... To me such rewrite makes sense if we end up in something structural not just because maple tree exists. The criteria i would go with are: at least same performance level, remove more then add, the design stays at least in same good shape. There are some drawback i am thinking of. One of them is maple insert path, mas_store_gfp()? First we need to find an empty area, then set-range and do mas_store_gfp() that uses gfp flag for its internal allocation. If we are under spin-lock sleeping is not possible, using NOWAIT or ATOMIC is not a case thus we should somehow pre-allocate outside the lock and store the range without any allocation. The allocator operation: - finds an empty range; - publishes VA that blocks that range. those two have to be serialized among other writes. Otherwise two CPUs can use same empty range and both try to reserve them. If preallocate outside the lock, the "alloc" side has to validate that a selected range is still empty and only then store VA to block the range. I think it is worth to prototype something to see how it would go. I may be missing something for sure. Thank you for your input! -- Uladzislau Rezki