From patchwork Thu Oct 27 04:26:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13021572 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 CD7D1C67871 for ; Thu, 27 Oct 2022 04:27:01 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4B5A48E0003; Thu, 27 Oct 2022 00:27:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 43F468E0001; Thu, 27 Oct 2022 00:27:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 307838E0003; Thu, 27 Oct 2022 00:27:01 -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 2400D8E0001 for ; Thu, 27 Oct 2022 00:27:01 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id EB43A80459 for ; Thu, 27 Oct 2022 04:27:00 +0000 (UTC) X-FDA: 80065444200.13.167EB5F Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by imf02.hostedemail.com (Postfix) with ESMTP id 9B5C08003D for ; Thu, 27 Oct 2022 04:27:00 +0000 (UTC) Received: by mail-pl1-f180.google.com with SMTP id 4so263024pli.0 for ; Wed, 26 Oct 2022 21:27:00 -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=57/g83Q1A5B+7wYv3+Gd1tLG4FTDJnhj+xIMySGShWo=; b=LZs2JMXZj7KI645ET3ePzlYTovXfQcMuYjwdrOg5BaYkxa+fijxsky6kZpjuSMeQBJ BGkN2zAjC2aEEU+sHnEyYaqBqEMT2fIAi2bNnzs5itLbkhK39LWk6qQJg3L+YKJT1DY1 q0wrekK8aRmyK+zz13YXy8QchBMVywGgfKGjc= 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=57/g83Q1A5B+7wYv3+Gd1tLG4FTDJnhj+xIMySGShWo=; b=OkUwWcR90QHTNVklOnDmZN81ba9r361WaoST9/5qdMIqA6SQHSWvUvdx0effkDnzkm X3m/D0fdOs8IqaBGJnIwUifoX8ArC7/wXyGkvaAKw1TWVCnh6dz7ykjrcoDp0vtl0p+P 4EK4r7NeF7devMpx0JFs73A/+xY1yuvtKp0ZHCesR+gqCH+0/SV6Uhg4JOEoMMC2DiSQ NwZOat9sgouCsK4AMYIWUNo5CtaoqMTjho8zVCAhKFMwzXVFYEt2jOV6ILtgxFWF8XR/ GnWO2QUuk5juOHRI5wJOg1XH16MgA4bdNjzv3+fhYHXr+NDuJUmmRrZ6+4yiP5AptUgZ k53w== X-Gm-Message-State: ACrzQf34eX8uCNTiZUWeWN2fdHmRWUavYsx10vZb9WbTEfv8B/by2sdo F57MVVrIJ/LPw1/nPgMAC59q8A== X-Google-Smtp-Source: AMsMyM5PObH8+UVD6/TXg62DaefgWJnjzeH/HC6fFf1zxc0vCIYe8Ts+HBK8eTrV8813vgGH6x6wAg== X-Received: by 2002:a17:90a:bf11:b0:211:84c5:42d7 with SMTP id c17-20020a17090abf1100b0021184c542d7mr7800117pjs.122.1666844819541; Wed, 26 Oct 2022 21:26:59 -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.26.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 21:26:59 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Alexey Romanov Subject: [PATCHv3 1/9] zram: add size class equals check into recompression Date: Thu, 27 Oct 2022 13:26:43 +0900 Message-Id: <20221027042651.234524-2-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=1666844820; a=rsa-sha256; cv=none; b=Y0XGa1D66bEXWI0uWOLN3NuYF0ryWSSx+/HwJvRcC0PITpB6FFWYxhIv+ewMIQJ0jekwzd M2uCG13n2gvLeQYCpNTk7zOdzflalnU3GjdXSHFkj/d5MtODRbEYdp8hvQdFnOoGKjVzRB TOY7jRS8z/1YaZMg7zxycW15fAec36U= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=LZs2JMXZ; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf02.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.180 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666844820; 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=57/g83Q1A5B+7wYv3+Gd1tLG4FTDJnhj+xIMySGShWo=; b=Qc9965hSjxWx0u+kf+KCss7/Ke+vmwh4D2Ci5DplMcAirL5cBoMK4ZdDvgevv0Omr5y9Qq SY/3aXo4DIUkfdiKuWj3q4S53jJ/fvDiVgmTfR6BrJtlO/bRjfje+i5RKEV7FRY3B/DFjA a935Y7LQpl3zhUJHcdTpvbYTgq7nihA= X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 9B5C08003D X-Rspam-User: Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=LZs2JMXZ; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf02.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.180 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org X-Stat-Signature: q8bx4k5k5h41jtayjwm17uzqdufsgfi1 X-HE-Tag: 1666844820-272124 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: From: Alexey Romanov It makes no sense for us to recompress the object if it will be in the same size class. We anyway don't get any memory gain. But, at the same time, we get a CPU time overhead when inserting this object into zspage and decompressing it afterwards. Signed-off-by: Alexey Romanov --- drivers/block/zram/zram_drv.c | 5 +++++ include/linux/zsmalloc.h | 2 ++ mm/zsmalloc.c | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index 364323713393..fd31beb6491a 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1632,6 +1632,8 @@ static int zram_recompress(struct zram *zram, u32 index, struct page *page, unsigned long handle_next; unsigned int comp_len_next; unsigned int comp_len_prev; + unsigned int class_index_prev; + unsigned int class_index_next; struct zcomp_strm *zstrm; void *src, *dst; int ret; @@ -1656,6 +1658,8 @@ static int zram_recompress(struct zram *zram, u32 index, struct page *page, ret = zcomp_compress(zstrm, src, &comp_len_next); kunmap_atomic(src); + class_index_prev = zs_lookup_class_index(zram->mem_pool, comp_len_prev); + class_index_next = zs_lookup_class_index(zram->mem_pool, comp_len_next); /* * Either a compression error or we failed to compressed the object * in a way that will save us memory. Mark the object so that we @@ -1663,6 +1667,7 @@ static int zram_recompress(struct zram *zram, u32 index, struct page *page, */ if (comp_len_next >= huge_class_size || comp_len_next >= comp_len_prev || + class_index_next >= class_index_prev || ret) { zram_set_flag(zram, index, ZRAM_RECOMP_SKIP); zram_clear_flag(zram, index, ZRAM_IDLE); diff --git a/include/linux/zsmalloc.h b/include/linux/zsmalloc.h index 2a430e713ce5..a48cd0ffe57d 100644 --- a/include/linux/zsmalloc.h +++ b/include/linux/zsmalloc.h @@ -55,5 +55,7 @@ void zs_unmap_object(struct zs_pool *pool, unsigned long handle); unsigned long zs_get_total_pages(struct zs_pool *pool); unsigned long zs_compact(struct zs_pool *pool); +unsigned int zs_lookup_class_index(struct zs_pool *pool, unsigned int size); + void zs_pool_stats(struct zs_pool *pool, struct zs_pool_stats *stats); #endif diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index d03941cace2c..065744b7e9d8 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -1205,6 +1205,27 @@ static bool zspage_full(struct size_class *class, struct zspage *zspage) return get_zspage_inuse(zspage) == class->objs_per_zspage; } +/** + * zs_lookup_class_index() - Returns index of the zsmalloc &size_class + * that hold objects of the provided size. + * @pool: zsmalloc pool to use + * @size: object size + * + * Context: Any context. + * + * Return: the index of the zsmalloc &size_class that hold objects of the + * provided size. + */ +unsigned int zs_lookup_class_index(struct zs_pool *pool, unsigned int size) +{ + struct size_class *class; + + class = pool->size_class[get_size_class_index(size)]; + + return class->index; +} +EXPORT_SYMBOL_GPL(zs_lookup_class_index); + unsigned long zs_get_total_pages(struct zs_pool *pool) { return atomic_long_read(&pool->pages_allocated); From patchwork Thu Oct 27 04:26:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13021573 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 9B23DC38A2D for ; Thu, 27 Oct 2022 04:27:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2E0818E0005; Thu, 27 Oct 2022 00:27:04 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 291028E0001; Thu, 27 Oct 2022 00:27:04 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 132378E0005; Thu, 27 Oct 2022 00:27:04 -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 0362C8E0001 for ; Thu, 27 Oct 2022 00:27:04 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id CA8161A119F for ; Thu, 27 Oct 2022 04:27:03 +0000 (UTC) X-FDA: 80065444326.04.680BE56 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by imf17.hostedemail.com (Postfix) with ESMTP id 6A49640003 for ; Thu, 27 Oct 2022 04:27:03 +0000 (UTC) Received: by mail-pj1-f48.google.com with SMTP id v4-20020a17090a088400b00212cb0ed97eso333979pjc.5 for ; Wed, 26 Oct 2022 21:27:03 -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=kYHwDZX+OTDKDC8bU+o1NT+EmIjRRumGisUxBf1X8rE=; b=bexune8pI6Uy21iUlP4GG9GCpBFjRe8EFRX7nN8YQJEdsVLRyWAfP2Vwz6ygkU9Ir1 umthpyDwCoB00Bf1WPkiW282pCg/RtYIfOCKNup0dV68mOMsIAeLJeUjyDvPy2Dhc9Mh l8gsXpCx2HTYO5LPj/Y7PS1HcHmhgZylkXMLw= 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=kYHwDZX+OTDKDC8bU+o1NT+EmIjRRumGisUxBf1X8rE=; b=LoxgWry05cV73Sb+v35CM37s1VOrGvvjQBcff0pbyHWzDuVUw/GEVPlVCQaztTtvnu sNmnNEq1gdx0UdBbZj2KUwA6qswGuHzOh0qtjnSvisohyQyPj8iOGEpZCyrX3HYTuFwz PXC/iQxvHD9c+eSMbqFgvooCnMs6tFbVr+pUbnxB90iyOO8ommgExJ0t8KT9enxnmAT4 HwZzDKjVXpUePrNPEJ89jnGByGLCw4jO5GpTrUSdaXrdtYj3VQQyHTA8QEtJrUuY7/uB MOd4YIYIRo2ASpO9lcC795q97bCzvYqhYIk0QZTyRATSAeBvjGD94qxGuF9ycpVQ6Gic iiDw== X-Gm-Message-State: ACrzQf0BpLLxVNz6LpNoMoe9qWQ3uEJfED96E1BkEJidB/7tL2tvFMTj EbYBn+9lZsPsI9gcq12dMzAzdA== X-Google-Smtp-Source: AMsMyM4qTdzDS5R5xjUFTA5obo5u/csdgNdnIBLvo5gpnLsstmSlHxA5re4GGXV+mv9aSxxXmmfxnA== X-Received: by 2002:a17:90b:4d84:b0:212:c78f:8d6e with SMTP id oj4-20020a17090b4d8400b00212c78f8d6emr7879516pjb.201.1666844822182; Wed, 26 Oct 2022 21:27:02 -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.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 21:27:01 -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 2/9] zsmalloc: turn zspage order into runtime variable Date: Thu, 27 Oct 2022 13:26:44 +0900 Message-Id: <20221027042651.234524-3-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=1666844823; a=rsa-sha256; cv=none; b=qtZPZul7fCo4VN7FWldVinF37k3cOB/kYeUOy/muYMuPk6iWAthZGwafhi7xo1BxZK8frv sxEII/RDGqghAtNC+j+nW19qgEMd7ulBQC8PsaXUrzK5AH8vVKfurQ7jrNX5qNNkQ5s1cG Q7C4G5IN7F/zs5RwjwlQIrFg1dHnNPk= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=bexune8p; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf17.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.48 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666844823; 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=kYHwDZX+OTDKDC8bU+o1NT+EmIjRRumGisUxBf1X8rE=; b=IIVNePdwqrqd8VG+1dJ2DbK4yi6YHobxr945b12RtoybanKpKhmTCDhzKM53ueTenqeSxO KK15fYKpSbLmVuqI1g2JrbtFXm0qUllE22bebszVxPlAhVrTeEGgwWEcUA1BI3wfprfwBK wR+G/F8lIZpv4ZIDDPPM9UI2fQNym7w= X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 6A49640003 X-Rspam-User: Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=bexune8p; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf17.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.48 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org X-Stat-Signature: kmdwfqcsqdzexzgsinyp6biui9u93aot X-HE-Tag: 1666844823-16231 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: zsmalloc has 255 size classes. Size classes contain a number of zspages, which store objects of the same size. zspage can consist of up to four physical pages. The exact (most optimal) zspage size is calculated for each size class during zsmalloc pool creation. As a reasonable optimization, zsmalloc merges size classes that have similar characteristics: number of pages per zspage and number of objects zspage can store. For example, let's look at the following size classes: class size almost_full almost_empty obj_allocated obj_used pages_used pages_per_zspage freeable .. 94 1536 0 0 0 0 0 3 0 100 1632 0 0 0 0 0 2 0 .. Size classes #95-99 are merged with size class #100. That is, each time we store an object of size, say, 1568 bytes instead of using class #96 we end up storing it in size class #100. Class #100 is for objects of 1632 bytes in size, hence every 1568 bytes object wastes 1632-1568 bytes. Class #100 zspages consist of 2 physical pages and can hold 5 objects. When we need to store, say, 13 objects of size 1568 we end up allocating three zspages; in other words, 6 physical pages. However, if we'll look closer at size class #96 (which should hold objects of size 1568 bytes) and trace get_pages_per_zspage(): pages per zspage wasted bytes used% 1 960 76 2 352 95 3 1312 89 4 704 95 5 96 99 We'd notice that the most optimal zspage configuration for this class is when it consists of 5 physical pages, but currently we never let zspages to consists of more than 4 pages. A 5 page class #96 configuration would store 13 objects of size 1568 in a single zspage, allocating 5 physical pages, as opposed to 6 physical pages that class #100 will allocate. A higher order zspage for class #96 also changes its key characteristics: pages per-zspage and objects per-zspage. As a result classes #96 and #100 are not merged anymore, which gives us more compact zsmalloc. Of course the described effect does not apply only to size classes #96 and We still merge classes, but less often so. In other words classes are grouped in a more compact way, which decreases memory wastage: zspage order # unique size classes 2 69 3 123 4 191 Let's take a closer look at the bottom of /sys/kernel/debug/zsmalloc/zram0/classes: class size almost_full almost_empty obj_allocated obj_used pages_used pages_per_zspage freeable ... 202 3264 0 0 0 0 0 4 0 254 4096 0 0 0 0 0 1 0 ... For exactly same reason - maximum 4 pages per zspage - the last non-huge size class is #202, which stores objects of size 3264 bytes. Any object larger than 3264 bytes, hence, is considered to be huge and lands in size class #254, which uses a whole physical page to store every object. To put it slightly differently - objects in huge classes don't share physical pages. 3264 bytes is too low of a watermark and we have too many huge classes: classes from #203 to #254. Similarly to class size #96 above, higher order zspages change key characteristics for some of those huge size classes and thus those classes become normal classes, where stored objects share physical pages. Hence yet another consequence of higher order zspages: we move the huge size class watermark with higher order zspages, have less huge classes and store large objects in a more compact way. For order 3, huge class watermark becomes 3632 bytes: class size almost_full almost_empty obj_allocated obj_used pages_used pages_per_zspage freeable ... 202 3264 0 0 0 0 0 4 0 211 3408 0 0 0 0 0 5 0 217 3504 0 0 0 0 0 6 0 222 3584 0 0 0 0 0 7 0 225 3632 0 0 0 0 0 8 0 254 4096 0 0 0 0 0 1 0 ... For order 4, huge class watermark becomes 3840 bytes: class size almost_full almost_empty obj_allocated obj_used pages_used pages_per_zspage freeable ... 202 3264 0 0 0 0 0 4 0 206 3328 0 0 0 0 0 13 0 207 3344 0 0 0 0 0 9 0 208 3360 0 0 0 0 0 14 0 211 3408 0 0 0 0 0 5 0 212 3424 0 0 0 0 0 16 0 214 3456 0 0 0 0 0 11 0 217 3504 0 0 0 0 0 6 0 219 3536 0 0 0 0 0 13 0 222 3584 0 0 0 0 0 7 0 223 3600 0 0 0 0 0 15 0 225 3632 0 0 0 0 0 8 0 228 3680 0 0 0 0 0 9 0 230 3712 0 0 0 0 0 10 0 232 3744 0 0 0 0 0 11 0 234 3776 0 0 0 0 0 12 0 235 3792 0 0 0 0 0 13 0 236 3808 0 0 0 0 0 14 0 238 3840 0 0 0 0 0 15 0 254 4096 0 0 0 0 0 1 0 ... TESTS ===== Test untars linux-6.0.tar.xz and compiles the kernel. zram is configured as a block device with ext4 file system, lzo-rle compression algorithm. We captured /sys/block/zram0/mm_stat after every test and rebooted the VM. orig_data_size mem_used_total mem_used_max pages_compacted compr_data_size mem_limit same_pages huge_pages ORDER 2 (BASE) zspage 1691791360 628086729 655171584 0 655171584 60 0 34043 1691787264 628089196 655175680 0 655175680 60 0 34046 1691803648 628098840 655187968 0 655187968 59 0 34047 1691795456 628091503 655183872 0 655183872 60 0 34044 1691799552 628086877 655183872 0 655183872 60 0 34047 ORDER 3 zspage 1691803648 627792993 641794048 0 641794048 60 0 33591 1691787264 627779342 641708032 0 641708032 59 0 33591 1691811840 627786616 641769472 0 641769472 60 0 33591 1691803648 627794468 641818624 0 641818624 59 0 33592 1691783168 627780882 641794048 0 641794048 61 0 33591 ORDER 4 zspage 1691803648 627726635 639655936 0 639655936 60 0 33435 1691811840 627733348 639643648 0 639643648 61 0 33434 1691795456 627726290 639614976 0 639614976 60 0 33435 1691803648 627730458 639688704 0 639688704 60 0 33434 1691811840 627727771 639688704 0 639688704 60 0 33434 Order 3 and order 4 show statistically significant improvement in `mem_used_max` metrics. T-test for order 3: x order-2-maxmem + order-3-maxmem N Min Max Median Avg Stddev x 5 6.5517158e+08 6.5518797e+08 6.5518387e+08 6.551806e+08 6730.4157 + 5 6.4170803e+08 6.4181862e+08 6.4179405e+08 6.4177684e+08 42210.666 Difference at 95.0% confidence -1.34038e+07 +/- 44080.7 -2.04581% +/- 0.00672802% (Student's t, pooled s = 30224.5) T-test for order 4: x order-2-maxmem + order-4-maxmem N Min Max Median Avg Stddev x 5 6.5517158e+08 6.5518797e+08 6.5518387e+08 6.551806e+08 6730.4157 + 5 6.3961498e+08 6.396887e+08 6.3965594e+08 6.3965839e+08 31408.602 Difference at 95.0% confidence -1.55222e+07 +/- 33126.2 -2.36915% +/- 0.00505604% (Student's t, pooled s = 22713.4) This test tends to benefit more from order 4 zspages, due to test's data patterns. zsmalloc object distribution analysis ============================================================================= Order 2 (4 pages per zspage) tends to put many objects in size class 2048, which is merged with size classes #112-#125: class size almost_full almost_empty obj_allocated obj_used pages_used pages_per_zspage freeable ... 71 1168 0 0 6146 6146 1756 2 0 74 1216 0 1 4560 4552 1368 3 0 76 1248 0 1 2938 2934 904 4 0 83 1360 0 0 10971 10971 3657 1 0 91 1488 0 0 16126 16126 5864 4 0 94 1536 0 1 5912 5908 2217 3 0 100 1632 0 0 11990 11990 4796 2 0 107 1744 0 1 15771 15768 6759 3 0 111 1808 0 1 10386 10380 4616 4 0 126 2048 0 0 45444 45444 22722 1 0 144 2336 0 0 47446 47446 27112 4 0 151 2448 1 0 10760 10759 6456 3 0 168 2720 0 0 10173 10173 6782 2 0 190 3072 0 1 1700 1697 1275 3 0 202 3264 0 1 290 286 232 4 0 254 4096 0 0 34051 34051 34051 1 0 Order 3 (8 pages per zspage) changed pool characteristics and unmerged some of the size classes, which resulted in less objects being put into size class 2048, because there are lower size classes are now available for more compact object storage: class size almost_full almost_empty obj_allocated obj_used pages_used pages_per_zspage freeable ... 71 1168 0 1 2996 2994 856 2 0 72 1184 0 1 1632 1609 476 7 0 73 1200 1 0 1445 1442 425 5 0 74 1216 0 0 1510 1510 453 3 0 75 1232 0 1 1495 1479 455 7 0 76 1248 0 1 1456 1451 448 4 0 78 1280 0 1 3040 3033 950 5 0 79 1296 0 1 1584 1571 504 7 0 83 1360 0 0 6375 6375 2125 1 0 84 1376 0 1 1817 1796 632 8 0 87 1424 0 1 6020 6006 2107 7 0 88 1440 0 1 2108 2101 744 6 0 89 1456 0 1 2072 2064 740 5 0 91 1488 0 1 4169 4159 1516 4 0 92 1504 0 1 2014 2007 742 7 0 94 1536 0 1 3904 3900 1464 3 0 95 1552 0 1 1890 1873 720 8 0 96 1568 0 1 1963 1958 755 5 0 97 1584 0 1 1980 1974 770 7 0 100 1632 0 1 6190 6187 2476 2 0 103 1680 0 0 6477 6477 2667 7 0 104 1696 0 1 2256 2253 940 5 0 105 1712 0 1 2356 2340 992 8 0 107 1744 1 0 4697 4696 2013 3 0 110 1792 0 1 7744 7734 3388 7 0 111 1808 0 1 2655 2649 1180 4 0 114 1856 0 1 8371 8365 3805 5 0 116 1888 1 0 5863 5862 2706 6 0 117 1904 0 1 2955 2942 1379 7 0 118 1920 0 1 3009 2997 1416 8 0 126 2048 0 0 25276 25276 12638 1 0 128 2080 0 1 6060 6052 3232 8 0 129 2096 1 0 3081 3080 1659 7 0 134 2176 0 1 14835 14830 7912 8 0 135 2192 0 1 2769 2758 1491 7 0 137 2224 0 1 5082 5077 2772 6 0 140 2272 0 1 7236 7232 4020 5 0 144 2336 0 1 8428 8423 4816 4 0 147 2384 0 1 5316 5313 3101 7 0 151 2448 0 1 5445 5443 3267 3 0 155 2512 0 0 4121 4121 2536 8 0 158 2560 0 1 2208 2205 1380 5 0 160 2592 0 0 1133 1133 721 7 0 168 2720 0 0 2712 2712 1808 2 0 177 2864 1 0 1100 1098 770 7 0 180 2912 0 1 189 183 135 5 0 184 2976 0 1 176 166 128 8 0 190 3072 0 0 252 252 189 3 0 197 3184 0 1 198 192 154 7 0 202 3264 0 1 100 96 80 4 0 211 3408 0 1 210 208 175 5 0 217 3504 0 1 98 94 84 6 0 222 3584 0 0 104 104 91 7 0 225 3632 0 1 54 50 48 8 0 254 4096 0 0 33591 33591 33591 1 0 Note, the huge size watermark is above 3632 and there are a number of new normal classes available that previously were merged with the huge class. For instance, size class #211 holds 210 objects of size 3408 and uses 175 physical pages, while previously for those objects we would have used 210 physical pages. Signed-off-by: Sergey Senozhatsky --- include/linux/zsmalloc.h | 12 +++++++ mm/zsmalloc.c | 75 +++++++++++++++++++++++----------------- 2 files changed, 56 insertions(+), 31 deletions(-) diff --git a/include/linux/zsmalloc.h b/include/linux/zsmalloc.h index a48cd0ffe57d..6cd1d95b928a 100644 --- a/include/linux/zsmalloc.h +++ b/include/linux/zsmalloc.h @@ -33,6 +33,18 @@ enum zs_mapmode { */ }; +#define ZS_PAGE_ORDER_2 2 +#define ZS_PAGE_ORDER_4 4 + +/* + * A single 'zspage' is composed of up to 2^N discontiguous 0-order (single) + * pages. ZS_MAX_PAGE_ORDER defines upper limit on N, ZS_MIN_PAGE_ORDER + * defines lower limit on N. ZS_DEFAULT_PAGE_ORDER is recommended value. + */ +#define ZS_MIN_PAGE_ORDER ZS_PAGE_ORDER_2 +#define ZS_MAX_PAGE_ORDER ZS_PAGE_ORDER_4 +#define ZS_DEFAULT_PAGE_ORDER ZS_PAGE_ORDER_2 + struct zs_pool_stats { /* How many pages were migrated (freed) */ atomic_long_t pages_compacted; diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 065744b7e9d8..bc377e5d3417 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -74,12 +74,7 @@ */ #define ZS_ALIGN 8 -/* - * A single 'zspage' is composed of up to 2^N discontiguous 0-order (single) - * pages. ZS_MAX_ZSPAGE_ORDER defines upper limit on N. - */ -#define ZS_MAX_ZSPAGE_ORDER 2 -#define ZS_MAX_PAGES_PER_ZSPAGE (_AC(1, UL) << ZS_MAX_ZSPAGE_ORDER) +#define ZS_MAX_PAGES_PER_ZSPAGE (_AC(1, UL) << ZS_MAX_PAGE_ORDER) #define ZS_HANDLE_SIZE (sizeof(unsigned long)) @@ -124,10 +119,8 @@ #define ISOLATED_BITS 3 #define MAGIC_VAL_BITS 8 -#define MAX(a, b) ((a) >= (b) ? (a) : (b)) -/* ZS_MIN_ALLOC_SIZE must be multiple of ZS_ALIGN */ -#define ZS_MIN_ALLOC_SIZE \ - MAX(32, (ZS_MAX_PAGES_PER_ZSPAGE << PAGE_SHIFT >> OBJ_INDEX_BITS)) +#define ZS_MIN_ALLOC_SIZE 32U + /* each chunk includes extra space to keep handle */ #define ZS_MAX_ALLOC_SIZE PAGE_SIZE @@ -141,12 +134,10 @@ * determined). NOTE: all those class sizes must be set as multiple of * ZS_ALIGN to make sure link_free itself never has to span 2 pages. * - * ZS_MIN_ALLOC_SIZE and ZS_SIZE_CLASS_DELTA must be multiple of ZS_ALIGN - * (reason above) + * pool->min_alloc_size (ZS_MIN_ALLOC_SIZE) and ZS_SIZE_CLASS_DELTA must + * be multiple of ZS_ALIGN (reason above) */ #define ZS_SIZE_CLASS_DELTA (PAGE_SIZE >> CLASS_BITS) -#define ZS_SIZE_CLASSES (DIV_ROUND_UP(ZS_MAX_ALLOC_SIZE - ZS_MIN_ALLOC_SIZE, \ - ZS_SIZE_CLASS_DELTA) + 1) enum fullness_group { ZS_EMPTY, @@ -230,12 +221,15 @@ struct link_free { struct zs_pool { const char *name; - struct size_class *size_class[ZS_SIZE_CLASSES]; + struct size_class **size_class; struct kmem_cache *handle_cachep; struct kmem_cache *zspage_cachep; atomic_long_t pages_allocated; + u32 num_size_classes; + u32 min_alloc_size; + struct zs_pool_stats stats; /* Compact classes */ @@ -523,15 +517,15 @@ static void set_zspage_mapping(struct zspage *zspage, * classes depending on its size. This function returns index of the * size class which has chunk size big enough to hold the given size. */ -static int get_size_class_index(int size) +static int get_size_class_index(struct zs_pool *pool, int size) { int idx = 0; - if (likely(size > ZS_MIN_ALLOC_SIZE)) - idx = DIV_ROUND_UP(size - ZS_MIN_ALLOC_SIZE, + if (likely(size > pool->min_alloc_size)) + idx = DIV_ROUND_UP(size - pool->min_alloc_size, ZS_SIZE_CLASS_DELTA); - return min_t(int, ZS_SIZE_CLASSES - 1, idx); + return min_t(int, pool->num_size_classes - 1, idx); } /* type can be of enum type class_stat_type or fullness_group */ @@ -591,7 +585,7 @@ static int zs_stats_size_show(struct seq_file *s, void *v) "obj_allocated", "obj_used", "pages_used", "pages_per_zspage", "freeable"); - for (i = 0; i < ZS_SIZE_CLASSES; i++) { + for (i = 0; i < pool->num_size_classes; i++) { class = pool->size_class[i]; if (class->index != i) @@ -777,13 +771,13 @@ static enum fullness_group fix_fullness_group(struct size_class *class, * link together 3 PAGE_SIZE sized pages to form a zspage * since then we can perfectly fit in 8 such objects. */ -static int get_pages_per_zspage(int class_size) +static int get_pages_per_zspage(u32 class_size, u32 max_pages_per_zspage) { int i, max_usedpc = 0; /* zspage order which gives maximum used size per KB */ int max_usedpc_order = 1; - for (i = 1; i <= ZS_MAX_PAGES_PER_ZSPAGE; i++) { + for (i = 1; i <= max_pages_per_zspage; i++) { int zspage_size; int waste, usedpc; @@ -1220,7 +1214,7 @@ unsigned int zs_lookup_class_index(struct zs_pool *pool, unsigned int size) { struct size_class *class; - class = pool->size_class[get_size_class_index(size)]; + class = pool->size_class[get_size_class_index(pool, size)]; return class->index; } @@ -1431,7 +1425,7 @@ unsigned long zs_malloc(struct zs_pool *pool, size_t size, gfp_t gfp) /* extra space in chunk to keep the handle */ size += ZS_HANDLE_SIZE; - class = pool->size_class[get_size_class_index(size)]; + class = pool->size_class[get_size_class_index(pool, size)]; /* class->lock effectively protects the zpage migration */ spin_lock(&class->lock); @@ -1980,7 +1974,7 @@ static void async_free_zspage(struct work_struct *work) struct zs_pool *pool = container_of(work, struct zs_pool, free_work); - for (i = 0; i < ZS_SIZE_CLASSES; i++) { + for (i = 0; i < pool->num_size_classes; i++) { class = pool->size_class[i]; if (class->index != i) continue; @@ -2129,7 +2123,7 @@ unsigned long zs_compact(struct zs_pool *pool) struct size_class *class; unsigned long pages_freed = 0; - for (i = ZS_SIZE_CLASSES - 1; i >= 0; i--) { + for (i = pool->num_size_classes - 1; i >= 0; i--) { class = pool->size_class[i]; if (class->index != i) continue; @@ -2173,7 +2167,7 @@ static unsigned long zs_shrinker_count(struct shrinker *shrinker, struct zs_pool *pool = container_of(shrinker, struct zs_pool, shrinker); - for (i = ZS_SIZE_CLASSES - 1; i >= 0; i--) { + for (i = pool->num_size_classes - 1; i >= 0; i--) { class = pool->size_class[i]; if (class->index != i) continue; @@ -2215,11 +2209,28 @@ struct zs_pool *zs_create_pool(const char *name) int i; struct zs_pool *pool; struct size_class *prev_class = NULL; + u32 max_pages_per_zspage; pool = kzalloc(sizeof(*pool), GFP_KERNEL); if (!pool) return NULL; + max_pages_per_zspage = 1U << ZS_DEFAULT_PAGE_ORDER; + /* min_alloc_size must be multiple of ZS_ALIGN */ + pool->min_alloc_size = (max_pages_per_zspage << PAGE_SHIFT) >> + OBJ_INDEX_BITS; + pool->min_alloc_size = max(pool->min_alloc_size, ZS_MIN_ALLOC_SIZE); + + pool->num_size_classes = + DIV_ROUND_UP(ZS_MAX_ALLOC_SIZE - pool->min_alloc_size, + ZS_SIZE_CLASS_DELTA) + 1; + + pool->size_class = kmalloc_array(pool->num_size_classes, + sizeof(struct size_class *), + GFP_KERNEL | __GFP_ZERO); + if (!pool->size_class) + goto err; + init_deferred_free(pool); rwlock_init(&pool->migrate_lock); @@ -2234,17 +2245,18 @@ struct zs_pool *zs_create_pool(const char *name) * Iterate reversely, because, size of size_class that we want to use * for merging should be larger or equal to current size. */ - for (i = ZS_SIZE_CLASSES - 1; i >= 0; i--) { + for (i = pool->num_size_classes - 1; i >= 0; i--) { int size; int pages_per_zspage; int objs_per_zspage; struct size_class *class; int fullness = 0; - size = ZS_MIN_ALLOC_SIZE + i * ZS_SIZE_CLASS_DELTA; + size = pool->min_alloc_size + i * ZS_SIZE_CLASS_DELTA; if (size > ZS_MAX_ALLOC_SIZE) size = ZS_MAX_ALLOC_SIZE; - pages_per_zspage = get_pages_per_zspage(size); + pages_per_zspage = get_pages_per_zspage(size, + max_pages_per_zspage); objs_per_zspage = pages_per_zspage * PAGE_SIZE / size; /* @@ -2328,7 +2340,7 @@ void zs_destroy_pool(struct zs_pool *pool) zs_flush_migration(pool); zs_pool_stat_destroy(pool); - for (i = 0; i < ZS_SIZE_CLASSES; i++) { + for (i = 0; i < pool->num_size_classes; i++) { int fg; struct size_class *class = pool->size_class[i]; @@ -2348,6 +2360,7 @@ void zs_destroy_pool(struct zs_pool *pool) } destroy_cache(pool); + kfree(pool->size_class); kfree(pool->name); kfree(pool); } From patchwork Thu Oct 27 04:26:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13021574 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 A3F55C67871 for ; Thu, 27 Oct 2022 04:27:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3CADE8E0006; Thu, 27 Oct 2022 00:27:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 37B3C8E0001; Thu, 27 Oct 2022 00:27:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 243D28E0006; Thu, 27 Oct 2022 00:27:06 -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 1452E8E0001 for ; Thu, 27 Oct 2022 00:27:06 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id DD6CF1C3F1F for ; Thu, 27 Oct 2022 04:27:05 +0000 (UTC) X-FDA: 80065444410.23.0390062 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) by imf30.hostedemail.com (Postfix) with ESMTP id 818B780006 for ; Thu, 27 Oct 2022 04:27:05 +0000 (UTC) Received: by mail-pj1-f48.google.com with SMTP id pb15so391178pjb.5 for ; Wed, 26 Oct 2022 21:27:05 -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=GHzCyKbWb+aU+sZGmdZ8m8JVMN9OaN+P/JFQjaIcOqo=; b=aSq+upzUZDdmC75naLxSlP8YpIcWBfuiUS998Gz2iB6tqN4yzH7e5GMJvSc97pighw 2VTDsvilUhxegpUo5ItOSWNQxe90NnQg8p8L2B4P00g7f3R7tGeHEqtGVJNNWBRveOLP GcBCvqAX/L8G3fn/4j3Jkaf7d3yUXYdkv3s7k= 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=GHzCyKbWb+aU+sZGmdZ8m8JVMN9OaN+P/JFQjaIcOqo=; b=j0u9NmJ1U7F0prrbYb46/3O83DeSzZ9DkC8RANDfTaLOmZnlc7CQj0ddWRjEOVnzz9 khTqEN5BlXpryfSTG0jMWsG38XlE6VyN8aD/nXnYCqK+ICq4jM3CIaiB50IFY63AdpX8 UVje6Zk9L4X5+4t5hTTR6tSw23CT8R+SESAJLo7koFoZG4Mjan6S2fqnDYOOF/haqlxO vGyS+JpWG3GOvbATG+g8CzayYFOliFJTXbjht0BXuWjZyZZvqtrkmCquMm7POafO2BCO RJwR7aU1yWgR6GXRYMUOmlS/YUCcORJZYNWCnyTRhodRlzgaVUk57pKU464wkpweG3ym 0eIA== X-Gm-Message-State: ACrzQf2YPEoZX55B43aGx1SY3Z4ajEhjG53e3HyMZHNwb4VPykLVIYBX vUc4/wlDwM2lHYnj9qFg34bYE9RHAZEU3g== X-Google-Smtp-Source: AMsMyM797j3sc8YkFDNvzD0Xr0D9iMhxgxZ66M0yX/pGyuoc9PJt02IDJYOIeyuvGuiXXR2j0GAi2g== X-Received: by 2002:a17:90b:3ec6:b0:20a:eb6b:c832 with SMTP id rm6-20020a17090b3ec600b0020aeb6bc832mr7917557pjb.22.1666844824643; Wed, 26 Oct 2022 21:27:04 -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.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 21:27:04 -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 3/9] zsmalloc: move away from page order defines Date: Thu, 27 Oct 2022 13:26:45 +0900 Message-Id: <20221027042651.234524-4-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=1666844825; a=rsa-sha256; cv=none; b=KMrYPiEz88XEKpf5jO4fvUJoA0keOiwXJDptJRg4RPXqZgR/Ok6b7sVMDOnCIt82a/38d+ E0d/AGl+gfQPTwLEYx458etk78wjcCnrK6eruAMo+sWMMZdrmJ9DNtXrARERae9dD0J3V/ Z/DFNtGP5gLduhViQ0MuA4mCRiX+VLE= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=aSq+upzU; spf=pass (imf30.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.48 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=1666844825; 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=GHzCyKbWb+aU+sZGmdZ8m8JVMN9OaN+P/JFQjaIcOqo=; b=30gY4tFyXoeEP8mJN+z+joSKZjeQS2nz/7k5BSJDvX6uRSKE75IhMkFSmojneJ+Exa/Ihy aOZrwTAcZzjcasOu64by15ML+0B1SkkmPWF1JHenUD6dgu5vtVi1tzatJ8zYkougy1cFCK R5xF4bylhxXiwkwB/tr5rts3s3k5J00= X-Rspamd-Queue-Id: 818B780006 X-Rspam-User: Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=aSq+upzU; spf=pass (imf30.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.48 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam04 X-Stat-Signature: ydiu4q15n5zjgte3qcr5bsx38okguzx8 X-HE-Tag: 1666844825-843447 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: There is no reason for us to require pages per-zspage to be a power of two. Rename macros and use plain limit numbers there instead of 2 ^ N values. This will let us to have more tunable limits. Signed-off-by: Sergey Senozhatsky --- include/linux/zsmalloc.h | 16 +++++++--------- mm/zsmalloc.c | 4 +--- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/include/linux/zsmalloc.h b/include/linux/zsmalloc.h index 6cd1d95b928a..b6b8654a2d45 100644 --- a/include/linux/zsmalloc.h +++ b/include/linux/zsmalloc.h @@ -33,17 +33,15 @@ enum zs_mapmode { */ }; -#define ZS_PAGE_ORDER_2 2 -#define ZS_PAGE_ORDER_4 4 - /* - * A single 'zspage' is composed of up to 2^N discontiguous 0-order (single) - * pages. ZS_MAX_PAGE_ORDER defines upper limit on N, ZS_MIN_PAGE_ORDER - * defines lower limit on N. ZS_DEFAULT_PAGE_ORDER is recommended value. + * A single 'zspage' is composed of up to N discontiguous 0-order + * (single) pages. ZS_MAX_PAGES_PER_ZSPAGE defines upper limit on N, + * ZS_MIN_PAGES_PER_ZSPAGE defines lower limit on N. + * ZS_DEFAULT_PAGES_PER_ZSPAGE is a recommended value. */ -#define ZS_MIN_PAGE_ORDER ZS_PAGE_ORDER_2 -#define ZS_MAX_PAGE_ORDER ZS_PAGE_ORDER_4 -#define ZS_DEFAULT_PAGE_ORDER ZS_PAGE_ORDER_2 +#define ZS_MIN_PAGES_PER_ZSPAGE 1 +#define ZS_MAX_PAGES_PER_ZSPAGE 16 +#define ZS_DEFAULT_PAGES_PER_ZSPAGE 4 struct zs_pool_stats { /* How many pages were migrated (freed) */ diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index bc377e5d3417..d4f68fba746b 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -74,8 +74,6 @@ */ #define ZS_ALIGN 8 -#define ZS_MAX_PAGES_PER_ZSPAGE (_AC(1, UL) << ZS_MAX_PAGE_ORDER) - #define ZS_HANDLE_SIZE (sizeof(unsigned long)) /* @@ -2215,7 +2213,7 @@ struct zs_pool *zs_create_pool(const char *name) if (!pool) return NULL; - max_pages_per_zspage = 1U << ZS_DEFAULT_PAGE_ORDER; + 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; From patchwork Thu Oct 27 04:26:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13021575 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 1009EC38A2D for ; Thu, 27 Oct 2022 04:27:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A0CF18E0007; Thu, 27 Oct 2022 00:27:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 995A78E0001; Thu, 27 Oct 2022 00:27:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 85F498E0007; Thu, 27 Oct 2022 00:27:09 -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 77EE98E0001 for ; Thu, 27 Oct 2022 00:27:09 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4D1D040FF6 for ; Thu, 27 Oct 2022 04:27:09 +0000 (UTC) X-FDA: 80065444578.10.E35A503 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by imf02.hostedemail.com (Postfix) with ESMTP id DAA648003D for ; Thu, 27 Oct 2022 04:27:07 +0000 (UTC) Received: by mail-pl1-f170.google.com with SMTP id c2so207034plz.11 for ; Wed, 26 Oct 2022 21:27:07 -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=ZXAqqjDk6mAz2KU4pc8JUXu1b5D+3y6f+8lsfEOMErU=; b=WngvKc8vcBYMk1kZ5arHHYitYLIPzMf9lvgsPMzCnmgpIOkw/9/8hqJ7boohJPjK84 1/GpQJvSc9hWAZAbj89XueIUHcvodWbahm+jty7rdLIhluMQy7c2Agh3CZZ8EztEsHT5 xkqhhdRhVa3ztF3+mmlNK9my9cEQZaqSq6j54= 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=ZXAqqjDk6mAz2KU4pc8JUXu1b5D+3y6f+8lsfEOMErU=; b=EzNFLsaatV9BK4aO6GaMv6JML/3hdvVGem/ykwsaSbdhckWszBzXewHfKtXucUaFvR 6hV9j7Yc9zuy2LkV/zyOsPMPz2gJcsx4oWsPdplx+D0Gb0fkRks7XypIXNLZgpsv3VtW UZnrWa1PDOMS4K2rY++UQ0tfl9biNF+txbZKJImQSFJwPkv46HYoAcvPz5OTULIK0GWZ G4YkgRXuQE9bMIDefGtFEtf99psV3D780m89cIJ8KJ8+Ae76D8p+WSGO2ZDGU0F9To9Q LhGoDHsVQ9qnQiwqMsGyOKoRnJUCTdDuwo5Hfe9vWl9AbxyanrixOKJI0boUm9MwAXjV /roA== X-Gm-Message-State: ACrzQf3N9cT2i0WkdLcjp5ag4q/fu00Uzc187dyzGWandy5cb9WUcOn2 rjNZ8bEoS2XTqqgBhwfcrN8AEnkfetTITw== X-Google-Smtp-Source: AMsMyM7PNp0OP2QcmW90+E2XrzDzR0wbvfLWMoR4FKeUYoOPqf84Z//D7HEkMOLtbVS2Ygqpvg0hAA== X-Received: by 2002:a17:90b:1b0b:b0:20d:7c31:e75d with SMTP id nu11-20020a17090b1b0b00b0020d7c31e75dmr7711106pjb.101.1666844826902; Wed, 26 Oct 2022 21:27:06 -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.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 21:27:06 -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 4/9] zsmalloc: make huge class watermark zs_pool member Date: Thu, 27 Oct 2022 13:26:46 +0900 Message-Id: <20221027042651.234524-5-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=1666844827; a=rsa-sha256; cv=none; b=4wy7z6BtRmaCWi6I+aWfLHiFss6YUlPJIB373482RCtvjX7+4rcwemw9aDv0330VAiWZRh v0VjvFGcl5ehip6T7WqYCwOhZRDh/EnqlJSLYNypre67UyDXC0HvznOOAcMDiQMBiXUWC5 aB4y5zG+sLzooWaCrw2OqtJem+eW91Q= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=WngvKc8v; spf=pass (imf02.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.170 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=1666844827; 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=ZXAqqjDk6mAz2KU4pc8JUXu1b5D+3y6f+8lsfEOMErU=; b=kIVikWZ6l1Wogjc97eIzLy+jj5w6U8eQV3/gAIXt3RPvf+Frw5p3rqCMiCimntQJlL421M edRLreVU76rOSi88iHacROLfuqzClSBy/lzx1XboQPrflXr5Rdbq7DYbRR4pP1WbxIW0Td Mn2oAD7Q50slX2sA6Wy5rl3fqIgR+bw= X-Rspamd-Queue-Id: DAA648003D X-Rspam-User: Authentication-Results: imf02.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=WngvKc8v; spf=pass (imf02.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.170 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam04 X-Stat-Signature: qm3puh5oanpxb5efhayu8akbsuu1yxih X-HE-Tag: 1666844827-392557 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000012, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: We will permit per-pool configuration of pages per-zspage value, which changes characteristics of the classes and moves around huge class size watermark. Thus huge class size needs to be a per-pool variable. Signed-off-by: Sergey Senozhatsky --- mm/zsmalloc.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index d4f68fba746b..cab8080e2fc6 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -178,7 +178,6 @@ static struct dentry *zs_stat_root; * (see: fix_fullness_group()) */ static const int fullness_threshold_frac = 4; -static size_t huge_class_size; struct size_class { spinlock_t lock; @@ -227,6 +226,7 @@ struct zs_pool { u32 num_size_classes; u32 min_alloc_size; + size_t huge_class_size; struct zs_pool_stats stats; @@ -1350,7 +1350,7 @@ EXPORT_SYMBOL_GPL(zs_unmap_object); */ size_t zs_huge_class_size(struct zs_pool *pool) { - return huge_class_size; + return pool->huge_class_size; } EXPORT_SYMBOL_GPL(zs_huge_class_size); @@ -2264,8 +2264,8 @@ struct zs_pool *zs_create_pool(const char *name) * endup in the huge class. */ if (pages_per_zspage != 1 && objs_per_zspage != 1 && - !huge_class_size) { - huge_class_size = size; + !pool->huge_class_size) { + pool->huge_class_size = size; /* * The object uses ZS_HANDLE_SIZE bytes to store the * handle. We need to subtract it, because zs_malloc() @@ -2275,7 +2275,7 @@ struct zs_pool *zs_create_pool(const char *name) * class because it grows by ZS_HANDLE_SIZE extra bytes * right before class lookup. */ - huge_class_size -= (ZS_HANDLE_SIZE - 1); + pool->huge_class_size -= (ZS_HANDLE_SIZE - 1); } /* From patchwork Thu Oct 27 04:26:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13021576 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 69DD5FA3740 for ; Thu, 27 Oct 2022 04:27:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0BE948E0008; Thu, 27 Oct 2022 00:27:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0700D8E0001; Thu, 27 Oct 2022 00:27:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E2A5E8E0008; Thu, 27 Oct 2022 00:27:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id C95188E0001 for ; Thu, 27 Oct 2022 00:27:10 -0400 (EDT) Received: from smtpin03.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7A03F81015 for ; Thu, 27 Oct 2022 04:27:10 +0000 (UTC) X-FDA: 80065444620.03.411244F Received: from mail-pl1-f175.google.com (mail-pl1-f175.google.com [209.85.214.175]) by imf07.hostedemail.com (Postfix) with ESMTP id 2A7BD40009 for ; Thu, 27 Oct 2022 04:27:09 +0000 (UTC) Received: by mail-pl1-f175.google.com with SMTP id c24so212940pls.9 for ; Wed, 26 Oct 2022 21:27:09 -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=J+4diO4tSVOFVgnXFSt8zIWx9H1y7/ENZOnwMcOSb2Q=; b=cn9fO+L4ylQungziAbx0awEs0vb/rKJImh058JzWlfF+li8hh8QOCkIy7ev44qIVZl k59U8YOl63gc23DdX2UTbPMidbjb9WxTXcI/kNjWCc7ayygy6Erb5iJfC4lOgp4O1d0O /G3x/L16VlMAa5SzTaoytD/pyczoCa/jU8X3g= 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=J+4diO4tSVOFVgnXFSt8zIWx9H1y7/ENZOnwMcOSb2Q=; b=fcQG2AJjWiiR2OYS79DfkoFrcjuYE1CIkbirVwi0OvdbnUIYio1qVTXr9i64gD9sw7 BqbdXrgKsneVaDfLYT+B/RnIdsR0ssKlqS9QDe02LH08W2qU5oPohgGqMpUIHopgqRZ7 cEhuZ/GT8NAMnAiAVomZmCFSxuzj+kTrpL/pzHXwcDw1YkR5WFAUrQMuW5ZYE8DBKEeB 82o3lxl6Qdmdsu44DK6F8udhYUECoFq6u9ybOx1gq2RAlKRKZM9LM61FGgqgqjZgeERb 4X7MBTawXEER6PRyTzO564zcnwGusJsgwahzndMJqAayUj8ZWWn7UgfuxYhJPV4Qmg71 wP7A== X-Gm-Message-State: ACrzQf14KBZ4HgmlYJxtZcUqUxA6c7WQha5NEmofqxlJs67NRnRLpWN8 ffy5tRwhuv8/PEHivtsKvBWZPQ== X-Google-Smtp-Source: AMsMyM7v1jym/Cfi8DjTcdl/L23EwROOmnJ6NDSPAaf1P/bpFyCsr1yAR0pZjfjcTePtikPBXXdinQ== X-Received: by 2002:a17:90b:3b4c:b0:213:f05:6a8 with SMTP id ot12-20020a17090b3b4c00b002130f0506a8mr7907854pjb.108.1666844829155; Wed, 26 Oct 2022 21:27:09 -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.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 21:27:08 -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 5/9] zram: huge size watermark cannot be global Date: Thu, 27 Oct 2022 13:26:47 +0900 Message-Id: <20221027042651.234524-6-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=1666844830; a=rsa-sha256; cv=none; b=19C4jo8muzB28vrgWWSCjIJZM6eX0ScV+LnEo+6l5pNndw4SH5rJsG+36Y8KBRWYiCXy1N QcbVnI+ql+F7kutC+fgqOeeQVNJuaU7nQZJfdWWql7il3UjGrxUx0+mG4gfpSMLB6lTNQe k3UV1JSgO+nFzw4yoteY+apepmDH9Gk= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=cn9fO+L4; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf07.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.175 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666844830; 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=J+4diO4tSVOFVgnXFSt8zIWx9H1y7/ENZOnwMcOSb2Q=; b=yZ7sN4XpE0gE6HvQaL5pLu1Lyg0wH92hoeM+s3J9INzX1EjHKxqWVUNroSkpiU/0s2YAie 3tlQTm7hHLfH+rDAddwbX+aDp5FyBf1WY3LzH+e53tVO+ZUBId3IXkNw3Tl7/ExFbsKBIc oDzcl9LCmg+co1uw+kqj6SM5V/KFhAY= X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: 2A7BD40009 X-Rspam-User: Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=cn9fO+L4; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf07.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.175 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org X-Stat-Signature: xxeoiy8xx8r1p59d17cxynups6dd4ggf X-HE-Tag: 1666844829-407380 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: ZRAM will pass pool specific limit on number of pages per-zspages which will affect pool's characteristics. Namely huge size class watermark value. Move huge_class_size to struct zram, because this value now can be unique to the pool (zram device). Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 13 +++---------- drivers/block/zram/zram_drv.h | 5 +++++ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index fd31beb6491a..90b0c66bbd5b 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -50,12 +50,6 @@ static const char *default_comp_algs[ZRAM_MAX_ZCOMPS] = { /* Module params (documentation at end) */ static unsigned int num_devices = 1; -/* - * Pages that compress to sizes equals or greater than this are stored - * uncompressed in memory. - */ -static size_t huge_class_size; - static const struct block_device_operations zram_devops; static void zram_free_page(struct zram *zram, size_t index); @@ -1259,8 +1253,7 @@ static bool zram_meta_alloc(struct zram *zram, u64 disksize) return false; } - if (!huge_class_size) - huge_class_size = zs_huge_class_size(zram->mem_pool); + zram->huge_class_size = zs_huge_class_size(zram->mem_pool); return true; } @@ -1488,7 +1481,7 @@ static int __zram_bvec_write(struct zram *zram, struct bio_vec *bvec, return ret; } - if (comp_len >= huge_class_size) + if (comp_len >= zram->huge_class_size) comp_len = PAGE_SIZE; /* * handle allocation has 2 paths: @@ -1665,7 +1658,7 @@ static int zram_recompress(struct zram *zram, u32 index, struct page *page, * in a way that will save us memory. Mark the object so that we * don't attempt to re-compress it again (RECOMP_SKIP). */ - if (comp_len_next >= huge_class_size || + if (comp_len_next >= zram->huge_class_size || comp_len_next >= comp_len_prev || class_index_next >= class_index_prev || ret) { diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index 09b9ceb5dfa3..9d6fcfdf7aa7 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -120,6 +120,11 @@ struct zram { */ u64 disksize; /* bytes */ const char *comp_algs[ZRAM_MAX_ZCOMPS]; + /* + * Pages that compress to sizes equal or greater than this are stored + * uncompressed in memory. + */ + size_t huge_class_size; /* * zram is claimed so open request will be failed */ 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; From patchwork Thu Oct 27 04:26:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13021578 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 B5621FA3740 for ; Thu, 27 Oct 2022 04:27:15 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 579018E000A; Thu, 27 Oct 2022 00:27:15 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 4DB7E8E0001; Thu, 27 Oct 2022 00:27:15 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3CA8C8E000A; Thu, 27 Oct 2022 00:27:15 -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 2B43C8E0001 for ; Thu, 27 Oct 2022 00:27:15 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 1460640FF6 for ; Thu, 27 Oct 2022 04:27:15 +0000 (UTC) X-FDA: 80065444830.08.3665059 Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf09.hostedemail.com (Postfix) with ESMTP id ACFC6140016 for ; Thu, 27 Oct 2022 04:27:14 +0000 (UTC) Received: by mail-pl1-f174.google.com with SMTP id io19so216551plb.8 for ; Wed, 26 Oct 2022 21:27:14 -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=aT/Z4fhTkuAT6uqwfGOJvQ0sBMgcsQNCZVCxP8pxlBo=; b=N5K33E3z8EtL3Icy53kN5Y/g5Ea0lQ1Ab6ops7aLBNIS+jXKsvuIKf7pl/StQO4Sxi Tk2eabTStj0K/nNq7wkf19HB2NKmemzwv5wsGWC77OPM6noiXJ2I+dHJ0KiOK1Gup9o3 5Gc4eP30PwzFxV3FVrn9FP0Y+2Rz5+04mAQvU= 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=aT/Z4fhTkuAT6uqwfGOJvQ0sBMgcsQNCZVCxP8pxlBo=; b=KD1jiMuAHoxajbEJEqTih1yTe1ryOjcxiz7M5BxsZ3EnThUd4C2dD5IfeAHMhBoH+Z v5+w7LTgNaZP06v0V6ITBiaJoHbkR1WbgvbA2jrMNtV0WsYgPXq5end1EorkBum6Evdd U1/tDliNvEpQMXuVKP6w6CZ/pVEs/WciRxlooHnTIpC0zfQF1YpQ+1fj3m3oJB3ftBvR OEdXMh4UgBYW7JPyk4V8PFakUt+Fhj95fpRucMeUGmbNnxojrASwkpePDRwd88TEdm3g 91LEPlwax43mDAcYiQc8cm/g84rhFCuTM8j9HPwXggsBrpH601qFKi9blXv4cMzgtJvK 7Nvg== X-Gm-Message-State: ACrzQf3EYsD7GSRLTHgsE97+UGJ4wVXNlUBWIPluEjesUQ+PMdmiNVX1 Z8eFpZvWKHGgTRgjt4TKtYV4jYMk78MAGQ== X-Google-Smtp-Source: AMsMyM64mQZiimWa8RxiZWxhQFGP3BD4EABEcOR3b5zGX9WlpvKLw+7QLjmGphKnAgGT50SjeoSrWw== X-Received: by 2002:a17:90b:1950:b0:212:de19:b3ce with SMTP id nk16-20020a17090b195000b00212de19b3cemr7807059pjb.16.1666844833835; Wed, 26 Oct 2022 21:27:13 -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.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 21:27:13 -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 7/9] zram: add pages_per_pool_page device attribute Date: Thu, 27 Oct 2022 13:26:49 +0900 Message-Id: <20221027042651.234524-8-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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666844834; 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=aT/Z4fhTkuAT6uqwfGOJvQ0sBMgcsQNCZVCxP8pxlBo=; b=hOILPNInJVv5zQMvDyKVhkJ3lLjf8giaz7wcAmIHJk/p9P3EiOkjLe2YJGGc8xTSfoR/uP WT9PzjnvQOJOb2XMlh/LHUksuw2yKxKuCeBSFLZcirh4oQwuIfhnndLtMxSYtJB57U9JTm DeVZ4E268IM5pC1oCz/3GOnZqzEqZNk= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=N5K33E3z; spf=pass (imf09.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.174 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666844834; a=rsa-sha256; cv=none; b=i2iCiLSaIbuTPuA34viH6YABpDqI0ods46RukltpbRBhKKcs01hpdZvhnR0y3YDeKv7j1v Mo0fm2hWZ2i8g3VZoEZUR/qFz3mSRRWSZQMvOQwdKQc2vZs3pMHEB2CrtRq6JTp6403IVk avA3jJd9F/BM3X8NOkkT+8OR9dUGLoE= Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=N5K33E3z; spf=pass (imf09.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.174 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Stat-Signature: crrsebjbcuyw5czjdktuih1a8b81h6jz X-Rspamd-Queue-Id: ACFC6140016 X-Rspamd-Server: rspam07 X-Rspam-User: X-HE-Tag: 1666844834-87732 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: Add a new sysfs knob that allows user-space to set zsmalloc pages per-zspage limit value on per-device basis. Signed-off-by: Sergey Senozhatsky --- drivers/block/zram/zram_drv.c | 44 ++++++++++++++++++++++++++++++++++- drivers/block/zram/zram_drv.h | 2 ++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/drivers/block/zram/zram_drv.c b/drivers/block/zram/zram_drv.c index bec02f636bce..cf9d3474b80c 100644 --- a/drivers/block/zram/zram_drv.c +++ b/drivers/block/zram/zram_drv.c @@ -1180,6 +1180,45 @@ static ssize_t mm_stat_show(struct device *dev, return ret; } +static ssize_t pages_per_pool_page_show(struct device *dev, + struct device_attribute *attr, + char *buf) +{ + u32 val; + struct zram *zram = dev_to_zram(dev); + + down_read(&zram->init_lock); + val = zram->pages_per_pool_page; + up_read(&zram->init_lock); + + return scnprintf(buf, PAGE_SIZE, "%d\n", val); +} + +static ssize_t pages_per_pool_page_store(struct device *dev, + struct device_attribute *attr, + const char *buf, size_t len) +{ + struct zram *zram = dev_to_zram(dev); + u32 val; + + if (kstrtou32(buf, 10, &val)) + return -EINVAL; + + if (val < ZS_MIN_PAGES_PER_ZSPAGE || val > ZS_MAX_PAGES_PER_ZSPAGE) + return -EINVAL; + + down_read(&zram->init_lock); + if (init_done(zram)) { + up_read(&zram->init_lock); + return -EINVAL; + } + + zram->pages_per_pool_page = val; + up_read(&zram->init_lock); + + return len; +} + #ifdef CONFIG_ZRAM_WRITEBACK #define FOUR_K(x) ((x) * (1 << (PAGE_SHIFT - 12))) static ssize_t bd_stat_show(struct device *dev, @@ -1248,7 +1287,7 @@ static bool zram_meta_alloc(struct zram *zram, u64 disksize) return false; zram->mem_pool = zs_create_pool(zram->disk->disk_name, - ZS_DEFAULT_PAGES_PER_ZSPAGE); + zram->pages_per_pool_page); if (!zram->mem_pool) { vfree(zram->table); return false; @@ -2174,6 +2213,7 @@ static DEVICE_ATTR_RW(writeback_limit_enable); static DEVICE_ATTR_RW(recomp_algorithm); static DEVICE_ATTR_WO(recompress); #endif +static DEVICE_ATTR_RW(pages_per_pool_page); static struct attribute *zram_disk_attrs[] = { &dev_attr_disksize.attr, @@ -2201,6 +2241,7 @@ static struct attribute *zram_disk_attrs[] = { &dev_attr_recomp_algorithm.attr, &dev_attr_recompress.attr, #endif + &dev_attr_pages_per_pool_page.attr, NULL, }; @@ -2238,6 +2279,7 @@ static int zram_add(void) goto out_free_idr; } + zram->pages_per_pool_page = ZS_DEFAULT_PAGES_PER_ZSPAGE; zram->disk->major = zram_major; zram->disk->first_minor = device_id; zram->disk->minors = 1; diff --git a/drivers/block/zram/zram_drv.h b/drivers/block/zram/zram_drv.h index 9d6fcfdf7aa7..bdfc9bf0bdd5 100644 --- a/drivers/block/zram/zram_drv.h +++ b/drivers/block/zram/zram_drv.h @@ -120,6 +120,8 @@ struct zram { */ u64 disksize; /* bytes */ const char *comp_algs[ZRAM_MAX_ZCOMPS]; + + u32 pages_per_pool_page; /* * Pages that compress to sizes equal or greater than this are stored * uncompressed in memory. From patchwork Thu Oct 27 04:26:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13021579 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 0A635C38A2D for ; Thu, 27 Oct 2022 04:27:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A33E28E000B; Thu, 27 Oct 2022 00:27:17 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9BCDB8E0001; Thu, 27 Oct 2022 00:27:17 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 861038E000B; Thu, 27 Oct 2022 00:27:17 -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 71E5B8E0001 for ; Thu, 27 Oct 2022 00:27:17 -0400 (EDT) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 4A6E6141099 for ; Thu, 27 Oct 2022 04:27:17 +0000 (UTC) X-FDA: 80065444914.22.2D92653 Received: from mail-pg1-f176.google.com (mail-pg1-f176.google.com [209.85.215.176]) by imf17.hostedemail.com (Postfix) with ESMTP id E71D940003 for ; Thu, 27 Oct 2022 04:27:16 +0000 (UTC) Received: by mail-pg1-f176.google.com with SMTP id b5so138897pgb.6 for ; Wed, 26 Oct 2022 21:27:16 -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=FfJZOEZUcigJa5MAkTFt0GQw8t62BAN+ikSaaiyKqzg=; b=Ha3HWb3QEL2wAUei2E+xdtM/8MgiD5xkJ2+KGW7ASzNP1x7TN4j0HYIFu+8jGt+wPC RBWYYxFesKjH5fTCLTVjXR7Bh8OmrCWl/XzgyrX5MUGIKV8GVywLF9wAmH7NijSYHVGG QYr7eTqzjKYjJoyp0rodElpITNvzWxYDgPiMA= 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=FfJZOEZUcigJa5MAkTFt0GQw8t62BAN+ikSaaiyKqzg=; b=jifCOUxq4fX+dZNRheyifPtEG27e6EdRLSq5bEMqZBvn6sRzm0MicS/np92VpiY79G USkHRKxrqI6BN1hoKwWuO8vfY3D/n/GbcsFWLfymk/NotpANEZ1Aa2qSLrp9MR1FRbN0 R7xE5GIqdR13jmHixqydFsXN32anNtGOyQkAIWjiLwP2Qg6TQQDfnnD0n2I/Y/wLNOim Y19Jv8yYylVAUuqonHmYjJnPrRyXITPMNQVLrIrVZyLdRbpJALUW/I5glbtq21ojkU0i AyZgDJv3jf/n0ewi5KcXt0UeNJ9QG2leO9K0oGZfBHRX6d9jFJWInxAqx+kt7kaNTTnl xToA== X-Gm-Message-State: ACrzQf28T8IWX6ATLpMAAOlq/PumNZL+rdK/67DuETwtHcYqG8U/AMiY 1uYeIaERc86E0rb8o85/euw2PA== X-Google-Smtp-Source: AMsMyM7ThsUAVtRWF4QYvAYelWAHXIMYiM1JSDHU9HcoznhoEpkt3lbidbLFOWqSQq0TVrKr9qB6Kg== X-Received: by 2002:a05:6a00:150e:b0:56c:83b3:d148 with SMTP id q14-20020a056a00150e00b0056c83b3d148mr3568040pfu.48.1666844836111; Wed, 26 Oct 2022 21:27:16 -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.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 21:27:15 -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 8/9] Documentation: document zram pages_per_pool_page attribute Date: Thu, 27 Oct 2022 13:26:50 +0900 Message-Id: <20221027042651.234524-9-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=1666844837; a=rsa-sha256; cv=none; b=tXBaiB5YywJzJpAiiiScKB+QpNF9QdyYx6/BXiBJtjZrp66G0KdANgz4hXlo+0RaV3j5mo cXGlc936zwLukz1CitBsSPHT1nnDzdaKcXNEOON9ZExFKohXC3kz3PkjAYA7bnLjXZriI3 1O0WOPIlhvrI6uUsP14pEKOu7kHT70o= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Ha3HWb3Q; spf=pass (imf17.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.215.176 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=1666844837; 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=FfJZOEZUcigJa5MAkTFt0GQw8t62BAN+ikSaaiyKqzg=; b=EShjQ7rOJbkrHA1aCBBn+uTN8W+rK03wIz2+Ecs/ycdbPAs/ObimZU4rrBu0vWikCb70na QF3p6ui/Dxe5MHE1ZVp9QGUH9cSj7O8P0I4b4sMhxalwt9+fqYxcnAZy7jvmK7JKd9zywm psRapDxFZNzawq4fiMJ6RcpE2iHlr84= X-Rspamd-Queue-Id: E71D940003 X-Rspam-User: Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=Ha3HWb3Q; spf=pass (imf17.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.215.176 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org; dmarc=pass (policy=none) header.from=chromium.org X-Rspamd-Server: rspam04 X-Stat-Signature: 37huojcyt4ipjs9z34hmt9891ythydsu X-HE-Tag: 1666844836-759926 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: Provide a simple documentation for pages_per_pool_page ZRAM device attribute. Signed-off-by: Sergey Senozhatsky --- Documentation/admin-guide/blockdev/zram.rst | 38 ++++++++++++++++----- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/Documentation/admin-guide/blockdev/zram.rst b/Documentation/admin-guide/blockdev/zram.rst index 010fb05a5999..4cb287520d45 100644 --- a/Documentation/admin-guide/blockdev/zram.rst +++ b/Documentation/admin-guide/blockdev/zram.rst @@ -112,7 +112,29 @@ to list all of them using, for instance, /proc/crypto or any other method. This, however, has an advantage of permitting the usage of custom crypto compression modules (implementing S/W or H/W compression). -4) Set Disksize +4) Set pages per-pool page limit: Optional +========================================== + +zsmalloc pages can consist of up to ZS_DEFAULT_PAGES_PER_ZSPAGE (single) +physical pages. The exact number is calculated for each zsmalloc size +class during zsmalloc pool creation. ZRAM provides pages_per_pool_page +device attribute that lets one adjust that limit (maximum possible value +is ZS_MAX_PAGES_PER_ZSPAGE). The default limit is considered to be good +enough, so tweak this value only when the changes in zsmalloc size classes +characteristics are beneficial for your data patterns. The limit on the +pages per zspages (currently) should be in [1,16] range; default value +is 4. + +Examples:: + + #show current zsmalloc pages per-pool page limit + cat /sys/block/zramX/pages_per_pool_page + 4 + + #set zsmalloc pages per-pool page limit + echo 8 > /sys/block/zramX/pages_per_pool_page + +5) Set Disksize =============== Set disk size by writing the value to sysfs node 'disksize'. @@ -132,7 +154,7 @@ There is little point creating a zram of greater than twice the size of memory since we expect a 2:1 compression ratio. Note that zram uses about 0.1% of the size of the disk when not in use so a huge zram is wasteful. -5) Set memory limit: Optional +6) Set memory limit: Optional ============================= Set memory limit by writing the value to sysfs node 'mem_limit'. @@ -151,7 +173,7 @@ Examples:: # To disable memory limit echo 0 > /sys/block/zram0/mem_limit -6) Activate +7) Activate =========== :: @@ -162,7 +184,7 @@ Examples:: mkfs.ext4 /dev/zram1 mount /dev/zram1 /tmp -7) Add/remove zram devices +8) Add/remove zram devices ========================== zram provides a control interface, which enables dynamic (on-demand) device @@ -182,7 +204,7 @@ execute:: echo X > /sys/class/zram-control/hot_remove -8) Stats +9) Stats ======== Per-device statistics are exported as various nodes under /sys/block/zram/ @@ -283,15 +305,15 @@ a single line of text and contains the following stats separated by whitespace: Unit: 4K bytes ============== ============================================================= -9) Deactivate -============= +10) Deactivate +============== :: swapoff /dev/zram0 umount /dev/zram1 -10) Reset +11) Reset ========= Write any positive value to 'reset' sysfs node:: From patchwork Thu Oct 27 04:26:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13021580 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 7DF18C38A2D for ; Thu, 27 Oct 2022 04:27:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 132788E000C; Thu, 27 Oct 2022 00:27:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E3548E0001; Thu, 27 Oct 2022 00:27:20 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F147E8E000C; Thu, 27 Oct 2022 00:27:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id E257F8E0001 for ; Thu, 27 Oct 2022 00:27:19 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id C1098120CC4 for ; Thu, 27 Oct 2022 04:27:19 +0000 (UTC) X-FDA: 80065444998.04.82C923E Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf03.hostedemail.com (Postfix) with ESMTP id 6E90920008 for ; Thu, 27 Oct 2022 04:27:19 +0000 (UTC) Received: by mail-pl1-f169.google.com with SMTP id c2so207407plz.11 for ; Wed, 26 Oct 2022 21:27:19 -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=7FNBg/Bhf+QH0mnqszhtlK9l4+LQ4+hxFffFVTQHkLU=; b=VTCt4sWyUlHu3XwJaayi2bF65TY7ie/rwhOYEU+57lhIbz1GKvZDHXuccXF5EjAfuh 7FEovYIidq2NDbGQrRakQxt/e+Tutl18/H0f3yoDqHk33zKQwnxEA5P5ubClFTnmp49x vtWfyu4sNUmcuiCa3BE8lSE4BNmsluANiBs5g= 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=7FNBg/Bhf+QH0mnqszhtlK9l4+LQ4+hxFffFVTQHkLU=; b=IKu7cCpTcjGqabUFnJLgw61K3n5w1hblPbCpvo0Qkl1FfA68mf7//vTei7tWq5Gxj+ /U/qte6QYQ+59Ts7i3VqQJXhkNnvidgE/1Zbairln7aKLbx5AIgjVQ3E6oj0wG7wN/bG wvARKFrTch7aQhV8Gh06/z3Z54EMdZuCbthVTP1Q0abeqLJ3R5sgeIxxcB92gsb0IV0B H8aFccVPJLdJ3YLuJr6LTFnp44XTVQTO8Y21yyzT1SyHqWVuuoyM1uFFAL6p+rrAYV2J pA/HuVnuyQ4xBie+lEY6zWMeMum9ExrlUSEwmSFkeJqtD7Xedzibd1OmaK2JWcEfVF3g mDfQ== X-Gm-Message-State: ACrzQf0q59ylVKs3l/Fcl+k3Qh6XNCZ3+a7p11eQPCvozB9B3Xky4Y7z g5t2uwNxqfVWhgF24xMeHqeKAw== X-Google-Smtp-Source: AMsMyM6mLY1dGQXaB9/3tNuXFNI8esnOKI319xKEiHu48v+dy2FaSTPUqy9QaGZSM24wlt0gt5x2eA== X-Received: by 2002:a17:90a:1b44:b0:213:1035:f913 with SMTP id q62-20020a17090a1b4400b002131035f913mr7776402pjq.133.1666844838446; Wed, 26 Oct 2022 21:27:18 -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.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 21:27:18 -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 9/9] zsmalloc: break out of loop when found perfect zspage order Date: Thu, 27 Oct 2022 13:26:51 +0900 Message-Id: <20221027042651.234524-10-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-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666844839; 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=7FNBg/Bhf+QH0mnqszhtlK9l4+LQ4+hxFffFVTQHkLU=; b=qIdr+r48oBy7tQUQhvUYhqp1XVqU1HEW7AaRAWfIKXISbOguJv59jSNIQjGTm4U6rAoFli WUvz59EeqGEtLMnbik0hGgjD3ylTzaSVk6yODuZZ32TBOA3euD8sPCILAPLb6dqoW3apf6 dCVYS/IY7QO+E3PKrpekxXdpZxsr0QQ= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=VTCt4sWy; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf03.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.169 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666844839; a=rsa-sha256; cv=none; b=UMh7+HxAxyAlkHYXJ1Vw5De9gZ2zYpDNBUM1v0t6ZECS5LV6fNr4pLRj/efnG4ObS4UxV6 w7gS4z4eu5QvgxarIhlioNJ5YLyrjHiZyzNCl1wXfU7epGMM2daY53bhM7IC2ttgD6FoX9 Q4sHlTfldJgo27IrGi/GtMkoHF/KhTY= X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: 6E90920008 X-Rspam-User: Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=VTCt4sWy; dmarc=pass (policy=none) header.from=chromium.org; spf=pass (imf03.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.214.169 as permitted sender) smtp.mailfrom=senozhatsky@chromium.org X-Stat-Signature: 87szo1i55phir9sp7h1ieej5e6t8ncra X-HE-Tag: 1666844839-180612 X-Bogosity: Ham, tests=bogofilter, spamicity=0.001608, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: If we found zspage configuration that gives us perfect 100% used percentage (zero wasted space) then there is no point it trying any other configuration Signed-off-by: Sergey Senozhatsky --- mm/zsmalloc.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 7465a45495bf..0bc9ed1f1a5d 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -787,6 +787,9 @@ static int get_pages_per_zspage(u32 class_size, u32 max_pages_per_zspage) max_usedpc = usedpc; max_usedpc_order = i; } + + if (usedpc == 100) + break; } return max_usedpc_order;