diff mbox series

[v2,3/9] mm/vmscan: introduce helper function reclaim_page_list()

Message ID 20220409093500.10329-4-linmiaohe@huawei.com (mailing list archive)
State New
Headers show
Series A few cleanup and fixup patches for vmscan | expand

Commit Message

Miaohe Lin April 9, 2022, 9:34 a.m. UTC
Introduce helper function reclaim_page_list() to eliminate the duplicated
code of doing shrink_page_list() and putback_lru_page. Also We can separate
node reclaim from node page list operation this way. No functional change
intended.

Signed-off-by: Miaohe Lin <linmiaohe@huawei.com>
---
 mm/vmscan.c | 50 +++++++++++++++++++++++++-------------------------
 1 file changed, 25 insertions(+), 25 deletions(-)

Comments

Matthew Wilcox April 9, 2022, 1:44 p.m. UTC | #1
On Sat, Apr 09, 2022 at 05:34:54PM +0800, Miaohe Lin wrote:
> +	nr_reclaimed = shrink_page_list(page_list, pgdat, &sc, &dummy_stat, false);
> +	while (!list_empty(page_list)) {
> +		folio = lru_to_folio(page_list);
> +		list_del(&folio->lru);
> +		putback_lru_page(&folio->page);

folio_putback_lru()
Miaohe Lin April 11, 2022, 1:53 a.m. UTC | #2
On 2022/4/9 21:44, Matthew Wilcox wrote:
> On Sat, Apr 09, 2022 at 05:34:54PM +0800, Miaohe Lin wrote:
>> +	nr_reclaimed = shrink_page_list(page_list, pgdat, &sc, &dummy_stat, false);
>> +	while (!list_empty(page_list)) {
>> +		folio = lru_to_folio(page_list);
>> +		list_del(&folio->lru);
>> +		putback_lru_page(&folio->page);
> 
> folio_putback_lru()

I thought folio_putback_lru is deliberately not to use because there is no caller of folio_putback_lru now.
But it seems I was wrong. Will do it in next version.

Thanks a lot!

> 
> .
>
Matthew Wilcox April 11, 2022, 3:17 a.m. UTC | #3
On Mon, Apr 11, 2022 at 09:53:15AM +0800, Miaohe Lin wrote:
> On 2022/4/9 21:44, Matthew Wilcox wrote:
> > On Sat, Apr 09, 2022 at 05:34:54PM +0800, Miaohe Lin wrote:
> >> +	nr_reclaimed = shrink_page_list(page_list, pgdat, &sc, &dummy_stat, false);
> >> +	while (!list_empty(page_list)) {
> >> +		folio = lru_to_folio(page_list);
> >> +		list_del(&folio->lru);
> >> +		putback_lru_page(&folio->page);
> > 
> > folio_putback_lru()
> 
> I thought folio_putback_lru is deliberately not to use because there is no caller of folio_putback_lru now.
> But it seems I was wrong. Will do it in next version.

Looks like all of the uses of it that I mooted during the last merge
window ended up going away.

https://lore.kernel.org/all/20220204195852.1751729-47-willy@infradead.org/
was obsoleted by commit b109b87050df

https://lore.kernel.org/all/20220204195852.1751729-48-willy@infradead.org/
and
https://lore.kernel.org/all/20220204195852.1751729-50-willy@infradead.org/
were also obsoleted by Hugh's mlock changes

I also sent
https://lore.kernel.org/all/YjJJIrENYb1qFHzl@casper.infradead.org/

but never quite got it up to submittable quality.
Miaohe Lin April 11, 2022, 3:26 a.m. UTC | #4
On 2022/4/11 11:17, Matthew Wilcox wrote:
> On Mon, Apr 11, 2022 at 09:53:15AM +0800, Miaohe Lin wrote:
>> On 2022/4/9 21:44, Matthew Wilcox wrote:
>>> On Sat, Apr 09, 2022 at 05:34:54PM +0800, Miaohe Lin wrote:
>>>> +	nr_reclaimed = shrink_page_list(page_list, pgdat, &sc, &dummy_stat, false);
>>>> +	while (!list_empty(page_list)) {
>>>> +		folio = lru_to_folio(page_list);
>>>> +		list_del(&folio->lru);
>>>> +		putback_lru_page(&folio->page);
>>>
>>> folio_putback_lru()
>>
>> I thought folio_putback_lru is deliberately not to use because there is no caller of folio_putback_lru now.
>> But it seems I was wrong. Will do it in next version.
> 
> Looks like all of the uses of it that I mooted during the last merge
> window ended up going away.
> 
> https://lore.kernel.org/all/20220204195852.1751729-47-willy@infradead.org/
> was obsoleted by commit b109b87050df
> 
> https://lore.kernel.org/all/20220204195852.1751729-48-willy@infradead.org/
> and
> https://lore.kernel.org/all/20220204195852.1751729-50-willy@infradead.org/
> were also obsoleted by Hugh's mlock changes
> 
> I also sent
> https://lore.kernel.org/all/YjJJIrENYb1qFHzl@casper.infradead.org/
> 
> but never quite got it up to submittable quality.

I see. This is really a pity. Many thanks for clarifying. :)

> 
> .
>
diff mbox series

Patch

diff --git a/mm/vmscan.c b/mm/vmscan.c
index 01f5db75a507..59b96320f481 100644
--- a/mm/vmscan.c
+++ b/mm/vmscan.c
@@ -2531,14 +2531,12 @@  static void shrink_active_list(unsigned long nr_to_scan,
 			nr_deactivate, nr_rotated, sc->priority, file);
 }
 
-unsigned long reclaim_pages(struct list_head *page_list)
+static unsigned int reclaim_page_list(struct list_head *page_list,
+				      struct pglist_data *pgdat)
 {
-	int nid = NUMA_NO_NODE;
-	unsigned int nr_reclaimed = 0;
-	LIST_HEAD(node_page_list);
 	struct reclaim_stat dummy_stat;
-	struct page *page;
-	unsigned int noreclaim_flag;
+	unsigned int nr_reclaimed;
+	struct folio *folio;
 	struct scan_control sc = {
 		.gfp_mask = GFP_KERNEL,
 		.may_writepage = 1,
@@ -2547,6 +2545,24 @@  unsigned long reclaim_pages(struct list_head *page_list)
 		.no_demotion = 1,
 	};
 
+	nr_reclaimed = shrink_page_list(page_list, pgdat, &sc, &dummy_stat, false);
+	while (!list_empty(page_list)) {
+		folio = lru_to_folio(page_list);
+		list_del(&folio->lru);
+		putback_lru_page(&folio->page);
+	}
+
+	return nr_reclaimed;
+}
+
+unsigned long reclaim_pages(struct list_head *page_list)
+{
+	int nid = NUMA_NO_NODE;
+	unsigned int nr_reclaimed = 0;
+	LIST_HEAD(node_page_list);
+	struct page *page;
+	unsigned int noreclaim_flag;
+
 	noreclaim_flag = memalloc_noreclaim_save();
 
 	while (!list_empty(page_list)) {
@@ -2562,28 +2578,12 @@  unsigned long reclaim_pages(struct list_head *page_list)
 			continue;
 		}
 
-		nr_reclaimed += shrink_page_list(&node_page_list,
-						NODE_DATA(nid),
-						&sc, &dummy_stat, false);
-		while (!list_empty(&node_page_list)) {
-			page = lru_to_page(&node_page_list);
-			list_del(&page->lru);
-			putback_lru_page(page);
-		}
-
+		nr_reclaimed += reclaim_page_list(&node_page_list, NODE_DATA(nid));
 		nid = NUMA_NO_NODE;
 	}
 
-	if (!list_empty(&node_page_list)) {
-		nr_reclaimed += shrink_page_list(&node_page_list,
-						NODE_DATA(nid),
-						&sc, &dummy_stat, false);
-		while (!list_empty(&node_page_list)) {
-			page = lru_to_page(&node_page_list);
-			list_del(&page->lru);
-			putback_lru_page(page);
-		}
-	}
+	if (!list_empty(&node_page_list))
+		nr_reclaimed += reclaim_page_list(&node_page_list, NODE_DATA(nid));
 
 	memalloc_noreclaim_restore(noreclaim_flag);