From patchwork Fri Apr 11 22:11:11 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Gregory Price X-Patchwork-Id: 14048812 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 399CEC369AF for ; Fri, 11 Apr 2025 22:11:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 4129E68002F; Fri, 11 Apr 2025 18:11:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3BFFE680024; Fri, 11 Apr 2025 18:11:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1EF0668002F; Fri, 11 Apr 2025 18:11:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id E337E680024 for ; Fri, 11 Apr 2025 18:11:40 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 0F05A1208F9 for ; Fri, 11 Apr 2025 22:11:41 +0000 (UTC) X-FDA: 83323160802.07.D5D5170 Received: from mail-qk1-f179.google.com (mail-qk1-f179.google.com [209.85.222.179]) by imf17.hostedemail.com (Postfix) with ESMTP id 3B88B4000B for ; Fri, 11 Apr 2025 22:11:39 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=AH1kP2YE; dmarc=none; spf=pass (imf17.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.179 as permitted sender) smtp.mailfrom=gourry@gourry.net ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1744409499; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=lWwZ2vfL+KhsRUswnAKZ8QRNf9jCtW28RDZA6bxWNqI=; b=A03IFBcT0Vm9IiIPUKkTgWKuhQcG1M4nTDX58g8BA2b0tqdRZIqyF4ghsYQzFCS/XtZB0z ysA3wzQ9NZqtIuNpt9VM7mTnt260OFI3srkBNxnOaR34AOQjACgo+teMmwKQ/ouN/+g5LK NwvKI4U0Rt+wI15Q73k2IiETCcsdnGk= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1744409499; a=rsa-sha256; cv=none; b=eKYsxSdKELvbu13c7BK8qX0I4Wpu1G8jrf118GzOcwZZYb8MiglwEFvpv2GzR6vwxT/ZXF /VefLggyJCZl4LBL7oQJIOUytpHiUgE6Z5RzblmSMaCprC6uwb2OsL1JPqzhgWxp7EQ9Uf efc7ELfEb8LnT8njfWJjkHSj9mFT2kg= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gourry.net header.s=google header.b=AH1kP2YE; dmarc=none; spf=pass (imf17.hostedemail.com: domain of gourry@gourry.net designates 209.85.222.179 as permitted sender) smtp.mailfrom=gourry@gourry.net Received: by mail-qk1-f179.google.com with SMTP id af79cd13be357-7be49f6b331so283319985a.1 for ; Fri, 11 Apr 2025 15:11:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gourry.net; s=google; t=1744409498; x=1745014298; darn=kvack.org; 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=lWwZ2vfL+KhsRUswnAKZ8QRNf9jCtW28RDZA6bxWNqI=; b=AH1kP2YE7+mpYghhnXL+y3BTBGSsi0bwom775fi0/H9yAyI7Wk2bdqFjp6zy/SHL03 u3QTIsh3ViGL5lmMMPldrkDmmvU8veFv1txPUEfdmbpmhMlnDONwDRvD8UQ7hxbBAozb glWUWAHX0jERd5N4PAZvF/TbiqCXoIZWPjPNlafy9+FHq/ryfHcQRB1gTshD+fhd4p6K Epxdfaj8pdj/5LF29YQYs8ijT9XxYvcoTnduszE0L5+ZQYHk1QAzWUesi48wQMBZS/Wd b1I6cB0OpLK/kcwzl1RAscDgdvusmnuPqUCItv5l51W5zW25HNKXdOMy1KJXgAbkb3MG HQLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744409498; x=1745014298; 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=lWwZ2vfL+KhsRUswnAKZ8QRNf9jCtW28RDZA6bxWNqI=; b=r6Rux1wjuBW3ZhfGdiMQ8zuTbSHwuYybCVKwYuItRBlnFpk76hPP6i01y1S6AM3bmE kclYojHrmUJnQxHwTML8ML3x84bmlEaN06lb+h72F4rn6dVnb64RO+r6NCSbBAxp6LoN LCcXq90wc5TI8qZg2xUtOgAkspNJBdxhcOnFy8+XbOUvxLnFBTzynl4NCRSroM7rpzbt HH1POP1Qq+hNQCh6iBOQkuDtNSHXDOwI3q4LHW0VVOT5wHYN03QPCyj7w8TsDxzxFYTg gP80/j+8ZJ3zd+b4mGpeMet4/Vwp9UlcXmzUG+QPJxU9VClx6l+lyv9hZotHi3Qw3gey IuwQ== X-Gm-Message-State: AOJu0Yys0r6RhtIOaJ3LaJB9dfuKHBwz+x/9RkexSba0VTIwABwJCnDF H2pOEYYLraHmoLxe3QWbjU0fZDyJO3zNRle1JJuoLh7klPhkczFkgPikZWyMU5antKfsHZ4eFS4 U X-Gm-Gg: ASbGncu1u5QKmGzPhIQOgJUHUa/5U5rDX0E+STs/bRUzNbrWNnWP2jFugYM561BbaB9 ZxzVhYVnum3wsXvz4P6m1/rI8Ez2ZyDUq8spqk7x5PXIh2UZW1gLDjwSM+RUC2N5HOD3HYzp5k8 HTkU/fllMi9+J2lXxGMA4F/Ixfiblz09wh6XEED1Jn3jUyEIRK+x4e3BevDh64AxjtOze68YLvF BO+3/A6c2hIzz0T9+zVNEMCLTCfNLvj0MQWQdyRdUoAdyCm3M0qjj7nhCVPNshRVrc7GvF0k06u LxEgXcN57JtWJwmyRNozLw8iQtdTnoE4mxtWwFx6H/YtCbiUU90JtqO4jRLmHl5PrvVunfy7OXz Vx6rQpuJCgo846zwTc3P7yLkgGnyF X-Google-Smtp-Source: AGHT+IGLtJZR0JJVKRILz/ZiqYmeVboSBH4PK1DJ0UoO9oX8aCb9uz98PkTHNKxCb1p4ZJETUczmng== X-Received: by 2002:a05:620a:3913:b0:7c7:a602:66ee with SMTP id af79cd13be357-7c7af0bd2fbmr513370685a.10.1744409497970; Fri, 11 Apr 2025 15:11:37 -0700 (PDT) Received: from gourry-fedora-PF4VCD3F.lan (pool-173-79-56-208.washdc.fios.verizon.net. [173.79.56.208]) by smtp.gmail.com with ESMTPSA id af79cd13be357-7c7a8943afcsm321264485a.16.2025.04.11.15.11.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Apr 2025 15:11:37 -0700 (PDT) From: Gregory Price To: linux-mm@kvack.org Cc: cgroups@vger.kernel.org, linux-kernel@vger.kernel.org, kernel-team@meta.com, akpm@linux-foundation.org, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, hannes@cmpxchg.org, mhocko@kernel.org, roman.gushchin@linux.dev, shakeel.butt@linux.dev, donettom@linux.ibm.com Subject: [RFC PATCH v4 6/6] mm/swap.c: Enable promotion of unmapped MGLRU page cache pages Date: Fri, 11 Apr 2025 18:11:11 -0400 Message-ID: <20250411221111.493193-7-gourry@gourry.net> X-Mailer: git-send-email 2.49.0 In-Reply-To: <20250411221111.493193-1-gourry@gourry.net> References: <20250411221111.493193-1-gourry@gourry.net> MIME-Version: 1.0 X-Rspamd-Server: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OVh/e9cvvYdh0c Mp4NHr9V D2VCDLJVppMsKiZCUNo5u/PPOuA2/pOPbaug3kr0ncRj89AQY5iGrF1bZwGp3sgfbuR3Pd1JOjHIz7CACj4Wu5bBynVrebWYcLOPUk+xA0PsGJxWv5VBjhCICRyFS4OTnu67CuqsEWzgh3IYEQoCgG7jgy/tDCDBt2qqMJc1+t4tHMRKAsH7LaOyfniHOAMNd5JQ8fZloIWbX9Vi/PfiuZZRMWtLmMz1qubL/zhG1sz8F1Ux6xdvZC1WboA5mTnd4yBczzHtcpww33eS5d+30lD1kqeaMTjO5CFm3VSSqebPXM115OWvqRmTtKA== 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: List-Subscribe: List-Unsubscribe: From: Donet Tom Extend MGLRU to support promotion of page cache pages. An MGLRU page cache page is eligible for promotion when: 1. Memory Tiering and pagecache_promotion_enabled are enabled 2. It resides in a lower memory tier. 3. It is referenced. 4. It is part of the working set. 5. folio reference count is maximun (LRU_REFS_MASK). When a page is accessed through a file descriptor, folio_inc_refs() is invoked. The first access will set the folio’s referenced flag, and subsequent accesses will increment the reference count in the folio flag (reference counter size in folio flags is 2 bits). Once the referenced flag is set, and the folio’s reference count reaches the maximum value (LRU_REFS_MASK), the working set flag will be set as well. If a folio has both the referenced and working set flags set, and its reference count equals LRU_REFS_MASK, it becomes a good candidate for promotion. These pages will be added to the promotion list. The per-process task task_numa_promotion_work() takes the pages from the promotion list and promotes them to a higher memory tier. In the MGLRU, for folios accessed through a file descriptor, if the folio’s referenced and working set flags are set, and the folio's reference count is equal to LRU_REFS_MASK, the folio is lazily promoted to the second oldest generation in the eviction path. When folio_inc_gen() does this, it clears the LRU_REFS_FLAGS so that lru_gen_inc_refs() can start over. Test process: We measured the read time in below scenarios for both LRU and MGLRU. Scenario 1: Pages are on Lower tier + promotion off Scenario 2: Pages are on Lower tier + promotion on Scenario 3: Pages are on higher tier Test Results MGLRU ---------------------------------------------------------------- Pages on higher | Pages Lower tier | Pages on Lower Tier | Tier | promotion off | Promotion On | ---------------------------------------------------------------- 0.48s | 1.6s |During Promotion - 3.3s | | |After Promotion - 0.48s | | | | ---------------------------------------------------------------- Test Results LRU ---------------------------------------------------------------- Pages on higher | Pages Lower tier | Pages on Lower Tier | Tier | promotion off | Promotion On | ---------------------------------------------------------------- 0.48s | 1.6s |During Promotion - 3.3s | | |After Promotion - 0.48s | | | | ---------------------------------------------------------------- MGLRU and LRU are showing similar performance benefit. Signed-off-by: Donet Tom --- mm/swap.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/mm/swap.c b/mm/swap.c index 382828fde505..3af2377515ad 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -399,8 +399,13 @@ static void lru_gen_inc_refs(struct folio *folio) do { if ((old_flags & LRU_REFS_MASK) == LRU_REFS_MASK) { - if (!folio_test_workingset(folio)) + if (!folio_test_workingset(folio)) { folio_set_workingset(folio); + } else if (!folio_test_isolated(folio) && + (sysctl_numa_balancing_mode & NUMA_BALANCING_MEMORY_TIERING) && + numa_pagecache_promotion_enabled) { + promotion_candidate(folio); + } return; }