Message ID | 20230522110849.2921-2-urezki@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp1366946vqo; Mon, 22 May 2023 04:16:08 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5N51AuAw9XmvsRqfeZaRnednmyefEoekiNuwbXWd17gleK9nCkHxnyytFYewojNXclUZmd X-Received: by 2002:a05:6a20:6a13:b0:101:2ad0:1347 with SMTP id p19-20020a056a206a1300b001012ad01347mr9665499pzk.23.1684754168500; Mon, 22 May 2023 04:16:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684754168; cv=none; d=google.com; s=arc-20160816; b=hvblAPlB8SR81OzqqUoTis7i7GroiQ3mZpNbsS/aNq6/R7HE4bFghNpVVh4j49yZBc CiPjIH0fl8gaTiOfAaVp6RqXkMeKtOoynWWmHAq6nEKhbjBdvl6OWyZ06kGbb+jy6HVQ nDt/az74X82+rVoSorT/vJyw28tDDiZI1TRfDVuyQ3CRlJuyiWboIkT89CjfUPP9IRyB USpXtXabFcFBLEpnXmbsU0bzY7gRpR+a4JYhFYpxOQcfzJHQOULuMw82tW9iww91+Cx3 AzYfK5O3cWvdHsudUVnBb0KjAEMn/10IZlCv/OzvUeVnru3hW5C87hN/nqk3amGYDFHU VutA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=C3POfPMkD0T4i+gkKz2qkPU4t7/WZTiyT2qCdNLU280=; b=bqI7oPHjBJzCV9XxwMEUHyudt/bVJF7aQqraLuyDGoB6WGPbFfkBYOOP01dHZfKxiD KCxPkXzyudj+VDQD0X/aFJWTRw5FrdiSgoOhxCuTHPA6YZ/qSehlcx3u4iwNnN901/SC 34mx6rj5S9Ned5se8MefdqmSb1CddbOYvZ6xTWe0yb3bWnYYM81fWFeLOD+0fNQ6Oa+l H7g0mskCIhHh1N3wAKisBoSgs0OpGZE79LJZIvq6hPKlGXStNHZlWv7vYrMrjpohLMnZ OvZ+hIT4eRaGlU8OYHuGnUv1vuiocSTtDH8x02+C2W0ldhCwygOpB1yxPBEKd/Rbsigk plnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=VBUTLfKb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n10-20020a17090ade8a00b002532c9b252asi2656528pjv.73.2023.05.22.04.15.53; Mon, 22 May 2023 04:16:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=VBUTLfKb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230470AbjEVLOg (ORCPT <rfc822;cscallsign@gmail.com> + 99 others); Mon, 22 May 2023 07:14:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58030 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232524AbjEVLN4 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 22 May 2023 07:13:56 -0400 Received: from mail-ej1-x630.google.com (mail-ej1-x630.google.com [IPv6:2a00:1450:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BA8FA19BF for <linux-kernel@vger.kernel.org>; Mon, 22 May 2023 04:08:54 -0700 (PDT) Received: by mail-ej1-x630.google.com with SMTP id a640c23a62f3a-96fffe11714so96048966b.0 for <linux-kernel@vger.kernel.org>; Mon, 22 May 2023 04:08:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1684753733; x=1687345733; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=C3POfPMkD0T4i+gkKz2qkPU4t7/WZTiyT2qCdNLU280=; b=VBUTLfKbApHu6QZhrVrOCB3BjALZb8HbF0H20xKFhc6s2ddiN7suwTGMU0bL+g+sYn RmbQ1cww5mUZenVFKfKM0obeU2G6DDRfd8SBMnH9fmFpOyakPo9ae6ksAd2XakoCBv0E 7Ov6b3cng1MnPemi03HJHLAXu9L7D+fD1mqdF1IW9NYQd6lcGKgDypewZcwaRLFcrhmr yjR9yAKjvtwtrmWZi3nCGabZYIW/EQNSzPSvJbp0e3+m5rd5yon1lw8lX3KGm/ik7TPO pykNacp5zTZge80vp2rYbryAhbquVFUZS46oKag6NjrQQcMLsIE3M8wIwP5IFy1Gt0Ul IcQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684753733; x=1687345733; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=C3POfPMkD0T4i+gkKz2qkPU4t7/WZTiyT2qCdNLU280=; b=DWtQWnPxDRa1HKXMy1KSj82cHj8PG0ivfj7kHpBRqlKmAq1c9cwWNx7JuqjB/uyLhd 724tTd3H7bcTKZKiaqW/lsoucF1kp4pp6jRKBGJ49vQ9IWvKvThWQRjPtam1hSyMh5VW KHYlnSUu5y0BnF2MtjX7LRPnLOfrNayGgIgw3g9pBsBv/2GPt5kpS/6Z6HTxKvzbc+Ll kA9gihmshuOG0bMac15MuCSINPSwO0Ulw0XNX0aXjrvgHML0lz3PKclmA/PTkEXX9Hw0 uRQLvshb0HDNwJWdDjCBESsR6legxTOnMkWOYVRdw+ZimhAqrmBfhf/7i3+5G/ZlrDnK 28rQ== X-Gm-Message-State: AC+VfDwcV5lPdrlOBNl+U6j9o7Tbtx+Gp8YlQE3vEnVamPEefOLFT3sL AASTmX4gz81/Qzk/w2IkyPE= X-Received: by 2002:a17:907:1c8b:b0:94e:48ac:9a51 with SMTP id nb11-20020a1709071c8b00b0094e48ac9a51mr11815922ejc.4.1684753732807; Mon, 22 May 2023 04:08:52 -0700 (PDT) Received: from pc638.lan ([155.137.26.201]) by smtp.gmail.com with ESMTPSA id lx19-20020a170906af1300b0094f07545d40sm2949453ejb.220.2023.05.22.04.08.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 May 2023 04:08:52 -0700 (PDT) From: "Uladzislau Rezki (Sony)" <urezki@gmail.com> To: linux-mm@kvack.org, Andrew Morton <akpm@linux-foundation.org> Cc: LKML <linux-kernel@vger.kernel.org>, Baoquan He <bhe@redhat.com>, Lorenzo Stoakes <lstoakes@gmail.com>, Christoph Hellwig <hch@infradead.org>, Matthew Wilcox <willy@infradead.org>, "Liam R . Howlett" <Liam.Howlett@oracle.com>, Dave Chinner <david@fromorbit.com>, "Paul E . McKenney" <paulmck@kernel.org>, Joel Fernandes <joel@joelfernandes.org>, Uladzislau Rezki <urezki@gmail.com>, Oleksiy Avramchenko <oleksiy.avramchenko@sony.com> Subject: [PATCH 1/9] mm: vmalloc: Add va_alloc() helper Date: Mon, 22 May 2023 13:08:41 +0200 Message-Id: <20230522110849.2921-2-urezki@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230522110849.2921-1-urezki@gmail.com> References: <20230522110849.2921-1-urezki@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1766592786913018301?= X-GMAIL-MSGID: =?utf-8?q?1766592786913018301?= |
Series |
Mitigate a vmap lock contention
|
|
Commit Message
Uladzislau Rezki
May 22, 2023, 11:08 a.m. UTC
Currently __alloc_vmap_area() function contains an open codded
logic that finds and adjusts a VA based on allocation request.
Introduce a va_alloc() helper that adjusts found VA only. It
will be used later at least in two places.
There is no a functional change as a result of this patch.
Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com>
---
mm/vmalloc.c | 41 ++++++++++++++++++++++++++++-------------
1 file changed, 28 insertions(+), 13 deletions(-)
Comments
On Mon, May 22, 2023 at 01:08:41PM +0200, Uladzislau Rezki (Sony) wrote: > Currently __alloc_vmap_area() function contains an open codded > logic that finds and adjusts a VA based on allocation request. > > Introduce a va_alloc() helper that adjusts found VA only. It > will be used later at least in two places. > > There is no a functional change as a result of this patch. > > Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com> > --- > mm/vmalloc.c | 41 ++++++++++++++++++++++++++++------------- > 1 file changed, 28 insertions(+), 13 deletions(-) > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index 31ff782d368b..409285b68a67 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -1482,6 +1482,32 @@ adjust_va_to_fit_type(struct rb_root *root, struct list_head *head, > return 0; > } > > +static unsigned long > +va_alloc(struct vmap_area *va, > + struct rb_root *root, struct list_head *head, > + unsigned long size, unsigned long align, > + unsigned long vstart, unsigned long vend) Prototype continuations don't use a single tab indent. Either two tabs (my preference) or after the opening brace. I.e.: static unsigned long va_alloc(struct vmap_area *va, struct rb_root *root, struct list_head *head, unsigned long size, unsigned long align, unsigned long vstart, unsigned long vend) Otherwise looks good: Reviewed-by: Christoph Hellwig <hch@lst.de>
On Mon, May 22, 2023 at 11:05:57PM -0700, Christoph Hellwig wrote: > On Mon, May 22, 2023 at 01:08:41PM +0200, Uladzislau Rezki (Sony) wrote: > > Currently __alloc_vmap_area() function contains an open codded > > logic that finds and adjusts a VA based on allocation request. > > > > Introduce a va_alloc() helper that adjusts found VA only. It > > will be used later at least in two places. > > > > There is no a functional change as a result of this patch. > > > > Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com> > > --- > > mm/vmalloc.c | 41 ++++++++++++++++++++++++++++------------- > > 1 file changed, 28 insertions(+), 13 deletions(-) > > > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > > index 31ff782d368b..409285b68a67 100644 > > --- a/mm/vmalloc.c > > +++ b/mm/vmalloc.c > > @@ -1482,6 +1482,32 @@ adjust_va_to_fit_type(struct rb_root *root, struct list_head *head, > > return 0; > > } > > > > +static unsigned long > > +va_alloc(struct vmap_area *va, > > + struct rb_root *root, struct list_head *head, > > + unsigned long size, unsigned long align, > > + unsigned long vstart, unsigned long vend) > > Prototype continuations don't use a single tab indent. Either two > tabs (my preference) or after the opening brace. I.e.: > Will go with two tabs. > static unsigned long > va_alloc(struct vmap_area *va, struct rb_root *root, struct list_head *head, > unsigned long size, unsigned long align, unsigned long vstart, > unsigned long vend) > > > Otherwise looks good: > > Reviewed-by: Christoph Hellwig <hch@lst.de> > Added. Appreciate you look at it! -- Uladizislau Rezki
On Mon, May 22, 2023 at 01:08:41PM +0200, Uladzislau Rezki (Sony) wrote: > Currently __alloc_vmap_area() function contains an open codded > logic that finds and adjusts a VA based on allocation request. > > Introduce a va_alloc() helper that adjusts found VA only. It > will be used later at least in two places. > > There is no a functional change as a result of this patch. > > Signed-off-by: Uladzislau Rezki (Sony) <urezki@gmail.com> > --- > mm/vmalloc.c | 41 ++++++++++++++++++++++++++++------------- > 1 file changed, 28 insertions(+), 13 deletions(-) > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index 31ff782d368b..409285b68a67 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -1482,6 +1482,32 @@ adjust_va_to_fit_type(struct rb_root *root, struct list_head *head, > return 0; > } > > +static unsigned long > +va_alloc(struct vmap_area *va, > + struct rb_root *root, struct list_head *head, > + unsigned long size, unsigned long align, > + unsigned long vstart, unsigned long vend) > +{ > + unsigned long nva_start_addr; > + int ret; > + > + if (va->va_start > vstart) > + nva_start_addr = ALIGN(va->va_start, align); > + else > + nva_start_addr = ALIGN(vstart, align); > + > + /* Check the "vend" restriction. */ > + if (nva_start_addr + size > vend) > + return vend; > + > + /* Update the free vmap_area. */ > + ret = adjust_va_to_fit_type(root, head, va, nva_start_addr, size); > + if (WARN_ON_ONCE(ret)) > + return vend; > + > + return nva_start_addr; > +} > + > /* > * Returns a start address of the newly allocated area, if success. > * Otherwise a vend is returned that indicates failure. > @@ -1494,7 +1520,6 @@ __alloc_vmap_area(struct rb_root *root, struct list_head *head, > bool adjust_search_size = true; > unsigned long nva_start_addr; > struct vmap_area *va; > - int ret; > > /* > * Do not adjust when: > @@ -1512,18 +1537,8 @@ __alloc_vmap_area(struct rb_root *root, struct list_head *head, > if (unlikely(!va)) > return vend; > > - if (va->va_start > vstart) > - nva_start_addr = ALIGN(va->va_start, align); > - else > - nva_start_addr = ALIGN(vstart, align); > - > - /* Check the "vend" restriction. */ > - if (nva_start_addr + size > vend) > - return vend; > - > - /* Update the free vmap_area. */ > - ret = adjust_va_to_fit_type(root, head, va, nva_start_addr, size); > - if (WARN_ON_ONCE(ret)) > + nva_start_addr = va_alloc(va, root, head, size, align, vstart, vend); > + if (nva_start_addr == vend) > return vend; > > #if DEBUG_AUGMENT_LOWEST_MATCH_CHECK > -- > 2.30.2 > LGTM, Reviewed-by: Lorenzo Stoakes <lstoakes@gmail.com>
diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 31ff782d368b..409285b68a67 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -1482,6 +1482,32 @@ adjust_va_to_fit_type(struct rb_root *root, struct list_head *head, return 0; } +static unsigned long +va_alloc(struct vmap_area *va, + struct rb_root *root, struct list_head *head, + unsigned long size, unsigned long align, + unsigned long vstart, unsigned long vend) +{ + unsigned long nva_start_addr; + int ret; + + if (va->va_start > vstart) + nva_start_addr = ALIGN(va->va_start, align); + else + nva_start_addr = ALIGN(vstart, align); + + /* Check the "vend" restriction. */ + if (nva_start_addr + size > vend) + return vend; + + /* Update the free vmap_area. */ + ret = adjust_va_to_fit_type(root, head, va, nva_start_addr, size); + if (WARN_ON_ONCE(ret)) + return vend; + + return nva_start_addr; +} + /* * Returns a start address of the newly allocated area, if success. * Otherwise a vend is returned that indicates failure. @@ -1494,7 +1520,6 @@ __alloc_vmap_area(struct rb_root *root, struct list_head *head, bool adjust_search_size = true; unsigned long nva_start_addr; struct vmap_area *va; - int ret; /* * Do not adjust when: @@ -1512,18 +1537,8 @@ __alloc_vmap_area(struct rb_root *root, struct list_head *head, if (unlikely(!va)) return vend; - if (va->va_start > vstart) - nva_start_addr = ALIGN(va->va_start, align); - else - nva_start_addr = ALIGN(vstart, align); - - /* Check the "vend" restriction. */ - if (nva_start_addr + size > vend) - return vend; - - /* Update the free vmap_area. */ - ret = adjust_va_to_fit_type(root, head, va, nva_start_addr, size); - if (WARN_ON_ONCE(ret)) + nva_start_addr = va_alloc(va, root, head, size, align, vstart, vend); + if (nva_start_addr == vend) return vend; #if DEBUG_AUGMENT_LOWEST_MATCH_CHECK