From nobody Sun Oct 5 01:44:58 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 896A627877B for ; Mon, 11 Aug 2025 14:39:58 +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=1754923200; cv=none; b=EGJrriH1tEDsr8PBy462fH43Cj9MMGZTLSz+wVWx1XrzKc/FtX5nL/KdyaSh4A+duX8+cY4WWIRWYmIf30TCyK8UjJ+XT9gHbwucw8adweWOMjYRhte2L6QvZvl05HZAV8dM6+W780KN5mkdBp0pCmBqNyceAP5j4/7OIxmEShY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754923200; c=relaxed/simple; bh=/RkJtjEV80XxhNf5as20u3EFMwDFY27Gb0v/Rq5JlbA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jYzoXkDoVhFWgZ988G7iSJ/8c1S9zvzEwMr4U+KNIW30dYLPnPT8mwIizLIALNoQ2ZpOOva6/HWaDVQgY2QkuWTEJpx7krABj2AuugrudI/uC2+pxgWN2V6tuqHlysntrfk+Gt7NSz8nYZg3Xv6mDTow+J+x82vBsBmy+yPYqao= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=PkayUyg9; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="PkayUyg9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1754923197; 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=xm0iYFfBOfajjEoxheRfcdwl0u9A+taNg4Dew7papsc=; b=PkayUyg9xwuO0gq3Iip+vFP2EBfR8K9mq66WdTxJaz3ZPaaFTnty9QABPxDj5i/4ETjuR+ ehyemP/ozAK19swpvFRTWV7RnDwfxgW+dllrtxG3Fr1Z8ErfuAfMU1ZKVPqCi4ENJkZ6LH cRIvqa+vUKPiC8apGDW9XpHSLKyInOg= 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-138-PLZ8N_9NOxOxvTiH3QI99A-1; Mon, 11 Aug 2025 10:39:56 -0400 X-MC-Unique: PLZ8N_9NOxOxvTiH3QI99A-1 X-Mimecast-MFC-AGG-ID: PLZ8N_9NOxOxvTiH3QI99A_1754923195 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-4595cfed9f4so20642235e9.1 for ; Mon, 11 Aug 2025 07:39:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754923195; x=1755527995; 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=xm0iYFfBOfajjEoxheRfcdwl0u9A+taNg4Dew7papsc=; b=iBxpd8k8vQxfOch8XgCyVuioI8bEJo9F128MJH0/scibxLd9d/btb7b/zNfjqhG2Ju Zmi9dDT0RapH0Hn0ebwrcCq63jthEK6q3N8BPSU5twGW6MI5ea7SRz6ypr/3UsACMNQk o+5HehJxXNcSjupH8euBesxzsVXpigRu9/zXAW5QglfywvYxaaChqmubx0HGQ3lu6agC d4960xF13FJqmsL9lIN88r/4U+4LoV3Cyoh7U6Ab/wTAttrw0F+TmAvNRs95rDjFvk0P lP8KNq6139/cAM9uoLrzBCB5FUC7HDoCY6EKuxl7tizo8mkguvaPvboh/XrN2wJiurSI RPrw== X-Gm-Message-State: AOJu0YwnrmwaYBhtMBF+27eDJBisMIEoOIPqqN17TkAyeGoTU7vY6JMi lE5xOHXGsC15ku2KDV3rLpbO3yUCc9EvLz3gLOQBi1e+PB9R0XPmiUKo+POCpwzVe8AwcTdHvOQ +xpxwZel5TcFoV5Zuf9NJpPCO2mIiy6nHy80bnI1rJoZ2xOj3cL2S6Hefigh+khf6Ocrp5iKtX8 n3B10uEGVBH+GJBxCt/EFOMA9vN5oXPSMuyoLhBkEMaiUh4A== X-Gm-Gg: ASbGncux621f5JYCPrshH1IGVOwKa0h5ktmyc04LthAnmiq0yN2T5qDwfC2dEcVEyP2 xIY12v/1Wpij5hVO27Q0FDqr1qhoOKUgfJsWL1KvUzlcow9b5yQeLmgVGU90iIphtJhmG33vTi4 qlqf1HExCB8bHfZUQcOQ4PebhlGyfo/cr3dVu3lsyyzWgDvVjRUdpzqzbd9h2MusH5/pq9BGS8z ieciZl2SjuPewaz/mIUGtMuhY25375pBzjW8U9byd+2zAh0n1XmU/ZDrdWSfoNC2TRtkRpSfOZf KgJic3IPaJ8LjQBKxJblbQS3KuoxOGzxdt5XwfGbEWjmnOBK+pLv+g/k0cSKEmFWcNiXavMfhwb ebIoqcPr+IkRFJqwA6asGhDxh X-Received: by 2002:a05:600c:1d01:b0:458:be62:dcd3 with SMTP id 5b1f17b1804b1-459f4f9bd34mr130468655e9.17.1754923195053; Mon, 11 Aug 2025 07:39:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHiigg+0PNvGEb3wRzSSq9JM70VE9hLMIH2EVbNkuJbtlZWW3Ch7GW5N/kbNcHDKqZhLgst/w== X-Received: by 2002:a05:600c:1d01:b0:458:be62:dcd3 with SMTP id 5b1f17b1804b1-459f4f9bd34mr130467845e9.17.1754923194477; Mon, 11 Aug 2025 07:39:54 -0700 (PDT) Received: from localhost (p200300d82f06a600a397de1d2f8bb66f.dip0.t-ipconnect.de. [2003:d8:2f06:a600:a397:de1d:2f8b:b66f]) by smtp.gmail.com with UTF8SMTPSA id 5b1f17b1804b1-459fb43b491sm120611835e9.3.2025.08.11.07.39.52 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 11 Aug 2025 07:39:54 -0700 (PDT) From: David Hildenbrand To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, linuxppc-dev@lists.ozlabs.org, virtualization@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-aio@kvack.org, linux-btrfs@vger.kernel.org, jfs-discussion@lists.sourceforge.net, David Hildenbrand , Andrew Morton , Madhavan Srinivasan , Michael Ellerman , Nicholas Piggin , Christophe Leroy , Jerrin Shaji George , Arnd Bergmann , Greg Kroah-Hartman , "Michael S. Tsirkin" , Jason Wang , Xuan Zhuo , =?UTF-8?q?Eugenio=20P=C3=A9rez?= , Alexander Viro , Christian Brauner , Jan Kara , Benjamin LaHaise , Chris Mason , Josef Bacik , David Sterba , Muchun Song , Oscar Salvador , Dave Kleikamp , Zi Yan , Matthew Brost , Joshua Hahn , Rakie Kim , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Minchan Kim , Sergey Senozhatsky Subject: [PATCH v1 1/2] mm/migrate: remove MIGRATEPAGE_UNMAP Date: Mon, 11 Aug 2025 16:39:47 +0200 Message-ID: <20250811143949.1117439-2-david@redhat.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20250811143949.1117439-1-david@redhat.com> References: <20250811143949.1117439-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" migrate_folio_unmap() is the only user of MIGRATEPAGE_UNMAP. We want to remove MIGRATEPAGE_* completely. It's rather weird to have a generic MIGRATEPAGE_UNMAP, documented to be returned from address-space callbacks, when it's only used for an internal helper. Let's start by having only a single "success" return value for migrate_folio_unmap() -- 0 -- by moving the "folio was already freed" check into the single caller. There is a remaining comment for PG_isolated, which we renamed to PG_movable_ops_isolated recently and forgot to update. While we might still run into that case with zsmalloc, it's something we want to get rid of soon. So let's just focus that optimization on real folios only for now by excluding movable_ops pages. Note that concurrent freeing can happen at any time and this "already freed" check is not relevant for correctness. Signed-off-by: David Hildenbrand Reviewed-by: Lance Yang --- include/linux/migrate.h | 1 - mm/migrate.c | 40 ++++++++++++++++++++-------------------- 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/include/linux/migrate.h b/include/linux/migrate.h index acadd41e0b5cf..40f2b5a37efbb 100644 --- a/include/linux/migrate.h +++ b/include/linux/migrate.h @@ -18,7 +18,6 @@ struct migration_target_control; * - zero on page migration success; */ #define MIGRATEPAGE_SUCCESS 0 -#define MIGRATEPAGE_UNMAP 1 =20 /** * struct movable_operations - Driver page migration diff --git a/mm/migrate.c b/mm/migrate.c index 425401b2d4e14..e9dacf1028dc7 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1176,16 +1176,6 @@ static int migrate_folio_unmap(new_folio_t get_new_f= olio, bool locked =3D false; bool dst_locked =3D false; =20 - if (folio_ref_count(src) =3D=3D 1) { - /* Folio was freed from under us. So we are done. */ - folio_clear_active(src); - folio_clear_unevictable(src); - /* free_pages_prepare() will clear PG_isolated. */ - list_del(&src->lru); - migrate_folio_done(src, reason); - return MIGRATEPAGE_SUCCESS; - } - dst =3D get_new_folio(src, private); if (!dst) return -ENOMEM; @@ -1275,7 +1265,7 @@ static int migrate_folio_unmap(new_folio_t get_new_fo= lio, =20 if (unlikely(page_has_movable_ops(&src->page))) { __migrate_folio_record(dst, old_page_state, anon_vma); - return MIGRATEPAGE_UNMAP; + return 0; } =20 /* @@ -1305,7 +1295,7 @@ static int migrate_folio_unmap(new_folio_t get_new_fo= lio, =20 if (!folio_mapped(src)) { __migrate_folio_record(dst, old_page_state, anon_vma); - return MIGRATEPAGE_UNMAP; + return 0; } =20 out: @@ -1848,14 +1838,28 @@ static int migrate_pages_batch(struct list_head *fr= om, continue; } =20 + /* + * If we are holding the last folio reference, the folio + * was freed from under us, so just drop our reference. + */ + if (likely(!page_has_movable_ops(&folio->page)) && + folio_ref_count(folio) =3D=3D 1) { + folio_clear_active(folio); + folio_clear_unevictable(folio); + list_del(&folio->lru); + migrate_folio_done(folio, reason); + stats->nr_succeeded +=3D nr_pages; + stats->nr_thp_succeeded +=3D is_thp; + continue; + } + rc =3D migrate_folio_unmap(get_new_folio, put_new_folio, private, folio, &dst, mode, reason, ret_folios); /* * The rules are: - * Success: folio will be freed - * Unmap: folio will be put on unmap_folios list, - * dst folio put on dst_folios list + * 0: folio will be put on unmap_folios list, + * dst folio put on dst_folios list * -EAGAIN: stay on the from list * -ENOMEM: stay on the from list * Other errno: put on ret_folios list @@ -1905,11 +1909,7 @@ static int migrate_pages_batch(struct list_head *fro= m, thp_retry +=3D is_thp; nr_retry_pages +=3D nr_pages; break; - case MIGRATEPAGE_SUCCESS: - stats->nr_succeeded +=3D nr_pages; - stats->nr_thp_succeeded +=3D is_thp; - break; - case MIGRATEPAGE_UNMAP: + case 0: list_move_tail(&folio->lru, &unmap_folios); list_add_tail(&dst->lru, &dst_folios); break; --=20 2.50.1