From patchwork Tue Jan 2 18:46:23 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Uladzislau Rezki X-Patchwork-Id: 13509273 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 A15C0C46CD2 for ; Tue, 2 Jan 2024 18:46:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B99066B01F8; Tue, 2 Jan 2024 13:46:42 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B6F5A6B01F7; Tue, 2 Jan 2024 13:46:42 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 92C166B01FA; Tue, 2 Jan 2024 13:46:42 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 64C0E6B01F5 for ; Tue, 2 Jan 2024 13:46:42 -0500 (EST) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 37599808B2 for ; Tue, 2 Jan 2024 18:46:42 +0000 (UTC) X-FDA: 81635252244.03.27E7CBE Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) by imf10.hostedemail.com (Postfix) with ESMTP id 5E444C0029 for ; Tue, 2 Jan 2024 18:46:39 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=du1uKiRL; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.52 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=1704221199; 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=K5/Q6NIxJkZyoBWCsC5LnGeneeGSY9jSGkshkmqw6aM=; b=07ySmBCX8v5rSbhVOYUFsMEntb6Jw5ZUxdK5TSzxiifyabm0zDoIrslVcLKmQzQtihsYxh mMkLjMRmYB9y/+KohbEt5Zjx9z+ErQ5fxnQUQSJV1j+HB5qBN95aRQIsljQahO3XJgyJS0 D+HZ8QA9kDTKuKh10TvglMZnmixN1Bg= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=du1uKiRL; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf10.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.52 as permitted sender) smtp.mailfrom=urezki@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1704221199; a=rsa-sha256; cv=none; b=8mHdFEDCVBuYmZMecs3vNSNzAoDdj8kA81NaYrG8ILSFpiAJvxteIo9TfQaHKe+b5SHVaA wn48BmAMpPlFopRf81vbgQfSvkXQntc8vHJqZ+xgP9ZX5KZoxyMpe/MX0+jpcHgfEBBI2a FGtKuJP7ZAEfJ6iFqsPipW6y0plLwsA= Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-50e7288a6e1so7913191e87.2 for ; Tue, 02 Jan 2024 10:46:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1704221198; x=1704825998; darn=kvack.org; 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=K5/Q6NIxJkZyoBWCsC5LnGeneeGSY9jSGkshkmqw6aM=; b=du1uKiRL3dn7VHwTqlFywYFslAJq0kb7xgkH+3X0LVrXfHUgpWosygxlu07CHRSqYI jLnTd9Mt4qIM6yJwyFPc2HYDXsWoD0R+5V5kJGRjqT0FdaG8vkdBSyRBigJRp7QROfu4 SSZ0uPOma3229hi3jINvEVJOU/OP02AzVWAg8s3qY8Gz0hQraSyASPpFofnIUkX9VDHm /Whw9OZwZTP90IWZmV1QfcmFTFIlPgSvCUtDg6aTde3gmjACYGxplr9OiN96ZyZGxDcp jn0DMb7pEj61pKu5lnyB5hLt/vXbvACEF5IiQov2HDtIn33VaiyotERhYM+HSuDgsAKi FMog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704221198; x=1704825998; 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=K5/Q6NIxJkZyoBWCsC5LnGeneeGSY9jSGkshkmqw6aM=; b=E2sZpIjGo8FtSpWLBCUUF9SMC/wMwSLnw8mM6r9gwy9zRJ4wZz8td2lfqmCljKRpyY wrj9dicueLjqBBbVfng5EK+ybDJXA0KLJMYJlrziu7QS6aKqLcGfQAIS4t+xbvAj/3nv LRNVgKdBuoInmCMoJkt/m4Rny5iWqd2s58YDMSr7ttBS6cutXjSXASkBAcDTAytQZlv6 Ar0c+E3L+NPXHdoXRoiTmy2mCDIqteqnSc4FYp0T/70aOu0Up1jSAFjMURwezkpFj/XD PAvd44Iu+yTf8FIghP/DcxUfBGqi8e/5ho+UoDBjOZz2X370E6KgHsNKrdJCHEln6c8q verA== X-Gm-Message-State: AOJu0Yz2dDpLm1qFJYq5boNRO30RMoQJSbedhtLaqqPXJN6JdSGwkmJL 6sBxy1fNJQ4KuKX2ssEM8HmtfZlbSIWXCg== X-Google-Smtp-Source: AGHT+IE9SbS94bEP8HryLcFLJIOhLEWknY4qeLso9+WpHYNNJ55PDxr0/9mn78utpteQ9g4ePL4CRw== X-Received: by 2002:a05:6512:1055:b0:50e:7e93:4d34 with SMTP id c21-20020a056512105500b0050e7e934d34mr5999337lfb.128.1704221197571; Tue, 02 Jan 2024 10:46:37 -0800 (PST) Received: from pc638.lan (host-185-121-47-193.sydskane.nu. [185.121.47.193]) by smtp.gmail.com with ESMTPSA id q1-20020ac246e1000000b0050e7be886d9sm2592656lfo.56.2024.01.02.10.46.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jan 2024 10:46:37 -0800 (PST) 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 v3 01/11] mm: vmalloc: Add va_alloc() helper Date: Tue, 2 Jan 2024 19:46:23 +0100 Message-Id: <20240102184633.748113-2-urezki@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240102184633.748113-1-urezki@gmail.com> References: <20240102184633.748113-1-urezki@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 5E444C0029 X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: rtxsg6cgs1zy75on33yztd56a53a7oys X-HE-Tag: 1704221199-354098 X-HE-Meta: U2FsdGVkX19v6PXcNRZ4yrKhC7SGBYcPBDNK4L7STtoAHpNC4a7Y8KrDE6WOStSl3PHXmXw2dtbhziapypASJPr3X2jg7yXkOO6KyxrDvoBHGPaMW6wMtsYqCsokSYkNtQF9TZDayLFzkQw8WPtzh+MTpSfNCy97Ywip4RxvgvW5Tnji+a2dQTa5ESPbaHzrdWvcKwbnLYzU8iWrOvq2iG1i0isu+dxWfehH0aM7Um3SRoSQkeR4ozO03GQmKh6rx9L3+dWNoA/uatQEnBQS6MwC8VnIqrBLOUfr9SECS7QwV8LEyDsIrZ74wcjhi2rxHLOJXuZmU4bN3Y/AOCIq0QsZ+VHVaCUtOYVzviI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1j8wpjOELaCPA513X8XjV9hkMGLJY81sMjjaBfTmO+HaZyrg2NMlz5EaEx1wj7x7xb+3w+zy/ 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: List-Subscribe: List-Unsubscribe: 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. There is no a functional change as a result of this patch. Reviewed-by: Baoquan He Reviewed-by: Christoph Hellwig Reviewed-by: Lorenzo Stoakes Signed-off-by: Uladzislau Rezki (Sony) --- mm/vmalloc.c | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index d12a17fc0c17..739401a9eafc 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