Skip to contentSkip to conversation

+ swap-change-swap_info-singly-linked-list-to-list_head.patch added to -mm tree

PATCH [email protected] 1 participant 1 message May 12, 2014

Subsystems (2)
lore
Share & tools
lore

[email protected]

author maintainer
#0 lore raw

Subject: + swap-change-swap_info-singly-linked-list-to-list_head.patch added to -mm tree
To: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected]
From: [email protected]
Date: Mon, 12 May 2014 14:01:25 -0700

The patch titled
Subject: swap: change swap_info singly-linked list to list_head
has been added to the -mm tree. Its filename is
swap-change-swap_info-singly-linked-list-to-list_head.patch

This patch should soon appear at
http://ozlabs.org/~akpm/mmots/broken-out/swap-change-swap_info-singly-linked-list-to-list_head.patch
and later at
http://ozlabs.org/~akpm/mmotm/broken-out/swap-change-swap_info-singly-linked-list-to-list_head.patch

Before you just go and hit "reply", please:
a) Consider who else should be cc'ed
b) Prefer to cc a suitable mailing list as well
c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's

*** Remember to use Documentation/SubmitChecklist when testing your code ***

The -mm tree is included into linux-next and is updated there every 3-4 working days

------------------------------------------------------
From: Dan Streetman <[email protected]>
Subject: swap: change swap_info singly-linked list to list_head

The logic controlling the singly-linked list of swap_info_struct entries for all active, i.e. swapon'ed, swap targets is rather complex, because:

-it stores the entries in priority order
-there is a pointer to the highest priority entry
-there is a pointer to the highest priority not-full entry -there is a highest_priority_index variable set outside the swap_lock -swap entries of equal priority should be used equally

this complexity leads to bugs such as: https://lkml.org/lkml/2014/2/13/181
where different priority swap targets are incorrectly used equally.

That bug probably could be solved with the existing singly-linked lists, but I think it would only add more complexity to the already difficult to understand get_swap_page() swap_list iteration logic.

The first patch changes from a singly-linked list to a doubly-linked list using list_heads; the highest_priority_index and related code are removed and get_swap_page() starts each iteration at the highest priority swap_info entry, even if it's full. While this does introduce unnecessary list iteration (i.e. Schlemiel the painter's algorithm) in the case where one or more of the highest priority entries are full, the iteration and manipulation code is much simpler and behaves correctly re: the above bug; and the fourth patch removes the unnecessary iteration.

The second patch adds some minor plist helper functions; nothing new really, just functions to match existing regular list functions. These are used by the next two patches.

The third patch adds plist_requeue(), which is used by get_swap_page() in the next patch - it performs the requeueing of same-priority entries (which moves the entry to the end of its priority in the plist), so that all equal-priority swap_info_structs get used equally.

The fourth patch converts the main list into a plist, and adds a new plist that contains only swap_info entries that are both active and not full. As Mel suggested using plists allows removing all the ordering code from swap - plists handle ordering automatically. The list naming is also clarified now that there are two lists, with the original list changed from swap_list_head to swap_active_head and the new list named swap_avail_head. A new spinlock is also added for the new list, so swap_info entries can be added or removed from the new list immediately as they become full or not full.

This patch (of 4):

Replace the singly-linked list tracking active, i.e. swapon'ed, swap_info_struct entries with a doubly-linked list using struct list_heads. Simplify the logic iterating and manipulating the list of entries, especially get_swap_page(), by using standard list_head functions, and removing the highest priority iteration logic.

The change fixes the bug:
https://lkml.org/lkml/2014/2/13/181
in which different priority swap entries after the highest priority entry are incorrectly used equally in pairs. The swap behavior is now as advertised, i.e. different priority swap entries are used in order, and equal priority swap targets are used concurrently.

Cc Shaohua Li <[email protected]>
Cc Hugh Dickins <[email protected]>
Cc Dan Streetman <[email protected]>
Cc Michal Hocko <[email protected]>
Cc Christian Ehrhardt <[email protected]>
Cc Weijie Yang <[email protected]>
Cc Rik van Riel <[email protected]>
Cc Johannes Weiner <[email protected]>
Cc Bob Liu <[email protected]>
Cc Steven Rostedt <[email protected]>
Cc Peter Zijlstra <[email protected]>
Cc Paul Gortmaker <[email protected]>
Cc Thomas Gleixner <[email protected]>

---

 include/linux/swap.h     |    7 -
 include/linux/swapfile.h |    2 
 mm/frontswap.c           |   13 --
 mm/swapfile.c            |  171 +++++++++++++++----------------------
 4 files changed, 78 insertions(+), 115 deletions(-)
include/linux/swap.h renamed from include/linux/swap.h~swap-change-swap_info-singly-linked-list-to-list_head +1 -6
diff -puN include/linux/swap.h~swap-change-swap_info-singly-linked-list-to-list_head include/linux/swap.h
@@ -214,8 +214,8 @@ struct percpu_cluster {
 struct swap_info_struct {
 	unsigned long	flags;		/* SWP_USED etc: see above */
 	signed short	prio;		/* swap priority of this type */
+	struct list_head list;		/* entry in swap list */
 	signed char	type;		/* strange name for an index */
-	signed char	next;		/* next type on the swap list */
 	unsigned int	max;		/* extent of the swap_map */
 	unsigned char *swap_map;	/* vmalloc'ed array of usage counts */
 	struct swap_cluster_info *cluster_info; /* cluster info. Only for SSD */
@@ -255,11 +255,6 @@ struct swap_info_struct {
 	struct swap_cluster_info discard_cluster_tail; /* list tail of discard clusters */
 };
 
-struct swap_list_t {
-	int head;	/* head of priority-ordered swapfile list */
-	int next;	/* swapfile to be used next */
-};
-
 /* linux/mm/workingset.c */
 void *workingset_eviction(struct address_space *mapping, struct page *page);
 bool workingset_refault(void *shadow);
include/linux/swapfile.h renamed from include/linux/swapfile.h~swap-change-swap_info-singly-linked-list-to-list_head +1 -1
diff -puN include/linux/swapfile.h~swap-change-swap_info-singly-linked-list-to-list_head include/linux/swapfile.h
@@ -6,7 +6,7 @@
  * want to expose them to the dozens of source files that include swap.h
  */
 extern spinlock_t swap_lock;
-extern struct swap_list_t swap_list;
+extern struct list_head swap_list_head;
 extern struct swap_info_struct *swap_info[];
 extern int try_to_unuse(unsigned int, bool, unsigned long);
 
mm/frontswap.c renamed from mm/frontswap.c~swap-change-swap_info-singly-linked-list-to-list_head +4 -9
diff -puN mm/frontswap.c~swap-change-swap_info-singly-linked-list-to-list_head mm/frontswap.c
@@ -327,15 +327,12 @@ EXPORT_SYMBOL(__frontswap_invalidate_are
 
 static unsigned long __frontswap_curr_pages(void)
 {
-	int type;
 	unsigned long totalpages = 0;
 	struct swap_info_struct *si = NULL;
 
 	assert_spin_locked(&swap_lock);
-	for (type = swap_list.head; type >= 0; type = si->next) {
-		si = swap_info[type];
+	list_for_each_entry(si, &swap_list_head, list)
 		totalpages += atomic_read(&si->frontswap_pages);
-	}
 	return totalpages;
 }
 
@@ -347,11 +344,9 @@ static int __frontswap_unuse_pages(unsig
 	int si_frontswap_pages;
 	unsigned long total_pages_to_unuse = total;
 	unsigned long pages = 0, pages_to_unuse = 0;
-	int type;
 
 	assert_spin_locked(&swap_lock);
-	for (type = swap_list.head; type >= 0; type = si->next) {
-		si = swap_info[type];
+	list_for_each_entry(si, &swap_list_head, list) {
 		si_frontswap_pages = atomic_read(&si->frontswap_pages);
 		if (total_pages_to_unuse < si_frontswap_pages) {
 			pages = pages_to_unuse = total_pages_to_unuse;
@@ -366,7 +361,7 @@ static int __frontswap_unuse_pages(unsig
 		}
 		vm_unacct_memory(pages);
 		*unused = pages_to_unuse;
-		*swapid = type;
+		*swapid = si->type;
 		ret = 0;
 		break;
 	}
@@ -413,7 +408,7 @@ void frontswap_shrink(unsigned long targ
 	/*
 	 * we don't want to hold swap_lock while doing a very
 	 * lengthy try_to_unuse, but swap_list may change
-	 * so restart scan from swap_list.head each time
+	 * so restart scan from swap_list_head each time
 	 */
 	spin_lock(&swap_lock);
 	ret = __frontswap_shrink(target_pages, &pages_to_unuse, &type);
mm/swapfile.c renamed from mm/swapfile.c~swap-change-swap_info-singly-linked-list-to-list_head +72 -99

285 lines not on this page · raw message

_

Patches currently in -mm which might be from [email protected] are

swap-change-swap_info-singly-linked-list-to-list_head.patch plist-add-helper-functions.patch plist-add-plist_requeue.patch swap-change-swap_list_head-to-plist-add-swap_avail_head.patch documentation-expand-clarify-debug-documentation.patch lib-plistc-replace-pr_debug-with-printk-in-plist_test.patch lib-plistc-make-config_debug_pi_list-selectable.patch