From nobody Sat Feb 7 21:15:29 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38424211A3B for ; Fri, 10 Jan 2025 18:21:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736533319; cv=none; b=tBSsbUw+0pzzesV1JNxY4d3yposf8h5N6jB1tsUZTtKRWj+LWJlawbBlcFaX9AIkecT41yh6XxckmRP4JIjtBWoMaQ83xMuyoQIswYAsiziacxsQ7E/FexQ1oRI5TT3EWjzenONPrnUwDR8DNEnfu0tHZfrgw3x2D2uR/lUlzRk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736533319; c=relaxed/simple; bh=+MWWPlqCmvUhj/Rtce7ZzsYKfy/qc8fWZpevL+AhAxo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=UTDxzEMtx6bMPNxN608Di3XzmESeoETAFVAcIKgBfFaWKp6ZWPlF2fkBopC7phat2xejhdbm1cIG5jOu13lWrO+usMTvLq+q95qfSgICwCWo0fuVDPn/wzGjPIMJfwGU4EN/Jbtk56Pjr3fytSLVHrUVrZmxZjklTdXY4zoswt0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=f9IdTpeV; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="f9IdTpeV" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736533317; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=QDSAyCtg1fX0bp4z+4H4qfpYEbFsAwRyrL3Z8KQqD4k=; b=f9IdTpeVu6jvhsYpXnBYTMLzGrv/yYcyCyd9GPSxr/QD1NjB8qsCZjxKSnr5TzDIOHGyXN Qz5WsaOKwgB3R39v+tZy1hWfTBfoJLHJ6pQ4w8e29HTKF+X84PnN7HqIm7ulcr8kMII7a/ tsKNl5T/6Z0lY4oFMiLBP0+QH4/xJfw= Received: from mail-wm1-f71.google.com (mail-wm1-f71.google.com [209.85.128.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-607-Plru_hO3PSSmiR0Ec8oarA-1; Fri, 10 Jan 2025 13:21:55 -0500 X-MC-Unique: Plru_hO3PSSmiR0Ec8oarA-1 X-Mimecast-MFC-AGG-ID: Plru_hO3PSSmiR0Ec8oarA Received: by mail-wm1-f71.google.com with SMTP id 5b1f17b1804b1-436723db6c4so16305345e9.3 for ; Fri, 10 Jan 2025 10:21:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736533315; x=1737138115; 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=QDSAyCtg1fX0bp4z+4H4qfpYEbFsAwRyrL3Z8KQqD4k=; b=kJK9972uB+Rw9UU5BUq2I99E19DvpJwVSBwnsHfm0aG3L1dBztRnJOhM4YM/JSjp2c O0eliuXkjG+XnW93/7G9/yj7FlsJFkQXCZTuUN495qOHAdaHozaHiNo216I5mewo7ZnP 1sKxud5x0n4nt4mBz0H/C0yUYbjI3AAoHbR7X2GF7mUqWOJWLxxIPj/1yXQDirsccf93 AlSYkfZ1i8tvlTPVR65pE0BSaCnU9tIPaHDM8nXVLOaoF3gqnqjpeLJlrOr1eX2aX8DJ eHr0oVCTDc8u0VLtBz8P2bVR7X5GJYoSyEKNcLrFH+D0JdXgva/0C+q5NRRGJDOOdKP2 u7CQ== X-Gm-Message-State: AOJu0Yzb/nZHC3nNdwnI/b0GD356mrIf7OXjBBWCfAGKDDAufaIBV2Rc FTW9x3+pjVmdXG7XTFbqdpeE1KEC1NncgfWv5/Xt0gOMNTsWei8xIPwQO4e4D1omdArpNmyFmum FEnLXwPxBs0Yc5R3idKfDIdHS7U3xdGjpi4Ic89bRuxCzunRo+N6Y/c94ZnpPt4cigzLW5lxZOF NFEaO/6WIqa0NAV11qKP9Xc2tOfuiGwcMqI3hegPhWQAr9 X-Gm-Gg: ASbGncs1zrnN4OcOoAmQzjgD0/RRGv/svcz0dgPHSTKO+3Bk6p0VRAbRJoK6WG8wEjd O7f+Xacjc9Qh4d4h1UXMdZfJ8mueIEA1g5rKLKB3bIu3qXN6ffp1wqWMO+8Xfeko/jLSy9Sjsyn jJBGmrSVzaLTcQEF31j4TX4p+eEGeCxWTeHAc8wU9gcE6UqH+i0VnnhorrV8jicmVOxeGU1MlbR CrrwWYDM/NwkXYZO5vqNz3AWP2WbSIyVJOjNe9t081mJ336tY31DQj1zl7FLpc3NsK98B6nM6K6 GzURwSJtabvOlMzRHRtPVkGb6rDN/a9SDZ943E+yKA== X-Received: by 2002:a05:600c:4fc6:b0:435:172:5052 with SMTP id 5b1f17b1804b1-436e2686492mr96784455e9.1.1736533314849; Fri, 10 Jan 2025 10:21:54 -0800 (PST) X-Google-Smtp-Source: AGHT+IEo3WdtgynR79gKF0TnPXRhuxMI+Oij1Fl43vOkRd3CWqDDLxRyW9C4c5GgRBUMq5QKHX25YA== X-Received: by 2002:a05:600c:4fc6:b0:435:172:5052 with SMTP id 5b1f17b1804b1-436e2686492mr96784245e9.1.1736533314489; Fri, 10 Jan 2025 10:21:54 -0800 (PST) Received: from localhost (p200300cbc708e1004f41ff29a59f8c7a.dip0.t-ipconnect.de. [2003:cb:c708:e100:4f41:ff29:a59f:8c7a]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-436dd11ddfdsm77133265e9.1.2025.01.10.10.21.53 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 Jan 2025 10:21:54 -0800 (PST) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Muchun Song , "Matthew Wilcox (Oracle)" Subject: [PATCH v1 1/6] mm/huge_memory: convert has_hwpoisoned into a pure folio flag Date: Fri, 10 Jan 2025 19:21:44 +0100 Message-ID: <20250110182149.746551-2-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250110182149.746551-1-david@redhat.com> References: <20250110182149.746551-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Let's stop setting it on pages, there is no need to anymore. Signed-off-by: David Hildenbrand Reviewed-by: Matthew Wilcox (Oracle) --- include/linux/page-flags.h | 6 ++---- mm/huge_memory.c | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index 14226d6bd6f84..3f6a64ff968a7 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -948,11 +948,9 @@ TESTPAGEFLAG_FALSE(TransCompound, transcompound) * * This flag is set by hwpoison handler. Cleared by THP split or free pag= e. */ -PAGEFLAG(HasHWPoisoned, has_hwpoisoned, PF_SECOND) - TESTSCFLAG(HasHWPoisoned, has_hwpoisoned, PF_SECOND) +FOLIO_FLAG(has_hwpoisoned, FOLIO_SECOND_PAGE) #else -PAGEFLAG_FALSE(HasHWPoisoned, has_hwpoisoned) - TESTSCFLAG_FALSE(HasHWPoisoned, has_hwpoisoned) +FOLIO_FLAG_FALSE(has_hwpoisoned) #endif =20 /* diff --git a/mm/huge_memory.c b/mm/huge_memory.c index 2654a95487499..3d3ebdc002d59 100644 --- a/mm/huge_memory.c +++ b/mm/huge_memory.c @@ -3290,7 +3290,7 @@ static void __split_huge_page(struct page *page, stru= ct list_head *list, /* lock lru list/PageCompound, ref frozen by page_ref_freeze */ lruvec =3D folio_lruvec_lock(folio); =20 - ClearPageHasHWPoisoned(head); + folio_clear_has_hwpoisoned(folio); =20 for (i =3D nr - new_nr; i >=3D new_nr; i -=3D new_nr) { struct folio *tail; --=20 2.47.1 From nobody Sat Feb 7 21:15:29 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F17592144D4 for ; Fri, 10 Jan 2025 18:22:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736533323; cv=none; b=NRykFE04GKsdQV5E1W+DdXmF4YgiSXfLmdQlr9UVgVis44kcDTd9xFlT/q35Yu48jIzPlbwoj43ka35aghNJYbv1ZSvmKTJOaAcEkf+px7zbKNdcXs+hdREA/+/KwSz0iL3bWdaJA7GC2COqR9FgVh/2J3in4yDisixetp49n1k= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736533323; c=relaxed/simple; bh=x+jx+lZFi9RdGo//UuHj5uXGcSqk3aKdpGA/LUS/wTM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=DbJtT9UjcXT+aPyjqst9GwukVijHxMR5GHPji3BJNiOEx40itj+X+KhzgPMbHCczt1F/zHKOF3gMgrZa7exhFgev5GhvPvXvuMAAw+/l+4EYv0HkjS5O6TbrugnGSwoBde8PPTMbAMWY7JcVOYsPdtRIx7vE7R2udI8kG5DtJm4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=ddud1pXY; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="ddud1pXY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736533320; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=tRBcf145a4wbVi9jTDlwWferknOn1sr5Qv/yEdUMYsU=; b=ddud1pXY8Kk/NaNB/k2flYjZqOwr5s+yAXzOTP0b2pIOSdW0ocarCUcgDxONxhov6cFYHQ kUNac905y23ttkiU9t3RFY0kXdPX+sw+FoxaHC89h8uNS8knvh6/3zUYpnfLdqqYE3hZkT FV1WsrCfEpOB1eSfMOlva7CCunEALkI= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-308-7pl9SbOgP5GVT4ODLqOIFw-1; Fri, 10 Jan 2025 13:21:59 -0500 X-MC-Unique: 7pl9SbOgP5GVT4ODLqOIFw-1 X-Mimecast-MFC-AGG-ID: 7pl9SbOgP5GVT4ODLqOIFw Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-3862c67763dso921854f8f.3 for ; Fri, 10 Jan 2025 10:21:59 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736533318; x=1737138118; 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=tRBcf145a4wbVi9jTDlwWferknOn1sr5Qv/yEdUMYsU=; b=f0IJQC+8ti2dRFxNPP5X0Fv7S2uesdwpMw8OOKFRG87m/GzbeZuj0gsRUI2Msyl9pI JSjk/Vebi7OM2MQSyzUdMZQRJsBuKquzGMM7Ayej88ijbTVJ35twUJdNu/epkbMD3/63 bt9ubM/UNQpauSx1KeoA6JVghrIoDg+mXxR1m+EaPC0rHnPAU7NOXB0zhyozxffsELOx ouIHTghuCX3/+ZFnj9M446gnI57KABDx96oX3n9i9evysYFjmO9zcF5emn2PqsKXVFkI 4FUjL9qoegp1RnFeab6I4QSY81JoPDt6BdkyJls9637Dh4dQOB9ZeMQ3vmPaJJi7JQ9O 0Neg== X-Gm-Message-State: AOJu0YxRRmPsXs0FqVC9dTUeseUBpfm0sGZh8iij2Wmd6Py+KdOgxFXI D3rwQQV4eeGJRky8ApozV8UxgwDVgpBmK2S5qsayNirgwA5Z3lxwER+jwgU7N75EkIvAZaIP3NU Mz9vbbPftUDcEmiNO2W2EF90ZgjotlknOxh2hXyxvmqRwOtDE0D/4FquY3kh3hluFDwtBQ/lw0q FKeE78aR3bf9qrAFbRhyPVFOZcp73osE1fVhO7YRci1mq7 X-Gm-Gg: ASbGncu3zh5kdJtbk3DMCt/7radPD1Ep/NSZXB8gySau0xZZMgvqMeO9ehwucUUowgf obYepp92f3N+u5fSiv42WN2WORwY4aDbmzAt6DV08rTqD6APUlur50mt6vVyxr/ilNXJ0+ohA1c YroXvlWdvzW+1tZxOMTnZMi38qEnAAxXPxbi8tBJXoAgiiFEPmONvW/diQGvjsoPDnz+1d81JDf 5WsmWyOjp3NTr8LLwRzJ60AmjNmH9nfipgmP8XSPuTnEdgX7XHt1EL02/wifdrdO0wblSE0avIt R5CylaYnog+iomtMge4VrdGKKyg/0j16S/9FIZoAVQ== X-Received: by 2002:a5d:64ce:0:b0:385:f092:e16 with SMTP id ffacd0b85a97d-38a87358eaamr10067260f8f.55.1736533317703; Fri, 10 Jan 2025 10:21:57 -0800 (PST) X-Google-Smtp-Source: AGHT+IEQVVcAg2GfKFgY/NCz7qN+LDaq6+VWQgH7WNixvGBrnqPMWFIuBEKOik8O9disKHaGf0f0SA== X-Received: by 2002:a5d:64ce:0:b0:385:f092:e16 with SMTP id ffacd0b85a97d-38a87358eaamr10067233f8f.55.1736533317258; Fri, 10 Jan 2025 10:21:57 -0800 (PST) Received: from localhost (p200300cbc708e1004f41ff29a59f8c7a.dip0.t-ipconnect.de. [2003:cb:c708:e100:4f41:ff29:a59f:8c7a]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38a8e3838a3sm5187851f8f.33.2025.01.10.10.21.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 Jan 2025 10:21:56 -0800 (PST) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Muchun Song , "Matthew Wilcox (Oracle)" Subject: [PATCH v1 2/6] mm/hugetlb: rename isolate_hugetlb() to folio_isolate_hugetlb() Date: Fri, 10 Jan 2025 19:21:45 +0100 Message-ID: <20250110182149.746551-3-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250110182149.746551-1-david@redhat.com> References: <20250110182149.746551-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Let's make the function name match "folio_isolate_lru()", and add some kernel doc. Signed-off-by: David Hildenbrand Reviewed-by: Baolin Wang Reviewed-by: Matthew Wilcox (Oracle) --- include/linux/hugetlb.h | 4 ++-- mm/gup.c | 2 +- mm/hugetlb.c | 23 ++++++++++++++++++++--- mm/mempolicy.c | 2 +- mm/migrate.c | 6 +++--- 5 files changed, 27 insertions(+), 10 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 49ec2362ce926..c95ad5cd7894d 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -153,7 +153,7 @@ bool hugetlb_reserve_pages(struct inode *inode, long fr= om, long to, vm_flags_t vm_flags); long hugetlb_unreserve_pages(struct inode *inode, long start, long end, long freed); -bool isolate_hugetlb(struct folio *folio, struct list_head *list); +bool folio_isolate_hugetlb(struct folio *folio, struct list_head *list); int get_hwpoison_hugetlb_folio(struct folio *folio, bool *hugetlb, bool un= poison); int get_huge_page_for_hwpoison(unsigned long pfn, int flags, bool *migratable_cleared); @@ -414,7 +414,7 @@ static inline pte_t *huge_pte_offset(struct mm_struct *= mm, unsigned long addr, return NULL; } =20 -static inline bool isolate_hugetlb(struct folio *folio, struct list_head *= list) +static inline bool folio_isolate_hugetlb(struct folio *folio, struct list_= head *list) { return false; } diff --git a/mm/gup.c b/mm/gup.c index 00a1269cbee0a..2cc3a9d28e70e 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -2344,7 +2344,7 @@ static unsigned long collect_longterm_unpinnable_foli= os( continue; =20 if (folio_test_hugetlb(folio)) { - isolate_hugetlb(folio, movable_folio_list); + folio_isolate_hugetlb(folio, movable_folio_list); continue; } =20 diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 9a5596022c4b3..da98d671088d0 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -2808,7 +2808,7 @@ static int alloc_and_dissolve_hugetlb_folio(struct hs= tate *h, * Fail with -EBUSY if not possible. */ spin_unlock_irq(&hugetlb_lock); - isolated =3D isolate_hugetlb(old_folio, list); + isolated =3D folio_isolate_hugetlb(old_folio, list); ret =3D isolated ? 0 : -EBUSY; spin_lock_irq(&hugetlb_lock); goto free_new; @@ -2893,7 +2893,7 @@ int isolate_or_dissolve_huge_page(struct page *page, = struct list_head *list) if (hstate_is_gigantic(h)) return -ENOMEM; =20 - if (folio_ref_count(folio) && isolate_hugetlb(folio, list)) + if (folio_ref_count(folio) && folio_isolate_hugetlb(folio, list)) ret =3D 0; else if (!folio_ref_count(folio)) ret =3D alloc_and_dissolve_hugetlb_folio(h, folio, list); @@ -7417,7 +7417,24 @@ __weak unsigned long hugetlb_mask_last_page(struct h= state *h) =20 #endif /* CONFIG_ARCH_WANT_GENERAL_HUGETLB */ =20 -bool isolate_hugetlb(struct folio *folio, struct list_head *list) +/** + * folio_isolate_hugetlb: try to isolate an allocated hugetlb folio + * @folio: the folio to isolate + * @list: the list to add the folio to on success + * + * Isolate an allocated (refcount > 0) hugetlb folio, marking it as + * isolated/non-migratable, and moving it from the active list to the + * given list. + * + * Isolation will fail if @folio is not an allocated hugetlb folio, or if + * it is already isolated/non-migratable. + * + * On success, an additional folio reference is taken that must be dropped + * using folio_putback_active_hugetlb() to undo the isolation. + * + * Return: True if isolation worked, otherwise False. + */ +bool folio_isolate_hugetlb(struct folio *folio, struct list_head *list) { bool ret =3D true; =20 diff --git a/mm/mempolicy.c b/mm/mempolicy.c index f83b73236ffe7..bbaadbeeb2919 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -647,7 +647,7 @@ static int queue_folios_hugetlb(pte_t *pte, unsigned lo= ng hmask, */ if ((flags & MPOL_MF_MOVE_ALL) || (!folio_likely_mapped_shared(folio) && !hugetlb_pmd_shared(pte))) - if (!isolate_hugetlb(folio, qp->pagelist)) + if (!folio_isolate_hugetlb(folio, qp->pagelist)) qp->nr_failed++; unlock: spin_unlock(ptl); diff --git a/mm/migrate.c b/mm/migrate.c index caadbe393aa21..80887cadb2774 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -128,7 +128,7 @@ static void putback_movable_folio(struct folio *folio) * * This function shall be used whenever the isolated pageset has been * built from lru, balloon, hugetlbfs page. See isolate_migratepages_range= () - * and isolate_hugetlb(). + * and folio_isolate_hugetlb(). */ void putback_movable_pages(struct list_head *l) { @@ -169,7 +169,7 @@ bool isolate_folio_to_list(struct folio *folio, struct = list_head *list) bool isolated, lru; =20 if (folio_test_hugetlb(folio)) - return isolate_hugetlb(folio, list); + return folio_isolate_hugetlb(folio, list); =20 lru =3D !__folio_test_movable(folio); if (lru) @@ -2203,7 +2203,7 @@ static int __add_folio_for_migration(struct folio *fo= lio, int node, return -EACCES; =20 if (folio_test_hugetlb(folio)) { - if (isolate_hugetlb(folio, pagelist)) + if (folio_isolate_hugetlb(folio, pagelist)) return 1; } else if (folio_isolate_lru(folio)) { list_add_tail(&folio->lru, pagelist); --=20 2.47.1 From nobody Sat Feb 7 21:15:29 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8C4C02139B6 for ; Fri, 10 Jan 2025 18:22:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736533326; cv=none; b=TG+3h52+icWbU8c6qSyehQw6nxn6fe8BaFXNdv/tX2QI4Tg0FHqzXmCawGGTk2viec3bX9U0ZKIiLKPHEG6b1AOvWTmvCsXoiPQ7u5d5ZdK/UKBIFiEVtF+DXr5G/3LTV8Z36qtxNbBVlvSEvrJnmoU7i/TAmjmfla0NF8A+2l8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736533326; c=relaxed/simple; bh=baQ9XIDqSvAwquPXxSXI3giATBOT6DgOA+vM19Qyddg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=LRmB7zpFmnMQZVpgEXNiU9xvo1qvz8zAOwxmSZBaHymcfOFm1yUXdw3qnHElUHfYH3Ph3A7w1Vks7vyqFzV13/z7+FTJNNiNOy/4XSkXT0TQLjHCJ1+JIoMjhhxQ2fNDCz1Q14u+kY6rnIptH4nbv1eYQKZlcUMlTzDSvXLFklA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=WuO8P/lY; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="WuO8P/lY" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736533323; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=v8hq4g4DhybxUwRn0BKWdtx8BUqV1Iw/Qc0FsV0dDNg=; b=WuO8P/lYbO6WgADyMdHJBQTySIK+Mvr4M4buT/TooP2iciWN69/rg2cwLxi8pdaWkueHqT K7peoWDaJRT0vl4ExIqSf/r+Ya4WLGLk0eyhONn1Kb2XTQAMlN7bALKkBc1In6Ty+HJhjq 1FYSSXal4G7LrUY4pxEXpjZdHVQqans= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-664-kVGkUQJdOR-SAU5COAqSmQ-1; Fri, 10 Jan 2025 13:22:02 -0500 X-MC-Unique: kVGkUQJdOR-SAU5COAqSmQ-1 X-Mimecast-MFC-AGG-ID: kVGkUQJdOR-SAU5COAqSmQ Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-436248d1240so11481425e9.0 for ; Fri, 10 Jan 2025 10:22:01 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736533321; x=1737138121; 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=v8hq4g4DhybxUwRn0BKWdtx8BUqV1Iw/Qc0FsV0dDNg=; b=jq5yXMaqgSSiQfz4tn4iEeBb7D2zHi3S5b4MCJi+SMwYMzp+wHqtiQi0R2zYO/514u y8GXHfLvWvRWdxgPGlqTrnAiuvsWxJKUuUtL/Nj8g0bO0JwwT30aoTmSddpdM+XKHyB+ hQhuys5/qPB9PnOIQUo3CLOjC041zkCfQaMX967lm9AJOGVW84uotZEIb2+cE5nekczR 3nI9f9GMMJqpN3ioPPT8xpgSvEnx1XiaKSs2OmgY4EqnaO4ajT4ArZP3U96tJV1PLGS3 F7RWdEyd2iO+L2nCeWNulQ232skfqaYmdeZ+4u+pGQHZG7trdTlHyG+smn/z1tB945al 9k9Q== X-Gm-Message-State: AOJu0YyeinpcFPYZB6gtlzML9rx7Vj4W4wrP9x8g7oqxdJOKTMA755XE QM+do5M6UcmatmuL+rwyoOez8Ij4vIwif9wOjUry7/MTpQkVuNJ5quMskQufaFQZ7ougP9BckD8 xTpJLx4+Y3/LAgldQltygVLH5j6REGb6tDdx/BrEEvHcu9BgLAflcXdYqW0E9FnwZgpBGxExyq9 z195I5yVzGUkH6CV/YGTV8wNiRhstw4/0Hpnvevferdg8R X-Gm-Gg: ASbGncs4Sdr9aaTw9VSe7kIZpqD+SKBcZe/502Asl22d3BWUph6/0cCrA3Ag0yMYEAb aXl9YHRLy2RaCbf9VygRtWOIki5ryUJPkIOkEkrFAAglyrO+tuJ94sm2uuUbPsuc8T0ed2mZR9Y c6lV6txqGFFUMuzHVo8E2Ya9nltgbjiTuvjhxzMPVdnKqxLsvDhTS8FJR9N5gPeEtjxPTeyQI2p +os05Iv0LcsSYPTZ7gRX2EjM8uRf3cpLqgQgsDteJ1+WTjxFD2AS/Iccuit9Ndu3WSqpMtyjsYL hguvoGjq/5mfYvvxie0fPzeTjBK0pFHhgH1zaLy4Ig== X-Received: by 2002:a5d:648b:0:b0:386:3e3c:ef1 with SMTP id ffacd0b85a97d-38a87312f36mr11978777f8f.35.1736533320899; Fri, 10 Jan 2025 10:22:00 -0800 (PST) X-Google-Smtp-Source: AGHT+IHsNI1nT/mSiB4lNoNG7hpy+n586x8LDR/iUFuGNavqE1Zjg9u3TYOy+Hd2kEulLAgwJ82EoA== X-Received: by 2002:a5d:648b:0:b0:386:3e3c:ef1 with SMTP id ffacd0b85a97d-38a87312f36mr11978752f8f.35.1736533320488; Fri, 10 Jan 2025 10:22:00 -0800 (PST) Received: from localhost (p200300cbc708e1004f41ff29a59f8c7a.dip0.t-ipconnect.de. [2003:cb:c708:e100:4f41:ff29:a59f:8c7a]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-436e2da66d9sm95077415e9.1.2025.01.10.10.21.58 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 Jan 2025 10:21:59 -0800 (PST) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Muchun Song , "Matthew Wilcox (Oracle)" Subject: [PATCH v1 3/6] mm/migrate: don't call folio_putback_active_hugetlb() on dst hugetlb folio Date: Fri, 10 Jan 2025 19:21:46 +0100 Message-ID: <20250110182149.746551-4-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250110182149.746551-1-david@redhat.com> References: <20250110182149.746551-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We replaced a simple put_page() by a putback_active_hugepage() call in commit 3aaa76e125c1 ("mm: migrate: hugetlb: putback destination hugepage to active list"), to set the "active" flag on the dst hugetlb folio. Nowadays, we decoupled the "active" list from the flag, by calling the flag "migratable". Calling "putback" on something that wasn't allocated is weird and not future proof, especially if we might reach that path when migration failed and we just want to free the freshly allocated hugetlb folio. Let's simply set the "migratable" flag in move_hugetlb_state(), where we know that allocation succeeded, and use simple folio_put() to return our reference. Do we need the hugetlb_lock for setting that flag? Staring at other users of folio_set_hugetlb_migratable(), it does not look like it. After all, the dst folio should already be on the active list, and we are not modifying that list. Signed-off-by: David Hildenbrand Reviewed-by: Baolin Wang --- mm/hugetlb.c | 5 +++++ mm/migrate.c | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index da98d671088d0..b24ccf8ecbf38 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -7529,6 +7529,11 @@ void move_hugetlb_state(struct folio *old_folio, str= uct folio *new_folio, int re } spin_unlock_irq(&hugetlb_lock); } + /* + * Our old folio is isolated and has "migratable" cleared until it + * is putback. As migration succeeded, set the new folio "migratable". + */ + folio_set_hugetlb_migratable(new_folio); } =20 static void hugetlb_unshare_pmds(struct vm_area_struct *vma, diff --git a/mm/migrate.c b/mm/migrate.c index 80887cadb2774..7e23e78f1e57b 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1542,14 +1542,14 @@ static int unmap_and_move_huge_page(new_folio_t get= _new_folio, list_move_tail(&src->lru, ret); =20 /* - * If migration was not successful and there's a freeing callback, use - * it. Otherwise, put_page() will drop the reference grabbed during - * isolation. + * If migration was not successful and there's a freeing callback, + * return the folio to that special allocator. Otherwise, simply drop + * our additional reference. */ if (put_new_folio) put_new_folio(dst, private); else - folio_putback_active_hugetlb(dst); + folio_put(dst); =20 return rc; } --=20 2.47.1 From nobody Sat Feb 7 21:15:29 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9E82121423F for ; Fri, 10 Jan 2025 18:22:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736533333; cv=none; b=UIvcAsUBHEYJ7z+yBFLrybB7UfpkofAuSFE5I4reSoiY811lOtHouvzjn54S7SglZp4BYsvbe+aoHLgdtHzVujVJdx27iz5GmZHgMQEEuQYRG4ujJ+xHEiThzQWROJvVS+6Tv3PpY67VM4r4eiqT57k3d+ssoHoI9OlC2vroDbY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736533333; c=relaxed/simple; bh=iEK/YDu+08UL/AKxpodbweKdplQEIahFN4WAYnoKPUg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=OSI5oBg92MKb+bZL+B9XB/A6W66zWUqv7XIKh4KeCZAaQyuXGXikuI4A+n0t/6ROP6aQ+HnB69nN/LOmhQ7IVWdLMMigDx80oHwOyS4vmN1HyOF+3HtHkpLSrshWGiYGSaTrUEP1fGsEQStx7h3Dppl/u0K/KN5oQX8bNJJ/i6o= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=H+EA3ouH; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="H+EA3ouH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736533330; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OXRC2m94ydMkiYC7QjOXtCup/ACjP0VRhTV9k+2JNqs=; b=H+EA3ouH8SNWi9lyxWAqC2iOQTtHPELzGlJ9zNJ1fuYyNXjA26c9JUx+T+6knmVws82nfF XWJ3hE9bxfhI261JKhiC/6CKLPLAmpV/mQtW8BMmUvWQkyFoT937qd38bOOHC7WQUoClrO U7kCBG6Eu3xAp5h68nclcxkJO8CjuGU= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-605-d2P9QQKvMDS78a4lYXwovA-1; Fri, 10 Jan 2025 13:22:04 -0500 X-MC-Unique: d2P9QQKvMDS78a4lYXwovA-1 X-Mimecast-MFC-AGG-ID: d2P9QQKvMDS78a4lYXwovA Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43625ceae52so12724455e9.0 for ; Fri, 10 Jan 2025 10:22:04 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736533323; x=1737138123; 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=OXRC2m94ydMkiYC7QjOXtCup/ACjP0VRhTV9k+2JNqs=; b=ER7hi/WdVq6bszMl6q4IQYuZIiSTwR27EnQ3KvoIuc9tH7SduJWqQsiTAAjf/Dej2L Ua8kpbKqp/7BT+Yn6IZRhy81jaJXeFuwY4KYp2ZoJ0SvFBNZeMC7eBm/+Vibw537KW8z wAERrVHW5eiVmLaga2W6Fn/WYN7GpNsgxsDJngjCCMp/38vfi3jzPsfhrADFZ6ZVHcvu LK8nbFQvPZgkGX+ReCDEWd4XQBXXvl38GHLsiIUtF2ht6BBLlclhSSUo5g72dW5r/Ajp dwa0yFK/RrHVk6MQNI7ogePey7hbl0MIktnpEP0y2wiiX8SL1eLg9iGSxFhuXj9GcJH4 97aQ== X-Gm-Message-State: AOJu0YwVJ++8nair3Aj6RJbFRXGWITkmnR7qsHkuW9z5rN2M6BDArHSG nrt8eKHrEVUP6jtojUwutjZbfJUKGZJthRoGxrklZAyfOb8VZ2ICj6mqFIQJs+jV/O0OSUzCkoj U210bVzrrr3W+Gp2aveRLnQKXmY9qe/bGEP+r7kwq/rPjnCQ0pDfA8YG9YSbyT6IaMzED/HqZcB CSRvbwz6hp9NUkFG+5nuTNCcCBlVb5epi4oXSMWM/Eq0J6 X-Gm-Gg: ASbGncuUoqB+Sl9q5l0VmclG21+RPT7J0VmDneYy7XfIK0/SMTmRqpDhRVYeek/VvOF hW3rLrQiuJiwsxXaQ0bKPkttv8+hgbMDSudJdacWPj11E7AVeP1hMIppDQlxAByciSvugSjjXe+ mrIY8q4tUSGbISyMEq/wcRGfjB8P5iRE3aT6UaN0woYy5r/nUCUoSGKYVpmxa3KUQ6lLKg5GUdQ Rfjg7PRC8pkVCwreERDl51MI7uxyHsxAZsmMKNQq9pGywavKlk/9teFr86nLvHPEPfpBiW8/d8S p6zuQ7I+rvaJe5b8aK4heyG83+N3SXywoYsn3Cidyw== X-Received: by 2002:a5d:6c66:0:b0:38a:4184:151a with SMTP id ffacd0b85a97d-38a87336d7emr10411547f8f.37.1736533323293; Fri, 10 Jan 2025 10:22:03 -0800 (PST) X-Google-Smtp-Source: AGHT+IHcugPNnXNH6gMdckC0/5oXNeYEtkcYkpb+AZRe4LzLi94i5qkTLkfuV2gaEgGD05bAwgio+g== X-Received: by 2002:a5d:6c66:0:b0:38a:4184:151a with SMTP id ffacd0b85a97d-38a87336d7emr10411528f8f.37.1736533322896; Fri, 10 Jan 2025 10:22:02 -0800 (PST) Received: from localhost (p200300cbc708e1004f41ff29a59f8c7a.dip0.t-ipconnect.de. [2003:cb:c708:e100:4f41:ff29:a59f:8c7a]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38a8e38c990sm5194620f8f.56.2025.01.10.10.22.01 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 Jan 2025 10:22:02 -0800 (PST) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Muchun Song , "Matthew Wilcox (Oracle)" Subject: [PATCH v1 4/6] mm/hugetlb: rename folio_putback_active_hugetlb() to folio_putback_hugetlb() Date: Fri, 10 Jan 2025 19:21:47 +0100 Message-ID: <20250110182149.746551-5-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250110182149.746551-1-david@redhat.com> References: <20250110182149.746551-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Now that folio_putback_hugetlb() is only called on folios that were previously isolated through folio_isolate_hugetlb(), let's rename it to match folio_putback_lru(). Add some kernel doc to clarify how this function is supposed to be used. Signed-off-by: David Hildenbrand Reviewed-by: Baolin Wang --- include/linux/hugetlb.h | 4 ++-- mm/hugetlb.c | 15 +++++++++++++-- mm/migrate.c | 6 +++--- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index c95ad5cd7894d..ec8c0ccc8f959 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -157,7 +157,7 @@ bool folio_isolate_hugetlb(struct folio *folio, struct = list_head *list); int get_hwpoison_hugetlb_folio(struct folio *folio, bool *hugetlb, bool un= poison); int get_huge_page_for_hwpoison(unsigned long pfn, int flags, bool *migratable_cleared); -void folio_putback_active_hugetlb(struct folio *folio); +void folio_putback_hugetlb(struct folio *folio); void move_hugetlb_state(struct folio *old_folio, struct folio *new_folio, = int reason); void hugetlb_fix_reserve_counts(struct inode *inode); extern struct mutex *hugetlb_fault_mutex_table; @@ -430,7 +430,7 @@ static inline int get_huge_page_for_hwpoison(unsigned l= ong pfn, int flags, return 0; } =20 -static inline void folio_putback_active_hugetlb(struct folio *folio) +static inline void folio_putback_hugetlb(struct folio *folio) { } =20 diff --git a/mm/hugetlb.c b/mm/hugetlb.c index b24ccf8ecbf38..60617eecb99dd 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -7430,7 +7430,7 @@ __weak unsigned long hugetlb_mask_last_page(struct hs= tate *h) * it is already isolated/non-migratable. * * On success, an additional folio reference is taken that must be dropped - * using folio_putback_active_hugetlb() to undo the isolation. + * using folio_putback_hugetlb() to undo the isolation. * * Return: True if isolation worked, otherwise False. */ @@ -7482,7 +7482,18 @@ int get_huge_page_for_hwpoison(unsigned long pfn, in= t flags, return ret; } =20 -void folio_putback_active_hugetlb(struct folio *folio) +/** + * folio_putback_hugetlb: unisolate a hugetlb folio + * @folio: the isolated hugetlb folio + * + * Putback/un-isolate the hugetlb folio that was previous isolated using + * folio_isolate_hugetlb(): marking it non-isolated/migratable and putting= it + * back onto the active list. + * + * Will drop the additional folio reference obtained through + * folio_isolate_hugetlb(). + */ +void folio_putback_hugetlb(struct folio *folio) { spin_lock_irq(&hugetlb_lock); folio_set_hugetlb_migratable(folio); diff --git a/mm/migrate.c b/mm/migrate.c index 7e23e78f1e57b..be9e3b48cd622 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -137,7 +137,7 @@ void putback_movable_pages(struct list_head *l) =20 list_for_each_entry_safe(folio, folio2, l, lru) { if (unlikely(folio_test_hugetlb(folio))) { - folio_putback_active_hugetlb(folio); + folio_putback_hugetlb(folio); continue; } list_del(&folio->lru); @@ -1454,7 +1454,7 @@ static int unmap_and_move_huge_page(new_folio_t get_n= ew_folio, =20 if (folio_ref_count(src) =3D=3D 1) { /* page was freed from under us. So we are done. */ - folio_putback_active_hugetlb(src); + folio_putback_hugetlb(src); return MIGRATEPAGE_SUCCESS; } =20 @@ -1537,7 +1537,7 @@ static int unmap_and_move_huge_page(new_folio_t get_n= ew_folio, folio_unlock(src); out: if (rc =3D=3D MIGRATEPAGE_SUCCESS) - folio_putback_active_hugetlb(src); + folio_putback_hugetlb(src); else if (rc !=3D -EAGAIN) list_move_tail(&src->lru, ret); =20 --=20 2.47.1 From nobody Sat Feb 7 21:15:29 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 69BA7214238 for ; Fri, 10 Jan 2025 18:22:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736533332; cv=none; b=So3jLW7/PK1otwohzbJrQPec+18EyJUE+HIV3WO9+Im0pQMA8PUccRkgEOcfPXhDdfeRGjdR2ezE5OPnNUGmwkVh5d7NnpDXA7b4pUwrg7F61RnmLMytRdZUcUENnAsQ8N5EDVRJvlgcWPSbjWyWNArczXCYw1ZdiczwsHZUKdg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736533332; c=relaxed/simple; bh=8yRm31RVXs28F/17HMbcSmPgKLu6NOYU1V1JMoeGwoA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=dAwUwQ3rvIP7PvtJc/cZIUXZ4QR4CrTilKdplSSWmfqMatUUB6l77bQUL1Wko2E2LgVZcsKRV4b7kZPN/MRtA7A5i73hjEbb0TC9/zKwrpYhrRRyMoYMXeyfO8n5azCtyvtE+5ZjTZwIYMsyHXvZCBdB1Ph0H93q8gzRW7vmxf0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=PYa1JOSU; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PYa1JOSU" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736533329; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=7Y6jXgybxRkLjI1AHQdA/uUdE381WdqnkZcDYSI/y9A=; b=PYa1JOSU2TGNoBqeHqME9vvcFUqdqgAYhz6mo0LcX1xeQUfP/gChNOj2d/urVfybTHSGq3 3pixoCZgvvronrp6C7Y4XwgQ/RiflQzW2QQ0lvB4OrBA4QL6rV/swwuaJVokutgXX1b5kj L70/4Gwkx4ywX+o3EdI4O0xLjqxESjs= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-338-agxhUekVN56-q_NpkPE-aA-1; Fri, 10 Jan 2025 13:22:07 -0500 X-MC-Unique: agxhUekVN56-q_NpkPE-aA-1 X-Mimecast-MFC-AGG-ID: agxhUekVN56-q_NpkPE-aA Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43619b135bcso12022415e9.1 for ; Fri, 10 Jan 2025 10:22:06 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736533326; x=1737138126; 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=7Y6jXgybxRkLjI1AHQdA/uUdE381WdqnkZcDYSI/y9A=; b=mpLL8U5pTBv+u3koDECqnP1P6NhkiGWXppBBR+O3DErnf7PHSpUD1uVTsO9fOLSixM fglnlnL/MW/gclycqvCJWrBAorHQBGjVauzdQAcqdWCcc/wRtNeTg9Qa4w+N3+SYngNN oNJvBlFXsFVNbfLF0oKXhszqF8yVFqxDDdd+LLPDVkR/ASX1mLf1kHxq7f6gOLv9xy0m T9qP/yGgOetQwmwvRV4GXJC7EvI1UkNpaSRDq+Ac3gO1U9ORJxcMrUppuAnxzELly2YZ 8tREFzxpy0GTZgSmzDO7e/14qaLv7ayrxXN72YSNgqr8ir6fx55GL4gzKd0ns8uyaUim k7LA== X-Gm-Message-State: AOJu0YzDUKm745HKw+y1qJktIEvKM5pd5WTY4Vu5+IKQ/s/g8yVpj+CL HZqiWvQpHXpGWHQqfNyRAZzWxSzndnX8+BOZmEEylzLL4iM1weSTa+aKWVYiSUW1GoHQCnVv9v8 ot+xjXtJq2y2jMkxv79HAAHeYBR2T10w2Jl9ekIPTM210TY1YldUyEhAaIkHPKEGAUM8NwGxiyt 6tqC3yiu3vQBRZSmo4Tc0bPdIianChFLVMJbhEEZDu872Z X-Gm-Gg: ASbGncsb3+HDi4HKaO++WZYEiwYnbczLIqqiS43VxmxlAwIFL+hbG6B/BLsO+g51zLL TWllAga89ARNFBtCHx9883RUHXIwlivPwv0W1iN5+nLeK8f9t1aDy32+S2v2Q5N+blgP2+iZ68J A71OeXaY90CP+pP0V/8FGkGQv/RQ/Vg+PyY1vJaH/BOPQRqYTJL+CDCclIWLyv/x02pHfazR3+L 1mpr2BkTAnMGgdBBegadxNPq1ZhDXeAq7ReNBw2FMumotMtMRN8UvgUeJJimT2P5U9IcHx6FYD3 3qrwT+akBGbuoEGm99K8HdOUzLwzQ9lyQbtJ89q9hw== X-Received: by 2002:a05:600c:138e:b0:431:55c1:f440 with SMTP id 5b1f17b1804b1-436e26f5f3fmr121514375e9.30.1736533325803; Fri, 10 Jan 2025 10:22:05 -0800 (PST) X-Google-Smtp-Source: AGHT+IGfyPcq4pW/J8BG/r5An3xGWFuEtFy8aWLFQ30egdSLXBVyBhWxqaKAHMz46OsWfBiI1GqFlA== X-Received: by 2002:a05:600c:138e:b0:431:55c1:f440 with SMTP id 5b1f17b1804b1-436e26f5f3fmr121514035e9.30.1736533325352; Fri, 10 Jan 2025 10:22:05 -0800 (PST) Received: from localhost (p200300cbc708e1004f41ff29a59f8c7a.dip0.t-ipconnect.de. [2003:cb:c708:e100:4f41:ff29:a59f:8c7a]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-436e2da65a3sm95656095e9.7.2025.01.10.10.22.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 Jan 2025 10:22:04 -0800 (PST) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Muchun Song , "Matthew Wilcox (Oracle)" Subject: [PATCH v1 5/6] mm/hugetlb-cgroup: convert hugetlb_cgroup_css_offline() to work on folios Date: Fri, 10 Jan 2025 19:21:48 +0100 Message-ID: <20250110182149.746551-6-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250110182149.746551-1-david@redhat.com> References: <20250110182149.746551-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Let's convert hugetlb_cgroup_css_offline() and hugetlb_cgroup_move_parent() to work on folios. hugepage_activelist contains folios, not pages. While at it, rename page_hcg simply to hcg, removing most of the "page" terminology. Signed-off-by: David Hildenbrand Reviewed-by: Matthew Wilcox (Oracle) --- mm/hugetlb_cgroup.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/mm/hugetlb_cgroup.c b/mm/hugetlb_cgroup.c index 89a8ad45a533d..bb9578bd99f98 100644 --- a/mm/hugetlb_cgroup.c +++ b/mm/hugetlb_cgroup.c @@ -195,24 +195,23 @@ static void hugetlb_cgroup_css_free(struct cgroup_sub= sys_state *css) * cannot fail. */ static void hugetlb_cgroup_move_parent(int idx, struct hugetlb_cgroup *h_c= g, - struct page *page) + struct folio *folio) { unsigned int nr_pages; struct page_counter *counter; - struct hugetlb_cgroup *page_hcg; + struct hugetlb_cgroup *hcg; struct hugetlb_cgroup *parent =3D parent_hugetlb_cgroup(h_cg); - struct folio *folio =3D page_folio(page); =20 - page_hcg =3D hugetlb_cgroup_from_folio(folio); + hcg =3D hugetlb_cgroup_from_folio(folio); /* * We can have pages in active list without any cgroup * ie, hugepage with less than 3 pages. We can safely * ignore those pages. */ - if (!page_hcg || page_hcg !=3D h_cg) + if (!hcg || hcg !=3D h_cg) goto out; =20 - nr_pages =3D compound_nr(page); + nr_pages =3D folio_nr_pages(folio); if (!parent) { parent =3D root_h_cgroup; /* root has no limit */ @@ -235,13 +234,13 @@ static void hugetlb_cgroup_css_offline(struct cgroup_= subsys_state *css) { struct hugetlb_cgroup *h_cg =3D hugetlb_cgroup_from_css(css); struct hstate *h; - struct page *page; + struct folio *folio; =20 do { for_each_hstate(h) { spin_lock_irq(&hugetlb_lock); - list_for_each_entry(page, &h->hugepage_activelist, lru) - hugetlb_cgroup_move_parent(hstate_index(h), h_cg, page); + list_for_each_entry(folio, &h->hugepage_activelist, lru) + hugetlb_cgroup_move_parent(hstate_index(h), h_cg, folio); =20 spin_unlock_irq(&hugetlb_lock); } --=20 2.47.1 From nobody Sat Feb 7 21:15:29 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 169DF2144A0 for ; Fri, 10 Jan 2025 18:22:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736533333; cv=none; b=bCCSHhfP9sJcnB5wLLew1RxJuSuSWPLvQ2pDfnPDWIWC0b1E6ZmGX6H64akPG8SjhkojNGzYrvznhmUEoxeyosOlionqcuS7EuKjwLXNXwbZeGtdr94H4eiOdse503zhlGDVAryHcVSohmfDSAerxfJx71OKIkFmCs/0QaTuICw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736533333; c=relaxed/simple; bh=OBNabx68A3WCOoWaE1wczOaBRSdK2JwJ3Dc6veQUO/c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=nCoJBPbznYyZgWtXAXEtLd74Ofa0rnzlkANBr+Na7wanoBAc1yqWn63VDWgORPI97gO0Su8nkzM1XRd9av5qFm4D8myazQ9h0k3Xhfm90TuNSO4tNvzsr8GAgYgvSWF32le/BMKCU6E/LPmmzOa3JkUp+cLwMRSCDxZQHqDCCXo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=LCkm+CGQ; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="LCkm+CGQ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736533331; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=B64bx35uOXxQMEAOflKQlNSdLN9JGSwoqDOXWjVU1Rs=; b=LCkm+CGQ3r7FIVnCHhSo5MSRwLksMC7YQ7sAB/SOcuxb+zq3H1DKUIEHKgdCkiT6iMmUTm wmT+JODVrGQawXUJEdQ0nlOyb6B/oDJ/Tj66ruEMMUy3+S+wG1ACdjQg7CVZ88id6tb010 Rz2iL4+Xkjn45Z80+K901vFBTH0OR80= Received: from mail-wr1-f71.google.com (mail-wr1-f71.google.com [209.85.221.71]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-556-f4jMKYN9PUqSaWXhL_4s9w-1; Fri, 10 Jan 2025 13:22:09 -0500 X-MC-Unique: f4jMKYN9PUqSaWXhL_4s9w-1 X-Mimecast-MFC-AGG-ID: f4jMKYN9PUqSaWXhL_4s9w Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-385e49efd59so935569f8f.0 for ; Fri, 10 Jan 2025 10:22:09 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736533328; x=1737138128; 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=B64bx35uOXxQMEAOflKQlNSdLN9JGSwoqDOXWjVU1Rs=; b=aqPTvPYZAI55PHitiNW2nQltJHbFzJhNhTv1AYd9Cq4CSyCmIGMTLYok+xaoZrmHiq BG79TtxlBg3cCI9WA6X7Ia211BjNji7Q7lv9REb9vJH5Jo93An/bnhEgoGgI5jZzr18d C/lTiF/ZS8NTTG62rAnujqn7e4qxrilous2/bMElM27RIwLmMMir1C2Ra0yAqOoPwT2e bCiX8fF0cisyRT8rtjHBMavkoGMknMOftR5Umpr2mfic9OCK3pTVK4jYr00zeKT/MR0o DAyP4qJEfwnPEHL4aH2vAuLs/b1Si/olsT4Tszr0loYe43QkBwROrlfE9k8Jn9EqNDdZ Wc4w== X-Gm-Message-State: AOJu0Ywr/AIZKWhyjkWAYXqKmhAljm13X+DxTOaUEBnBXv9T/bTLkg64 XsJhK//iC/8eWU5ir3CQVVAFzU9K+H9fAESUJjNdk4d6U4+CubLiBLI1WtXy2jg/XZoU0ujW2s5 OJbCIt5PEhRHCAy51j/pztm1QJCOqDzhGzB04hUU1wxzOBo07NV9sMbE+rocuHnGf7DfNibXA6i PL2ryNepF14XLHXOwifcoOhSU+n6yBPO1sEaQDg8Evk7id X-Gm-Gg: ASbGnct+jLWhDWoE/I23+Aa9ZrOTZDfAc2H7pxtx6aLT8tETR1UPmSNTlvdM2bE/Wpa 6vW3rTSjchQL2za/2maMjbsA1/Agi8Yx51CI3xuZWwsPbrxBAGGdcPgX4fD1aVfm7nUQJe5vOse l83U/i8KbPom1MoU2xUa+9UD5TmnQ+ZyixnCeNSTF3shpqHO99d+kVpTapt7vV/UjZfEJxJZW+X V5w6g0HKlu5FgPURNkQNnXOX/LExbZgCFtMZz8tOOi1sCnZGZVZvTdSqW6RA8JUlAmJLtxuvgMY zEwo5nRFq6LMuWtBfvfjZswmBTqDNqn2/YvwFrwYsQ== X-Received: by 2002:a5d:6da1:0:b0:385:dc45:ea06 with SMTP id ffacd0b85a97d-38a872deb27mr10509781f8f.13.1736533328660; Fri, 10 Jan 2025 10:22:08 -0800 (PST) X-Google-Smtp-Source: AGHT+IF3vUT1h0m8haDgPT04bLRnZs0bSDTSjfCTisAMBTneAwCAWQyget6Tg/ZqSntMqTbfop892g== X-Received: by 2002:a5d:6da1:0:b0:385:dc45:ea06 with SMTP id ffacd0b85a97d-38a872deb27mr10509760f8f.13.1736533328325; Fri, 10 Jan 2025 10:22:08 -0800 (PST) Received: from localhost (p200300cbc708e1004f41ff29a59f8c7a.dip0.t-ipconnect.de. [2003:cb:c708:e100:4f41:ff29:a59f:8c7a]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38a8e383654sm5232309f8f.30.2025.01.10.10.22.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 10 Jan 2025 10:22:07 -0800 (PST) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, David Hildenbrand , Andrew Morton , Muchun Song , "Matthew Wilcox (Oracle)" Subject: [PATCH v1 6/6] mm/hugetlb: use folio->lru int demote_free_hugetlb_folios() Date: Fri, 10 Jan 2025 19:21:49 +0100 Message-ID: <20250110182149.746551-7-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250110182149.746551-1-david@redhat.com> References: <20250110182149.746551-1-david@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" We are demoting hugetlb folios to smaller hugetlb folios; let's avoid messing with pages where avoidable. Signed-off-by: David Hildenbrand --- mm/hugetlb.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index 60617eecb99dd..e872eff124abb 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -3822,13 +3822,15 @@ static long demote_free_hugetlb_folios(struct hstat= e *src, struct hstate *dst, =20 for (i =3D 0; i < pages_per_huge_page(src); i +=3D pages_per_huge_page(d= st)) { struct page *page =3D folio_page(folio, i); + struct folio *new_folio; =20 page->mapping =3D NULL; clear_compound_head(page); prep_compound_page(page, dst->order); + new_folio =3D page_folio(page); =20 - init_new_hugetlb_folio(dst, page_folio(page)); - list_add(&page->lru, &dst_list); + init_new_hugetlb_folio(dst, new_folio); + list_add(&new_folio->lru, &dst_list); } } =20 --=20 2.47.1