From patchwork Mon Oct 31 05:41:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13025395 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 E8844FA3740 for ; Mon, 31 Oct 2022 05:41:34 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4418780008; Mon, 31 Oct 2022 01:41:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3A12780007; Mon, 31 Oct 2022 01:41:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2690B80008; Mon, 31 Oct 2022 01:41:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id F28DA80007 for ; Mon, 31 Oct 2022 01:41:33 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id A66EDC0B72 for ; Mon, 31 Oct 2022 05:41:33 +0000 (UTC) X-FDA: 80080147266.23.EE8C3A8 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by imf15.hostedemail.com (Postfix) with ESMTP id 419A3A000E for ; Mon, 31 Oct 2022 05:41:33 +0000 (UTC) Received: by mail-pj1-f50.google.com with SMTP id d59-20020a17090a6f4100b00213202d77e1so14963232pjk.2 for ; Sun, 30 Oct 2022 22:41:32 -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=VFR0j+YHx2uepPKlT+sIE6AyjijOgidhHUVwtVRcfQ8=; b=OsAM7e9gpky/PEpM6ussXnheiEIyAvoyhxEKv4YeN/y8428flisIoxqVDVQ/Z5NMre D5X/AKopD/9c9t4iyXFDie1MqC4kbMjkn2bPY7QhKi1M3jJRRwADtpxzFPYqbiKC4lsG L5Ihy/ujEO9g3F150Tblm3TeaA8a+A20XJX98= 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=VFR0j+YHx2uepPKlT+sIE6AyjijOgidhHUVwtVRcfQ8=; b=xn3cC/y6j5x/xnZNNGmn08gU1eGsJcDhItYOw8lry96nTha9C+ETXzy+YIVaqiDZR1 BiRUtR+RDQ//O3PpeOM4IjVZVvZM9+2VhAfLyC99H6ivYKh4rP4TlLP4oSyJ5e1a4UoL DIxpOD5KKsdlHJYk095HZ38gdACY2o+oYZaKRosm4FPRdAOFA03M1poADdhRsnRMaWNr knSwAZxeD8er8Nc7BjsbE3+oTuByMjGAm3diXLlrQ3sG5VlmpuzF5Zjs4Bm5pydarl1G v55BMYqwphLVRBqyUk7TrlvKSoCX9jMb6XC1urw+1KnRa2ZcOtjieGjiSXiZ/uCFRiYc 7EAw== X-Gm-Message-State: ACrzQf2pcVZLJpinlQ+VI+5S8mpYoNNTvZcmQ4oenTQRaHsv8E59ZPC/ 9qOUkVpv875HocGnU+xti56MBIGVZfE0hw== X-Google-Smtp-Source: AMsMyM4naYgrzZsBUcVNory6T4TNl8WUIPDEeh31C5BordS6k/33LBC4k0wlPp/qKRKbgdkdntEu6g== X-Received: by 2002:a17:90b:2705:b0:20a:b4fa:f624 with SMTP id px5-20020a17090b270500b0020ab4faf624mr13010028pjb.124.1667194892609; Sun, 30 Oct 2022 22:41:32 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:7616:afe0:ba6c:96f4]) by smtp.gmail.com with ESMTPSA id w12-20020aa79a0c000000b0056befcd7958sm3573308pfj.84.2022.10.30.22.41.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 30 Oct 2022 22:41:32 -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: [PATCHv4 6/9] zsmalloc: pass limit on pages per-zspage to zs_create_pool() Date: Mon, 31 Oct 2022 14:41:05 +0900 Message-Id: <20221031054108.541190-7-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.1.273.g43a17bfeac-goog In-Reply-To: <20221031054108.541190-1-senozhatsky@chromium.org> References: <20221031054108.541190-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667194893; 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=VFR0j+YHx2uepPKlT+sIE6AyjijOgidhHUVwtVRcfQ8=; b=CW4DqSKR16UC14WanMN+y1Rlq3ZsWQANXQZD5HPdDs+uWNs3ueSllP7OkNDdpTEplukTCB pRI3UvYAzf5UyLkD0gSzXV7XNPpS8LF85BvQARREvYB7xSBAYGg7nCPHTqrPZfiptbHc3D 9ANNZwBi6UrE2RL66jPIVz3F1yf5l9U= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=OsAM7e9g; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf15.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.50 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667194893; a=rsa-sha256; cv=none; b=2wokFjjd6tqGjTudlB/Kg/cwLchQy5M8a5j+AfLEzsDx7z7c2z2cTixCU8FzDAKRCxlvxP 1VTd3OTpgCn530QCvWxAJMP/FEgPfU2jRE+Qx5wSV485kGz7AqiAapW9PqR9cmItJUDFX3 11ARlHFDdM8v/hxbNyONlpHmJzrGvsw= X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 419A3A000E X-Rspam-User: Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=OsAM7e9g; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf15.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.50 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org X-Stat-Signature: 3gq91nu9i4r3h761aw4qrixp6rt9xwoy X-HE-Tag: 1667194893-397681 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..28f2b9cb1c47 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, unsigned long num_pages); 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 d329bd673baa..42987a913f45 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 + * @num_pages: 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, unsigned long num_pages) { int i; struct zs_pool *pool; struct size_class *prev_class = NULL; - unsigned long num_pages; + + if (WARN_ON(num_pages < ZS_MIN_PAGES_PER_ZSPAGE || + num_pages > ZS_MAX_PAGES_PER_ZSPAGE)) + return NULL; pool = kzalloc(sizeof(*pool), GFP_KERNEL); if (!pool) return NULL; - num_pages = ZS_DEFAULT_PAGES_PER_ZSPAGE; /* min_alloc_size must be multiple of ZS_ALIGN */ pool->min_alloc_size = num_pages << PAGE_SHIFT >> OBJ_INDEX_BITS; pool->min_alloc_size = max(pool->min_alloc_size, ZS_MIN_ALLOC_SIZE);