From patchwork Mon Jan 30 20:49:31 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: 50465 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2390441wrn; Mon, 30 Jan 2023 12:52:45 -0800 (PST) X-Google-Smtp-Source: AK7set97LVHiSi6SzgYqN4TATWeZVgBrdeHM9u01cqKXsdI6WQbAYKL8VyCJpHgrWNAuTc8np+1f X-Received: by 2002:a17:907:a2ca:b0:879:9bf4:b88a with SMTP id re10-20020a170907a2ca00b008799bf4b88amr16709822ejc.77.1675111965607; Mon, 30 Jan 2023 12:52:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675111965; cv=none; d=google.com; s=arc-20160816; b=X/Zvk2A9EJqGh12micydSmZRQb6VXZeqoZHw5suvuREqouDGwDz6diE8601wKtL4vA YH9sem0dvGy/VX4S9B+PqIvk8KXLcAxlEcD/SE78SzeFBvgdKpawhcPnolNGaoGSWFPb s/hI+AUAroKmvQo2JUmNsMhOkpU0chnTt24GpaOj4/E7NPy6minzh0FAb9Lae5eJkSoI x0rLy7/eu70G/XN1P7lTT9ymcWMweXy0r9Bmyc5q3L8wUpktfNrdBka6wz88luiGX0e0 KlfAfXFGiFkT+WoDXZGxeNF3vi9WSZhNqhmwB/epwj2MRCuPVu3hMrJvasOP2x9MnoXS e0RQ== 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=tjOybIkwS91rz6SeT9/1Q1LG8Upe4qgP6MFeV739ipg=; b=L6W9VSBQzB1NTew4KkZfAMvCsNN0/++BfI1qbWwWP0Jb1m81tLKWWFZDD1cII3S3jX TGgumKIUXUhwxDv6xSqr+C3XFdULzJERs/6EpZtx/4Q0l9Rgxhrd7rIhYKJ3W88LZIld 03j08IQGVsrvAVlt0G222ljFkXQxWlN20mkp3T9KfRVemUtBARqGIDp6oCzR7AGROyzR BwoJG5BdOBVPR14vC3D7UnHuNd8727rFkGMq4ZxqOjuPDkQVNqNS4qAiTmjvV7XGjnH9 9HiDX6F9OlhS22iIDoPxhr3t8POk9bqSF7iFGDw15474bgD1Z1vFPz4jOa+jzVOT5zhN xmNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=OaUFrjC9; 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 f3-20020a170906738300b00878272927e3si14468415ejl.285.2023.01.30.12.52.21; Mon, 30 Jan 2023 12:52:45 -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=OaUFrjC9; 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 S229985AbjA3Uu6 (ORCPT + 99 others); Mon, 30 Jan 2023 15:50:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45130 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229508AbjA3Uuy (ORCPT ); Mon, 30 Jan 2023 15:50:54 -0500 Received: from out-62.mta0.migadu.com (out-62.mta0.migadu.com [IPv6:2001:41d0:1004:224b::3e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7C51C10AA2 for ; Mon, 30 Jan 2023 12:50:53 -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=1675111851; 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=tjOybIkwS91rz6SeT9/1Q1LG8Upe4qgP6MFeV739ipg=; b=OaUFrjC9mmR+C+LBAr653ALAA4e7MQZabwuqvf4knolohngrfhCy2mosvw6gzcWCNRkTMN e4lFrKKKYsFoufKHKOU+htEFWJY05stO+hGZZ42o5pGje6WBWk41AYL8bVD4znF7k68LuE CXnkNDDkYwdEcPDPk+BQYLTO4g/oDug= 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 07/18] lib/stackdepot: lower the indentation in stack_depot_init Date: Mon, 30 Jan 2023 21:49:31 +0100 Message-Id: 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?1756482204480302533?= X-GMAIL-MSGID: =?utf-8?q?1756482204480302533?= 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. Signed-off-by: Andrey Konovalov Reviewed-by: Alexander Potapenko --- lib/stackdepot.c | 70 +++++++++++++++++++++++++----------------------- 1 file changed, 37 insertions(+), 33 deletions(-) diff --git a/lib/stackdepot.c b/lib/stackdepot.c index b06f6a5caa83..cb098bc99286 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);