From patchwork Wed Oct 26 11:29:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 11203 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp206070wru; Wed, 26 Oct 2022 04:32:46 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5oU9g3e1h8UrZ37cio5Fdw1yry0hV5nmJPa8BlxXiBZIXpge9JrL0xCo0H3QV4oTKTLy6r X-Received: by 2002:a17:906:8458:b0:7ac:a48d:a680 with SMTP id e24-20020a170906845800b007aca48da680mr6692484ejy.105.1666783956001; Wed, 26 Oct 2022 04:32:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666783955; cv=none; d=google.com; s=arc-20160816; b=eAgHl6In45Jv1d03gDDsRxtcdJGajGbktxPLe9j9OwldBynAIh9TSXR5Wj1lO2hPBH l+fZUJZG+MyFBqgXSlbjpac5jDinuAO+ywIhpg2oZIwLzvj10uiCIBpUKfNGkbK8UoA2 NR7CbJM2FyPxeHYr36uS3RVLbAW1QEIf+X9Bh6UgONCdP4N1YeYz0dYzTsJdJo4BumtN Uh8GHnTnAK32bW4epWEcRstJlkTfooAXUbPVhTmAFaQLSGet0RQphrPXw+HxVPRJmdne H4DJQ/PWqd2RHqJm36Vkrau5QaLtdyvlqQBIsq+ypwT3vE0DG4D6tpYkEJk/frJjfUaW 1FaA== 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=/LEdREXOiedl6vGVYMbQ82TGs+PZXFhY4wbRwwr21TI=; b=Occ2hMMth24gVpK/0s9J5l9UJtU8IRMAK6OpC+Uw/HXOZRtP+B0NL+l9UNsmZQkhMK TvRO60hLroUCwxUnSVvksj1dCUKH23pKn4pStjnHFOGzNJp60RivVqblBrNrl8W39Cfg RVZwbcvKkJmdfT8MuMb9RMHoLLb/Uip0zUqo8GZiS9AFfRkkYPOamhr9dDpeEo/QKd7/ PB4MWj0+8qKBmgkrht4dBSyYFXlutHLSEBfrFmuaSxisnqnjr8RKRLq/Dn2RzgWerfWY lVbmiyqK/RKuGD5oagS5DItJiIHTe8xhL3ZQEmkHBKB3WxRC60cxHI5TdKLQubj6bvrM Kb4w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=Diy7j3zk; 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=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d19-20020a50cd53000000b00461c5846e1asi5080602edj.371.2022.10.26.04.32.11; Wed, 26 Oct 2022 04:32:35 -0700 (PDT) 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=@chromium.org header.s=google header.b=Diy7j3zk; 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=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233489AbiJZLau (ORCPT + 99 others); Wed, 26 Oct 2022 07:30:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233180AbiJZLac (ORCPT ); Wed, 26 Oct 2022 07:30:32 -0400 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5AE4356E6 for ; Wed, 26 Oct 2022 04:30:25 -0700 (PDT) Received: by mail-pj1-x1036.google.com with SMTP id v13-20020a17090a6b0d00b0021332e5388fso1830103pjj.1 for ; Wed, 26 Oct 2022 04:30:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; 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=/LEdREXOiedl6vGVYMbQ82TGs+PZXFhY4wbRwwr21TI=; b=Diy7j3zktq4e7C7/lyeuqCeK7BfLCaiBNFf2nJojM3QB89B7f5aq+y1t1VA20KUzOY yeKlCET8FKVMHH3kBYSAGSjnQftjzXKWAbPtt2+8V3gnuK5deEjzkSyb0ltFbhK6FVVi 3wYMvNtD34QgEmWLWPgsTpRLVUJpfnNaQLHvU= 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=/LEdREXOiedl6vGVYMbQ82TGs+PZXFhY4wbRwwr21TI=; b=ltxh1QrZpsFHcQtdWIiPAvYxb7chEjTP5tFtW5TcR7t93bgWcVmY12Of2fiC9qAEm4 gs1nEG51i2tGJg5M2aPffGPOnDD3NhAXAhhV6noX60kRPZNQTp8cfsedO6oB47nVvS2k jS9el3tYCgL3WPs5/xgh+ywwLaMyG5fhKZdsiGiSurDkJBfNoch9nzIxhxBhK5ZE6GHj weWaQqUkvMSnh6knQFd3EtfN5mGRhFZHMp8cl50DfDXhZxdxlxC/dZ0B+dJQEh6/UC82 qRdDYV0+h1DBv6w5n5SeIMG6X7S25mfSg9Or2QXknEL1ZjtTzaCg+ijFRWgOwPAAS/kX ZQmg== X-Gm-Message-State: ACrzQf3tI9FpATiU28LWyceVzhlHI7v1RJ++nSHYSkFtMVocY3pN31qC dec4tASXmMHv6UbaciINCReebg== X-Received: by 2002:a17:903:124c:b0:184:cb7e:67c5 with SMTP id u12-20020a170903124c00b00184cb7e67c5mr44025630plh.117.1666783825473; Wed, 26 Oct 2022 04:30:25 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:749c:f7f5:1a8e:d0be]) by smtp.gmail.com with ESMTPSA id x127-20020a626385000000b005627868e27esm2814919pfb.127.2022.10.26.04.30.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 04:30:24 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCHv2 6/9] zsmalloc: pass limit on pages per-zspage to zs_create_pool() Date: Wed, 26 Oct 2022 20:29:30 +0900 Message-Id: <20221026112933.4122957-7-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog In-Reply-To: <20221026112933.4122957-1-senozhatsky@chromium.org> References: <20221026112933.4122957-1-senozhatsky@chromium.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED 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?1747749653729601834?= X-GMAIL-MSGID: =?utf-8?q?1747749653729601834?= Allow zsmalloc pool owner to specify max number of pages per-zspage (during pool creation), so that different pools can have different characteristics. By default we pass ZS_DEFAULT_PAGES_PER_ZSPAGE which is 4 (matches the current order 2 zspages limit). Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 3 ++- include/linux/zsmalloc.h | 2 +- mm/zsmalloc.c | 11 +++++++---- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 90b0c66bbd5b..bec02f636bce 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1247,7 +1247,8 @@ static bool zram_meta_alloc(struct zram *zram, u64 disksize) if (!zram->table) return false; - zram->mem_pool = zs_create_pool(zram->disk->disk_name); + zram->mem_pool = zs_create_pool(zram->disk->disk_name, + ZS_DEFAULT_PAGES_PER_ZSPAGE); if (!zram->mem_pool) { vfree(zram->table); return false; diff --git a/include/linux/zsmalloc.h b/include/linux/zsmalloc.h index b6b8654a2d45..ebd1ff3e8115 100644 --- a/include/linux/zsmalloc.h +++ b/include/linux/zsmalloc.h @@ -50,7 +50,7 @@ struct zs_pool_stats { struct zs_pool; -struct zs_pool *zs_create_pool(const char *name); +struct zs_pool *zs_create_pool(const char *name, u32 max_pages_per_zspage); void zs_destroy_pool(struct zs_pool *pool); unsigned long zs_malloc(struct zs_pool *pool, size_t size, gfp_t flags); diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index cab8080e2fc6..7465a45495bf 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -366,7 +366,7 @@ static void *zs_zpool_create(const char *name, gfp_t gfp, * different contexts and its caller must provide a valid * gfp mask. */ - return zs_create_pool(name); + return zs_create_pool(name, ZS_DEFAULT_PAGES_PER_ZSPAGE); } static void zs_zpool_destroy(void *pool) @@ -2195,6 +2195,7 @@ static int zs_register_shrinker(struct zs_pool *pool) /** * zs_create_pool - Creates an allocation pool to work from. * @name: pool name to be created + * @max_pages_per_zspage: maximum number of pages per-zspage * * This function must be called before anything when using * the zsmalloc allocator. @@ -2202,18 +2203,20 @@ static int zs_register_shrinker(struct zs_pool *pool) * On success, a pointer to the newly created pool is returned, * otherwise NULL. */ -struct zs_pool *zs_create_pool(const char *name) +struct zs_pool *zs_create_pool(const char *name, u32 max_pages_per_zspage) { int i; struct zs_pool *pool; struct size_class *prev_class = NULL; - u32 max_pages_per_zspage; + + if (WARN_ON(max_pages_per_zspage < ZS_MIN_PAGES_PER_ZSPAGE || + max_pages_per_zspage > ZS_MAX_PAGES_PER_ZSPAGE)) + return NULL; pool = kzalloc(sizeof(*pool), GFP_KERNEL); if (!pool) return NULL; - max_pages_per_zspage = ZS_DEFAULT_PAGES_PER_ZSPAGE; /* min_alloc_size must be multiple of ZS_ALIGN */ pool->min_alloc_size = (max_pages_per_zspage << PAGE_SHIFT) >> OBJ_INDEX_BITS;