From nobody Fri Dec 19 07:43:42 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