From patchwork Thu Oct 27 04:26:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13021577 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 C739FC38A2D for ; Thu, 27 Oct 2022 04:27:13 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1F6A18E0009; Thu, 27 Oct 2022 00:27:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 180918E0001; Thu, 27 Oct 2022 00:27:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F3C8A8E0009; Thu, 27 Oct 2022 00:27:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id E5FC58E0001 for ; Thu, 27 Oct 2022 00:27:12 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id C4766141099 for ; Thu, 27 Oct 2022 04:27:12 +0000 (UTC) X-FDA: 80065444704.23.30CA26C Received: from mail-pj1-f54.google.com (mail-pj1-f54.google.com [209.85.216.54]) by imf20.hostedemail.com (Postfix) with ESMTP id 779511C0003 for ; Thu, 27 Oct 2022 04:27:12 +0000 (UTC) Received: by mail-pj1-f54.google.com with SMTP id b11so413692pjp.2 for ; Wed, 26 Oct 2022 21:27:12 -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=Zcq6gzJXc8pDC3sz236YGfd+bdTaFcvYac+GMH/ktY7y0857LiRjJT4CxQDoiKpJ5W dlHU93yewjxd3BjXMcxT/FViOsi4RfL608ETdPBbYx0sn/EdYGowB5McvhvZoD7KRoEe 1xgvWfDhrbUSpMvvhR5Mbdlp6ZKQ0qoSOui2U= 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=epdja5THOUY4GQjM1sZ+tcLUB3K77Ec3epn5xnTA2Mys/VIQLcgl/OD3BhWMt5tpu9 O1qYI6wycr2X5xyEKrF5Gh0/fXOJUqGxMF7XQusPR2wqEkQg71kEnek6D+1z7Wfiquvc oPiiC0QJDL0hWG6LwBvIh/o4hVHlrTOhr3mQptEBWwJDEpQUD7S9XTMMXYzriHFJ5jVt VX/oh/oYwjGGTK91P/B9g5bft7GkKqDNOMXyJYpraAwqa90C+f4zFneMR06IzhmWN4+b R8fhuimIyCkmISugolac9TVL8S6iWtRtTmdjkNHz6uuoy+R/9nfDFBCc9eltL/8aewmc FZdg== X-Gm-Message-State: ACrzQf2CjSrcBEH6kwR89beFBvPJsLVWwQfxqI0zZO63chsCM3tAX8Ao MAuCL6ePX/tHJjNeNSRsOLKUcA== X-Google-Smtp-Source: AMsMyM7F3N7gSPDHuv3QFtEaAFzVeHH03Bzk1UisZYyH0NIWqm7Tvfg4uaYQHifloXF/S65xeUmrSg== X-Received: by 2002:a17:90b:3141:b0:20d:49d6:30c with SMTP id ip1-20020a17090b314100b0020d49d6030cmr7781973pjb.175.1666844831526; Wed, 26 Oct 2022 21:27:11 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:30f2:4501:65fa:df12]) by smtp.gmail.com with ESMTPSA id w23-20020aa79557000000b00565c8634e55sm203140pfq.135.2022.10.26.21.27.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 21:27:11 -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: [PATCHv3 6/9] zsmalloc: pass limit on pages per-zspage to zs_create_pool() Date: Thu, 27 Oct 2022 13:26:48 +0900 Message-Id: <20221027042651.234524-7-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog In-Reply-To: <20221027042651.234524-1-senozhatsky@chromium.org> References: <20221027042651.234524-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666844832; a=rsa-sha256; cv=none; b=lrAVETPKmlKiyhJNrDyfCq6GbX0rX0fYGT45JsC6vAm85G0aXu0ZxcsztZjurxaqF2Kotd 28QCCUvwaxoD0hzo5t/EJ7qp/gJXRGVdaGwC6993HZ3RRSnz7Xwft4JVrtbJupO/lATqB5 9ZojKMnk+S1lEnepbh1ITZbzGFDWOus= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Zcq6gzJX; spf=pass (imf20.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.54 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666844832; 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=/LEdREXOiedl6vGVYMbQ82TGs+PZXFhY4wbRwwr21TI=; b=NBrHu4h5Yc3oYp2mgL9FZ1Lk7BdFwlsaA5sOjb+lI3hKhvzXA9qkEYPf2SSsZbVZ1zzmWY jZLTkCJuOa6a+wKsdVUUsziwIxlmVOmOvU6u5q0qEUjgifSlWIuK20kytsig7MyMCXvn/n /nroqP5NlG9G0VefaDTCgz6QdKnLGRc= X-Rspamd-Queue-Id: 779511C0003 X-Rspam-User: Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Zcq6gzJX; spf=pass (imf20.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.54 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam04 X-Stat-Signature: 35q9w8xxtr1akuk77gb4i4c45qcoa1z4 X-HE-Tag: 1666844832-214678 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: 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;