From patchwork Fri Oct 20 18:33:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vishal Moola X-Patchwork-Id: 13431020 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 66BC4C004C0 for ; Fri, 20 Oct 2023 18:33:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 68648800C5; Fri, 20 Oct 2023 14:33:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6356780044; Fri, 20 Oct 2023 14:33:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 41329800C5; Fri, 20 Oct 2023 14:33:50 -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 31C4280044 for ; Fri, 20 Oct 2023 14:33:50 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id F32C91CB5D3 for ; Fri, 20 Oct 2023 18:33:49 +0000 (UTC) X-FDA: 81366688578.11.A6C11AF Received: from mail-pf1-f169.google.com (mail-pf1-f169.google.com [209.85.210.169]) by imf30.hostedemail.com (Postfix) with ESMTP id 2F90A8001E for ; Fri, 20 Oct 2023 18:33:47 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IyLnUqtu; spf=pass (imf30.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.210.169 as permitted sender) smtp.mailfrom=vishal.moola@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1697826828; a=rsa-sha256; cv=none; b=3XTHdnLn4EqEYvHpaBpT/WrIOA+dBd3dMiAAuHovtmYM37GCZbDa1z+lB9jPLpXaM0W/0Z fx6c4Pshr13X+OvyhRyxZsei5bBHjec7w8JpDitV0xe77My2/Qbj4q+cSoI24j5kAdJGfK /VEweQqF0fFWFyibj0zifKMdBZ7NP/g= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=IyLnUqtu; spf=pass (imf30.hostedemail.com: domain of vishal.moola@gmail.com designates 209.85.210.169 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=1697826828; 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=xk5ybvp+SNZIaZ3pEA3Be7vi8BfZn75lCz2iohEvZyM=; b=Xz3MU9VS5Bj1HnmvMAs4Na2qlXVyfgTtMkVJWSF/uWot0Qhdmw2hFK8QdZW+8va8Dp4hd5 4u8546M5FWWX6tc5I7ypbeR9ggXZMXwGPvgf5pa+/55ksSzpLNVNIo3Zxd2XpuVuCBuYy+ 9DfVDO/HVnkgle80eGXUJ+KXGNhhZH4= Received: by mail-pf1-f169.google.com with SMTP id d2e1a72fcca58-6b497c8575aso1107725b3a.1 for ; Fri, 20 Oct 2023 11:33:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1697826827; x=1698431627; 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=xk5ybvp+SNZIaZ3pEA3Be7vi8BfZn75lCz2iohEvZyM=; b=IyLnUqtuD5l/+L9a9vP08QOgkSFVThoiQNZeEYZkmiadt+aBOUoXd+NHR6whFnm7ve YFyIS5MAUe5hre3B4yDpBswDbfYCOyFtjC4Bon6MfsjWaIxZqKkDwO/UD8zZziUORNOU dm/OrpEyIMmPbapGDRGy6Z5zPPnQNunjDDKw01w+FpBx+fPsbFNMm5XxsgWtsOiUKglb 2tA+BqA4JkVcG5O0R7G7CiBrFm6/r3s67+/ODt+71p/pvvOmjxIRqS98ayvudhFi2EMm IyJpTumVirVPHJ6I5CTrF04pYQxXZOWlly6VWem8rS02uxOGPN/5qL9zIbbaMcraT/xE kHXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697826827; x=1698431627; 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=xk5ybvp+SNZIaZ3pEA3Be7vi8BfZn75lCz2iohEvZyM=; b=k75mc0VQBcBKm460JvRDHRdZTLHCBgA1gjOME+nB/zSaGYIEL+LJmyM90pHxuKIJRv +09z6kMLpToTLu/rMU55I3rjjvKGYr1u5CA9p1mPMP67GOjSLnx5fHCNE/jDSWaNzjZE /F3SuiIMWLsgzH64+ZGbjgMyUpQbwv3J1wuCgM/fzGCZXvh0uOpAKayP+gF9aoC0D4qm n+Q28kgJ4W75+VKrWECZVaR0lxA84CLoLPkLLi8BDhrjkakC0CcfzzGdtNyPVNentCjo j72c6x7agbJnE7dR5L0Vh0oZ/DZ2ih/+D+VmWuphLSnCwX1s9twjNxxwvAh3H9x2RTr/ OGOw== X-Gm-Message-State: AOJu0YwBVU7NRwrjjrSpnWi/ftakrdXNiqjuqrg7jYQBeslcfHpmvZTr dYFEkx9IcPArL3Pbpczag/GOv2kxDC8= X-Google-Smtp-Source: AGHT+IHGxs5mKwV0SIfJTy/1PmcUSW12rF0lShgSZsg2OVE3kvZusMC/81y+OW2KnKIPoi+leXoxBg== X-Received: by 2002:a05:6a21:78aa:b0:141:69d:8041 with SMTP id bf42-20020a056a2178aa00b00141069d8041mr3176731pzc.48.1697826826732; Fri, 20 Oct 2023 11:33:46 -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 z14-20020aa7990e000000b006b4ac8885b4sm1911345pff.14.2023.10.20.11.33.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 Oct 2023 11:33:46 -0700 (PDT) From: "Vishal Moola (Oracle)" To: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, akpm@linux-foundation.org, "Vishal Moola (Oracle)" Subject: [PATCH v3 4/5] mm/khugepaged: Convert alloc_charge_hpage() to use folios Date: Fri, 20 Oct 2023 11:33:30 -0700 Message-Id: <20231020183331.10770-5-vishal.moola@gmail.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20231020183331.10770-1-vishal.moola@gmail.com> References: <20231020183331.10770-1-vishal.moola@gmail.com> MIME-Version: 1.0 X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 2F90A8001E X-Stat-Signature: x349ypst3yxnn3z5o8ituce5ftziimo5 X-Rspam-User: X-HE-Tag: 1697826827-306497 X-HE-Meta: U2FsdGVkX1+eLYkH+qGCcsRglHCfmjgFAFf73ajAPiu65iTQO3Fn2Zj+IUeHvqTrumX4sBwhPs5fDQuaJZ/gqAyhygdanRnKDM4+TtfZnd8Zri6yBvfWEaSZuzSCdTYQwUupS/3Utkz/sc+gZiowRSu+dmGpj0RYMmEa9/7vK6XtRE8ZJ//ncQOHhJDtEdSYYWZKdsJ9jBOtO1luyMpmLDhAoduh+Za0yFlk16QHvkWWrlZQs0R7b4Rm+2fB9o9TLKXYh0eFimk+3RUrlAz0216tpUEsa/Wz2HrZxhX07BsIxDxP32zmeaNf9fdHHpcBzNF48mYs0/8YO6RdO9vFqRJhitFRhGLNYfLwjXc9bh2uxiJ1LweX37NdEeHCzQ+TfZ/OzL7JtrBLwrcFdc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YrGmQR/sL4NJDam1C5EPSxgft62CJ/zqk5iE+RLF8NUOwH37xPmz8HTabogrYPsttL0fwSEytt/eJgcZv2trbWf1XwKz2EEhkxcZrg/C8zn0FmwGg== 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: Also remove count_memcg_page_event now that its last caller no longer uses it and reword hpage_collapse_alloc_page() to hpage_collapse_alloc_folio(). This removes 1 call to compound_head() and helps convert khugepaged to use folios throughout. Signed-off-by: Vishal Moola (Oracle) Reviewed-by: Rik van Riel Reviewed-by: Yang Shi --- include/linux/memcontrol.h | 14 -------------- mm/khugepaged.c | 17 ++++++++++------- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/include/linux/memcontrol.h b/include/linux/memcontrol.h index ab94ad4597d0..3126bde982e8 100644 --- a/include/linux/memcontrol.h +++ b/include/linux/memcontrol.h @@ -1080,15 +1080,6 @@ static inline void count_memcg_events(struct mem_cgroup *memcg, local_irq_restore(flags); } -static inline void count_memcg_page_event(struct page *page, - enum vm_event_item idx) -{ - struct mem_cgroup *memcg = page_memcg(page); - - if (memcg) - count_memcg_events(memcg, idx, 1); -} - static inline void count_memcg_folio_events(struct folio *folio, enum vm_event_item idx, unsigned long nr) { @@ -1565,11 +1556,6 @@ static inline void __count_memcg_events(struct mem_cgroup *memcg, { } -static inline void count_memcg_page_event(struct page *page, - int idx) -{ -} - static inline void count_memcg_folio_events(struct folio *folio, enum vm_event_item idx, unsigned long nr) { diff --git a/mm/khugepaged.c b/mm/khugepaged.c index 9efd8ff68f06..6a7184cd291b 100644 --- a/mm/khugepaged.c +++ b/mm/khugepaged.c @@ -888,16 +888,16 @@ static int hpage_collapse_find_target_node(struct collapse_control *cc) } #endif -static bool hpage_collapse_alloc_page(struct page **hpage, gfp_t gfp, int node, +static bool hpage_collapse_alloc_folio(struct folio **folio, gfp_t gfp, int node, nodemask_t *nmask) { - *hpage = __alloc_pages(gfp, HPAGE_PMD_ORDER, node, nmask); - if (unlikely(!*hpage)) { + *folio = __folio_alloc(gfp, HPAGE_PMD_ORDER, node, nmask); + + if (unlikely(!*folio)) { count_vm_event(THP_COLLAPSE_ALLOC_FAILED); return false; } - folio_prep_large_rmappable((struct folio *)*hpage); count_vm_event(THP_COLLAPSE_ALLOC); return true; } @@ -1064,17 +1064,20 @@ static int alloc_charge_hpage(struct page **hpage, struct mm_struct *mm, int node = hpage_collapse_find_target_node(cc); struct folio *folio; - if (!hpage_collapse_alloc_page(hpage, gfp, node, &cc->alloc_nmask)) + if (!hpage_collapse_alloc_folio(&folio, gfp, node, &cc->alloc_nmask)) { + *hpage = NULL; return SCAN_ALLOC_HUGE_PAGE_FAIL; + } - folio = page_folio(*hpage); if (unlikely(mem_cgroup_charge(folio, mm, gfp))) { folio_put(folio); *hpage = NULL; return SCAN_CGROUP_CHARGE_FAIL; } - count_memcg_page_event(*hpage, THP_COLLAPSE_ALLOC); + count_memcg_folio_events(folio, THP_COLLAPSE_ALLOC, 1); + + *hpage = folio_page(folio, 0); return SCAN_SUCCEED; }