Commit 213516ac authored by chenqiwu's avatar chenqiwu Committed by Linus Torvalds

mm/swapfile: use list_{prev,next}_entry() instead of open-coding

Use list_{prev,next}_entry() instead of list_entry() for better
code readability.
Signed-off-by: default avatarchenqiwu <chenqiwu@xiaomi.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Reviewed-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Cc: Matthew Wilcox <willy@infradead.org>
Cc: David Hildenbrand <david@redhat.com>
Cc: Wei Yang <richard.weiyang@gmail.com>
Cc: Michal Hocko <mhocko@suse.com>
Cc: Pankaj Gupta <pankaj.gupta.linux@gmail.com>
Cc: Yang Shi <yang.shi@linux.alibaba.com>
Cc: Qian Cai <cai@lca.pw>
Cc: Baoquan He <bhe@redhat.com>
Link: http://lkml.kernel.org/r/1586599916-15456-2-git-send-email-qiwuchen55@gmail.comSigned-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 548b6a1e
...@@ -3654,7 +3654,7 @@ static bool swap_count_continued(struct swap_info_struct *si, ...@@ -3654,7 +3654,7 @@ static bool swap_count_continued(struct swap_info_struct *si,
spin_lock(&si->cont_lock); spin_lock(&si->cont_lock);
offset &= ~PAGE_MASK; offset &= ~PAGE_MASK;
page = list_entry(head->lru.next, struct page, lru); page = list_next_entry(head, lru);
map = kmap_atomic(page) + offset; map = kmap_atomic(page) + offset;
if (count == SWAP_MAP_MAX) /* initial increment from swap_map */ if (count == SWAP_MAP_MAX) /* initial increment from swap_map */
...@@ -3666,13 +3666,13 @@ static bool swap_count_continued(struct swap_info_struct *si, ...@@ -3666,13 +3666,13 @@ static bool swap_count_continued(struct swap_info_struct *si,
*/ */
while (*map == (SWAP_CONT_MAX | COUNT_CONTINUED)) { while (*map == (SWAP_CONT_MAX | COUNT_CONTINUED)) {
kunmap_atomic(map); kunmap_atomic(map);
page = list_entry(page->lru.next, struct page, lru); page = list_next_entry(page, lru);
BUG_ON(page == head); BUG_ON(page == head);
map = kmap_atomic(page) + offset; map = kmap_atomic(page) + offset;
} }
if (*map == SWAP_CONT_MAX) { if (*map == SWAP_CONT_MAX) {
kunmap_atomic(map); kunmap_atomic(map);
page = list_entry(page->lru.next, struct page, lru); page = list_next_entry(page, lru);
if (page == head) { if (page == head) {
ret = false; /* add count continuation */ ret = false; /* add count continuation */
goto out; goto out;
...@@ -3682,12 +3682,10 @@ init_map: *map = 0; /* we didn't zero the page */ ...@@ -3682,12 +3682,10 @@ init_map: *map = 0; /* we didn't zero the page */
} }
*map += 1; *map += 1;
kunmap_atomic(map); kunmap_atomic(map);
page = list_entry(page->lru.prev, struct page, lru); while ((page = list_prev_entry(page, lru)) != head) {
while (page != head) {
map = kmap_atomic(page) + offset; map = kmap_atomic(page) + offset;
*map = COUNT_CONTINUED; *map = COUNT_CONTINUED;
kunmap_atomic(map); kunmap_atomic(map);
page = list_entry(page->lru.prev, struct page, lru);
} }
ret = true; /* incremented */ ret = true; /* incremented */
...@@ -3698,7 +3696,7 @@ init_map: *map = 0; /* we didn't zero the page */ ...@@ -3698,7 +3696,7 @@ init_map: *map = 0; /* we didn't zero the page */
BUG_ON(count != COUNT_CONTINUED); BUG_ON(count != COUNT_CONTINUED);
while (*map == COUNT_CONTINUED) { while (*map == COUNT_CONTINUED) {
kunmap_atomic(map); kunmap_atomic(map);
page = list_entry(page->lru.next, struct page, lru); page = list_next_entry(page, lru);
BUG_ON(page == head); BUG_ON(page == head);
map = kmap_atomic(page) + offset; map = kmap_atomic(page) + offset;
} }
...@@ -3707,13 +3705,11 @@ init_map: *map = 0; /* we didn't zero the page */ ...@@ -3707,13 +3705,11 @@ init_map: *map = 0; /* we didn't zero the page */
if (*map == 0) if (*map == 0)
count = 0; count = 0;
kunmap_atomic(map); kunmap_atomic(map);
page = list_entry(page->lru.prev, struct page, lru); while ((page = list_prev_entry(page, lru)) != head) {
while (page != head) {
map = kmap_atomic(page) + offset; map = kmap_atomic(page) + offset;
*map = SWAP_CONT_MAX | count; *map = SWAP_CONT_MAX | count;
count = COUNT_CONTINUED; count = COUNT_CONTINUED;
kunmap_atomic(map); kunmap_atomic(map);
page = list_entry(page->lru.prev, struct page, lru);
} }
ret = count == COUNT_CONTINUED; ret = count == COUNT_CONTINUED;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment