From patchwork Fri Feb 10 21:15:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 55589 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp1181573wrn; Fri, 10 Feb 2023 13:19:34 -0800 (PST) X-Google-Smtp-Source: AK7set+qxuHSqoGC2guvnEl+L7u3wFZ3OkwfrONE0BjMrseaULq4J4s1KDR0MWxk0lVuDMF04g/P X-Received: by 2002:a17:907:c683:b0:887:d0e6:fa28 with SMTP id ue3-20020a170907c68300b00887d0e6fa28mr18754584ejc.1.1676063973918; Fri, 10 Feb 2023 13:19:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676063973; cv=none; d=google.com; s=arc-20160816; b=E7TYCILIXQLEfGV+hjkS7xlW4b+1F6Nn8NNSMFjL3J74jPC+hmBtul8uW6I1uaWKxe J9N5EbWztIxttmHcv5N/mqyNDsRHHhaBXm2Sv5ek3Xgryw82Z5LGaTfq7DoF+bK3GGj7 DMhuMjy9UCrGikh1DS7wSAWsD9wKPa8agjsdUZvksR7VrWVpYq8lCVNiWVcc4p7qQizO 4Kq1P9AMheS9epccH3I4fUX/e+j8hWXhaB5DNJhlEvGIKCXVh5O/aRaOgD0a+VG9pqrB a5FgC0VkqttloLpVdEMQ8vJQ+iFjVEd3g6w9f8SFWYcH1gNthEgnI7HOqlfSImZn2+1F eyQg== 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=f9A90r0/KX/Fhu2j5j2j+xtwq4a98UiE0RWErOhidkA=; b=XOgSwUGNUdoNl+r6F/CEAI97s6ScQs5xfOlb3B1RzINsUVwRGGhF2qJacaNLKyJ6xA sqivEjhFXM0du8m/HGZH+axtV9RjhPKaKL2J6WDGXmn5Kq0f0l8O7cVc/PnObYv3i36W 6aDu5rm3q09uxSy3szhXnh3s1e4WkmO38wl/gy9Ov6BN46SjSAvUHeHXDkvtE943LuXO vHRc+CXMk6SZkLmTcytteJToIas7UjU2Cn1lhXhnxcJvDZ1rojUIpkAKFqt1Rx/XIZvC fbL2P8JmzoaizuSJLQyroPXgwqVYIXrXX7HBUEpb9U5yH/3bYPkemGf2lfx8KJgXF9kg R8sA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=oyhVeDaz; 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=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ft21-20020a170907801500b008af393e054bsi5608418ejc.137.2023.02.10.13.19.10; Fri, 10 Feb 2023 13:19:33 -0800 (PST) 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=@linux.dev header.s=key1 header.b=oyhVeDaz; 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=NONE dis=NONE) header.from=linux.dev Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233051AbjBJVRi (ORCPT + 99 others); Fri, 10 Feb 2023 16:17:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38808 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232740AbjBJVRf (ORCPT ); Fri, 10 Feb 2023 16:17:35 -0500 Received: from out-253.mta1.migadu.com (out-253.mta1.migadu.com [IPv6:2001:41d0:203:375::fd]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B5ED55A2 for ; Fri, 10 Feb 2023 13:17:15 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1676063833; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=f9A90r0/KX/Fhu2j5j2j+xtwq4a98UiE0RWErOhidkA=; b=oyhVeDazZBut0ST4TNl1RQwS/DL0yrlLv1E7JYFnymtKhHMiB0u4WihfIpRSbWuByfnfY8 ZL4ITqwDVRl0DLjQnKz5Wxc8IJHpjd/MW8dfSTAoazs2uZDQVgNmsTC1x8YcK2CMWQLY8D suYeEvzU/sxSRp/4iLW7FSTp/J4Bl7s= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Vlastimil Babka , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 06/18] lib/stackdepot: lower the indentation in stack_depot_init Date: Fri, 10 Feb 2023 22:15:54 +0100 Message-Id: <8e382f1f0c352e4b2ad47326fec7782af961fe8e.1676063693.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS 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: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757480457711367472?= X-GMAIL-MSGID: =?utf-8?q?1757480457711367472?= From: Andrey Konovalov stack_depot_init does most things inside an if check. Move them out and use a goto statement instead. No functional changes. Reviewed-by: Alexander Potapenko Signed-off-by: Andrey Konovalov --- lib/stackdepot.c | 70 +++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index 9fab711e4826..3c713f70b0a3 100644 --- a/lib/stackdepot.c +++ b/lib/stackdepot.c @@ -165,46 +165,50 @@ int __init stack_depot_early_init(void) int stack_depot_init(void) { static DEFINE_MUTEX(stack_depot_init_mutex); + unsigned long entries; int ret = 0; mutex_lock(&stack_depot_init_mutex); - if (!stack_depot_disabled && !stack_table) { - unsigned long entries; - /* - * Similarly to stack_depot_early_init, use stack_hash_order - * if assigned, and rely on automatic scaling otherwise. - */ - if (stack_hash_order) { - entries = 1UL << stack_hash_order; - } else { - int scale = STACK_HASH_SCALE; - - entries = nr_free_buffer_pages(); - entries = roundup_pow_of_two(entries); - - if (scale > PAGE_SHIFT) - entries >>= (scale - PAGE_SHIFT); - else - entries <<= (PAGE_SHIFT - scale); - } + if (stack_depot_disabled || stack_table) + goto out_unlock; - if (entries < 1UL << STACK_HASH_ORDER_MIN) - entries = 1UL << STACK_HASH_ORDER_MIN; - if (entries > 1UL << STACK_HASH_ORDER_MAX) - entries = 1UL << STACK_HASH_ORDER_MAX; - - pr_info("allocating hash table of %lu entries via kvcalloc\n", - entries); - stack_table = kvcalloc(entries, sizeof(struct stack_record *), GFP_KERNEL); - if (!stack_table) { - pr_err("hash table allocation failed, disabling\n"); - stack_depot_disabled = true; - ret = -ENOMEM; - } - stack_hash_mask = entries - 1; + /* + * Similarly to stack_depot_early_init, use stack_hash_order + * if assigned, and rely on automatic scaling otherwise. + */ + if (stack_hash_order) { + entries = 1UL << stack_hash_order; + } else { + int scale = STACK_HASH_SCALE; + + entries = nr_free_buffer_pages(); + entries = roundup_pow_of_two(entries); + + if (scale > PAGE_SHIFT) + entries >>= (scale - PAGE_SHIFT); + else + entries <<= (PAGE_SHIFT - scale); } + + if (entries < 1UL << STACK_HASH_ORDER_MIN) + entries = 1UL << STACK_HASH_ORDER_MIN; + if (entries > 1UL << STACK_HASH_ORDER_MAX) + entries = 1UL << STACK_HASH_ORDER_MAX; + + pr_info("allocating hash table of %lu entries via kvcalloc\n", entries); + stack_table = kvcalloc(entries, sizeof(struct stack_record *), GFP_KERNEL); + if (!stack_table) { + pr_err("hash table allocation failed, disabling\n"); + stack_depot_disabled = true; + ret = -ENOMEM; + goto out_unlock; + } + stack_hash_mask = entries - 1; + +out_unlock: mutex_unlock(&stack_depot_init_mutex); + return ret; } EXPORT_SYMBOL_GPL(stack_depot_init);