From patchwork Tue Nov 3 13:03:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 11885095 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 05E6714B4 for ; Thu, 5 Nov 2020 20:53:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8DA4420782 for ; Thu, 5 Nov 2020 20:53:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gaK5tfxo" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8DA4420782 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 62EDB6B0194; Thu, 5 Nov 2020 15:53:48 -0500 (EST) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 5C5DC6B0196; Thu, 5 Nov 2020 15:53:48 -0500 (EST) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 394696B0197; Thu, 5 Nov 2020 15:53:48 -0500 (EST) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0089.hostedemail.com [216.40.44.89]) by kanga.kvack.org (Postfix) with ESMTP id 00D0A6B0194 for ; Thu, 5 Nov 2020 15:53:47 -0500 (EST) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 96FA58249980 for ; Thu, 5 Nov 2020 20:53:47 +0000 (UTC) X-FDA: 77451566094.12.shirt73_210b23d272cc Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 773871801BE96 for ; Thu, 5 Nov 2020 20:53:47 +0000 (UTC) X-Spam-Summary: 1,0,0,1a64553b7eb92e2b,d41d8cd98f00b204,shy828301@gmail.com,,RULES_HIT:2:41:69:355:379:541:800:960:966:973:988:989:1202:1260:1311:1314:1345:1359:1437:1515:1535:1605:1730:1747:1777:1792:2196:2199:2393:2559:2562:2693:2899:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:3874:4049:4120:4250:4385:4605:5007:6261:6653:7514:7903:8660:8957:9010:9121:9413:10004:11026:11473:11658:11914:12043:12048:12291:12296:12297:12438:12517:12519:12555:12683:12895:13148:13161:13172:13229:13230:13894:14096:14394:14687:21060:21080:21444:21450:21451:21627:21666:21796:21939:21987:21990:30012:30034:30036:30054:30069:30070:30091,0,RBL:209.85.215.193:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.50.0.100;04yf5rdcj3nsn4oxrhpgpg1k8gzh5ycxmw518mamf9rkhfnixnw5son9cb9gdsy.fen7r88ubhd4wkqdbb6qb4d9hty8ztkdy4h3rmxwrof51s4g6yyz34bqph5coyo.q-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_ru les:0:0: X-HE-Tag: shirt73_210b23d272cc X-Filterd-Recvd-Size: 9165 Received: from mail-pg1-f193.google.com (mail-pg1-f193.google.com [209.85.215.193]) by imf01.hostedemail.com (Postfix) with ESMTP for ; Thu, 5 Nov 2020 20:53:46 +0000 (UTC) Received: by mail-pg1-f193.google.com with SMTP id r186so2204182pgr.0 for ; Thu, 05 Nov 2020 12:53:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jE4qSk2GuBQuLE3VKoSzbFTrSHhXqdRokaed5NT8Mes=; b=gaK5tfxoQSaRHHEbQMSlU8zj9YPCoi0uuimK2r5eJ7E4XnR07Ov3FH8IonVXyJdkCe v52OhSZKZom6zW8qiS10sZjo+wwutX1eZgMyfkEvFG2XdQC8EGkGJU9BkFuOsoS8Wiby /frtI43Ougmrq0bEyaMZwWv5YGk4kdAWEtoCwfQ1kS0nHu40ymqIK8Emhdz+sQ6GxgwD MnaClz+8XmCB9Qwq6M6uOF1nGux/OrJXch/pamebOBKnDbq7CtJNAZuj3J2hzedTr4AN KpmU1OyxwwNKmX2qbm2XLSnpfP3Gi0gEosHSFErb7jfhhxbI610KwLOBaJKIF+0UCzET 0jFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=jE4qSk2GuBQuLE3VKoSzbFTrSHhXqdRokaed5NT8Mes=; b=av/wVGLbNlBfUFm3QdXSR19bOnvncBS5pffjfPzBRdw/MIKh4bLGYZEV0W+aSdE1sV GuVgF1gvJ8VszRHE2g2Y9XFmzpSiXAp4z4SnR2csdIplCaZfsMOk3gDGkxGhL6t9piHX aos/POzJcL0yvY5m/snZAmLpI9Zzh7HWHbxWxEYnKCgQ4AhGRtsqGk7tsS7SGejBr/Wj DBC8IvhGaWgwreu9OlcLzSAWOm45D9Fy2WVtQV0yYPY4CeVQK/Pelx4c0f0eKY65PvOP A2K8oIvfLZNZmQ84KHeeRQCStnP5yS6zGGJS3WnCJ3qT9bpiRFXgpSUGD8RDcFfBqRMY lT+A== X-Gm-Message-State: AOAM53043FFsvk/F8K8afkPxVcDYmSt7CxYlYEjvyU+G2x66PZMeJprA AdbPm9n+pregnhH4UA1uDmw= X-Google-Smtp-Source: ABdhPJx0XwY0IdRHx1Njn+CvjHuWeJssCSQR+wFpwv9Wevxik8A5BqkXfjTXCuOQhoZHB6wAvZNscw== X-Received: by 2002:a63:3c1b:: with SMTP id j27mr4077005pga.79.1604609626212; Thu, 05 Nov 2020 12:53:46 -0800 (PST) Received: from localhost.localdomain (c-107-3-138-210.hsd1.ca.comcast.net. [107.3.138.210]) by smtp.gmail.com with ESMTPSA id u22sm3265528pgf.24.2020.11.05.12.53.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 05 Nov 2020 12:53:45 -0800 (PST) From: Yang Shi To: mhocko@suse.com, ziy@nvidia.com, songliubraving@fb.com, mgorman@suse.de, jack@suse.cz, akpm@linux-foundation.org Cc: shy828301@gmail.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/5] mm: migrate: simplify the logic for handling permanent failure Date: Tue, 3 Nov 2020 05:03:31 -0800 Message-Id: <20201103130334.13468-3-shy828301@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20201103130334.13468-1-shy828301@gmail.com> References: <20201103130334.13468-1-shy828301@gmail.com> MIME-Version: 1.0 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000002, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: When unmap_and_move{_huge_page}() returns !-EAGAIN and !MIGRATEPAGE_SUCCESS, the page would be put back to LRU or proper list if it is non-LRU movable page. But, the callers always call putback_movable_pages() to put the failed pages back later on, so it seems not very efficient to put every single page back immediately, and the code looks convoluted. Put the failed page on a separate list, then splice the list to migrate list when all pages are tried. It is the caller's responsibility to call putback_movable_pages() to handle failures. This also makes the code simpler and more readable. After the change the rules are: * Success: non hugetlb page will be freed, hugetlb page will be put back * -EAGAIN: stay on the from list * -ENOMEM: stay on the from list * Other errno: put on ret_pages list then splice to from list The from list would be empty iff all pages are migrated successfully, it was not so before. This has no impact to current existing callsites. Signed-off-by: Yang Shi --- mm/migrate.c | 58 ++++++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 8a2e7e19e27b..c33c92495ead 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1169,7 +1169,8 @@ static int unmap_and_move(new_page_t get_new_page, free_page_t put_new_page, unsigned long private, struct page *page, int force, enum migrate_mode mode, - enum migrate_reason reason) + enum migrate_reason reason, + struct list_head *ret) { int rc = MIGRATEPAGE_SUCCESS; struct page *newpage = NULL; @@ -1206,7 +1207,14 @@ static int unmap_and_move(new_page_t get_new_page, * migrated will have kept its references and be restored. */ list_del(&page->lru); + } + /* + * If migration is successful, releases reference grabbed during + * isolation. Otherwise, restore the page to right list unless + * we want to retry. + */ + if (rc == MIGRATEPAGE_SUCCESS) { /* * Compaction can migrate also non-LRU pages which are * not accounted to NR_ISOLATED_*. They can be recognized @@ -1215,35 +1223,16 @@ static int unmap_and_move(new_page_t get_new_page, if (likely(!__PageMovable(page))) mod_node_page_state(page_pgdat(page), NR_ISOLATED_ANON + page_is_file_lru(page), -thp_nr_pages(page)); - } - /* - * If migration is successful, releases reference grabbed during - * isolation. Otherwise, restore the page to right list unless - * we want to retry. - */ - if (rc == MIGRATEPAGE_SUCCESS) { if (reason != MR_MEMORY_FAILURE) /* * We release the page in page_handle_poison. */ put_page(page); } else { - if (rc != -EAGAIN) { - if (likely(!__PageMovable(page))) { - putback_lru_page(page); - goto put_new; - } + if (rc != -EAGAIN) + list_add_tail(&page->lru, ret); - lock_page(page); - if (PageMovable(page)) - putback_movable_page(page); - else - __ClearPageIsolated(page); - unlock_page(page); - put_page(page); - } -put_new: if (put_new_page) put_new_page(newpage, private); else @@ -1274,7 +1263,8 @@ static int unmap_and_move(new_page_t get_new_page, static int unmap_and_move_huge_page(new_page_t get_new_page, free_page_t put_new_page, unsigned long private, struct page *hpage, int force, - enum migrate_mode mode, int reason) + enum migrate_mode mode, int reason, + struct list_head *ret) { int rc = -EAGAIN; int page_was_mapped = 0; @@ -1290,7 +1280,7 @@ static int unmap_and_move_huge_page(new_page_t get_new_page, * kicking migration. */ if (!hugepage_migration_supported(page_hstate(hpage))) { - putback_active_hugepage(hpage); + list_move_tail(&hpage->lru, ret); return -ENOSYS; } @@ -1372,8 +1362,10 @@ static int unmap_and_move_huge_page(new_page_t get_new_page, out_unlock: unlock_page(hpage); out: - if (rc != -EAGAIN) + if (rc == MIGRATEPAGE_SUCCESS) putback_active_hugepage(hpage); + else if (rc != -EAGAIN && rc != MIGRATEPAGE_SUCCESS) + list_move_tail(&hpage->lru, ret); /* * If migration was not successful and there's a freeing callback, use @@ -1404,8 +1396,8 @@ static int unmap_and_move_huge_page(new_page_t get_new_page, * * The function returns after 10 attempts or if no pages are movable any more * because the list has become empty or no retryable pages exist any more. - * The caller should call putback_movable_pages() to return pages to the LRU - * or free list only if ret != 0. + * It is caller's responsibility to call putback_movable_pages() to return pages + * to the LRU or free list only if ret != 0. * * Returns the number of pages that were not migrated, or an error code. */ @@ -1426,6 +1418,7 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, struct page *page2; int swapwrite = current->flags & PF_SWAPWRITE; int rc, nr_subpages; + LIST_HEAD(ret_pages); if (!swapwrite) current->flags |= PF_SWAPWRITE; @@ -1448,11 +1441,12 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, if (PageHuge(page)) rc = unmap_and_move_huge_page(get_new_page, put_new_page, private, page, - pass > 2, mode, reason); + pass > 2, mode, reason, + &ret_pages); else rc = unmap_and_move(get_new_page, put_new_page, private, page, pass > 2, mode, - reason); + reason, &ret_pages); switch(rc) { case -ENOMEM: @@ -1519,6 +1513,12 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, nr_thp_failed += thp_retry; rc = nr_failed; out: + /* + * Put the permanent failure page back to migration list, they + * will be put back to the right list by the caller. + */ + list_splice(&ret_pages, from); + count_vm_events(PGMIGRATE_SUCCESS, nr_succeeded); count_vm_events(PGMIGRATE_FAIL, nr_failed); count_vm_events(THP_MIGRATION_SUCCESS, nr_thp_succeeded);