Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp2132859iof; Tue, 7 Jun 2022 20:50:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJze1yqlIS0X3Lher960yVvhtYdpqsdNZvMSZLujKQQhVJx0mSYEFNzMB+TAb/7nVGUMRCuI X-Received: by 2002:a05:6a00:1941:b0:50d:807d:530b with SMTP id s1-20020a056a00194100b0050d807d530bmr32696345pfk.17.1654660249154; Tue, 07 Jun 2022 20:50:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654660249; cv=none; d=google.com; s=arc-20160816; b=JhbW9mdCgEiFo+hdq9ymTptNq3ZvKMmJqCXLWWRSff7iOhwofNuUtwUzn9fRZ+bZBA B22AshelwCkNtis7zSgJ8C+Svp7gFO0xL6k5a2WLbywbA6RYkGmygynwHRkduIqAGtfs fvuSlbQV5EGYNOuUHypvnZSLcQyKW3aQE2Hx3/ITvAraGNxOTMBUr7e92hD1kWbiRf6H D1pQWLL26Ibvf/94fonsoLr6qfUK4ARniGQIXVDdN4mXSBpbNA3zBaIK8Six5cXlsXDi 4jnxm+M114MAiPQoPHoB4kg5BH9Z79KpxdPMDBH6/RJxEw1FagHYILx5YHwEkSemjxZw ELHg== 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=pv9OCphMJ8B8Yb2Tt0nMaxCJDDpQGMH/396frBVwZ80=; b=e0J2Ei1gXMWOwcroTPHYWeOyYC2o3Y0q96pKwG2BmfUZ6fwALpZq6AoXfax2QlYqF3 13HEEMxYPPx4dgg5Z68e63eTRTyyZYKMQysPyNT1GVszBMCAKOp+VC2KdyYnc6i+tX1m ni8enLaIOZ6C/k3IVIx04f6rkNPmpiO3cJsU3ZBv9WPtQQ+Ataj7njhljY/S8PlGWKNA P/YdFNC5RbzrROqGr5Fw2lwOkLwEDSqDI7hJiv9GVmiSavmxU2I4b0tRlKOorDUUlTAc cItMx/J3bfoju2SyshCOpyyy23/KbyP05eBXOlrqkUSvCyu1VwazunMe1Jf2ktga+c13 c+nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NHva8EfF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id x21-20020a1709027c1500b00163655bed22si24728295pll.501.2022.06.07.20.50.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jun 2022 20:50:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=NHva8EfF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id C27ED20611C; Tue, 7 Jun 2022 20:38:45 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242390AbiFGLEH (ORCPT + 99 others); Tue, 7 Jun 2022 07:04:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242820AbiFGLAw (ORCPT ); Tue, 7 Jun 2022 07:00:52 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 58F9CEB5 for ; Tue, 7 Jun 2022 04:00:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1654599612; 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=pv9OCphMJ8B8Yb2Tt0nMaxCJDDpQGMH/396frBVwZ80=; b=NHva8EfFc7Trmq/FtQyWqEvbG+CvGaedLwhsLRLXxxVqzMHKKbzf7ECaGT+Mo/vudtYfps pD8M2lJpw8F1Kvox924OQNdgVJwEg0dsfprhh+VVpfrlQQAR2jilnQGmmIG56bnIJixNEg axVBBmvpsteFw6P4/kpfPPNQ4j7wofE= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-488-vmbiaouaOw6D81OcAzc7AA-1; Tue, 07 Jun 2022 07:00:09 -0400 X-MC-Unique: vmbiaouaOw6D81OcAzc7AA-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id DBAA71D33867; Tue, 7 Jun 2022 11:00:08 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-13-113.pek2.redhat.com [10.72.13.113]) by smtp.corp.redhat.com (Postfix) with ESMTP id AE2C01121314; Tue, 7 Jun 2022 11:00:05 +0000 (UTC) From: Baoquan He To: akpm@linux-foundation.org, urezki@gmail.com Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, hch@infradead.org, Baoquan He Subject: [PATCH v2 1/4] mm/vmalloc: invoke classify_va_fit_type() in adjust_va_to_fit_type() Date: Tue, 7 Jun 2022 18:59:55 +0800 Message-Id: <20220607105958.382076-2-bhe@redhat.com> In-Reply-To: <20220607105958.382076-1-bhe@redhat.com> References: <20220607105958.382076-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.3 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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: X-Mailing-List: linux-kernel@vger.kernel.org In function adjust_va_to_fit_type(), it checks all values of passed in fit type, including NOTHING_FIT in the else branch. However, the check of NOTHING_FIT has been done inside adjust_va_to_fit_type() and before it's called in all call sites. In fact, both of these two functions are coupled tightly, since classify_va_fit_type() is doing the preparation work for adjust_va_to_fit_type(). So putting invocation of classify_va_fit_type() inside adjust_va_to_fit_type() can simplify code logic and the redundant check of NOTHING_FIT issue will go away. Suggested-by: Uladzislau Rezki (Sony) Signed-off-by: Baoquan He --- mm/vmalloc.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 07db42455dd4..f9d45aa90b7c 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -1335,10 +1335,10 @@ classify_va_fit_type(struct vmap_area *va, static __always_inline int adjust_va_to_fit_type(struct vmap_area *va, - unsigned long nva_start_addr, unsigned long size, - enum fit_type type) + unsigned long nva_start_addr, unsigned long size) { struct vmap_area *lva = NULL; + enum fit_type type = classify_va_fit_type(va, nva_start_addr, size); if (type == FL_FIT_TYPE) { /* @@ -1444,7 +1444,6 @@ __alloc_vmap_area(unsigned long size, unsigned long align, bool adjust_search_size = true; unsigned long nva_start_addr; struct vmap_area *va; - enum fit_type type; int ret; /* @@ -1472,14 +1471,9 @@ __alloc_vmap_area(unsigned long size, unsigned long align, if (nva_start_addr + size > vend) return vend; - /* Classify what we have found. */ - type = classify_va_fit_type(va, nva_start_addr, size); - if (WARN_ON_ONCE(type == NOTHING_FIT)) - return vend; - /* Update the free vmap_area. */ - ret = adjust_va_to_fit_type(va, nva_start_addr, size, type); - if (ret) + ret = adjust_va_to_fit_type(va, nva_start_addr, size); + if (WARN_ON_ONCE(ret)) return vend; #if DEBUG_AUGMENT_LOWEST_MATCH_CHECK @@ -3735,7 +3729,6 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets, int area, area2, last_area, term_area; unsigned long base, start, size, end, last_end, orig_start, orig_end; bool purged = false; - enum fit_type type; /* verify parameters and allocate data structures */ BUG_ON(offset_in_page(align) || !is_power_of_2(align)); @@ -3846,15 +3839,11 @@ struct vm_struct **pcpu_get_vm_areas(const unsigned long *offsets, /* It is a BUG(), but trigger recovery instead. */ goto recovery; - type = classify_va_fit_type(va, start, size); - if (WARN_ON_ONCE(type == NOTHING_FIT)) + ret = adjust_va_to_fit_type(va, start, size); + if (WARN_ON_ONCE(unlikely(ret))) /* It is a BUG(), but trigger recovery instead. */ goto recovery; - ret = adjust_va_to_fit_type(va, start, size, type); - if (unlikely(ret)) - goto recovery; - /* Allocated area. */ va = vas[area]; va->va_start = start; -- 2.34.1