From patchwork Sat Mar 25 02:46:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 13187520 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 2E023C761AF for ; Sat, 25 Mar 2023 02:46:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7F0D16B0074; Fri, 24 Mar 2023 22:46:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7A0566B0075; Fri, 24 Mar 2023 22:46:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 667FD6B0078; Fri, 24 Mar 2023 22:46:45 -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 591E26B0074 for ; Fri, 24 Mar 2023 22:46:45 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 04AE7140A7D for ; Sat, 25 Mar 2023 02:46:44 +0000 (UTC) X-FDA: 80605882770.08.1868A57 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) by imf30.hostedemail.com (Postfix) with ESMTP id 2F3C68000A for ; Sat, 25 Mar 2023 02:46:42 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=A8FdMTE0; spf=pass (imf30.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.50 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=1679712403; 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=V+zNaeNa8KtipVHVqtQfpLkM1H8wS2BsGCSalhkfXh8=; b=Yh0HL77TWiDFp/pVvixWOsc7mLIU2Jc04cPyodDxcIroChRj/UbZ2PkbBGkCy5vwcuuz71 C/tyn29pTAPbfgQOQI6/oUZD1CaDluAKsaviA4MgBQ0UmGJ0EvT3HHF+Y19PEPXhPTp1hD Fo7HWk5YO7GS5epCtksPslvIw8dAOvM= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=A8FdMTE0; spf=pass (imf30.hostedemail.com: domain of senozhatsky@chromium.org designates 209.85.216.50 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=1679712403; a=rsa-sha256; cv=none; b=k+6lDqhnVgvOnEfWDFFMsSnQKf7tBD+8nomcyV0VEG1aiLpjV2xCrhIK0xQAbVEJCyps97 nb2oQWX4kbTkPGDjkWgaS9Eu3QS2LLbTWPgkpGSjUxp7nGy8m3ghoTvxW3tB625tzzFZyS 9FnzS59Y9RpkJaE8pCiYWXTnLtwhebo= Received: by mail-pj1-f50.google.com with SMTP id om3-20020a17090b3a8300b0023efab0e3bfso6785041pjb.3 for ; Fri, 24 Mar 2023 19:46:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1679712402; 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=V+zNaeNa8KtipVHVqtQfpLkM1H8wS2BsGCSalhkfXh8=; b=A8FdMTE07F5SnwsmbzYWFDR7oYEBL7TZazUB5qLiXZ8BDlxW/vO5b9+Wj61sPlHCli yNRJRvZI3cH0EjjT9Fy1yl7oacLQC5SF1qjR+XHCzwiVXmntQFoZIcGeWhi7RdMaxDlI p62XvxpHzPhdzprKSTp2Tp/btyRwfxHjXhXYo= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679712402; 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=V+zNaeNa8KtipVHVqtQfpLkM1H8wS2BsGCSalhkfXh8=; b=luvmmjO9uAJfeg6Uqwn2onKwdxsfrq2XsqgTfm6+nfnI+UKMYw3Ly7AxTdb3SSyV6s LoqCnEm0IEbRFT5A8Z2z/c3/ldWlaAx1uwdGYGw/ySVcy+MZLDWXY2Ge2pjMfGLdYzeN /a8fYJU4+oKQuP3M7d4hLS9PgVfQ7OYb8hC3KgCvqdjaepdlZJ93mCBZUZPmNT4lzSql vOW69ASbz+7FXlJ63/rNlrpICpaPNF+H5yyPHKJSkz7QBbu+uqfsN2XWarsTQdi5iq05 PUM5kHieoV+g7fsVkEVQTwSxfLR0q4ca0oU8rjUW32669bJCZRGtrzqgLNwRbI4LXiJr 4r6Q== X-Gm-Message-State: AAQBX9eHhK60Trtw5U2FHSLMn/qCJwmf6OVplxtgtCDmD4g8XOenwgig YXu4nVsA5UBnP6bllyCxMLxtsg== X-Google-Smtp-Source: AKy350ZGxSZcXhGHIsJudw4E5aRTrARQF3WaLn/VwVERC6WqgkH08UieO+iF/njX/UCfvqt8O2i3ng== X-Received: by 2002:a17:90b:1647:b0:236:73d5:82cf with SMTP id il7-20020a17090b164700b0023673d582cfmr5198035pjb.9.1679712401876; Fri, 24 Mar 2023 19:46:41 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:6179:9cb5:be4d:f76b]) by smtp.gmail.com with ESMTPSA id hv19-20020a17090ae41300b0023b4d33bedbsm3675840pjb.21.2023.03.24.19.46.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Mar 2023 19:46:41 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCH 1/2] zsmalloc: document new fullness grouping Date: Sat, 25 Mar 2023 11:46:30 +0900 Message-Id: <20230325024631.2817153-2-senozhatsky@chromium.org> X-Mailer: git-send-email 2.40.0.348.gf938b09366-goog In-Reply-To: <20230325024631.2817153-1-senozhatsky@chromium.org> References: <20230325024631.2817153-1-senozhatsky@chromium.org> MIME-Version: 1.0 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 2F3C68000A X-Rspam-User: X-Stat-Signature: 9g68x3o7ej55ok1j36mdfpf8jjkbb3i4 X-HE-Tag: 1679712402-425733 X-HE-Meta: U2FsdGVkX19KPcB6F89nvZTlnlaICfsMTcDeTLALpTLH4pbWxDGCRSQruQSoU3qLCsEUVoa1U7BYc4joKnSKQwTvstqNcEhn5xwxK9Bktxoesvsgq93wuQRaJ2xuMyIqTUBoop9oHQahKHcRsbUjN8rky8x1DUNSqpMIdemlU3EpeN/L2loNvwmVB6DAOgq7VPt1UjmczxaXxbMI4dXK3neVZLSA5rPQo2A6nd2fbAP908GsLO/ybMPb2vjn9kPMdn32gJpUhRgso+ulLcipjHDVAg+gIAwti2R5aUB+7bxz5uHPo5yQmelkbMyXKI5zdbjFBOl7YLIo/jCG/ck6LptGKrZ4qjjislBmXhyyj1xDXMCNvJgiGwKbl0eDf1yg2RxHsCweFAR1KC5AARIG0Zdv//TD4Bup1qIjyMSc2qSOPE1ILxDgh8LbUr9KsfB7/ZpCBWz7RP4f4LI9uLdXs+eu664+Cp0ebIboap+pIV2dj9QWa+7rQD3FxDnYgJ1onJOGfxOQI4dOB59innw1+Mp4fN4s699ftgY8t1lziNjD9dFkaO4R3mQbsSKm19N2KxqZoNI4HU8NH5A9tUN3Pkt9v8NmT/7t01aJ4hBQQ/S1p5PB8qP7fbS6gLyZS7orTWWLnKT2ro4sLJcR7wRZAr0foja3AGUh7UAntx27n3CYd//KWWRtXvAME/+yaU8+3R/Ob3n/KmVA8eMIUJOftMSl9RHKhW1BJPJ/v3U8ZUqGfT+PQAMy+u8UnrvdGeKDOee14CS8uT5UA4x0JW+nshgNldkfeKJ/Zd75nmGfMNlhlECYP/vihz8w6DsdeBzv2K5KpSGImCNFEynxhndR/Di7sLFwoZdbCNBCd1nkDJcRj01DrVjuJvNmSYDN38IRTCwq1uqqhAjnP1tRU7HHrkj82CVPhdKfOKIo+1kwVAB9J6hzEHiTEJhwMqIeVhRK79f/23TIXuvju8hs71a 0R+x1aor ciN3CPX178B0eJLtNg/Y82yqSnPlDO0d7djVZn1nS6tPKw6gd2v6JCvCAQ+NoGDYEEnslUNnrIU0uxXanCKFK1vwJMMw1xcrOwlJ5GRibUalQBHXwf1SVLHZ6b268E3MiwWub5sCToHj4vYE7cFcOnsYQBI4rAjHGI/TsrmTmZwfo+ln4AxTdrbiWzzi3M+VqfKdbqGzGWAioSRSXQeGPUJFKTSTvLRXkyIQWCMRGgDkdZc7KWEmeKlfl+rzUvclIt+2qIYZ/8tkjQIWlaxGQjPZbucCaNy8ayUp1YuKLjhM9d2SkgKflj/0qJeCyClbq1jzipqJf9jDEg7BRXlgSBK9Nk9DY+67bad+9hEE995wj8sVVfNE0Liw2f6u4k76arbi5GhFmkdWz6oJ+puCyYH4JysApMfmnCFcUojuqOo+vij8= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000583, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Update documentation and reflect new zspages fullness grouping (we don't use almost_empty and almost_full anymore). Signed-off-by: Sergey Senozhatsky --- Documentation/mm/zsmalloc.rst | 133 +++++++++++++++++++--------------- 1 file changed, 74 insertions(+), 59 deletions(-) diff --git a/Documentation/mm/zsmalloc.rst b/Documentation/mm/zsmalloc.rst index 64d127bfc221..3c6bf639887f 100644 --- a/Documentation/mm/zsmalloc.rst +++ b/Documentation/mm/zsmalloc.rst @@ -39,13 +39,12 @@ With CONFIG_ZSMALLOC_STAT, we could see zsmalloc internal information via # cat /sys/kernel/debug/zsmalloc/zram0/classes - class size almost_full almost_empty obj_allocated obj_used pages_used pages_per_zspage + class size 10% 20% 30% 40% 50% 60% 70% 80% 90% 99% 100% obj_allocated obj_used pages_used pages_per_zspage freeable ... ... - 9 176 0 1 186 129 8 4 - 10 192 1 0 2880 2872 135 3 - 11 208 0 1 819 795 42 2 - 12 224 0 1 219 159 12 4 + 30 512 0 12 4 1 0 1 0 0 1 0 414 3464 3346 433 1 14 + 31 528 2 7 2 2 1 0 1 0 0 2 117 4154 3793 536 4 44 + 32 544 6 3 4 1 2 1 0 0 0 1 260 4170 3965 556 2 26 ... ... @@ -54,10 +53,28 @@ class index size object size zspage stores -almost_empty - the number of ZS_ALMOST_EMPTY zspages(see below) -almost_full - the number of ZS_ALMOST_FULL zspages(see below) +10% + the number of zspages with usage ratio less than 10% (see below) +20% + the number of zspages with usage ratio between 10% and 20% +30% + the number of zspages with usage ratio between 20% and 30% +40% + the number of zspages with usage ratio between 30% and 40% +50% + the number of zspages with usage ratio between 40% and 50% +60% + the number of zspages with usage ratio between 50% and 60% +70% + the number of zspages with usage ratio between 60% and 70% +80% + the number of zspages with usage ratio between 70% and 80% +90% + the number of zspages with usage ratio between 80% and 90% +99% + the number of zspages with usage ratio between 90% and 99% +100% + the number of zspages with usage ratio 100% obj_allocated the number of objects allocated obj_used @@ -67,18 +84,11 @@ pages_used pages_per_zspage the number of 0-order pages to make a zspage -We assign a zspage to ZS_ALMOST_EMPTY fullness group when n <= N / f, where - -* n = number of allocated objects -* N = total number of objects zspage can store -* f = fullness_threshold_frac(ie, 4 at the moment) - -Similarly, we assign zspage to: - -* ZS_ALMOST_FULL when n > N / f -* ZS_EMPTY when n == 0 -* ZS_FULL when n == N - +Each zspage maintains inuse counter which keeps track of the number of +objects stored in the zspage. The inuse counter determines the zspage's +"fullness group" which is calculated as the ratio of the "inuse" objects to +the total number of objects the zspage can hold (objs_per_zspage). The +closer the inuse counter is to objs_per_zspage, the better. Internals ========= @@ -94,10 +104,10 @@ of objects that each zspage can store. For instance, consider the following size classes::: - class size almost_full almost_empty obj_allocated obj_used pages_used pages_per_zspage freeable + class size 10% .... 100% 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 + 94 1536 0 .... 0 0 0 0 3 0 + 100 1632 0 .... 0 0 0 0 2 0 ... @@ -134,10 +144,11 @@ reduces memory wastage. Let's take a closer look at the bottom of `/sys/kernel/debug/zsmalloc/zramX/classes`::: - class size almost_full almost_empty obj_allocated obj_used pages_used pages_per_zspage freeable + class size 10% .... 100% 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 + 202 3264 0 .. 0 0 0 0 4 0 + 254 4096 0 .. 0 0 0 0 1 0 ... Size class #202 stores objects of size 3264 bytes and has a maximum of 4 pages @@ -151,40 +162,42 @@ efficient storage of large objects. For zspage chain size of 8, huge class watermark becomes 3632 bytes::: - class size almost_full almost_empty obj_allocated obj_used pages_used pages_per_zspage freeable + class size 10% .... 100% 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 + 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 zspage chain size of 16, huge class watermark becomes 3840 bytes::: - class size almost_full almost_empty obj_allocated obj_used pages_used pages_per_zspage freeable + class size 10% .... 100% 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 + 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 ... Overall the combined zspage chain size effect on zsmalloc pool configuration::: @@ -214,9 +227,10 @@ zram as a build artifacts storage (Linux kernel compilation). zsmalloc classes stats::: - class size almost_full almost_empty obj_allocated obj_used pages_used pages_per_zspage freeable + class size 10% .... 100% obj_allocated obj_used pages_used pages_per_zspage freeable + ... - Total 13 51 413836 412973 159955 3 + Total 13 .. 51 413836 412973 159955 3 zram mm_stat::: @@ -227,9 +241,10 @@ zram as a build artifacts storage (Linux kernel compilation). zsmalloc classes stats::: - class size almost_full almost_empty obj_allocated obj_used pages_used pages_per_zspage freeable + class size 10% .... 100% obj_allocated obj_used pages_used pages_per_zspage freeable + ... - Total 18 87 414852 412978 156666 0 + Total 18 .. 87 414852 412978 156666 0 zram mm_stat:::