From patchwork Wed Oct 18 20:32:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 13427842 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 951ADCDB482 for ; Wed, 18 Oct 2023 20:33:16 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B69BA8001E; Wed, 18 Oct 2023 16:33:12 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AF43E8D0016; Wed, 18 Oct 2023 16:33:12 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 91BEF8001E; Wed, 18 Oct 2023 16:33:12 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 7CA0A8D0016 for ; Wed, 18 Oct 2023 16:33:12 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 5265CA0F06 for ; Wed, 18 Oct 2023 20:33:12 +0000 (UTC) X-FDA: 81359731824.01.AC54827 Received: from mail-pg1-f181.google.com (mail-pg1-f181.google.com [209.85.215.181]) by imf29.hostedemail.com (Postfix) with ESMTP id 7E4AB12001F for ; Wed, 18 Oct 2023 20:33:10 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=i5wRpO3u; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.215.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=1697661190; 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=Q/rAUjlYbudj5wnw8lHkufWutUwYDRgsClPJWjawwgo=; b=tu7fpALvfgzBFXFAYT0hhcOd1VpJHdMCqfJW3NmIfecPH+Jll91yo42tmSsi5y9RQDOkA9 mx6s9SROXldCTEWdC9K+DsQdNNmNMwSfqqhBf8GXPuDzo3LjtSKduxN1JLxH9WRKgqzh03 SnTVATujP0msbOR2cx2Ym8HlvXlVETs= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=i5wRpO3u; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.215.181 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697661190; a=rsa-sha256; cv=none; b=GVPwoQEQVD52aw+FoBHSkBliGyTJj2VWyyo4udseRH5upiYKvFYMxT6GAXPKGioYN5WB1c QQX/+A6OepkMW22/dZWoavELecd2i/iY1brNkow7nBYlTjSXvZ1WOtfJ374bBwNDzTakd6 2KpG49a5azLQXx1/W7COTP0DlGMZtiE= Received: by mail-pg1-f181.google.com with SMTP id 41be03b00d2f7-5aaebfac4b0so3660734a12.2 for ; Wed, 18 Oct 2023 13:33:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697661189; x=1698265989; 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=Q/rAUjlYbudj5wnw8lHkufWutUwYDRgsClPJWjawwgo=; b=i5wRpO3u4HGYoSnpMdQgf6rXFmJ11otYFtqlbXH7IAzpq0WsgVpKYkRCyZdexR+1zJ CAMKyaNJpOVyzC+f0CW8toEeuJqbYykMpGbq2wpUTPQ4v+VbfWNchRGZucErSxZuaEMp WaZivVb3koitzW5gti1sKBdqXPNO5MG8yqQGXAy+0NE2nTdgSYhOo25NTc1DrQgcOxjh ZYnvqg8EgkJmpM2CEuK3vyPkMMtjVm6xp9ys8vswz7k1g4GWpf3B4fx4pviJhMM5dqR6 1tAcY+DF7ZlcMu6YCpAtOt61mkGPWL/mTy+ga6K/Sma8+5fapmBCSKflNUU7GpEa78vo W/8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697661189; x=1698265989; 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=Q/rAUjlYbudj5wnw8lHkufWutUwYDRgsClPJWjawwgo=; b=RDF4C+dLI5e63vM8ljdx+LpzIw+DQT0EZaF26N3T20rP9RPN4VhWcFEWURclews9yu Fxf40e7VD1WsRt9df/+xIMJlaUTfxSd2VlBwThpcIPls+QnYcfgrJeYLiuCRdHuLL8Vh 2avJbioB9hpeeNQ/vHBYuqDA7jRjiDgREebUuXlsAD8kk2h6+ozkPg/+jZHPqrldFWv/ 0hb2bonipUArTxRFmJ/xJFDxd+ZgtYPGDc+uMP6OMiKL986667iQVAX+WWhzByJ5XHr1 JV871VF7nKIs4l1338gfeK+BHGtKCVz/GVr1tVuDONHMlUVU8a0tzdUuzp6iHYfyAI8M wfeQ== X-Gm-Message-State: AOJu0Yw9uTcEPmOg94NB0484If18S63wEKNUqhumSXv1lKcsXrjo1SqG YdKNN7V/DkhM7PxQpoi8HVicrz9nphE= X-Google-Smtp-Source: AGHT+IHHKufGkhuDo4UJftnY7SwsN1FFsHrItzDWiS842QRY9mPhF1ZSrMfqcuvk3t7Vnjm0ZSWi9g== X-Received: by 2002:a05:6a21:3e0b:b0:171:c88a:890c with SMTP id bk11-20020a056a213e0b00b00171c88a890cmr269714pzc.25.1697661189243; Wed, 18 Oct 2023 13:33:09 -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 w12-20020a170902d3cc00b001c61e628e9dsm354412plb.77.2023.10.18.13.33.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Oct 2023 13:33:08 -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 v2 3/5] mm/khugepaged: Convert is_refcount_suitable() to use folios Date: Wed, 18 Oct 2023 13:32:11 -0700 Message-Id: <20231018203213.50224-4-vishal.moola@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231018203213.50224-1-vishal.moola@gmail.com> References: <20231018203213.50224-1-vishal.moola@gmail.com> MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 7E4AB12001F X-Stat-Signature: ip38s8p616enqztn9eqz4jndz7bfihm9 X-HE-Tag: 1697661190-372906 X-HE-Meta: U2FsdGVkX1+Gqm2YXT+a4P99mOyS3gc39ZVP2CH7SfJc42xSf3w4f6Q0purvKg0ZqlUL2NRaWzwi7hC4GpyRyCXmC3KtZX2wLyEsQscnK/Vl2iIhynuYy3BKWm84uUcPelfzr3vmELmpKv81pzHEdnMX+T8wmdO8XqiVHmjQwcv2qy0v60t2YD2ZKDfP4oog1PnWDb/ucJ+jc8FD6i0DC1xzlMPQcNCTLMFPpbl06OXNhhyagZkGq1WWPsPx97ebM6UPlN741M/gc0NpAnPljVycLA+aJ+I77c9h6FtYbWWNpOHzrXhu1SrBXY8VE0zj4eOCxVM3YRmRnLqjQtx12JgV4O5Fbf6TtvTUWTgxx2+ahQppPHxjnjSk2aFDrLMso5VAyQe3GR8YiQhjM8mtdfw83la+S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QPLZOhU5RexDPfBbC49Wjfg1MFVPKOnUT9sMfcWrbDjn5kNbMNmt1cE4/G+0cDM6zb6thsn37BYWrNEYE2rNPjA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000007, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: Both callers of is_refcount_suitable() have been converted to use folios, so convert it to take in a folio. Both callers only operate on head pages of folios so mapcount/refcount conversions here are trivial. Removes 3 calls to compound head, and removes 315 bytes of kernel text. Signed-off-by: Vishal Moola (Oracle) --- mm/khugepaged.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 6c4b5af43371..9efd8ff68f06 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -524,15 +524,15 @@ static void release_pte_pages(pte_t *pte, pte_t *_pte, } } -static bool is_refcount_suitable(struct page *page) +static bool is_refcount_suitable(struct folio *folio) { int expected_refcount; - expected_refcount = total_mapcount(page); - if (PageSwapCache(page)) - expected_refcount += compound_nr(page); + expected_refcount = folio_mapcount(folio); + if (folio_test_swapcache(folio)) + expected_refcount += folio_nr_pages(folio); - return page_count(page) == expected_refcount; + return folio_ref_count(folio) == expected_refcount; } static int __collapse_huge_page_isolate(struct vm_area_struct *vma, @@ -625,7 +625,7 @@ 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(&folio->page)) { + if (!is_refcount_suitable(folio)) { folio_unlock(folio); result = SCAN_PAGE_COUNT; goto out; @@ -1371,7 +1371,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(&folio->page)) { + if (!is_refcount_suitable(folio)) { result = SCAN_PAGE_COUNT; goto out_unmap; }