From patchwork Wed Oct 5 18:03:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 12999544 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 E16F8C4332F for ; Wed, 5 Oct 2022 18:03:56 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7D3E16B0073; Wed, 5 Oct 2022 14:03:56 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7839E6B0074; Wed, 5 Oct 2022 14:03:56 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 64C066B0075; Wed, 5 Oct 2022 14:03:56 -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 549296B0073 for ; Wed, 5 Oct 2022 14:03:56 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 0F899160FD7 for ; Wed, 5 Oct 2022 18:03:56 +0000 (UTC) X-FDA: 79987669272.10.EEE40BA Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by imf13.hostedemail.com (Postfix) with ESMTP id 4A2262002E for ; Wed, 5 Oct 2022 18:03:54 +0000 (UTC) Received: by mail-pj1-f48.google.com with SMTP id pq16so1016944pjb.2 for ; Wed, 05 Oct 2022 11:03:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=iroUAKdZ7R5Gx/z/KE5xhjM/Ew8lqKEyV5onJIu1MHY=; b=PIZwg3d0nAqXGCHGip9wpna0F2Rq/W9uZxN7XaeU73FBRauDrwoRGXRkihEuzQ2Fmj +8lBXmjefIoKl6B1WKFOLC1dAS3BqACPb+YgeUCRA5PYSduG8UnZBOjq2+jh1rVRc+hh csj0HpN3+6Fy9tmHtYNYQBKgSf/uTRmMOUWsDLvFQ+MQRA1psom1e8m54Vy6VYYdqC8A S3Bv5I6D3Z9jOE+HSoLYHjLwmIC4QZ3VNvh7AVl2SQC64Atje1J1AdlpNCfpW7liChLB 8HUzvPnEkYb+RyJrdCMB1YJCUfUNLD6IKt2XY73Fk5NCCYaia2pHQJOxD6LCExHNm4rJ vEAA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=iroUAKdZ7R5Gx/z/KE5xhjM/Ew8lqKEyV5onJIu1MHY=; b=Fi8fcXe5j2ZrEc2VlP553CqT8LyBjNEcRvNVM3teZ+zmBR5D4bmJNkLNMBZ73rjA6k qanqgKrBzc9tJiWdwO8VMt7gMGlkOYJx/NWM1FBm4lHxL/dV2N9EWQlFd08COY3RiyQr 5u0CqvvJ8Gx8eOwaYeTjbF9Hgc52frdh7XrZNQtmeKrUYDPSSBSf+DKbakvshCdAn3JA HQX570+fNSxq7J2T7NUQFkoOuRjocoPhaWs5zOgO0EdWiLS8HU4FmvoYG6JfcWYbL9eQ 6SOillJ1IDU6y6RUfu7LoXMb2GT4i4s6H+eezSHuri/ZMH1sBggqmSDtNYW8IdEZAQnb c+HQ== X-Gm-Message-State: ACrzQf2eST0Fo5S924dNodak/MhihIYi11Rcv86pjRcz1RVQClhwGnBl ZzLR7nN7kYx/0ieRSyZt2Gk= X-Google-Smtp-Source: AMsMyM7sKKoKZPF7OajApXBcH9gnY/xelKkIALaQi5/UQI5v92qoBDhlVKNCJ1myXqDizlCR9tzFmw== X-Received: by 2002:a17:90b:38cb:b0:203:100:bb53 with SMTP id nn11-20020a17090b38cb00b002030100bb53mr944531pjb.107.1664993034172; Wed, 05 Oct 2022 11:03:54 -0700 (PDT) Received: from localhost.localdomain (c-67-174-241-145.hsd1.ca.comcast.net. [67.174.241.145]) by smtp.gmail.com with ESMTPSA id y17-20020a170903011100b001788494b764sm10674639plc.231.2022.10.05.11.03.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Oct 2022 11:03:53 -0700 (PDT) From: Yang Shi To: mgorman@techsingularity.net, agk@redhat.com, snitzer@kernel.org, dm-devel@redhat.com, akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-block@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] mm: mempool: extract common initialization code Date: Wed, 5 Oct 2022 11:03:38 -0700 Message-Id: <20221005180341.1738796-2-shy828301@gmail.com> X-Mailer: git-send-email 2.26.3 In-Reply-To: <20221005180341.1738796-1-shy828301@gmail.com> References: <20221005180341.1738796-1-shy828301@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1664993035; a=rsa-sha256; cv=none; b=4wn2Jm8wRpjfVvVPjeKkomv6HgpLw7uG6gsrM3Ttr2hX7B396Xejkwml+JY3yanoFS9Ozx pKoI29yiOktx/0p6+FonMBWMDpjn3V1HEUHGoGuuVpyPuJV7jfG7OyViYiNq7e7g+lCOI4 18dqixK6WVsGjENs02wN2tZZgXl5Rbo= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=PIZwg3d0; spf=pass (imf13.hostedemail.com: domain of shy828301@gmail.com designates 209.85.216.48 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1664993035; 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=iroUAKdZ7R5Gx/z/KE5xhjM/Ew8lqKEyV5onJIu1MHY=; b=0su1aLWJyFu+AlH/mUzvY2npdRTvmgtMZxgzXYjvn03iPEh2tU4SGVfhY4b9CLYQqCdwzS wwOwaXSPRvjCG1nR0ddWp47BERRK4Cs4nnv4CGMv1BO5o6JCquObrbA8C3aGIej65erUmb tqPmeliSrZB1FfGUNs4Ujsqks92A7lM= X-Rspam-User: Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=PIZwg3d0; spf=pass (imf13.hostedemail.com: domain of shy828301@gmail.com designates 209.85.216.48 as permitted sender) smtp.mailfrom=shy828301@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Stat-Signature: d9ephk9oc4n6kpuaj8p43p6x8r8zzjsa X-Rspamd-Queue-Id: 4A2262002E X-Rspamd-Server: rspam01 X-HE-Tag: 1664993034-616749 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: Extract the common initialization code to __mempool_init() and __mempool_create(). This will make adding mempool bulk init code easier. Signed-off-by: Yang Shi --- mm/mempool.c | 57 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 20 deletions(-) diff --git a/mm/mempool.c b/mm/mempool.c index 96488b13a1ef..ba32151f3843 100644 --- a/mm/mempool.c +++ b/mm/mempool.c @@ -176,9 +176,10 @@ void mempool_destroy(mempool_t *pool) } EXPORT_SYMBOL(mempool_destroy); -int mempool_init_node(mempool_t *pool, int min_nr, mempool_alloc_t *alloc_fn, - mempool_free_t *free_fn, void *pool_data, - gfp_t gfp_mask, int node_id) +static inline int __mempool_init(mempool_t *pool, int min_nr, + mempool_alloc_t *alloc_fn, + mempool_free_t *free_fn, void *pool_data, + gfp_t gfp_mask, int node_id) { spin_lock_init(&pool->lock); pool->min_nr = min_nr; @@ -208,6 +209,14 @@ int mempool_init_node(mempool_t *pool, int min_nr, mempool_alloc_t *alloc_fn, return 0; } + +int mempool_init_node(mempool_t *pool, int min_nr, mempool_alloc_t *alloc_fn, + mempool_free_t *free_fn, void *pool_data, + gfp_t gfp_mask, int node_id) +{ + return __mempool_init(pool, min_nr, alloc_fn, free_fn, pool_data, + gfp_mask, node_id); +} EXPORT_SYMBOL(mempool_init_node); /** @@ -227,12 +236,31 @@ EXPORT_SYMBOL(mempool_init_node); int mempool_init(mempool_t *pool, int min_nr, mempool_alloc_t *alloc_fn, mempool_free_t *free_fn, void *pool_data) { - return mempool_init_node(pool, min_nr, alloc_fn, free_fn, - pool_data, GFP_KERNEL, NUMA_NO_NODE); + return __mempool_init(pool, min_nr, alloc_fn, free_fn, + pool_data, GFP_KERNEL, NUMA_NO_NODE); } EXPORT_SYMBOL(mempool_init); +static mempool_t *__mempool_create(int min_nr, mempool_alloc_t *alloc_fn, + mempool_free_t *free_fn, void *pool_data, + gfp_t gfp_mask, int node_id) +{ + mempool_t *pool; + + pool = kzalloc_node(sizeof(*pool), gfp_mask, node_id); + if (!pool) + return NULL; + + if (__mempool_init(pool, min_nr, alloc_fn, free_fn, pool_data, + gfp_mask, node_id)) { + kfree(pool); + return NULL; + } + + return pool; +} + /** * mempool_create - create a memory pool * @min_nr: the minimum number of elements guaranteed to be @@ -252,8 +280,8 @@ EXPORT_SYMBOL(mempool_init); mempool_t *mempool_create(int min_nr, mempool_alloc_t *alloc_fn, mempool_free_t *free_fn, void *pool_data) { - return mempool_create_node(min_nr, alloc_fn, free_fn, pool_data, - GFP_KERNEL, NUMA_NO_NODE); + return __mempool_create(min_nr, alloc_fn, free_fn, pool_data, + GFP_KERNEL, NUMA_NO_NODE); } EXPORT_SYMBOL(mempool_create); @@ -261,19 +289,8 @@ mempool_t *mempool_create_node(int min_nr, mempool_alloc_t *alloc_fn, mempool_free_t *free_fn, void *pool_data, gfp_t gfp_mask, int node_id) { - mempool_t *pool; - - pool = kzalloc_node(sizeof(*pool), gfp_mask, node_id); - if (!pool) - return NULL; - - if (mempool_init_node(pool, min_nr, alloc_fn, free_fn, pool_data, - gfp_mask, node_id)) { - kfree(pool); - return NULL; - } - - return pool; + return __mempool_create(min_nr, alloc_fn, free_fn, pool_data, + gfp_mask, node_id); } EXPORT_SYMBOL(mempool_create_node);