From patchwork Mon Oct 24 16:12:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sergey Senozhatsky X-Patchwork-Id: 9903 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp574206wru; Mon, 24 Oct 2022 10:40:06 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7Kd+JEBY+4bfsDt2K/lrKx3OZdP/QWha6Q7SVv7XccVlEkBZASoeO8WLAQV8vOy+wr2dxb X-Received: by 2002:a17:902:f789:b0:17f:8cb6:7da3 with SMTP id q9-20020a170902f78900b0017f8cb67da3mr34181452pln.167.1666633206670; Mon, 24 Oct 2022 10:40:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666633206; cv=none; d=google.com; s=arc-20160816; b=MaQzO06GJAHftqptb5bJ7rlcFemVSgwcylJwhINLeZ5AMAsLa8+WdWIDFEGMzpQVj7 OqBoXRUnEbMREuu5QVkXZ+0drCp+lu34VRGytX9C60t5cxI3Uya3wyLklyLtniMq+ypt yQjev66Dqf7u5rwtY11IsJwwABfVX6RzHwcHHIgeO4VpRLe3yYN8G8NOjsyp+4pyk7v7 UwiW4ylqkaRM64yjW48OIJ+sQBGcnsMLqZFmYtDMh2Ovey51M5zwpf3K2hpFFShhri0c /5yj0tmfYejIdje9VJL+1sZEl20S4HyoU/Kq0rovZBkk2hC1qPSQZv34bWDd6SXgKomM yKFw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=6K/W/tGQbEGTcjFYFF7obhZCetWTg/joFwdMrcbbg88=; b=qG5uUTtChB3YEWx7Hj7rlPNUQERX7TmJlr12iSspPciK2FKdvDQ9oJflmC9m1jZGO+ pI3Z5he2+5gE9zI7Wk1puayubEK9um2sUubb1T6KxXvvPr/qsyR0kVJ81bPOemDx0beo KJwIBZ9vZ5i/z8mCrITvpFJay/3TLwdCbBdS2qKGM3JUagpw0xZGcX9dY6HcqhLihz1A EcEdotZDjZtnyfTyVla1ukfSxXVRAS5ZT5sj/rEZfi2czeUMKdeSjNzOrHunt+1c2VJf NerIV6GDe7FmGdwWAkR/mQ0supYXSdfATPwHXiciA161gGR7fNKTAKWHj/MGlnXXn2Yi a4Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="h/ytl5e9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nu15-20020a17090b1b0f00b001f303395c8esi11092222pjb.141.2022.10.24.10.39.51; Mon, 24 Oct 2022 10:40:06 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b="h/ytl5e9"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231405AbiJXRje (ORCPT + 99 others); Mon, 24 Oct 2022 13:39:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233852AbiJXRi5 (ORCPT ); Mon, 24 Oct 2022 13:38:57 -0400 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9C8893341F for ; Mon, 24 Oct 2022 09:14:44 -0700 (PDT) Received: by mail-pg1-x529.google.com with SMTP id q1so9036358pgl.11 for ; Mon, 24 Oct 2022 09:14:44 -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=6K/W/tGQbEGTcjFYFF7obhZCetWTg/joFwdMrcbbg88=; b=h/ytl5e9/k/342yB1H8BeaL02HxFJn4GIfjrkkGet6ZLG4cPmCYS/DpaC6IXsHL+CF Dqi4snGmU88lbGI0yHxHTbbvOMuiht6icq3YEZzVWdCQhtsW7U7x/xCJt2ThlpE5kCpa Ai42HwHKaNshye+8lyPpeRjxySViQ+q8azKSc= 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=6K/W/tGQbEGTcjFYFF7obhZCetWTg/joFwdMrcbbg88=; b=Il9EaMoTwJSi+spYhN9sFPMGvPSEGGuAp/EmmwuCUAQPdcMO0qB8CCPQ/+AHEtKCFb M1DykAqNn+K3iICO/xbRqnLxu1ohN6im2Ftu3QGbA5x0GifybuKGGB/xuagFj0RdcSFg FnAzulVHwzi/49H9mPDM/dd3c8u5Rv09fPD/x/4Zk5Z3Jz0nVTGPE+n1JB4lAfZMmVHF rw9yI9m5BmVLfw2Kf4LRkk+qfaDFRm9VGfhkSBuzAVR+FCrG9AlXF6G877RP42CwS/a7 rzlQEMwWzSYYiK+BQG7p4RpRUSUJZtqt1e4zD4eqNHY3U+A1EMR/nS3wX5tFoPnl+o1b FB6g== X-Gm-Message-State: ACrzQf1PieDyh7a0bF+vn3cE24qzOaXmeVkT51KOWEuyT9d3D8tDrs49 rkkcOn4DjtnFy9uGsc2cLvrmwqNJ3BGxHQ== X-Received: by 2002:a05:6a00:1799:b0:56c:1495:70bc with SMTP id s25-20020a056a00179900b0056c149570bcmr119687pfg.12.1666627961483; Mon, 24 Oct 2022 09:12:41 -0700 (PDT) Received: from tigerii.tok.corp.google.com ([2401:fa00:8f:203:5f9c:c5bc:902f:3da4]) by smtp.gmail.com with ESMTPSA id u70-20020a627949000000b0056b8726d2d3sm5162pfc.157.2022.10.24.09.12.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Oct 2022 09:12:40 -0700 (PDT) From: Sergey Senozhatsky To: Andrew Morton , Minchan Kim Cc: Nitin Gupta , linux-kernel@vger.kernel.org, linux-mm@kvack.org, Sergey Senozhatsky Subject: [PATCH 6/6] zsmalloc: make sure we select best zspage size Date: Tue, 25 Oct 2022 01:12:13 +0900 Message-Id: <20221024161213.3221725-7-senozhatsky@chromium.org> X-Mailer: git-send-email 2.38.0.135.g90850a2211-goog In-Reply-To: <20221024161213.3221725-1-senozhatsky@chromium.org> References: <20221024161213.3221725-1-senozhatsky@chromium.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747591581023727055?= X-GMAIL-MSGID: =?utf-8?q?1747591581023727055?= We currently decide the best zspage size by looking at used percentage value. This is not exactly enough as zspage usage percentage calculation is not accurate. For example, let's look at size class 208 pages per zspage wasted bytes used% 1 144 96 2 80 99 3 16 99 4 160 99 We will select 2 page per zspage configuration, as it is the first one to reach 99%. However, 3 pages per zspage wastes less memory. Hence we need to also consider wasted space metrics when device zspage size. Additionally, rename max_usedpc_order because it does not hold zspage order, it holds maximum pages per-zspage value. Signed-off-by: Sergey Senozhatsky --- mm/zsmalloc.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 40a09b1f63b5..5de56f4cd16a 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -775,8 +775,9 @@ static enum fullness_group fix_fullness_group(struct size_class *class, static int get_pages_per_zspage(struct zs_pool *pool, int class_size) { int i, max_usedpc = 0; - /* zspage order which gives maximum used size per KB */ - int max_usedpc_order = 1; + /* zspage size which gives maximum used size per KB */ + int pages_per_zspage = 1; + int min_waste = INT_MAX; for (i = 1; i <= pool->max_pages_per_zspage; i++) { int zspage_size; @@ -788,14 +789,19 @@ static int get_pages_per_zspage(struct zs_pool *pool, int class_size) if (usedpc > max_usedpc) { max_usedpc = usedpc; - max_usedpc_order = i; + pages_per_zspage = i; } if (usedpc == 100) break; + + if (waste < min_waste) { + min_waste = waste; + pages_per_zspage = i; + } } - return max_usedpc_order; + return pages_per_zspage; } static struct zspage *get_zspage(struct page *page)