From patchwork Mon Oct 16 20:05:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 13424037 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 1D929CDB465 for ; Mon, 16 Oct 2023 20:07:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 15CC58D00C0; Mon, 16 Oct 2023 16:07:01 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0E6908D00BA; Mon, 16 Oct 2023 16:07:01 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E06148D00C0; Mon, 16 Oct 2023 16:07:00 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id CDF538D00BA for ; Mon, 16 Oct 2023 16:07:00 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A316B1A0C02 for ; Mon, 16 Oct 2023 20:07:00 +0000 (UTC) X-FDA: 81352408200.29.3E70AB0 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) by imf09.hostedemail.com (Postfix) with ESMTP id C9121140002 for ; Mon, 16 Oct 2023 20:06:58 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Kxjpjboa; spf=pass (imf09.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1697486818; 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=mMefHNBDnWRPz8cjT6IRO34+spfB9/Lnaff9PAvwfj8=; b=WBYc1LQtpsI0+RrcqwkdxqgtA6BxgbwGjh3VmYLxKFkCW6Gegcvbchf5KD4tVtSOgPapla 5t2UXn5ebxZgi8teug/UsJth5QyY9usnz0z3akGCbK4To6c2p+fSDhtRhZaktOscrZHy90 UBg2UC1YDncIzaNZaZqFhqn7CeR90eU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697486818; a=rsa-sha256; cv=none; b=jf+Hzl/7NXDb5ICygHBPyPN4gIIS7yai+nlB3rii/VH/38phKXgSz+sK+tYZx9VfGQ+oV+ Mp6KixYqqDIW52XyGOgNpzRhC7WKUXrxxF7VU0PEOk3249rDCCJSyK6Fn3EK7F8arVitDX zsVCBEB8fUbCUejJCi4pn7VhgyS+Kl4= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=Kxjpjboa; spf=pass (imf09.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.214.178 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-1c9b1e3a809so31331015ad.2 for ; Mon, 16 Oct 2023 13:06:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697486817; x=1698091617; 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=mMefHNBDnWRPz8cjT6IRO34+spfB9/Lnaff9PAvwfj8=; b=KxjpjboaVkiBJCUdGahmP7thGCdUoYKa2/lA0e+1dz4pn9EAwMAyuAm5w4kNTxmj4s 2T4fPqQ/1cA5frW5eITqvxiPpKDkMcPgIw9z3s41IZu9/88vMTIQihZhuausgw89t1Sv 9/H9TBZAJ0uMO5tQ06Sc2l/tFSvcciU1DhoPNYPBJhe68jPPkyqWrYJ+FMvdiDdR8fZI SZst/odM39hoL6XsnalqrIQjhuqzZ2FvdKbRFrmGQdsaVJoxC+zJH3DaDU8ozND/v17N D65X4xwVTeMEriEYuhxk7OCpkyZehLR4L/0JGdbWkAwu+kPZBvmJSgIAk2JjY+tcECBh puLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697486817; x=1698091617; 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=mMefHNBDnWRPz8cjT6IRO34+spfB9/Lnaff9PAvwfj8=; b=bNA6Htbg8ECaCFJwnNvrOgPrRpJ6NUdyR4qsPuktZHrXg8woVNPddCW/Qw5m+jTHGI j0Wy2ELblmGiHqKTcuN5QpvL5wR43bUTJrcPbNfmyyOkVQglIFkZZFBJhRlqi4xcol53 WhxLGuYpoJRVfmYoG4YbVu4HzTNjiv2o9Y23g0aw2VKLxROo8NPbOCA3gGqUGpowRn13 fpu4Srwv5hjKfHSWqnG34nVNLO84X8dnBnSfmk5RDqog7mUJBzKZbWDPkkhjUULpxFcV g854OlL0xkevfKIRmJpWUpq6aXImOMRrY+/KYeqREgzAy37hwJMHtwLEthlbeIMfkSdv jn/Q== X-Gm-Message-State: AOJu0YxW8H5w6YCFIYVzvS0vwsDW8Cr6cvY/lQkx8UqjxiY6JaNAcUNf RTPYX+wTSJ/niEGh1xdtnmXnJBNV/M4= X-Google-Smtp-Source: AGHT+IHA265DKTJz97l5pSxxF6Sh4mCEGazOefOWWexfxpvvfFDKrwesNxGieo7cqzTIX0SPaOQ/3w== X-Received: by 2002:a17:90a:1959:b0:27d:10ab:2325 with SMTP id 25-20020a17090a195900b0027d10ab2325mr161116pjh.27.1697486817436; Mon, 16 Oct 2023 13:06:57 -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.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Oct 2023 13:06:57 -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)" Subject: [PATCH 2/5] mm/khugepaged: Convert hpage_collapse_scan_pmd() to use folios Date: Mon, 16 Oct 2023 13:05:07 -0700 Message-Id: <20231016200510.7387-3-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-Stat-Signature: 9wwcc4phiu6rfhzys5ki7h1zm4j4jopr X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: C9121140002 X-Rspam-User: X-HE-Tag: 1697486818-72078 X-HE-Meta: U2FsdGVkX19k0vv/CqfrSC6lbS87Q36a/qXkYI8+A0S5E1G5KQwv9MByaVieGV/LIk+OMSWQj8qe3llzEB32MIY384NsYJKbiGkGPNWbaEc6gkgyOxCtGOP2+Iz5beSfLh3beVLq10RLd9b4CZ0cqcM/1SSKDruq0m2JtfzkX/S84oR+hlwQsnoXwp2YvUjU3hI2rcnMzJS/WAOaM/qOBtF6Ks/XozhejbxL0REoSUzzqcDLV463QDI02qN1QnsauRnwtZReIdLpJS+L10dOWUSSeUmItRgsJ4WZEizRsY3ENOgDzzvdBLccNbYse4+7cl1Hpv1Q6Ku4tNxeT4KBzBCEiDGERLrHd89LNUehrpc3cnsh2xSt7/H5NmOLzL4K35eIF8HiAPnoDpRnKAmcnV2GBx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ZaXOpWmqeadK+NHZrUK2pFuaE6xAxGQt8pIrCRdRr29e2GKqaQpRK/PQsH8TWOEtA7AujOuPr7jCSp+EHIJdONH1GYPdqK49nUwWJiC53YVatqu+Og== 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 5 calls to compound_head(), and removes 1466 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) --- mm/khugepaged.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 7a552fe16c92..67aac53b31c8 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -1245,7 +1245,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm, pte_t *pte, *_pte; int result = SCAN_FAIL, referenced = 0; int none_or_zero = 0, shared = 0; - struct page *page = NULL; + struct folio *folio = NULL; unsigned long _address; spinlock_t *ptl; int node = NUMA_NO_NODE, unmapped = 0; @@ -1316,13 +1316,13 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm, if (pte_write(pteval)) writable = true; - 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_unmap; } - if (page_mapcount(page) > 1) { + if (folio_estimated_sharers(folio) > 1) { ++shared; if (cc->is_khugepaged && shared > khugepaged_max_ptes_shared) { @@ -1332,29 +1332,27 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm, } } - page = compound_head(page); - /* * Record which node the original page is from and save this * information to cc->node_load[]. * Khugepaged will allocate hugepage from the node has the max * hit record. */ - node = page_to_nid(page); + node = folio_nid(folio); if (hpage_collapse_scan_abort(node, cc)) { result = SCAN_SCAN_ABORT; goto out_unmap; } cc->node_load[node]++; - if (!PageLRU(page)) { + if (!folio_test_lru(folio)) { result = SCAN_PAGE_LRU; goto out_unmap; } - if (PageLocked(page)) { + if (folio_test_locked(folio)) { result = SCAN_PAGE_LOCK; goto out_unmap; } - if (!PageAnon(page)) { + if (!folio_test_anon(folio)) { result = SCAN_PAGE_ANON; goto out_unmap; } @@ -1369,7 +1367,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm, * has excessive GUP pins (i.e. 512). Anyway the same check * will be done again later the risk seems low. */ - if (!is_refcount_suitable(page)) { + if (!is_refcount_suitable(&folio->page)) { result = SCAN_PAGE_COUNT; goto out_unmap; } @@ -1379,8 +1377,8 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm, * 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++; } @@ -1402,7 +1400,7 @@ static int hpage_collapse_scan_pmd(struct mm_struct *mm, *mmap_locked = false; } out: - trace_mm_khugepaged_scan_pmd(mm, page, writable, referenced, + trace_mm_khugepaged_scan_pmd(mm, &folio->page, writable, referenced, none_or_zero, result, unmapped); return result; }