]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
mm-swap-add-a-adaptive-full-cluster-cache-reclaim-fix
authorKairui Song <ryncsn@gmail.com>
Thu, 1 Aug 2024 09:59:17 +0000 (17:59 +0800)
committerAndrew Morton <akpm@linux-foundation.org>
Sat, 17 Aug 2024 00:52:48 +0000 (17:52 -0700)
fix discard of full cluster

Link: https://lkml.kernel.org/r/CAMgjq7CWwK75_2Zi5P40K08pk9iqOcuWKL6khu=x4Yg_nXaQag@mail.gmail.com
Signed-off-by: Kairui Song <kasong@tencent.com>
Reported-by: David Hildenbrand <david@redhat.com>
Closes: https://lkml.kernel.org/r/3c79021a-e9a0-4669-a4e7-7060edf12d58@redhat.com
Cc: Barry Song <21cnbao@gmail.com>
Cc: Chris Li <chrisl@kernel.org>
Cc: "Huang, Ying" <ying.huang@intel.com>
Cc: Hugh Dickins <hughd@google.com>
Cc: Kalesh Singh <kaleshsingh@google.com>
Cc: Ryan Roberts <ryan.roberts@arm.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
include/linux/swap.h
mm/swapfile.c

index 476354391a24c0b9b6b7c7df2a98ab0a1c3c2406..1c8f844a9f0f268bdb14ee79d4e9c93caeebf1e4 100644 (file)
@@ -260,6 +260,7 @@ struct swap_cluster_info {
 #define CLUSTER_FLAG_FREE 1 /* This cluster is free */
 #define CLUSTER_FLAG_NONFULL 2 /* This cluster is on nonfull list */
 #define CLUSTER_FLAG_FRAG 4 /* This cluster is on nonfull list */
+#define CLUSTER_FLAG_FULL 8 /* This cluster is on full list */
 
 /*
  * The first page in the swap file is the swap header, which is always marked
index 38f35aaf1fc2422ee3bbd0790c20a66d429ce7a7..6de12d712c7ed5a9e68659e9f83b8ac711074ad3 100644 (file)
@@ -450,7 +450,10 @@ static void __free_cluster(struct swap_info_struct *si, struct swap_cluster_info
        lockdep_assert_held(&si->lock);
        lockdep_assert_held(&ci->lock);
 
-       list_move_tail(&ci->list, &si->free_clusters);
+       if (ci->flags)
+               list_move_tail(&ci->list, &si->free_clusters);
+       else
+               list_add_tail(&ci->list, &si->free_clusters);
        ci->flags = CLUSTER_FLAG_FREE;
        ci->order = 0;
 }
@@ -474,7 +477,6 @@ static void swap_do_scheduled_discard(struct swap_info_struct *si)
                                SWAPFILE_CLUSTER);
 
                spin_lock(&si->lock);
-
                spin_lock(&ci->lock);
                __free_cluster(si, ci);
                memset(si->swap_map + idx * SWAPFILE_CLUSTER,
@@ -666,7 +668,7 @@ static void cluster_alloc_range(struct swap_info_struct *si, struct swap_cluster
                if (ci->flags & CLUSTER_FLAG_FRAG)
                        si->frag_cluster_nr[ci->order]--;
                list_move_tail(&ci->list, &si->full_clusters);
-               ci->flags = 0;
+               ci->flags = CLUSTER_FLAG_FULL;
        }
 }