From nobody Fri Dec 19 06:03:07 2025 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 9220E22C33C for ; Mon, 13 Jan 2025 13:16:40 +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=1736774202; cv=none; b=oCVRZkiW0Pxm89kct7joXOag0EUlRhpLm2OBsOQk79yDsRKAuukJ/2jhl+NwNcr9GTQPvUJPZhf1xk7pY5CDl4GqkQytoVjW5iSJIxxMfMuXpux9LykhvkXYiRt9D6kQDSAmbtL32QA4FJ1zUI6V7OOQk6H04aeV+6s7lSbsNFs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736774202; c=relaxed/simple; bh=rjOYsYAtuUV4kb7e8bPEkOmuK442dmDaiwFSYAD4mVc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sD+CsgAIr7Ff6Kd1ihp0P2aIPOZUi17zmI4+Hu3GSz9L/T1gr2iAWFGMCNn4T0To9ZmFAfgXkj1xNnUzFNs6dWdRFeBCr8UIO2r4R19UaVyOzRvKpiUV0zAzbvP40oft6ZmlgkZxfGgcSrXOnN/eUNuED81PxeLmO/QF5yjrYTE= 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=UmcwawSl; 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="UmcwawSl" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736774199; 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=yqxlMuEwJ96RDEbbwPDjzSu+ESMvaexzxAdOoodpgX0=; b=UmcwawSlDiXjGOz+7XX/Yw9W/r0HtSmJZx169hoBNMVRCz0H0aqdMP2bFLpUjA1MukgR7F /GZiocpM7A36WEgV2YdFHo8WvJS4ov2L/r/FhDKMuDTBpSJsTovAWLpx0zDFZr8ksfSAJm WruDPvagStfrDaEd/nKNGzQcRdP8Ezw= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-37-F9fBiKDVOR6aGPEyehZpuQ-1; Mon, 13 Jan 2025 08:16:36 -0500 X-MC-Unique: F9fBiKDVOR6aGPEyehZpuQ-1 X-Mimecast-MFC-AGG-ID: F9fBiKDVOR6aGPEyehZpuQ Received: by mail-wr1-f70.google.com with SMTP id ffacd0b85a97d-38a2140a400so2853894f8f.0 for ; Mon, 13 Jan 2025 05:16:36 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736774196; x=1737378996; 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=yqxlMuEwJ96RDEbbwPDjzSu+ESMvaexzxAdOoodpgX0=; b=d2THTKCfs4Ojs5AZhwdHdECMCfRl9VVOIhyybgXotRvn4ACDfhQEMI6JazE/b+f8am 7v1y0lcPPPd2x5kReUT3p6M1pn0IXrDBTpv7dYbrkN02Ew3F0SFLJlqgZhWAvUv0ALw2 1thlrfi4eVIgW9zAc7hareuA4ThCIUJLPvC9SzNYhOP/dr+Tka9a8AN/U8C//kB0dcly Fg2shYLf382Ugt0GRZf0t1ofajGjpSQnam9e46jIUFwSLjkZ1U7H45c+fFM4zvNBKU89 qgpXzc3SDRDUk6HtxDSOgloIWXCUUMro0GpRsS4tUqnVMWs9ZILttYvdfFkR26lRtH0w mavA== X-Gm-Message-State: AOJu0YzXuSGn25NGvrgdcEfxrPcvMNU5dIjMnWSSqB1GuyofaHwYODHj 4sRYpo5gdig0wg1OZd0VFn2Psr9Uml7ixmFRhXlnmpVu5Vdbw8siWu/jwi8enp/5cocO+8Vm0pO lXTN8C18dZJ2uWE+PQ/gZkabONBL42sCQy27F9T4cl3hTMvLLnaFA5XlWe1agm3dyCdRRoo+U+O POhGJtrTT2UZ5+AI/lWG6ps+OGx7pdF4KExV2LijVD04h4 X-Gm-Gg: ASbGnctndq/lqKesjiMnspitEyMkhtdLmk+W2ivUI5UmOoedrvUfbKn/nhGjAnlkYkm MvD09iGQmarT/ggrApQxuwzOPoNEZ8EE7GQPwbVSw9PXVywE+SmWlkIjKQ0ojN1NWeorSLUQmeT jwiJd7YCCTXypUIkjJ5kDXfxUMEXXbVaizxy+/r2DDO0yuYMU0TNqi1MiuV1sXv0+ayB72QLx/F KfDB/lTRj0IpYFmEO5JLwAkKY2XE3zMQUJuqfQXGM+S/cROUfJ+ X-Received: by 2002:a05:6000:4b0a:b0:385:fae2:f443 with SMTP id ffacd0b85a97d-38a87313975mr18780156f8f.34.1736774195718; Mon, 13 Jan 2025 05:16:35 -0800 (PST) X-Google-Smtp-Source: AGHT+IFwBMYQqXPQxzZdc6FGJ8e2Lbj3PmWZBYhXw8lnFx0RiF7sjzN8pyjkFTORSuuscZKg5QTaCw== X-Received: by 2002:a05:6000:4b0a:b0:385:fae2:f443 with SMTP id ffacd0b85a97d-38a87313975mr18780120f8f.34.1736774195249; Mon, 13 Jan 2025 05:16:35 -0800 (PST) Received: from localhost ([2a09:80c0:192:0:5dac:bf3d:c41:c3e7]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-436e2e92dc4sm176071985e9.39.2025.01.13.05.16.25 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Jan 2025 05:16:33 -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 v2 1/6] mm/huge_memory: convert has_hwpoisoned into a pure folio flag Date: Mon, 13 Jan 2025 14:16:06 +0100 Message-ID: <20250113131611.2554758-2-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113131611.2554758-1-david@redhat.com> References: <20250113131611.2554758-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. Reviewed-by: Matthew Wilcox (Oracle) Signed-off-by: David Hildenbrand --- 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 Fri Dec 19 06:03:07 2025 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 8458C22C33C for ; Mon, 13 Jan 2025 13:16:45 +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=1736774207; cv=none; b=MB1aeRlreqm924NLMTmr76HbIHA1fP0qSU4KV/bRMKL0XfEwGuiQfnJe0hm2Q+LuoiQAnTUm8PHZRvtxcOS/gwApU5IulQBm70ONymQsZFscNIV8ljjA8gEJGtJEGtov6NZQMIKFJ4voZtExAqj7T9S0fg0oYutTpix1ltTNQRs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736774207; c=relaxed/simple; bh=SF0kbN9Vy6DRrUS9rEO5e15pj8xPRgqZaaqNEWIxuWo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gcJOBcKjudXpgx0gaTDUgp9Kw9AaNilvTk+Y2nSmOfmVT2V5ao/1oiZpTn6mwndp0s15sJ3W1V8QwO/jb4kXpmmsS77eP4XHbnN8/pUv8cWUb7AhHxBh73xyQSIGkCGmzQ0QTIEUYaFYrUc51a4JeyZLxL/SrstAW7miCbqXcTg= 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=UvaNwq7i; 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="UvaNwq7i" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736774204; 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=9usYI5DgNUlDmY6F4Dug4aGXBw+qPPqxLUrXzQ1Tmoo=; b=UvaNwq7io4wZEMHzRZfyDII9XFC2YEypRJ5lLkxbk6VcdUFv5D52D6dzK8eAHpaItxZ15o ReLkXOYziycMIFa1ORwtpxKfRI3PWFVpToGFmS+1YIjyOYlAtlk6Ha93jcFWxcFnxcBgAC cdeTsg1QCT7XK/0DCmDuiZJeBzwIw3w= 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-639-HEjyey1jOYmz1QhQ6-9q5w-1; Mon, 13 Jan 2025 08:16:42 -0500 X-MC-Unique: HEjyey1jOYmz1QhQ6-9q5w-1 X-Mimecast-MFC-AGG-ID: HEjyey1jOYmz1QhQ6-9q5w Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4361fc2b2d6so24482855e9.3 for ; Mon, 13 Jan 2025 05:16:42 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736774202; x=1737379002; 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=9usYI5DgNUlDmY6F4Dug4aGXBw+qPPqxLUrXzQ1Tmoo=; b=IE334Gjk9nLkXEzXAukUnfkZgLjPiC7q5cbkNOrbjbs3ksikUn+ufhUeyQ7LN36/GL KOkK8eaIubnfdumPMBIaW8wO8xcwDjeQ4FOZAe9SN2cgmQNcdm9NL+1uMLy4jAqpvHju GoGszFSt+3ZoVCWfi2OObU1vNpw3hikraS9Ott/4GUbmOeFd5hn+Fge/kb0HfzQH2ycf 3+/OOBBsg13XGb8uXwhDBuit9knCcvSORaBhOsh2EMnGuDDWGeMKtD5s5j1hA8v5jpsv 5GKjLNb6WCX9Rd53/3iIePz5RxRgdz5Qr5sd/zJaygkgY9NKjFqUfSG9bcr99wZa3+Uk CfcQ== X-Gm-Message-State: AOJu0YwJdjIOr4WrD8RzAzYKSYhPAv/Pxu6VV3SS5sTLmq4SN89/q5OT pJjfLX6iyPwcARSjWfBOD5rghx4EaVN6BgtyTe/kGDd/ZzIsRlNza0RyO0xbmtAPbE7muKd8P2g p/0dv1K+a9fsCD0yglohj2e2oIv/wQAixn2IfBh3lf8UjaW5u0Tm8blxn8GrkTehzzMaUHWuLhv BBMK9P0ySkFByx6VaTLneVAOBiF61zDNM+4SNQy54I1lVT X-Gm-Gg: ASbGncsQI3qSwmaDRW+rYd3SH2jRojwvXq/ONsBK6bjqZ+B6JcJ3MHyo3euz87RUEUx mIP8rbws8uqYte65h5k45Y8mLwmJbtMpdwmlyQxSyFgIE44bOnEQbNlLofOo/Kf4fojiObscDee 58HHZWkVdtAALQzwqmUhMw+Cic04lc3n3rxqSg+7ju53XVdDNWN5nzr+GF5mAMm+tUn4q0rVmXJ yxXbPdXi8KDpzVddFb5EMzjXeMy27K8eemokuG480DffD6mXZWD X-Received: by 2002:a05:600c:314b:b0:436:5fc9:30ba with SMTP id 5b1f17b1804b1-436e26ebb6fmr73793275e9.29.1736774201754; Mon, 13 Jan 2025 05:16:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IF1QjX6fKScjtkrek3bHe4bgrZiW5f8BsOnYBHXEjoxDvqfSM2uADNbnmwxz9BF73D5jNf0aA== X-Received: by 2002:a05:600c:314b:b0:436:5fc9:30ba with SMTP id 5b1f17b1804b1-436e26ebb6fmr73792885e9.29.1736774201284; Mon, 13 Jan 2025 05:16:41 -0800 (PST) Received: from localhost ([2a09:80c0:192:0:5dac:bf3d:c41:c3e7]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-436e9e6263fsm146445655e9.39.2025.01.13.05.16.36 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Jan 2025 05:16:40 -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)" , Baolin Wang Subject: [PATCH v2 2/6] mm/hugetlb: rename isolate_hugetlb() to folio_isolate_hugetlb() Date: Mon, 13 Jan 2025 14:16:07 +0100 Message-ID: <20250113131611.2554758-3-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113131611.2554758-1-david@redhat.com> References: <20250113131611.2554758-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. Reviewed-by: Matthew Wilcox (Oracle) Reviewed-by: Baolin Wang Signed-off-by: David Hildenbrand --- 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..a93b508bc0e0e 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 Fri Dec 19 06:03:07 2025 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 37BD123DE90 for ; Mon, 13 Jan 2025 13:16:48 +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=1736774211; cv=none; b=CCGcq8m149ATP48tt/MniOZPbGpCsj1D7M9vFfAdcTjH28klB5W7lO1Kk61UiECgXVaeLm93jPDNuzVHv+fWYT6MUy9nDpHMszQyQjVsOYwdN0jqSNWXIrkPdbK1NyBcUOdUJ+AcSla4ppRhUPInLW1YT9OmLQroC7DZ3Txi14g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736774211; c=relaxed/simple; bh=A2k36MaPVyOuvbpPKLPBr0XrXQlRlBEIrpiJWzIAOWU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=aWhiP1mXdGe/StwM2+8oQ108RnrhVX2ICfWpmCUy3Rb8L4lQZ14OhhDA7KyZG2cZMtL2rcR172kxOdRGbYHs9OPK60Awk11WHkyOoiCqLVQ7h6xzhWIRNk9h0VSp2jZk2+txeAAK6yry7YfCtDv/GfAL2lpf6LqQ597IygQpZbo= 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=NSvcL+qf; 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="NSvcL+qf" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736774208; 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=cv8gcZXVG0aCvRchUy6M5ty//7bnFqYv0xGdrXbuesA=; b=NSvcL+qfRGTO4r5MTmhoykCLqnkbDjLptTl/PIjVUK+HGpaTZcivRzoDz4M+DJDWyjTiw4 eT4lgEaEaVIrCZSIeyJfkn3Sfh0Tw3RDr/zOVchjJ0xQLGibcH10HXGANTw6n+/8NMgZnC UILsVPdnoYFX/1FKQuY4j+d3SudG89w= 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-605-Va-_vfzkN4u6HP_-v0Oxdg-1; Mon, 13 Jan 2025 08:16:46 -0500 X-MC-Unique: Va-_vfzkN4u6HP_-v0Oxdg-1 X-Mimecast-MFC-AGG-ID: Va-_vfzkN4u6HP_-v0Oxdg Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-385d735965bso3112342f8f.1 for ; Mon, 13 Jan 2025 05:16:46 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736774205; x=1737379005; 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=cv8gcZXVG0aCvRchUy6M5ty//7bnFqYv0xGdrXbuesA=; b=QBJLTqpwTmea+ELLgVvdMzAwFm08gad8P76Bo9nho23GczAWmMTfLzh/Ark8zGvxQb MwYpo/bZp4krDaFB6LA6qizdjdPJvmKVv1T0TP9NyrOPZTIbgOpAPilVWuB3thJoPuFi W2Lwlu2/WhbTycMuw4Dmo+DhiojhsYpa6pLJzlfuSBqDZ9+xieY6IbVNTFQskvjh8d2G ZpFvmwGH3L5XVZNssmACd76UNWvwv4+uWs5dVe2pC+vGKA1qWx2ZURlurPHv6hZS0a7A 4dLH1XKIwtgHZjn2CHICIrGE0Pq/QZbtEJZlwPsZaK4rwSbIxLeiebYn2vren0xq8H3w Jubg== X-Gm-Message-State: AOJu0Yy9splvzcmC26lu8NO0homLs0Pm6EOHs/Z9XhicEnnDCHFBJD+K LNZPV4qvg0RySheauU5k+0jS/kHcHfG2p4tyACeOMZggfQFu3jEB4SpmPuaZJP70cAXIZNEseN1 KwnuezblcptPSKdCq71WoooP5f2L0NjhIs91+yVABFSZ1jZ3dNDom21R9s/6t+rs0OEXxKV8cCX 8pqbjbHReKTZyY0Zju+jBPwd0qKwcJBxZ1B0ajxne+/YgF X-Gm-Gg: ASbGncsSUl0QDbC0FcMrlzhnkVdaPcrCHumg5OzyHfpkvfH4W5Be2DaX65B/N1Sbla9 PTJ5RrnY0fUw6QNzkoT52P1IKgZR1r8XiK/VHKkCVhahYJUNdFdp1EPCvGb4sIfzV0uC1jjyTD2 7zD7Buia4CUNhFzo9aD0ltmn1nBKEc4ST7ry3TqZq6wXvJyJmZ9fAwSoPqovZ84W1Vy1ny2k5qJ 6QnUpsL5E53b0ZoIXtoqQ3KsU5mc9SdyWjcZjjwXiJ7QZjnDzOk X-Received: by 2002:a5d:47a1:0:b0:38a:a11e:7af6 with SMTP id ffacd0b85a97d-38aa11e7bbbmr5899258f8f.6.1736774205650; Mon, 13 Jan 2025 05:16:45 -0800 (PST) X-Google-Smtp-Source: AGHT+IHQTPL422wYOOzjgEgIHFmJ3rDpDAPc/5y/ASBw+pb+O+L0PBYtTTxIRKUApv2sGAZ8bIk3sA== X-Received: by 2002:a5d:47a1:0:b0:38a:a11e:7af6 with SMTP id ffacd0b85a97d-38aa11e7bbbmr5899222f8f.6.1736774205221; Mon, 13 Jan 2025 05:16:45 -0800 (PST) Received: from localhost ([2a09:80c0:192:0:5dac:bf3d:c41:c3e7]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-436dcceb374sm165750165e9.0.2025.01.13.05.16.41 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Jan 2025 05:16:43 -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)" , Baolin Wang Subject: [PATCH v2 3/6] mm/migrate: don't call folio_putback_active_hugetlb() on dst hugetlb folio Date: Mon, 13 Jan 2025 14:16:08 +0100 Message-ID: <20250113131611.2554758-4-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113131611.2554758-1-david@redhat.com> References: <20250113131611.2554758-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 handle the migratable flag and the active list flag in move_hugetlb_state(), where we know that allocation succeeded and already handle the temporary flag; use a simple folio_put() to return our reference. Reviewed-by: Baolin Wang Signed-off-by: David Hildenbrand --- mm/hugetlb.c | 10 ++++++++++ mm/migrate.c | 8 ++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index a93b508bc0e0e..95579bd8c4fe0 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -7529,6 +7529,16 @@ 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" + * and add it to the active list. + */ + spin_lock_irq(&hugetlb_lock); + folio_set_hugetlb_migratable(new_folio); + list_move_tail(&new_folio->lru, &(folio_hstate(new_folio))->hugepage_acti= velist); + spin_unlock_irq(&hugetlb_lock); } =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 Fri Dec 19 06:03:07 2025 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 7EFD423DE98 for ; Mon, 13 Jan 2025 13:16:50 +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=1736774212; cv=none; b=pRo7rZRlSmgiMSTLpf33VZiL32kNJZty4sZ62I9KD9p2eBX1lCyR8gUOD3QkIitvRv43C6GKoOFudPitLCL+QykaGnnww9yFTLK/4WiP7rU6I7EuwFnNqgXOp+r6QQlCRMOdnWOEqSrQ7rLYgq7Y4FWmZNQ6pw0LKv+c5hP0/bQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736774212; c=relaxed/simple; bh=ZBzdYtIZc2XZHPI/PcxCh+jv9RdFaJibeyCQ3zaVSaQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=s5dK1ZseMOSlX8ekxr4qUeb1Ee+NoK6rrdGRG+4I7RaZYd6fesCv1jiDv+fHqlz3ULGDLSbFjxwRj/G/u/qVCA7lkFOV9m26/VZk1iNjcR/mZDJjCbCy8Cx2zrOwk3RzKowrum1jIt1w4GX632ma5oRJsbH/CWr2fh0Mt21JbxY= 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=U6Btezh1; 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="U6Btezh1" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736774209; 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=Owz/t4LPLm8R10JBYoc8bZ8ehYgkHbNPd81HY1H1C4s=; b=U6Btezh1PcOBmqdNxarfbhMP65D+yMJBt3QizQ6SZXNn5HPJY2ymsyYDTo17FBfBSHm6w8 OO5cLLva7TiK/8Fx9IGpxeAEyTv+n8BbxT9v8pWryqnwVzfEPfCaXyvs38WJ+8h1dpus3E crgA4d+PejYR0zA9TMrcb0A7NT0YOjg= 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-160-jwmss5yYOOK9gDo-SsSHuA-1; Mon, 13 Jan 2025 08:16:48 -0500 X-MC-Unique: jwmss5yYOOK9gDo-SsSHuA-1 X-Mimecast-MFC-AGG-ID: jwmss5yYOOK9gDo-SsSHuA Received: by mail-wr1-f71.google.com with SMTP id ffacd0b85a97d-385ed79291eso2412849f8f.0 for ; Mon, 13 Jan 2025 05:16:48 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736774207; x=1737379007; 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=Owz/t4LPLm8R10JBYoc8bZ8ehYgkHbNPd81HY1H1C4s=; b=X5o1AVS2ITsyeyz94opb41U8ZO3NkmEE3vtlT1v8zluf3Cry40PjqrQEe+L7mOk604 iolB1nBFAQWKBjwan2pqv+tLj98V+eu95FNayPqsaqCgslQOIWBltb3P4fY8rkxKPgoA 4eGheTDNXHNb0fExX6U7eSEa0z3Orh0jKUe6/rXZJF0zVK4ow0DOIyVK4LqZdSa57vFO MrBXMa9vl1E5aCcC2sNbxScfJAikSmwFMvaLRpZPVuyXTD8uaeOP85rZEdrhVJk0c0dU fEj+RR0U72OFupAU4u6YHZ3Id0lUFA0bhu7a1+X3q4JdJt2qf0DmuluIOcTGdPtIAORQ /9QQ== X-Gm-Message-State: AOJu0YzugP5IGeNHlZ3MHC3VgJ9H2kL5ip3Qu06W5FJlGT2XbttfSFkW H8YA/IP5J12es75vNVQnE5mLYZ8ig9e4X0vFYM7Rxck4N7ezY5TK8ZtL8YIIvToglhuR0dtdfKe ANNUAxpayEJPZMe67oEV4d+vcn/VrLST7iiOM76Xxn8ZmvgCZmz9iQnuKV7f3InUKv2zQbxgRsg UP4X0F0aTnQoBa9ITam2aO+Q44nyuMYwKIG2hVfMY+Tc1s X-Gm-Gg: ASbGnctPOG6IWMVfIRjM5OALAyst7R1u42R78fndo7HRvvQPFf2ZoexcMKq73923vqn 1LRgydtjrvJNB3bJlgoCUfuRK3d+F1fVgcNhLk59jTGf7Za1GQFsBUtEApYV8YWlHHFdenjLFBt JnExrcR1JzY7itK2yVPxzJjZlXiLdYiIgliACm8lll5pQR7qSs+zxZok3iqD4QSAcxog4i+KugQ HxPMQ1OiULSP1MbxLkV6eK8o0QPNkEp7MyvmixRKlkPWYFL8wD6 X-Received: by 2002:a5d:5f42:0:b0:386:4570:ee3d with SMTP id ffacd0b85a97d-38a8b0f693emr14694197f8f.24.1736774207045; Mon, 13 Jan 2025 05:16:47 -0800 (PST) X-Google-Smtp-Source: AGHT+IEmlNBWKTxitwUU8z3/x/DgIgt/PZq5l0prYnPmi8qWosnAo/rWsMNVPpJ+h/+u9EwIDLlc0A== X-Received: by 2002:a5d:5f42:0:b0:386:4570:ee3d with SMTP id ffacd0b85a97d-38a8b0f693emr14694155f8f.24.1736774206584; Mon, 13 Jan 2025 05:16:46 -0800 (PST) Received: from localhost ([2a09:80c0:192:0:5dac:bf3d:c41:c3e7]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38a8e383965sm12339069f8f.31.2025.01.13.05.16.45 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Jan 2025 05:16:46 -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)" , Baolin Wang Subject: [PATCH v2 4/6] mm/hugetlb: rename folio_putback_active_hugetlb() to folio_putback_hugetlb() Date: Mon, 13 Jan 2025 14:16:09 +0100 Message-ID: <20250113131611.2554758-5-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113131611.2554758-1-david@redhat.com> References: <20250113131611.2554758-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. Reviewed-by: Baolin Wang Signed-off-by: David Hildenbrand --- 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 95579bd8c4fe0..bc4ab45d9b93b 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 Fri Dec 19 06:03:07 2025 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 6318B238736 for ; Mon, 13 Jan 2025 13:16:57 +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=1736774219; cv=none; b=UoYd6xlPdD3rMrMB1RB8RoxfZoVxVjcYo+b2ORbMM4Bjw15C7oNOn3IJ1kaVi3BKt9a9F+IvYO5UCMxD36C81GnhdrWqkno2+MvQGx5HdYadr0mDM/okMpmFLtRJeJJ+hioIb0/SYiuj5lEL4DvKDIsBsx+m5Y45nuhUDAMnBM0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736774219; c=relaxed/simple; bh=mAbkQKhUmgY7AwQivD9IZksXDx3cLCtSBZFJMEs8ba4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ltcrNmcExIzic0/Im8DSSnXypebCh0Z1wA3Dt1rj7NbloR5kR4/uQuQd/olebYWe+R7pgQAzPppidEVzSiXT/6d/0mIE1A08kDiUFJu+aAf2ETkJu4i4YDUU4JY0JIv027VRXcFvU0pKWxKgjdXDhJRXkk7Er0lcoyyv3n/sFKU= 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=SdMx3i4h; 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="SdMx3i4h" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736774216; 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=HRNEOcGf3GTMgcl4QTjKb5jV93l50oLMkY3MdRla6Ho=; b=SdMx3i4hwf+23oieFzf8hxQKHtevUdVbV7qa7zZml67/XlQ52kn9O/SD6OVjKxiD0W9IRT ipZw2EpHU2nYeKurtlryTeFLUsTe+SncdRmtbhczU3422eKZkK9q9JHJcPZPfHl1/bs+uP znho5/buFwzEfI6pr/h0B4G+AvOxBng= 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-600-f5En8dJLP7GqlJNYgUkpYQ-1; Mon, 13 Jan 2025 08:16:55 -0500 X-MC-Unique: f5En8dJLP7GqlJNYgUkpYQ-1 X-Mimecast-MFC-AGG-ID: f5En8dJLP7GqlJNYgUkpYQ Received: by mail-wm1-f70.google.com with SMTP id 5b1f17b1804b1-43619b135bcso23263425e9.1 for ; Mon, 13 Jan 2025 05:16:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736774214; x=1737379014; 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=HRNEOcGf3GTMgcl4QTjKb5jV93l50oLMkY3MdRla6Ho=; b=eJEua/a9GWVk/rSjVLpe01vDjlw3H0rfe2EKUR0FzBU2heFaKQxA7mqW9H7sDtTqwD dURb/Zl2+DisxVyw/lh/LV3nY/V1uW4QmO3LvEmThvPm/g4Z974gXHOBf3MOs9kq5m/Y dko7zrxEHkf24UbhDzLosFdViXKbMKR19fqlw12Pt2Dz4wdQgCYEk+10cR7byP5C88Sv TJC4RT6g4QCWAzLSyHtDAHSzoCVS5/bGdjAwYnnjArGpRensxNMZhL7cjjzx2C3XG7Sx we8FOIkdxR62HsJEepyvGyx2+2gQtazVPjz+IQ7aldoxpNvbTgTbQENdFnuf8LqKJ7h3 m7kg== X-Gm-Message-State: AOJu0Yz5vdKkdrZlPINGNx1NYMQOtDsfbOU6IQyohNe49692RBIArSLj czdf9k+y8RW8Q8idAWwuG6p6YHtXTLh+GXQ9Flj8u39NfvHNmSpU+0R00NMvr9Us5t9/9iJ6ZnN y09NoYxftEzGh/BKf85E2+b8KqudSDeI+2DgM6Gm2Y3fzRrd3xRjQEs0i7gR/1mH6c3tlXURZR6 H7ETDHwVC5BgGZTJLe/MJSnmEQvvF98kNmKTKDgymyRald X-Gm-Gg: ASbGncsTsJPs4Q/Qbu4GLdGjHtBSonoGSyFaXHMzUvJzEuGasHO+1405ENsdw8I2+od 7Y/hNQduciI/lIo8d336fr0vzTzQ2Kiwu87IHqNcjfBCvtS4jIsIcYEuoGysosJFhVT/k9WM1DZ xIgOjcsF3xSTjtEDrTs/rFpXVdZ0cTOaZmidptXJw3f5G9WIyl1/aDvEvFkuCWxkdLSSueNaxVE Ax0YdmvchZM5VAob1aM7HW7nbk+Hs+m0l/NeqDlyZa8UZN8w9Vw X-Received: by 2002:a05:600c:3543:b0:434:f767:68ea with SMTP id 5b1f17b1804b1-436e2677c7dmr207456135e9.5.1736774213989; Mon, 13 Jan 2025 05:16:53 -0800 (PST) X-Google-Smtp-Source: AGHT+IFKTq+E4NJrcYvXWDYuu54JFXgVM2MwdOi9Ma73C8Zz4ZeGeNjp6vUj/uympH2bo3v62O1gRA== X-Received: by 2002:a05:600c:3543:b0:434:f767:68ea with SMTP id 5b1f17b1804b1-436e2677c7dmr207455755e9.5.1736774213570; Mon, 13 Jan 2025 05:16:53 -0800 (PST) Received: from localhost ([2a09:80c0:192:0:5dac:bf3d:c41:c3e7]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-436e2da66d9sm179456795e9.1.2025.01.13.05.16.47 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Jan 2025 05:16:52 -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 v2 5/6] mm/hugetlb-cgroup: convert hugetlb_cgroup_css_offline() to work on folios Date: Mon, 13 Jan 2025 14:16:10 +0100 Message-ID: <20250113131611.2554758-6-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113131611.2554758-1-david@redhat.com> References: <20250113131611.2554758-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. This removes an unnecessary call to compound_head(). Reviewed-by: Matthew Wilcox (Oracle) Signed-off-by: David Hildenbrand --- 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 Fri Dec 19 06:03:07 2025 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 CD7A61F94A for ; Mon, 13 Jan 2025 13:17:02 +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=1736774224; cv=none; b=JBspWW62djoCZpuohQK0N06XXMgWvMZgpVHeWtpfT1m3duqhHKvfX8c5aJsb+BqqIwwnz2obtp0KQkUn4RDbxw7bjp6PvQIYGf8nI5ma5wkRDUS3JNXGUbR2OYaWrd5nTvVQK5MXxQ6TF/OdxXUEdPKr3ynN3qZRFeGIIDxmXWM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736774224; c=relaxed/simple; bh=ZO1hSVqmhl+b3CMSxqEoN4E0FWwDIHc0yaZyGGttpug=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=bIDPaSuJiOtSP+JvYA4HNY3N39XW1zTeeU3jsOYpXCD2WHMwPh18nSH04v0ZPhJpfbM5zrT0I4TytNsPpnsbirjReq8prR1mcltP8OzBCstWFVNG+5OOnO7FQ/9CrnFSWhC13yIkPIb/XGjY7nHngxGB9f/urIthzH7wZqPetLg= 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=FB3a2qU4; 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="FB3a2qU4" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736774220; 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=1WieYHqvNwLPc2kQdBClwQ4rx8s3Wr6RxbLoIHjGUPM=; b=FB3a2qU4GiijLeuTW5b+6NeaBiGGAaRYBGSo3ZjCV5jUv1ZFo2vAmxofBl2bZwt+qeOc0M BDuxl5OCf+4Qdg4YADuuYHMT50M+A6vaQWgOgkRO1zUmiYx5Zl/Gd2y0f17xHJUpaCq+1Z MEcTvJTjoQvYHRhUYhCg5LhkTG9hESg= Received: from mail-wr1-f72.google.com (mail-wr1-f72.google.com [209.85.221.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-247-HagaH-8CM6SnRTc7TSGgvw-1; Mon, 13 Jan 2025 08:16:57 -0500 X-MC-Unique: HagaH-8CM6SnRTc7TSGgvw-1 X-Mimecast-MFC-AGG-ID: HagaH-8CM6SnRTc7TSGgvw Received: by mail-wr1-f72.google.com with SMTP id ffacd0b85a97d-38a891d2aa5so2159559f8f.0 for ; Mon, 13 Jan 2025 05:16:57 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736774216; x=1737379016; 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=1WieYHqvNwLPc2kQdBClwQ4rx8s3Wr6RxbLoIHjGUPM=; b=eKOzOPKMySQ2caegCuoIbj9N+i2BQOwnjO+ZPdUwOL3vWmy4C471/8hlzToOyEveyp sLvIOa42sUGUk+WZIBep7afy0qr1JoVrXFql+rKE5HTGS3SHE4rWn0eDIwTCoRJ/mT54 cJFpjx1ElozrGrg6TeUPPmXKNCp9rOoZLRx0xEejmewRXk5FP8NtEQheWMRJdH4iKwy4 1jBFgcadc3ZMzZlsAVWMZtWCH+YRfWBtfDVL+XbQ5hul8mSWrsUVlm8cbEuI6QZtD7QM InLIh7svhsFPeF55oPDy+oIWN4RcacmQ4EQIhLwwn0rUNdhfsdfvQxp9iLDs/GjWJ2/q 9gqA== X-Gm-Message-State: AOJu0Yy02rFCrIO9iHbuxehyeMRZ3pjLqfKD1sjZdLmhNR3bUOR7Zlmf SizN8gVZ6ZPxfiY4sRiFgQ50RjTymCGqkb3KAwfvWH0aGzd1rSMwrMuhdMyw2lrAsHmngQi02l6 QerY9FqZzMDvptcSVWB00Mb0mSpgZ5dBPVyxeVLNfRv2gzlfMreV4dd3FEGDiOufiR0QCiUxuOf 8PdHiKIvJa/b0DOX9Xgwmi5MxkHTzIhlznl6eTLNrLGukO X-Gm-Gg: ASbGncuC/FpTQtqb4ei/Gbq0jvn/AfUYPhElKaN4xVNAtLKymLrLnGPzNTiBrRWh0bW tt8LLWItbIaKi2NN8gyFpGcqkLclzJdVrYFv0OGlu7/SVeQyzxdjHPm+345DNrNcogbKzIx+ikR oPokOPUIUpsD83GI7dS5odmSxsTJ+U/gBa1X0lW5heAyKEDGi2XnALD0L7I7ibXcymjg3Bb09Xl Gmup01z7K0Nd9oYed8u0HD+sX6jv8NTeCcwknMaPcNU/KiZp4mB X-Received: by 2002:a5d:6daf:0:b0:385:f64e:f177 with SMTP id ffacd0b85a97d-38a8b0dafa2mr13358489f8f.11.1736774216091; Mon, 13 Jan 2025 05:16:56 -0800 (PST) X-Google-Smtp-Source: AGHT+IHM8kqPNMvs4k+lMVb/1YEEDh2vMU1tnG15WGDH/BJuRUJ2BI9n6kMTuyVCDUkmDxXKO6pcnA== X-Received: by 2002:a5d:6daf:0:b0:385:f64e:f177 with SMTP id ffacd0b85a97d-38a8b0dafa2mr13358454f8f.11.1736774215697; Mon, 13 Jan 2025 05:16:55 -0800 (PST) Received: from localhost ([2a09:80c0:192:0:5dac:bf3d:c41:c3e7]) by smtp.gmail.com with UTF8SMTPSA id ffacd0b85a97d-38a8e37d0casm12226917f8f.11.2025.01.13.05.16.54 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 13 Jan 2025 05:16:55 -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 v2 6/6] mm/hugetlb: use folio->lru int demote_free_hugetlb_folios() Date: Mon, 13 Jan 2025 14:16:11 +0100 Message-ID: <20250113131611.2554758-7-david@redhat.com> X-Mailer: git-send-email 2.47.1 In-Reply-To: <20250113131611.2554758-1-david@redhat.com> References: <20250113131611.2554758-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 and handle it more similar to __split_huge_page_tail(). Signed-off-by: David Hildenbrand Reviewed-by: Sidhartha Kumar --- mm/hugetlb.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index bc4ab45d9b93b..a94d52dd53728 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); + /* Careful: see __split_huge_page_tail() */ + struct folio *new_folio =3D (struct folio *)page; =20 - page->mapping =3D NULL; clear_compound_head(page); prep_compound_page(page, dst->order); =20 - init_new_hugetlb_folio(dst, page_folio(page)); - list_add(&page->lru, &dst_list); + new_folio->mapping =3D NULL; + init_new_hugetlb_folio(dst, new_folio); + list_add(&new_folio->lru, &dst_list); } } =20 --=20 2.47.1