From patchwork Mon Oct 16 20:05:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 13424036 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 0C3B4CDB482 for ; Mon, 16 Oct 2023 20:07:00 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 750B58D00BF; Mon, 16 Oct 2023 16:07:00 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7003B8D00BA; Mon, 16 Oct 2023 16:07:00 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 553B98D00BF; Mon, 16 Oct 2023 16:07:00 -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 32CC08D00BA for ; Mon, 16 Oct 2023 16:07:00 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id EE392B5C05 for ; Mon, 16 Oct 2023 20:06:59 +0000 (UTC) X-FDA: 81352408158.10.E3000FC Received: from mail-pf1-f181.google.com (mail-pf1-f181.google.com [209.85.210.181]) by imf17.hostedemail.com (Postfix) with ESMTP id C9CA540016 for ; Mon, 16 Oct 2023 20:06:57 +0000 (UTC) Authentication-Results: imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=RGF0AruC; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.210.181 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697486817; 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=dowlsYISY/BEh4ltWtb6fy0PpeiHEk3DajdxWZY/uS8=; b=p2XuNhyrLvGAmdagKgH6R3QdQBHgdkbCjW912ZjtwvQZYVTEFwZnKOYGXWTiU2SYXM/846 zK8iPRvrmHaG9J2ykyEORyjFLAEPP9Mny8G0g/hnec7Lsb9dte8Z++M/+spfZSSbUMgLPH TzOJl5lVSNwWj82lt2UOgdW1sZ9lqMQ= ARC-Authentication-Results: i=1; imf17.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=RGF0AruC; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf17.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.210.181 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697486817; a=rsa-sha256; cv=none; b=iUaATz55kk7MCvjY0KhLMnbFKL1U0E1crdQOeHZyflQ133OSUZXsfk7xf1E9fyoTnyU4/P eCwhntyqg/HuUqLsK0X12Lu9PZiTO6659AF08McSI911VRacvFpSHni252VIwZKO/QlHcD J1Yx2/qv52WE9p/L0rDskrIIlRKQQ4s= Received: by mail-pf1-f181.google.com with SMTP id d2e1a72fcca58-6b6f4c118b7so2242064b3a.0 for ; Mon, 16 Oct 2023 13:06:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697486816; x=1698091616; 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=dowlsYISY/BEh4ltWtb6fy0PpeiHEk3DajdxWZY/uS8=; b=RGF0AruCsUwxk+vbZ+noUHndq5WuiHgWiP+tn2bVDgcMVu9lz3rAjNWc0H1PxQtiB6 MkCqdCSqHoqURqNEEy6XgQw4yzA4E34EW+cO2Tne9KB6zaUg9YCsE/LpDnJ9M1hdxZrF 3cQ89H3CT5W8r1+MmuteSPLOJ9fHD7NXEzzLdOsnMo/f3CrHPYoZXZK8OLKVZ+c0B5ZG xpd7f880J5ieRvh1S+bL+yWyoE84InTytPX5JO5gAX1HuunXl6U56ZvJ0Rx33BTwBKzM 0RqAp3pAK9kwRtaYVKORw2Tjrul9UfLpjAf3l8Dm2lmwFl4wIP/KsM7FN7+EtgogdAyc mZNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697486816; x=1698091616; 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=dowlsYISY/BEh4ltWtb6fy0PpeiHEk3DajdxWZY/uS8=; b=kXX219u2w5t4QGIDILAJp8umyP9IBKMHCZmoNLO72s7cBRzvmgr2SvbSGcPAYgGEaj um1aP/macWxztWKdtEgqutw+NhB5Px1j2bDFElKkwAF0Xgq6ADj4ObKOfPVnLQzL4olY RALbAYo4qJVeWTBcquhg2amRHXWlk5ED+dRwI87F2dfOujwH1qJRkqYQCtbZH+hjnMhx aArmlnNQ7lfLzBPnjBCSIXgtPEQPpXoC4sYr+cVtqVMLy5Fp+lEKFRNEaWSsoLgBwODt xhlCA4v7dCvU63c1O4vb9WmhkXYulELhucieEjYVdWn580OKxGWiI5EKwVyZLOypLF1g RyHQ== X-Gm-Message-State: AOJu0YwhqOb/qaBieG+4FJ8f3j/0DfftEtM1Y5xdIOgaR4Sr9MzmUYbg Jmg2ohWOOd17nRSGIB4UhtcE6AeT0Xs= X-Google-Smtp-Source: AGHT+IHNAbR5P9OXapRD4T0zOXCwzPhLQ3rt7wyj9Cgg9D9ndiZau71+lTiikiZfhKBGtwidV+lYHQ== X-Received: by 2002:a05:6300:8003:b0:12c:b10d:693d with SMTP id an3-20020a056300800300b0012cb10d693dmr97230pzc.6.1697486816530; Mon, 16 Oct 2023 13:06:56 -0700 (PDT) Received: from fedora.. (c-73-170-51-167.hsd1.ca.comcast.net. [73.170.51.167]) by smtp.googlemail.com with ESMTPSA id t16-20020a17090b019000b002772faee740sm5162367pjs.5.2023.10.16.13.06.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 13:06:56 -0700 (PDT) From: "Vishal Moola (Oracle)" To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, shy828301@gmail.com, "Vishal Moola (Oracle)" , Matthew Wilcox Subject: [PATCH 1/5] mm/khugepaged: Convert __collapse_huge_page_isolate() to use folios Date: Mon, 16 Oct 2023 13:05:06 -0700 Message-Id: <20231016200510.7387-2-vishal.moola@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231016200510.7387-1-vishal.moola@gmail.com> References: <20231016200510.7387-1-vishal.moola@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam09 X-Rspamd-Queue-Id: C9CA540016 X-Stat-Signature: 3wkyc6wb5axryszfuibjfbqgf7zjpdbp X-Rspam-User: X-HE-Tag: 1697486817-502444 X-HE-Meta: U2FsdGVkX1/H89/dlgYazQUjtCTDJ8tPiZFZtOWj0fKUYQULhx6rEulvYKNVIfZYLPxtv7s7DhWjl/cLf88S4tqB5eTd2QdW1cH2l1pS7GoJkA/HCpOdLTPqMcnwB3dJrqMPWDo0U/V0IMm7qoDQhvmliQbm6k9uSHQ/A+ucxtlhOrdbeDuue8Li02Cp1ZB3sc3HL/2QNmL8f7nvc5/gdvqmEOMUZKo0O8u4kd9K6xdHiv/pQp9Rrdv9uYdmDPzvNVEOusoH+o84ZAD9jB9hXn+jijoyUUT9Kg+QJ3s0CtGAEznMzLlXzfHzH07G0d2MLiT/dpPMZwH3P4vsuVIagBksmRjGl57AQ7Hbbf7DtGT4kfgmifGjidVhGhPop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6cuTxIjYtY5Jx1xvGlrzvAs0DbrJhXYfLyUl0nT56fPHSNT7aviKd0dsUF4k2nBH0y8OBBu06VhXEyckZJxwmlgHLlLidsXsZBI+OqGEOXRcrpPOrzeHggXQo74vcJkNipajNdUI8zEZq+A90k3A0QA2+eLMW7W2Bzdqokgdcg7pedFLTu4x0SlQy0ssqI5g== 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: Replaces 11 calls to compound_head() with 1, and removes 1375 bytes of kernel text. Previously, to determine if any pte was shared, the page mapcount corresponding exactly to the pte was checked. This gave us a precise number of shared ptes. Using folio_estimated_sharers() instead uses the mapcount of the head page, giving us an estimate for tail page ptes. This means if a tail page's mapcount is greater than its head page's mapcount, folio_estimated_sharers() would be underestimating the number of shared ptes, and vice versa. Signed-off-by: Vishal Moola (Oracle) Reviewed-by: Matthew Wilcox (Oracle) --- mm/khugepaged.c | 51 ++++++++++++++++++++++++------------------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 88433cc25d8a..7a552fe16c92 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -541,7 +541,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, struct collapse_control *cc, struct list_head *compound_pagelist) { - struct page *page = NULL; + struct folio *folio = NULL; pte_t *_pte; int none_or_zero = 0, shared = 0, result = SCAN_FAIL, referenced = 0; bool writable = false; @@ -570,15 +570,15 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, result = SCAN_PTE_UFFD_WP; goto out; } - page = vm_normal_page(vma, address, pteval); - if (unlikely(!page) || unlikely(is_zone_device_page(page))) { + folio = vm_normal_folio(vma, address, pteval); + if (unlikely(!folio) || unlikely(folio_is_zone_device(folio))) { result = SCAN_PAGE_NULL; goto out; } - VM_BUG_ON_PAGE(!PageAnon(page), page); + VM_BUG_ON_FOLIO(!folio_test_anon(folio), folio); - if (page_mapcount(page) > 1) { + if (folio_estimated_sharers(folio) > 1) { ++shared; if (cc->is_khugepaged && shared > khugepaged_max_ptes_shared) { @@ -588,16 +588,15 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, } } - if (PageCompound(page)) { - struct page *p; - page = compound_head(page); + if (folio_test_large(folio)) { + struct folio *f; /* * Check if we have dealt with the compound page * already */ - list_for_each_entry(p, compound_pagelist, lru) { - if (page == p) + list_for_each_entry(f, compound_pagelist, lru) { + if (folio == f) goto next; } } @@ -608,7 +607,7 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, * is needed to serialize against split_huge_page * when invoked from the VM. */ - if (!trylock_page(page)) { + if (!folio_trylock(folio)) { result = SCAN_PAGE_LOCK; goto out; } @@ -624,8 +623,8 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, * but not from this process. The other process cannot write to * the page, only trigger CoW. */ - if (!is_refcount_suitable(page)) { - unlock_page(page); + if (!is_refcount_suitable(&folio->page)) { + folio_unlock(folio); result = SCAN_PAGE_COUNT; goto out; } @@ -634,27 +633,27 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, * Isolate the page to avoid collapsing an hugepage * currently in use by the VM. */ - if (!isolate_lru_page(page)) { - unlock_page(page); + if (!folio_isolate_lru(folio)) { + folio_unlock(folio); result = SCAN_DEL_PAGE_LRU; goto out; } - mod_node_page_state(page_pgdat(page), - NR_ISOLATED_ANON + page_is_file_lru(page), - compound_nr(page)); - VM_BUG_ON_PAGE(!PageLocked(page), page); - VM_BUG_ON_PAGE(PageLRU(page), page); + node_stat_mod_folio(folio, + NR_ISOLATED_ANON + folio_is_file_lru(folio), + folio_nr_pages(folio)); + VM_BUG_ON_FOLIO(!folio_test_locked(folio), folio); + VM_BUG_ON_FOLIO(folio_test_lru(folio), folio); - if (PageCompound(page)) - list_add_tail(&page->lru, compound_pagelist); + if (folio_test_large(folio)) + list_add_tail(&folio->lru, compound_pagelist); next: /* * If collapse was initiated by khugepaged, check that there is * enough young pte to justify collapsing the page */ if (cc->is_khugepaged && - (pte_young(pteval) || page_is_young(page) || - PageReferenced(page) || mmu_notifier_test_young(vma->vm_mm, + (pte_young(pteval) || folio_test_young(folio) || + folio_test_referenced(folio) || mmu_notifier_test_young(vma->vm_mm, address))) referenced++; @@ -668,13 +667,13 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma, result = SCAN_LACK_REFERENCED_PAGE; } else { result = SCAN_SUCCEED; - trace_mm_collapse_huge_page_isolate(page, none_or_zero, + trace_mm_collapse_huge_page_isolate(&folio->page, none_or_zero, referenced, writable, result); return result; } out: release_pte_pages(pte, _pte, compound_pagelist); - trace_mm_collapse_huge_page_isolate(page, none_or_zero, + trace_mm_collapse_huge_page_isolate(&folio->page, none_or_zero, referenced, writable, result); return result; }