From patchwork Thu Jul 4 04:31:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oscar Salvador X-Patchwork-Id: 13723201 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 40CBBC3271F for ; Thu, 4 Jul 2024 04:32:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1086D6B00AE; Thu, 4 Jul 2024 00:32:23 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0905C6B00AF; Thu, 4 Jul 2024 00:32:23 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DFB326B00B0; Thu, 4 Jul 2024 00:32:22 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id B9D906B00AE for ; Thu, 4 Jul 2024 00:32:22 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 79B231A08BE for ; Thu, 4 Jul 2024 04:32:22 +0000 (UTC) X-FDA: 82300798524.10.878171E Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) by imf04.hostedemail.com (Postfix) with ESMTP id 65B3740004 for ; Thu, 4 Jul 2024 04:32:20 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1720067527; 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; bh=zjLSe21IECWIlLwNB5/Nlo0ijeI0XlWwGvDlsWxpGWs=; b=L5OBqppfVmf8/jkUh1q84F0+/WitSpZrDPa581ITMbZTG4SXWiQQAU1MFd64etp5MLlwLK koR0ls/jgzC+QNKsb5GYZJ7Fl6zQQdL+vRtePFE7ZvD/RxBrD+GgM2YSbyKqu/8a3UG9vH q19tjuKImSuiP6fygKSmNAs+b87hEnY= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of osalvador@suse.de designates 195.135.223.130 as permitted sender) smtp.mailfrom=osalvador@suse.de; dmarc=pass (policy=none) header.from=suse.de ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1720067527; a=rsa-sha256; cv=none; b=ABxVfvghmEx5IyO4lbor/Yat6ZUus/bFIUMHbPo21+j0ORWIJVAuXRaWKDhhRDKgF9YtZz 9VJlx9i/mTTWqoGLsDSM5TVegUYyoo2kDAgox6E0oy5nSFjp6iPNjLSsxZ8ysrBBgrmTXf fn5nZ+IP9OkQiUBmx92D+4i98KJt7io= Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 2B07D21C0D; Thu, 4 Jul 2024 04:32:19 +0000 (UTC) Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 06B6F13889; Thu, 4 Jul 2024 04:32:17 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id cMqbONElhmbnDAAAD6G6ig (envelope-from ); Thu, 04 Jul 2024 04:32:17 +0000 From: Oscar Salvador To: Andrew Morton Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, Peter Xu , Muchun Song , David Hildenbrand , SeongJae Park , Miaohe Lin , Michal Hocko , Matthew Wilcox , Christophe Leroy , Oscar Salvador Subject: [PATCH 23/45] mm/mempolicy: Create queue_folios_pud to handle PUD-mapped hugetlb vmas Date: Thu, 4 Jul 2024 06:31:10 +0200 Message-ID: <20240704043132.28501-24-osalvador@suse.de> X-Mailer: git-send-email 2.44.0 In-Reply-To: <20240704043132.28501-1-osalvador@suse.de> References: <20240704043132.28501-1-osalvador@suse.de> MIME-Version: 1.0 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Action: no action X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: 65B3740004 X-Stat-Signature: e5g1snwt8m5ijza1hu66y5rwwt6sqe5y X-Rspam-User: X-HE-Tag: 1720067540-971529 X-HE-Meta: U2FsdGVkX1+8ZHZ/XQo6ChzJ01BIfzSo7IPFWOBif9hbhYj5pWLM9dP8O/H8jruzTgphxvBw3p+vUsQORPsle+O8wtU3LP8cVSkQqG+Ckr3T9cqC1E62AiQWp8N3otyoSoFGGBUmaTYxX2tAQF0dk1QrOTe1/kRHnC1p0zNi6WKkv3XhnHMPDhSVECSqLHBlF+CeanDwicftANZerYi8bCLGyOrzjx9zuxJyHulnEmg3De1N9Yiqr1vlaDY/d30cQItUcMA58Gfe8SdC+b72ahM/t+yirEhPNul5srskgl5y0mqBHtQZ9IoaqkqRig47nSN1zTTr03FScUUw6BCD8kzD/1KBJG1CrOrbVgRiiZm6XcOaHam+PSu0knP8iCf7qjAjsM9+tn0PBdpoHJSoaTEltbs+gASSpUcokdkRma2ZPP5C6qQUNXCo+0FImn2cp+AzTpUdIkKKTIk9A6bPyrWgfRk4qk8ACeKwZeID8XapcjiBhyMJKp5UtxbKZGrfqchwttyUCvI5OAUCLPAg2n2UgF2CEwqRZgklt7N2o50ZHd3lDUqWXLDgrV77tmLkN9aSYMYMHwdblJuEBbwfn2wUMxjgJtD1Hh2dbqu6wx2rA+mpeepVt0UqCM74TdUtF2OOq60pH5I0dr+zYxhUtqaApLwR7B5WlPy+tSIQyQnejVHHwpVrZ2DcUgHt0wj26j2RIs1t5KcYu/zuHOk0adglx/c5G8CluMrEUyalau6ShSYyR+o0u34queLKO34F1vqw7DV5u3UznGpd7assDrsI64NJ5BeJFxLDYgHnADolJl9rspGAZ9cktJJ32t5Cu2GGz7DdsnHJUhU7UBt3efw2dKFLTkQUfpNpaqx+VkCAn8+oxm8VF8tSDUAQseiS9dNS1AZyC9Zfjed8FYCJ4gt9/cNXcptbJ9bulApVtLfEOWu+EX5iuHiBuIRw9b5enySKrS6UKBOLV6dgh8o 05HcuwBc 0IpUPtTMUgswyCxMzZ16oWUGO/7v4e2x4qR3W3o7HpDqYtmz9z0JfnhqK6A8NEVOXF80BDIBLkU+L33m+uWTGXF8ZcdC0Tm92fe7VpHpZmLu5t80UcLHxYF37+a/g6Eug9IdchxR2j25i5Xt4NNOb9NISyqq63iQ1sUkTyzHPJ/1zwBk= 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: List-Subscribe: List-Unsubscribe: Normal THP cannot be PUD-mapped (besides devmap), but hugetlb can, so create queue_folios_pud in order to handle PUD-mapped hugetlb vmas. Also implement is_pud_migration_entry and pud_folio, as they will be used in this patch. Signed-off-by: Oscar Salvador --- include/linux/pgtable.h | 1 + include/linux/swapops.h | 12 ++++++++++++ mm/mempolicy.c | 32 ++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+) diff --git a/include/linux/pgtable.h b/include/linux/pgtable.h index 458e3cbc96b2..23d51fec81ac 100644 --- a/include/linux/pgtable.h +++ b/include/linux/pgtable.h @@ -51,6 +51,7 @@ #endif #define pmd_folio(pmd) page_folio(pmd_page(pmd)) +#define pud_folio(pud) page_folio(pud_page(pud)) /* * A page table page can be thought of an array like this: pXd_t[PTRS_PER_PxD] diff --git a/include/linux/swapops.h b/include/linux/swapops.h index 182957f0d013..a23900961d11 100644 --- a/include/linux/swapops.h +++ b/include/linux/swapops.h @@ -542,6 +542,18 @@ static inline bool is_pfn_swap_entry(swp_entry_t entry) struct page_vma_mapped_walk; +#ifdef CONFIG_HUGETLB_PAGE +static inline int is_pud_migration_entry(pud_t pud) +{ + return is_swap_pud(pud) && is_migration_entry(pud_to_swp_entry(pud)); +} +#else +static inline int is_pud_migration_entry(pud_t pud) +{ + return 0; +} +#endif + #ifdef CONFIG_ARCH_ENABLE_THP_MIGRATION extern int set_pmd_migration_entry(struct page_vma_mapped_walk *pvmw, struct page *page); diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 5baf29da198c..93b14090d484 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -501,6 +501,37 @@ static inline bool queue_folio_required(struct folio *folio, return node_isset(nid, *qp->nmask) == !(flags & MPOL_MF_INVERT); } +static int queue_folios_pud(pud_t *pud, unsigned long addr, unsigned long end, + struct mm_walk *walk) +{ + spinlock_t *ptl; + struct folio *folio; + struct vm_area_struct *vma = walk->vma; + struct queue_pages *qp = walk->private; + + ptl = pud_huge_lock(pud, vma); + if (!ptl) + return 0; + + if (unlikely(is_pud_migration_entry(*pud))) { + qp->nr_failed++; + goto out; + } + folio = pud_folio(*pud); + if (!queue_folio_required(folio, qp)) + goto out; + if (!(qp->flags & (MPOL_MF_MOVE | MPOL_MF_MOVE_ALL)) || + !vma_migratable(walk->vma) || + !migrate_folio_add(folio, qp->pagelist, qp->flags, walk->vma, false)) + qp->nr_failed++; + + spin_unlock(ptl); +out: + if (qp->nr_failed && strictly_unmovable(qp->flags)) + return -EIO; + return 0; +} + static void queue_folios_pmd(pmd_t *pmd, struct mm_walk *walk) { struct folio *folio; @@ -730,6 +761,7 @@ static int queue_pages_test_walk(unsigned long start, unsigned long end, static const struct mm_walk_ops queue_pages_walk_ops = { .hugetlb_entry = queue_folios_hugetlb, + .pud_entry = queue_folios_pud, .pmd_entry = queue_folios_pte_range, .test_walk = queue_pages_test_walk, .walk_lock = PGWALK_RDLOCK,