From patchwork Thu Dec 22 19:48:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Stoakes X-Patchwork-Id: 13080284 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 48CC1C4167B for ; Thu, 22 Dec 2022 19:48:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id AD1DE940008; Thu, 22 Dec 2022 14:48:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id A0B1A940007; Thu, 22 Dec 2022 14:48:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 88419940008; Thu, 22 Dec 2022 14:48:47 -0500 (EST) 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 7A126940007 for ; Thu, 22 Dec 2022 14:48:47 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 530D280EAC for ; Thu, 22 Dec 2022 19:48:47 +0000 (UTC) X-FDA: 80270979894.28.6480405 Received: from mail-wr1-f44.google.com (mail-wr1-f44.google.com [209.85.221.44]) by imf10.hostedemail.com (Postfix) with ESMTP id 9976CC0008 for ; Thu, 22 Dec 2022 19:48:45 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=YBprBzKR; spf=pass (imf10.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.44 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1671738525; a=rsa-sha256; cv=none; b=Hl9bMsjyr88/hEKw3jPyVpuw/5pQujy3nm81g7SWMJn/NWcDbAxNTWJQ/JcsIhNY1tC3tT TdwCv+6UjIlR/keEL5ayzdjGJTuTA9IyhTzVHUvpNTEr1MlNzVm56O0DW425FECQ8fS++2 sjpz0jiRkdzKgVrRMnTDylLt8I5qZOY= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=YBprBzKR; spf=pass (imf10.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.44 as permitted sender) smtp.mailfrom=lstoakes@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=1671738525; 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=65qxl2pPQDnBMbGwdUZ+PFGonfHL4ihIaGu2BHcPC3E=; b=UaCTFF0FEV6/LJFGkofQkaLReJybB7tUTlp98JnsCHzhaLpYxuVxuObFNk6cISmBidBYrE rEYZlnaOsv6VMPJUNUkOhY/4H88uFmaI+ZuI/FjSNYNQ6Kh46ojbvV3u4mKgwRPle9UqAd EszQ16iymcgj3L6+VfMAaX4zqV4QSXQ= Received: by mail-wr1-f44.google.com with SMTP id co23so2697740wrb.4 for ; Thu, 22 Dec 2022 11:48:45 -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=YBprBzKRdYFFFrBXK09fE8px7jN7JkycOZoSJJjAiu6CndU2eQZb8+Xf3fYy3GAD3v xOI+SAV6Tyr2acqkHoN6iTJgCS0kKqBa4EOfn+GAhaXMGw8g4kEDHhJgim8plbwr9lrO We2YZqoCMcMb6zNFjEVorjE+cjFFgVqXcJaeqtxsPWpn92qndZj8PK8KsfqHwzU4td/C MPlhABSyTCapn60sbkdAfW08wE4NoAKJKQoAiU7EPEuarT16lBvzWuNnxM+t2K3KlxY3 2HqOxVBD0J3fg/ynr/s8S+K1JG65FmbI4U4wG5wi5Gapw2WckkhNpufSa32HP49icntM LkVQ== 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=VOrnZBI+WfqMurTp7B4YDQFRMjG0488C07h02x5TfDh/BR1iM+9w3fnfGJdsPLgnOG kRk2Rxz/qJHUMuMqDa+ALIPih0MrL7N65uSJzmku9s3BPdZ+3boYLPaBC+ixwUXiZuPE McnIph7j+4wu2OQ1cynfjV+I5/Wb4GGiE1IFeR/yBycqntA6K3RhewT8Ke5LLaNax/L5 LtnJkMV9MOJ6YjKaFjYxC1jGdaJAq5MHvU/pKFroOXtDRzoyMiY4HXIkN5Qpxg/uoFEW 60ia9H8p63vFmWl3w5iv8Dg66hfVgB6TGKQNyUcg3GjYAQtRnPLhU1YatmzayIxaLfG6 EU6Q== X-Gm-Message-State: AFqh2kq6dCLc39kFwWAlfBWv+zeAgGTZfoH2jTxLPXuf/FgKibqhSXom nlUVrDTmW/+ACgfvX+75B2x0nOC9Scfh4Q== X-Google-Smtp-Source: AMrXdXtJv2D8LcU9sAIqibpjZPAJqk11UKT8kZq7nYM+2O+d3EGDGtD/EMLR6gF5i8Ha/6mz3lRcPg== X-Received: by 2002:a5d:4803:0:b0:26a:b8e3:b772 with SMTP id l3-20020a5d4803000000b0026ab8e3b772mr4200098wrq.23.1671738524060; Thu, 22 Dec 2022 11:48:44 -0800 (PST) Received: from lucifer.home ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.googlemail.com with ESMTPSA id i1-20020adfb641000000b002425787c5easm1349317wre.96.2022.12.22.11.48.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Dec 2022 11:48:43 -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 , Lorenzo Stoakes Subject: [PATCH 3/4] mm: mlock: update the interface to use folios Date: Thu, 22 Dec 2022 19:48:32 +0000 Message-Id: <74874865335885dabe0751c1140a6d198dea333d.1671738120.git.lstoakes@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 X-Rspam-User: X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 9976CC0008 X-Stat-Signature: x1q5buseadh8rbf8e74nqbsxoqagwmpw X-HE-Tag: 1671738525-376938 X-HE-Meta: U2FsdGVkX1/f3iMKq8wzizi5R29eJb2+nlBuYkRCgBUuCgZE1tkC/d04petTngcCt4G7OGIoVxBcQDMM5s8xP2+bJ2n+/jqyisRgVnb52iaAQaFJOmPXp1MU3H3j67qkLuDhsY47kReDXM89raVcyr4Tp85Yn4/MUicV2sdle+7jHvMjxZR0imS9S4KeL+XFe57deO/xmlXwoh6GmwK0wv4CaOutk7vrYUe/plOApqgVFI/LPmbAlP1+5rHDcfmCw6+I2qVGmz/tb9t8ah4dmhpzn+rBsxU4bgDmUfsYfNE3A3rDyXItZQSfXSJ2FQyXWMvv6ahTvI3zRUt3JT0MFTie3otc2Q57HMK2u+tqBUrlEqdEO8kC68ee/gD1ipCExt1L8n7ubjBIuN+VLarGcZYt5J9nGSG9bl2Fj/hufvd1434HYdWuxbQBOtSenD8i1TZsb8kjObjsECdO2dXrJfB4vEHK+QsW+p6GEGVgs9I1045nA6I3SbvjU/xVJbH4XP2toJWzMSpyQHQFPU2RbtbpdKIE9U+QJEQTnRoYOHKszCY/W092ASdyootUugshUcK+IUJUZrKHCbG3ATZvmx1nUWW3m79iNta2kNShH/NaxaQCri7q6joH+OlL/xIe76IBAdr07NKg4AXlnmAfzZUCcdTl4LKeTUSGRZcb5tYtcK2bBcV1ChiO5OQuLfRUPKvM5RzvbTENwuyLQOAs0GPLMeyXu5p+/B25QSj0XsIkhI/g0ye4CJcPLfFEQXQxkrR09lOcoeosFU2iu9L88AeJLu1gFqnFOdy4lr+HwJgNV75k3VWhMbzV9QUIn6UUT9tyDMQ9kcJJM29Iu++A9bxVuB84nG303FYuHr7z1r4EaoCc9sspBGVnAmN48LftdZMguMinFN5f7XBFCHr0DhgHJhbUgDGuqGsR7ULvIGeNDLEI3VSENYXpDOzk7jjQLeq2V4L7dYN3I3+mNqJ s568bbOp vNi9Pd0UXMjZsX4j7TXKMxm3o6qvPdvQvSPOMIPRrw6qYxihQM/sc5XcmJyxuj4k3XJvtfRI5+c1nqg7kP5CmM/zmyYnAgEObQ+t/WUcQSL0sYQTzHkpUDNjcmpSeF/msX4cl 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: 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); }