From patchwork Tue Aug 29 08:11:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uladzislau Rezki X-Patchwork-Id: 13368658 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 4B755C6FA8F for ; Tue, 29 Aug 2023 08:11:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A40C08E001E; Tue, 29 Aug 2023 04:11:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F0D0280037; Tue, 29 Aug 2023 04:11:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 906388E0023; Tue, 29 Aug 2023 04:11:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 84D2B8E001E for ; Tue, 29 Aug 2023 04:11:48 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 5D338160666 for ; Tue, 29 Aug 2023 08:11:48 +0000 (UTC) X-FDA: 81176423496.28.BEFE22C Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) by imf16.hostedemail.com (Postfix) with ESMTP id 71362180011 for ; Tue, 29 Aug 2023 08:11:46 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=KBNx8+rM; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.53 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=1693296706; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=sL90/r5YfKaetndDygiXgRj9+82zEERzAQ0GDLDkLpU=; b=STZPq9MebWs6124Tri2pn39XFOgQXBiHUZ32oEyKgEa4RUD0m2cUry0nzzqcZTeBUfzTRv QUPpXcCqHnYTGKjHV9HuHAzhoRo6naEysE0AXpN03YZT1FmYlvambDtQzcW9frgeOMJSMG UdvhVzOu5snwjqVaY+jKt8Y41jcsoNc= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=gmail.com header.s=20221208 header.b=KBNx8+rM; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf16.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.53 as permitted sender) smtp.mailfrom=urezki@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693296706; a=rsa-sha256; cv=none; b=wPhRlTFFGiLwadP8RV2r6h28LkrVNpLyWxvKg8WPEWWnCe0BLlGDYbFBzy+m4x5eqBeGiV TnRdvbtAoJu/9zz8ygNHihQCtdxQVyq7ktaMua3ilyFw3AclFbGvjG5FtP2LljCMgl6fHa rYTLLunyojeCOiPXHm03KdQan/wfR6s= Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-500a398cda5so6586850e87.0 for ; Tue, 29 Aug 2023 01:11:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1693296705; x=1693901505; 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=sL90/r5YfKaetndDygiXgRj9+82zEERzAQ0GDLDkLpU=; b=KBNx8+rMsWH6nCoZ+bqmYd9kAnk7WAnmsK1kBQsrAlAXw5G8gE0GvO3mXpHwmsaxo6 2gpql4OfGm5mlUT87PooQWCwid+0V/L0gGFxqRSDE33LssOioQu9/J/GftDFL6eIFLP2 WxkgXO7BfDqg+QFz6qDLjaC8GnQeNtUf+7iVTY2FPuZQ/tnQIvQOLSskE2Oh9B9ZvZ4N k1zIv/bkiyfhvv0zqX0jqhpriTp5UMS5HJvEu/9ev2Hy7/A7kVeOcLNiym9jh4PUxSk8 3Seg6UEsuWTLjTaMi36vLbd4qiliQuH+YQaAE0zVR/5ngM7wauyPOpps+nix0j1IeD0M 0l1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693296705; x=1693901505; 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=sL90/r5YfKaetndDygiXgRj9+82zEERzAQ0GDLDkLpU=; b=Lw25TrywwCxxWwgXvf05fqIzTjNOMH3aumrPU01rDxF+ppxhWNAeiD0iHB5CONn3KN a/2WNcJ/KSv9blZEbuQqGabQnOZ4m/378T+04xc9DYmHhCIVY3f1vpQ8B29uDqFKkrE3 eqBPpVWuL243WhH9D/IPLxHeZYxcrv2Ip+ssHRYqdMYe7kSNrcinj5Z8O+S1frT8V6M2 gBzGycTo2MyE7ZT61hK5sVxXKse45KVE4L4Y+UnQvom5mff6JpNKOJlJxuXdC6JAyjAD avb/G3HRETaaBex4lLEAzUCgQyGZKIZz7h0Z6B+kmKMsXHcFEAupY92DNdtW4BUyHRoP 7gjg== X-Gm-Message-State: AOJu0YwKuu7F4BSS/h+sInXmdtx6t7dCVihS+Z7ZfTypoPmfKuF4Jtdb VleaVUB1ytcxs3eOV4M4x6IwVXqfVYiinw== X-Google-Smtp-Source: AGHT+IGMSDc2itGbnAweqsvba/FoxkJn/ThOjItzn70Gby98afKeT+YDst0o5W/Z6YiFsaM3uYPSNA== X-Received: by 2002:a19:911a:0:b0:500:acf1:b432 with SMTP id t26-20020a19911a000000b00500acf1b432mr5985858lfd.63.1693296704660; Tue, 29 Aug 2023 01:11:44 -0700 (PDT) Received: from pc638.lan ([155.137.26.201]) by smtp.gmail.com with ESMTPSA id f25-20020a19ae19000000b004fbad341442sm1868026lfc.97.2023.08.29.01.11.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Aug 2023 01:11:44 -0700 (PDT) From: "Uladzislau Rezki (Sony)" To: linux-mm@kvack.org, Andrew Morton Cc: LKML , Baoquan He , Lorenzo Stoakes , Christoph Hellwig , Matthew Wilcox , "Liam R . Howlett" , Dave Chinner , "Paul E . McKenney" , Joel Fernandes , Uladzislau Rezki , Oleksiy Avramchenko , Christoph Hellwig Subject: [PATCH v2 1/9] mm: vmalloc: Add va_alloc() helper Date: Tue, 29 Aug 2023 10:11:34 +0200 Message-Id: <20230829081142.3619-2-urezki@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230829081142.3619-1-urezki@gmail.com> References: <20230829081142.3619-1-urezki@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Stat-Signature: 97gpo83i8mgee9wfyk4keqd876rbew1w X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 71362180011 X-HE-Tag: 1693296706-323506 X-HE-Meta: U2FsdGVkX19JnACeE/smj4QOnIBuy6Gie8cUTGmdxT4bcDMiiDfwPbyf8cjDPQ5LfSyCzg0iX/GXy6wqVQZG2/rj9ET9S34DCAk2RhnrqS891ahuqDsgQ9Gj9g2Yg68ULCefkCIwXu/IZk+EpU+1s4MqMpm+dwx7g0lwL/q1OH3U+bjurnmf/xxwxFauy5IbI8dv2cQjhx8ibofPxmTYBOUD/YQhwOpvlarcZjCvDo1Id68mh020/n59b6SKGV60P2VlM12sqns0Cn+nlVAafUQC1McgVjNzkGWvDHxclbgMdf0jIuZTBmIl/lK0cME/POLLkDqFcZi2F7mRSqFPn1aP2INMPYQVdguWysQoAAZPHohuPf0qnlDJgQf6nVm0jhR5fU3MQkH9tF8wg8NYA/Fp6m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osity: 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: 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. Reviewed-by: Christoph Hellwig Reviewed-by: Lorenzo Stoakes Signed-off-by: Uladzislau Rezki (Sony) Reviewed-by: Baoquan He --- mm/vmalloc.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 93cf99aba335..00afc1ee4756 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -1481,6 +1481,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. @@ -1493,7 +1519,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: @@ -1511,18 +1536,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