From patchwork Wed Oct 26 20:06:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nhat Pham X-Patchwork-Id: 13021241 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 1208AC38A2D for ; Wed, 26 Oct 2022 20:06:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 015288E0006; Wed, 26 Oct 2022 16:06:20 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EE02C8E0001; Wed, 26 Oct 2022 16:06:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D319E8E0006; Wed, 26 Oct 2022 16:06:19 -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 BEFFC8E0001 for ; Wed, 26 Oct 2022 16:06:19 -0400 (EDT) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 92CF7C067F for ; Wed, 26 Oct 2022 20:06:19 +0000 (UTC) X-FDA: 80064182478.04.29B1513 Received: from mail-pj1-f51.google.com (mail-pj1-f51.google.com [209.85.216.51]) by imf11.hostedemail.com (Postfix) with ESMTP id 0A1AD4003A for ; Wed, 26 Oct 2022 20:06:18 +0000 (UTC) Received: by mail-pj1-f51.google.com with SMTP id m6-20020a17090a5a4600b00212f8dffec9so3257898pji.0 for ; Wed, 26 Oct 2022 13:06:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=vtNgGl1ujIcnJmyweLV5m7PzX6xgoQT5EqlkUSI6PN4=; b=Ak7cByKPgon/K+vDdR2mu/7sGLxErzFBRAs9CPl/Vts21w7AkP4S5jY0ZME5DdBENG CXkN2fTEH0rHR2UKBWxrMeBziN7WYtnWQCs1yDhMdkTf2P2F4oW0gbcPs2z1zSumYQGo IHMYEJZfsd6r1WI32+V2VvxUailYFWNanKeY6G40uKbzQStdjERrhsuyyWIbJtw7+Pz2 dlGR4WHcRAhuq2E+gh5FA7fB1Oa4T3YhkuU9BBmihLr6gtKeOHPFstO36u29uEdKCvCI ccn4mJ9sJ3YfcLwnXPJL0g7BoHme9xKx5zjKN/x0kRZo129LyklvxE0Gtv5GXcv4AiSs TMsg== 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=vtNgGl1ujIcnJmyweLV5m7PzX6xgoQT5EqlkUSI6PN4=; b=PmzTxqkKgujFiy+HrBc3DgIEZ0CElZDMqAIdTWgsCw4gddtbLwJJVtUO0pTflCPY/X 5GbuHaHsojGq+37ffg7Cobp5suFotAH1rQj7ohueXLSxWMqP1jewOsMNghaQkSaGRENV wizMaHguUMLpL6C0HeDBEKlnn7GPjFNsSlj0ifgDTPLp8CT3/RQ70rxgrIuZaefizzCd +KOwac9/IN7ZkHjfiv+AG/YiTzga2ZwAZUZW/unH013gzARw3RMwTX8wO2nLdOBrIQEp sUZ3KZkrUCDgzHE8wuljQeKA8M2nDQgrYzHtP8H8jd1yWzetv5O06v3pgq//x0UPm2V1 YlJA== X-Gm-Message-State: ACrzQf2h2DQ3m4pR5VhRHsrM+w9aPzGWMrvMTihWKUZqMKQloWr5TL1g 2ezSjRhY1NvXYCudyH/bUj4= X-Google-Smtp-Source: AMsMyM69dE2vohY2y2Qlpn6x5W7TgYhRydzzBEXDWYTfnYfcOfNhLM0TUS2OMp62BE0vJPDawoGQlA== X-Received: by 2002:a17:902:ab89:b0:186:7cfc:cde8 with SMTP id f9-20020a170902ab8900b001867cfccde8mr29379358plr.9.1666814778018; Wed, 26 Oct 2022 13:06:18 -0700 (PDT) Received: from localhost (fwdproxy-prn-019.fbsv.net. [2a03:2880:ff:13::face:b00c]) by smtp.gmail.com with ESMTPSA id y17-20020aa79e11000000b0056be4dbd4besm3363241pfq.111.2022.10.26.13.06.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Oct 2022 13:06:17 -0700 (PDT) From: Nhat Pham To: akpm@linux-foundation.org Cc: hannes@cmpxchg.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, minchan@kernel.org, ngupta@vflare.org, senozhatsky@chromium.org, sjenning@redhat.com, ddstreet@ieee.org, vitaly.wool@konsulko.com Subject: [PATCH 3/5] zsmalloc: Add a LRU to zs_pool to keep track of zspages in LRU order Date: Wed, 26 Oct 2022 13:06:11 -0700 Message-Id: <20221026200613.1031261-4-nphamcs@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20221026200613.1031261-1-nphamcs@gmail.com> References: <20221026200613.1031261-1-nphamcs@gmail.com> MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1666814779; a=rsa-sha256; cv=none; b=M9PSuScc+jO6bIScqSErPg9Vss1gbC8FS/N2LgCqjpuryflanKiLGAcpF+ddvmFGs0Q38t ccjlRtdbFn3IwJme43NCWXQxKG8UP3y8p5enUwZhs4/W4ZLhNRC13Fn9EOMPxMs0sMQ4fc YzxLBzYbH2fuSXrO/Yi/reeWcu+F1y0= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Ak7cByKP; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf11.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.216.51 as permitted sender) smtp.mailfrom=nphamcs@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1666814779; 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=vtNgGl1ujIcnJmyweLV5m7PzX6xgoQT5EqlkUSI6PN4=; b=PRMVIurRSbH7ygGv9JcENIt+ZrKwzghsdhcZaGSU8y6GCtN8qRTZHluCbd8a9rnDZuE0sf jA1GWWZNKlnTm2Ym4iUjiAQV+CHjHaV5NQysppQl0NBBHD4zJwHAV1JoEMybnCSEPMx5kd Y6a7XoQul0QPhbm4JGhBZaaFOMmwWxE= X-Rspam-User: Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=Ak7cByKP; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf11.hostedemail.com: domain of nphamcs@gmail.com designates 209.85.216.51 as permitted sender) smtp.mailfrom=nphamcs@gmail.com X-Rspamd-Server: rspam11 X-Stat-Signature: g1sqbgoyckyy4i3wegfs55dpttjegjsp X-Rspamd-Queue-Id: 0A1AD4003A X-HE-Tag: 1666814778-105126 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: This helps determines the coldest zspages as candidates for writeback. Signed-off-by: Nhat Pham Acked-by: Johannes Weiner --- mm/zsmalloc.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 326faa751f0a..600c40121544 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -239,6 +239,9 @@ struct zs_pool { /* Compact classes */ struct shrinker shrinker; + /* List tracking the zspages in LRU order by most recently added object */ + struct list_head lru; + #ifdef CONFIG_ZSMALLOC_STAT struct dentry *stat_dentry; #endif @@ -260,6 +263,10 @@ struct zspage { unsigned int freeobj; struct page *first_page; struct list_head list; /* fullness list */ + + /* links the zspage to the lru list in the pool */ + struct list_head lru; + struct zs_pool *pool; #ifdef CONFIG_COMPACTION rwlock_t lock; @@ -352,6 +359,16 @@ static void cache_free_zspage(struct zs_pool *pool, struct zspage *zspage) kmem_cache_free(pool->zspage_cachep, zspage); } +/* Moves the zspage to the front of the zspool's LRU */ +static void move_to_front(struct zs_pool *pool, struct zspage *zspage) +{ + assert_spin_locked(&pool->lock); + + if (!list_empty(&zspage->lru)) + list_del(&zspage->lru); + list_add(&zspage->lru, &pool->lru); +} + /* pool->lock(which owns the handle) synchronizes races */ static void record_obj(unsigned long handle, unsigned long obj) { @@ -953,6 +970,7 @@ static void free_zspage(struct zs_pool *pool, struct size_class *class, } remove_zspage(class, zspage, ZS_EMPTY); + list_del(&zspage->lru); __free_zspage(pool, class, zspage); } @@ -998,6 +1016,8 @@ static void init_zspage(struct size_class *class, struct zspage *zspage) off %= PAGE_SIZE; } + INIT_LIST_HEAD(&zspage->lru); + set_freeobj(zspage, 0); } @@ -1418,6 +1438,8 @@ unsigned long zs_malloc(struct zs_pool *pool, size_t size, gfp_t gfp) fix_fullness_group(class, zspage); record_obj(handle, obj); class_stat_inc(class, OBJ_USED, 1); + /* Move the zspage to front of pool's LRU */ + move_to_front(pool, zspage); spin_unlock(&pool->lock); return handle; @@ -1444,6 +1466,8 @@ unsigned long zs_malloc(struct zs_pool *pool, size_t size, gfp_t gfp) /* We completely set up zspage so mark them as movable */ SetZsPageMovable(pool, zspage); + /* Move the zspage to front of pool's LRU */ + move_to_front(pool, zspage); spin_unlock(&pool->lock); return handle; @@ -1967,6 +1991,7 @@ static void async_free_zspage(struct work_struct *work) VM_BUG_ON(fullness != ZS_EMPTY); class = pool->size_class[class_idx]; spin_lock(&pool->lock); + list_del(&zspage->lru); __free_zspage(pool, class, zspage); spin_unlock(&pool->lock); } @@ -2278,6 +2303,8 @@ struct zs_pool *zs_create_pool(const char *name) */ zs_register_shrinker(pool); + INIT_LIST_HEAD(&pool->lru); + return pool; err: