Received: by 2002:a05:6358:16cc:b0:ea:6187:17c9 with SMTP id r12csp1566414rwl; Mon, 26 Dec 2022 01:04:39 -0800 (PST) X-Google-Smtp-Source: AMrXdXuM28Xal074TzmDzuPNJJtD2yuXPp3T96ymBrsKrRHSnb/sSm5Gij9dyBkm7iz7v2r082TY X-Received: by 2002:a17:907:c242:b0:7c4:fc02:46a3 with SMTP id tj2-20020a170907c24200b007c4fc0246a3mr18082939ejc.30.1672045478871; Mon, 26 Dec 2022 01:04:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672045478; cv=none; d=google.com; s=arc-20160816; b=0Srplh8OzZHBTq/Rp+0MPZjnFOoOkjVP1Qdakc9FsbCH57LHNe0zokoXTmyAi94a0e 9MhJgKsoX/jEFMJA0XkEN5aSxtkueDqUS59uR1IMmFuKt89dduPd0vqaS23WifvXPBL7 AGPzw2tAuaqEMt1UbjHNiPuFuwlygfNxG1ljY6vKgoc84Aa9+1AhxXv0E9xPdPzX1aI5 Wih/nAJ7McnTEAwS/3x5DllOHEAFLjtj5GAbcO8NlalsneUD/ZAz+s6uI9IMLN+zu0JY 2DDiZ3yOX/6zCyAXL+plyD8FQpgKpJ+X9EmdCaetIkqp8Pv9IP1MWkjRCJSI7SmtFRlx 76ZQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=65qxl2pPQDnBMbGwdUZ+PFGonfHL4ihIaGu2BHcPC3E=; b=jgG7k73URdyAohefetOcMnsSJZeYGhDBbG3GsSrJd7Oa7pCfn7tVYYiwoeARVhacwW nfYJI6tWa+AuLRyW8AHIVDsseePnBS52+iPiTeme+iQeRe3alYqQ9mNb0gV4HTrHrAaN IDJggHwiSNmKbD5yIFinRxtxoQtnVy9q5p1higNbqXrlBId3ZnfuLAFLO0m2t3ZiYAP0 dZX+leEjFeNbRGxQJLRxHmsMqWLU3PJXPZWpD4RxuSr8gSmLUO6ECa+qh5IzJua6IsMg lrIX6JzatSeOS/K02oNYQ+fgx1C4mDMz1r81iWtl03Xm4mmW7TGQixZanpBZnUGiR83H AAcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=FgkDWhxX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qf27-20020a1709077f1b00b007bdf57f885esi9002187ejc.37.2022.12.26.01.04.23; Mon, 26 Dec 2022 01:04:38 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=FgkDWhxX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231966AbiLZIpB (ORCPT + 66 others); Mon, 26 Dec 2022 03:45:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231898AbiLZIoh (ORCPT ); Mon, 26 Dec 2022 03:44:37 -0500 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E4FD2BDB for ; Mon, 26 Dec 2022 00:44:34 -0800 (PST) Received: by mail-wr1-x430.google.com with SMTP id n3so8824012wrc.5 for ; Mon, 26 Dec 2022 00:44:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=65qxl2pPQDnBMbGwdUZ+PFGonfHL4ihIaGu2BHcPC3E=; b=FgkDWhxXChE2Ah6CAPAdtfnpZw2aUSmE9f8oFWA0FnR8ofTYUM1SDtwnT6VuCIBVNy PTMlbo4WkY0LpvkaVci/gogKcodFLwGQNAvF56lh2J0b6k/o+RGBIBtOFfVGggfA1tyh d6DG7FBQqIBKSoQY6KL3aKyVUq+3UAFwt8v/NevHvrNlJ4hsTj8jX1FiT3vdO/uj7SeO NYvf3X2VK5jEswRAfscG5X/I6pmd+e9ifMdsTrRNKKWzyCQ90hufV3nfffCgjuidGU3Y qMnOxEPFJ6f95vhqsj/XUwM+7uaOP5SYhs/t5uz40SFCHEBAneKTY22D/Z22mFN+P917 Am8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=65qxl2pPQDnBMbGwdUZ+PFGonfHL4ihIaGu2BHcPC3E=; b=JbLWoAuwrMEm6ubEq2VdvWU3gsa83vg7bZDhfD4KBsb9WmSAZ33OoLlui5FJxbSxGN lUJjaTZKACgrRctdZN7U5OEKzKixULAiA4GF5OaDW63LpshIXonmLcfzT5XbwPgS/OEo pmoD/O198a3pDrjhvGurHDZSDLF50uDXec6ih7wPiFYs8PcTTMkZ+2jZtdiYqbTnM+qd VHeC8/XYgRXKMVWtWs3MgSQDNDENYcBNTRnrBJMhkMwHKe/AnkyO8Iw5atXxv3uci4tc L+7v44sEZiGTrjHfZNXVSdFx0P6v1U7LFs+DjawZCJ0FKsyoOfCx8rDtM6GdxlEgnDfU 5/jQ== X-Gm-Message-State: AFqh2kpjLdhLag1Bpyd47C+ZUU2rEqTLhIdFuWPP61ClhbulY11iv8pl CtL9EEzH1OC3PCGa0sYc76U= X-Received: by 2002:adf:e5ce:0:b0:27e:520f:1093 with SMTP id a14-20020adfe5ce000000b0027e520f1093mr1282397wrn.37.1672044272478; Mon, 26 Dec 2022 00:44:32 -0800 (PST) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id m16-20020adffe50000000b00241bd7a7165sm10593253wrs.82.2022.12.26.00.44.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 26 Dec 2022 00:44:31 -0800 (PST) From: Lorenzo Stoakes To: linux-mm@kvack.org, Andrew Morton , linux-kernel@vger.kernel.org Cc: Matthew Wilcox , Hugh Dickins , Vlastimil Babka , Liam Howlett , William Kucharski , Christian Brauner , Jonathan Corbet , Mike Rapoport , Joel Fernandes , Geert Uytterhoeven , Lorenzo Stoakes Subject: [PATCH v3 4/5] mm: mlock: update the interface to use folios Date: Mon, 26 Dec 2022 08:44:22 +0000 Message-Id: X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch updates the mlock interface to accept folios rather than pages, bringing the interface in line with the internal implementation. munlock_vma_page() still requires a page_folio() conversion, however this is consistent with the existent mlock_vma_page() implementation and a product of rmap still dealing in pages rather than folios. Signed-off-by: Lorenzo Stoakes --- mm/internal.h | 26 ++++++++++++++++---------- mm/mlock.c | 32 +++++++++++++++----------------- mm/swap.c | 2 +- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/mm/internal.h b/mm/internal.h index 1d6f4e168510..8a6e83315369 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -515,10 +515,9 @@ extern int mlock_future_check(struct mm_struct *mm, unsigned long flags, * should be called with vma's mmap_lock held for read or write, * under page table lock for the pte/pmd being added or removed. * - * mlock is usually called at the end of page_add_*_rmap(), - * munlock at the end of page_remove_rmap(); but new anon - * pages are managed by lru_cache_add_inactive_or_unevictable() - * calling mlock_new_page(). + * mlock is usually called at the end of page_add_*_rmap(), munlock at + * the end of page_remove_rmap(); but new anon folios are managed by + * folio_add_lru_vma() calling mlock_new_folio(). * * @compound is used to include pmd mappings of THPs, but filter out * pte mappings of THPs, which cannot be consistently counted: a pte @@ -547,15 +546,22 @@ static inline void mlock_vma_page(struct page *page, mlock_vma_folio(page_folio(page), vma, compound); } -void munlock_page(struct page *page); -static inline void munlock_vma_page(struct page *page, +void munlock_folio(struct folio *folio); + +static inline void munlock_vma_folio(struct folio *folio, struct vm_area_struct *vma, bool compound) { if (unlikely(vma->vm_flags & VM_LOCKED) && - (compound || !PageTransCompound(page))) - munlock_page(page); + (compound || !folio_test_large(folio))) + munlock_folio(folio); +} + +static inline void munlock_vma_page(struct page *page, + struct vm_area_struct *vma, bool compound) +{ + munlock_vma_folio(page_folio(page), vma, compound); } -void mlock_new_page(struct page *page); +void mlock_new_folio(struct folio *folio); bool need_mlock_page_drain(int cpu); void mlock_page_drain_local(void); void mlock_page_drain_remote(int cpu); @@ -647,7 +653,7 @@ static inline void mlock_vma_page(struct page *page, struct vm_area_struct *vma, bool compound) { } static inline void munlock_vma_page(struct page *page, struct vm_area_struct *vma, bool compound) { } -static inline void mlock_new_page(struct page *page) { } +static inline void mlock_new_folio(struct folio *folio) { } static inline bool need_mlock_page_drain(int cpu) { return false; } static inline void mlock_page_drain_local(void) { } static inline void mlock_page_drain_remote(int cpu) { } diff --git a/mm/mlock.c b/mm/mlock.c index e9ba47fe67ed..3982ef4d1632 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -262,13 +262,12 @@ void mlock_folio(struct folio *folio) } /** - * mlock_new_page - mlock a newly allocated page not yet on LRU - * @page: page to be mlocked, either a normal page or a THP head. + * mlock_new_folio - mlock a newly allocated folio not yet on LRU + * @folio: folio to be mlocked, either normal or a THP head. */ -void mlock_new_page(struct page *page) +void mlock_new_folio(struct folio *folio) { struct folio_batch *fbatch; - struct folio *folio = page_folio(page); int nr_pages = folio_nr_pages(folio); local_lock(&mlock_fbatch.lock); @@ -286,13 +285,12 @@ void mlock_new_page(struct page *page) } /** - * munlock_page - munlock a page - * @page: page to be munlocked, either a normal page or a THP head. + * munlock_folio - munlock a folio + * @folio: folio to be munlocked, either normal or a THP head. */ -void munlock_page(struct page *page) +void munlock_folio(struct folio *folio) { struct folio_batch *fbatch; - struct folio *folio = page_folio(page); local_lock(&mlock_fbatch.lock); fbatch = this_cpu_ptr(&mlock_fbatch.fbatch); @@ -314,7 +312,7 @@ static int mlock_pte_range(pmd_t *pmd, unsigned long addr, struct vm_area_struct *vma = walk->vma; spinlock_t *ptl; pte_t *start_pte, *pte; - struct page *page; + struct folio *folio; ptl = pmd_trans_huge_lock(pmd, vma); if (ptl) { @@ -322,11 +320,11 @@ static int mlock_pte_range(pmd_t *pmd, unsigned long addr, goto out; if (is_huge_zero_pmd(*pmd)) goto out; - page = pmd_page(*pmd); + folio = page_folio(pmd_page(*pmd)); if (vma->vm_flags & VM_LOCKED) - mlock_folio(page_folio(page)); + mlock_folio(folio); else - munlock_page(page); + munlock_folio(folio); goto out; } @@ -334,15 +332,15 @@ static int mlock_pte_range(pmd_t *pmd, unsigned long addr, for (pte = start_pte; addr != end; pte++, addr += PAGE_SIZE) { if (!pte_present(*pte)) continue; - page = vm_normal_page(vma, addr, *pte); - if (!page || is_zone_device_page(page)) + folio = vm_normal_folio(vma, addr, *pte); + if (!folio || folio_is_zone_device(folio)) continue; - if (PageTransCompound(page)) + if (folio_test_large(folio)) continue; if (vma->vm_flags & VM_LOCKED) - mlock_folio(page_folio(page)); + mlock_folio(folio); else - munlock_page(page); + munlock_folio(folio); } pte_unmap(start_pte); out: diff --git a/mm/swap.c b/mm/swap.c index e54e2a252e27..7df297b143f9 100644 --- a/mm/swap.c +++ b/mm/swap.c @@ -562,7 +562,7 @@ void folio_add_lru_vma(struct folio *folio, struct vm_area_struct *vma) VM_BUG_ON_FOLIO(folio_test_lru(folio), folio); if (unlikely((vma->vm_flags & (VM_LOCKED | VM_SPECIAL)) == VM_LOCKED)) - mlock_new_page(&folio->page); + mlock_new_folio(folio); else folio_add_lru(folio); } -- 2.39.0