Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1081744pxb; Fri, 20 Nov 2020 00:05:44 -0800 (PST) X-Google-Smtp-Source: ABdhPJxj/rxrkm1SVe+dV+nvmeauTyjT8QWcRzR1MP62tjnqwiTkMt3RfpPAn7ueHyfTxsdERs4/ X-Received: by 2002:a05:6402:2373:: with SMTP id a19mr5724734eda.212.1605859544591; Fri, 20 Nov 2020 00:05:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1605859544; cv=none; d=google.com; s=arc-20160816; b=Jp63QgmBc+WIJj8i6l4YMQ/cT/6h51TVF7zstgSAPiVFvVmHkQD76weB6dVWX7ISYt 0eIm8PbFglEFHVC0p1hhqtGh5j8RrLkwvWceTl+tG8p1zw3CSNqAoXD2tbM8cSSmOQ/U 4QNF8vsFZUnYNP7SqrC2NqOtM+MBVX4Uyni0xVxDkQvfzgIluG/qBkaEj5D5Kf0wiynf PE6MsX8qpbFAHqKmSMA/6Hy6Y8wPtIUjCd6uWhQDg1hn44MC8PXlv5pYqd1VecOCWFLW BE/crtgYEDntXUNHmEUdR0ohM4HOeoS767X6nYbTV/ID6H1jaxZ073+hunSoZ5doCouz BEdg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:message-id:date:subject:cc:from; bh=bFUBUDLDvU7hn2Vtyx3SnF2hCaYywH7XR6fo2eHkw8o=; b=l/mEHz/+3wVfeZmX7LRTOueSgiR2irGdap77wHOsr23U3HtoJLmxz047vzsb7ebHMk 0hVWAc0IH0yEDbSLkpqa0Wi81Gkfd+zZsK+Znct0wsDqhw9uctt8yRGC5e52DxZRP/mE LlTv7LAHc3UA367A+EB1K0FYY39620fd518n5ZBnzBX6hVA92jdUDIu541ZyvjJtfJ3t gciZRGTopKcAJKdjK4aA8uRrEZ1MGDxXP3ExQUhDJ/MeEkNbGMI8fY8Exw7L7YQt/syU NSRLUxQR+E3ESJqYJNc8S3X2JxBNJxvF+f+z5tj8DjaI3ksfYPdQioSSMBKMI6pGfUeN yiWQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id d17si1223269ejh.451.2020.11.20.00.05.20; Fri, 20 Nov 2020 00:05:44 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1725858AbgKTIDu (ORCPT + 99 others); Fri, 20 Nov 2020 03:03:50 -0500 Received: from out30-56.freemail.mail.aliyun.com ([115.124.30.56]:35879 "EHLO out30-56.freemail.mail.aliyun.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725766AbgKTIDu (ORCPT ); Fri, 20 Nov 2020 03:03:50 -0500 X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R271e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=e01e04423;MF=alex.shi@linux.alibaba.com;NM=1;PH=DS;RN=7;SR=0;TI=SMTPD_---0UFyUd5s_1605859425; Received: from aliy80.localdomain(mailfrom:alex.shi@linux.alibaba.com fp:SMTPD_---0UFyUd5s_1605859425) by smtp.aliyun-inc.com(127.0.0.1); Fri, 20 Nov 2020 16:03:45 +0800 From: Alex Shi Cc: Andrew Morton , Hugh Dickins , Yu Zhao , Vlastimil Babka , Michal Hocko , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH next] mm/vmscan: __isolate_lru_page_prepare clean up Date: Fri, 20 Nov 2020 16:03:33 +0800 Message-Id: <1605859413-53864-1-git-send-email-alex.shi@linux.alibaba.com> X-Mailer: git-send-email 1.8.3.1 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The function just return 2 results, so use a 'switch' to deal with its result is unnecessary, and simplify it to a bool func as Vlastimil suggested. Also removed 'goto' in using by reusing list_move(). Signed-off-by: Alex Shi Cc: Andrew Morton Cc: Hugh Dickins Cc: Yu Zhao Cc: Vlastimil Babka Cc: Michal Hocko Cc: linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org --- mm/compaction.c | 2 +- mm/vmscan.c | 53 ++++++++++++++++++++++++------------------------- 2 files changed, 27 insertions(+), 28 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index b68931854253..8d71ffebe6cb 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -988,7 +988,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, if (unlikely(!get_page_unless_zero(page))) goto isolate_fail; - if (__isolate_lru_page_prepare(page, isolate_mode) != 0) + if (!__isolate_lru_page_prepare(page, isolate_mode)) goto isolate_fail_put; /* Try isolate the page */ diff --git a/mm/vmscan.c b/mm/vmscan.c index c6f94e55c3fe..7f32c1979804 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -1540,7 +1540,7 @@ unsigned int reclaim_clean_pages_from_list(struct zone *zone, */ int __isolate_lru_page_prepare(struct page *page, isolate_mode_t mode) { - int ret = -EBUSY; + int ret = false; /* Only take pages on the LRU. */ if (!PageLRU(page)) @@ -1590,7 +1590,7 @@ int __isolate_lru_page_prepare(struct page *page, isolate_mode_t mode) if ((mode & ISOLATE_UNMAPPED) && page_mapped(page)) return ret; - return 0; + return true; } /* @@ -1674,35 +1674,34 @@ static unsigned long isolate_lru_pages(unsigned long nr_to_scan, * only when the page is being freed somewhere else. */ scan += nr_pages; - switch (__isolate_lru_page_prepare(page, mode)) { - case 0: + if (!__isolate_lru_page_prepare(page, mode)) { + /* else it is being freed elsewhere */ + list_move(&page->lru, src); + continue; + } + /* + * Be careful not to clear PageLRU until after we're + * sure the page is not being freed elsewhere -- the + * page release code relies on it. + */ + if (unlikely(!get_page_unless_zero(page))) { + list_move(&page->lru, src); + continue; + } + + if (!TestClearPageLRU(page)) { /* - * Be careful not to clear PageLRU until after we're - * sure the page is not being freed elsewhere -- the - * page release code relies on it. + * This page may in other isolation path, + * but we still hold lru_lock. */ - if (unlikely(!get_page_unless_zero(page))) - goto busy; - - if (!TestClearPageLRU(page)) { - /* - * This page may in other isolation path, - * but we still hold lru_lock. - */ - put_page(page); - goto busy; - } - - nr_taken += nr_pages; - nr_zone_taken[page_zonenum(page)] += nr_pages; - list_move(&page->lru, dst); - break; - - default: -busy: - /* else it is being freed elsewhere */ + put_page(page); list_move(&page->lru, src); + continue; } + + nr_taken += nr_pages; + nr_zone_taken[page_zonenum(page)] += nr_pages; + list_move(&page->lru, dst); } /* -- 2.29.GIT