From patchwork Mon Oct 24 16:12:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13017767 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 D05D4FA373F for ; Mon, 24 Oct 2022 16:12:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 624C694000B; Mon, 24 Oct 2022 12:12:32 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 5D510940007; Mon, 24 Oct 2022 12:12:32 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 44E4E94000B; Mon, 24 Oct 2022 12:12:32 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 374B3940007 for ; Mon, 24 Oct 2022 12:12:32 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 09930A09C1 for ; Mon, 24 Oct 2022 16:12:32 +0000 (UTC) X-FDA: 80056335744.07.00EC3F0 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by imf15.hostedemail.com (Postfix) with ESMTP id 9A9E2A0007 for ; Mon, 24 Oct 2022 16:12:31 +0000 (UTC) Received: by mail-pg1-f174.google.com with SMTP id h185so9033333pgc.10 for ; Mon, 24 Oct 2022 09:12:31 -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=f2Veyg4Nf5OS8EqVCK8SMJvhKgZdYRnABHlUXCuatrY=; b=HofNrlVOtqi8ZwPhhW9uLCwc+6uzwE1KBoMF3VcMdZDnR7LFHq8ikzjf7Hv4G3zQLU rp/BxL8DdIY/NMbC/qDx8YBTVkcfegpnrh/dhIKWoX2D7HzG0gKjqqYmxflQmBzFy/jx E0/pLtZAe47U0RHpL3vFn+ytPI+h7Q5K7/eyQ= 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=f2Veyg4Nf5OS8EqVCK8SMJvhKgZdYRnABHlUXCuatrY=; b=qqIvYDiqqlMldap9P3SPdilCH6dWzfkJDNDKRy72Wl+0mEYEdetqwmqfoVmlTl50dn qIVCABmSBHST3DYJlWS4IrAk6BaGxwtGAbULxwz+1UZqBwsO0HxqlI0lsqSGWoHpJZ8W z1PDypKJivP8w93tFsadY57JgZBUsjaT8J+wq4m84Xg+ehcsJK50O4AS/+n2p62M3L0W Uq7WwrVovgmV7ztBLnnkOxJzL4GwsTqcUvSADhDSsDOzHO+699yF6YVTJGCsoeBE+bXo IPMaeyrO/X1nZs34OQN1f6rB8CE80s1V2zi7QsHhxlWlhRQKUhFav4z4IozqF17Cjm7T 4RKA== X-Gm-Message-State: ACrzQf0H+8I+xrafrP02BYH8tDYpXlwKwq1PZieNG9GO6tGAUD+af6tT lFs2wHz6rtjNn9rOzACZB46L/Q== X-Google-Smtp-Source: AMsMyM5seGttxnHPEAkSSnleJlRyABXkFEMuMx/U4i/q2Zh9h6VzJL9Bl/S2rm4EZjuyKYun+S0Xiw== X-Received: by 2002:a63:6b49:0:b0:46a:fcba:308f with SMTP id g70-20020a636b49000000b0046afcba308fmr29088458pgc.8.1666627950628; Mon, 24 Oct 2022 09:12:30 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5f9c:c5bc:902f:3da4]) by smtp.gmail.com with ESMTPSA id u70-20020a627949000000b0056b8726d2d3sm5162pfc.157.2022.10.24.09.12.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 09:12:30 -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: [PATCH 2/6] zsmalloc/zram: pass zspage order to zs_create_pool() Date: Tue, 25 Oct 2022 01:12:09 +0900 Message-Id: <20221024161213.3221725-3-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog In-Reply-To: <20221024161213.3221725-1-senozhatsky@chromium.org> References: <20221024161213.3221725-1-senozhatsky@chromium.org> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666627951; a=rsa-sha256; cv=none; b=GK3YnXJ2mVc8NuRD2HFsHKTElBvlpAiG8al3uMzi1om9W/yUbcHZ1iV/nOK4hY+SIX71s0 rxDT9roqcv/0+n8doSmWG7z2LCDrRyUBGHLJqLjcaqB3Bu2tiLg1qpNhj2j1970c2A6O8D OrV6EM2z3qREhqpSYcEEhi+m7LjhXrU= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=HofNrlVO; spf=pass (imf15.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.215.174 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=1666627951; 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=f2Veyg4Nf5OS8EqVCK8SMJvhKgZdYRnABHlUXCuatrY=; b=XhW5FVziF/v7VZl/eAfJvPHoFeIdsRU0YgSY4Amkh4qMiDFZotpZvDbvvnsHJuNL3UJpQR aMPGh5zfcy8wy+v51o86MjWwBNjEmL0BNODiReXChX6nv1jXjv/a406q1QA4ysbVyXKkMr WrQFhHjwukM+n3Vrc7GFLvbh3n9y5Is= X-Rspamd-Queue-Id: 9A9E2A0007 X-Rspam-User: Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=HofNrlVO; spf=pass (imf15.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.215.174 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam04 X-Stat-Signature: bdn76ckf3hfzoinfzi8peitb5ohawbeh X-HE-Tag: 1666627951-197474 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 zspage (during pool creation), so that different pools can have different characteristics. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 3 ++- include/linux/zsmalloc.h | 2 +- mm/zsmalloc.c | 11 ++++++++--- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 364323713393..e3ef542f9618 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1253,7 +1253,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_PAGE_ORDER); if (!zram->mem_pool) { vfree(zram->table); return false; diff --git a/include/linux/zsmalloc.h b/include/linux/zsmalloc.h index 2110b140e0fa..4a92c5e186ad 100644 --- a/include/linux/zsmalloc.h +++ b/include/linux/zsmalloc.h @@ -53,7 +53,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 zspage_order); 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 6ffa32b8b6c8..fa55e0c66f8d 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -369,7 +369,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_PAGE_ORDER); } static void zs_zpool_destroy(void *pool) @@ -2177,6 +2177,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 + * @zspage_order: maximum order of zspage * * This function must be called before anything when using * the zsmalloc allocator. @@ -2184,17 +2185,21 @@ 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 zspage_order) { int i; struct zs_pool *pool; struct size_class *prev_class = NULL; + if (WARN_ON(zspage_order < ZS_MIN_PAGE_ORDER || + zspage_order > ZS_MAX_PAGE_ORDER)) + return NULL; + pool = kzalloc(sizeof(*pool), GFP_KERNEL); if (!pool) return NULL; - pool->max_pages_per_zspage = 1U << ZS_MIN_PAGE_ORDER; + pool->max_pages_per_zspage = 1U << zspage_order; /* min_alloc_size must be multiple of ZS_ALIGN */ pool->min_alloc_size = (pool->max_pages_per_zspage << PAGE_SHIFT) >> OBJ_INDEX_BITS;