From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 860DDC6FA8B for ; Thu, 22 Sep 2022 06:03:46 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C58FF940008; Thu, 22 Sep 2022 02:03:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BE1EB940007; Thu, 22 Sep 2022 02:03:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A8251940008; Thu, 22 Sep 2022 02:03:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 94FE0940007 for ; Thu, 22 Sep 2022 02:03:45 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 6A89B1403EB for ; Thu, 22 Sep 2022 06:03:45 +0000 (UTC) X-FDA: 79938680010.10.A91B766 Received: from out30-45.freemail.mail.aliyun.com (out30-45.freemail.mail.aliyun.com [115.124.30.45]) by imf09.hostedemail.com (Postfix) with ESMTP id 93E81140009 for ; Thu, 22 Sep 2022 06:03:43 +0000 (UTC) X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R401e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046050;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=8;SR=0;TI=SMTPD_---0VQQzvIj_1663826617; Received: from 30.97.48.87(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VQQzvIj_1663826617) by smtp.aliyun-inc.com; Thu, 22 Sep 2022 14:03:39 +0800 Message-ID: <0a41c051-7d7e-cb1b-8273-192252e74b94@linux.alibaba.com> Date: Thu, 22 Sep 2022 14:03:55 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.3.0 Subject: Re: [RFC 1/6] mm/migrate_pages: separate huge page and normal pages migration To: Huang Ying , linux-mm@kvack.org Cc: linux-kernel@vger.kernel.org, Andrew Morton , Zi Yan , Yang Shi , Oscar Salvador , Matthew Wilcox References: <20220921060616.73086-1-ying.huang@intel.com> <20220921060616.73086-2-ying.huang@intel.com> From: Baolin Wang In-Reply-To: <20220921060616.73086-2-ying.huang@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663826625; a=rsa-sha256; cv=none; b=wsjXfQxHKJs8SgNQToC81I3z80i0f2TqBKGLZoU3u/9FY+mpO2tXA+3Ye3DdyF7vjWhxnn DFEo6vcp++NyueXJys+yfEHL6myaTfrJ6gDwfKv8M8DPjsDz5NrKHmKBufOsuxX5iKp4UE y+N9ql0FTWVBoJdtzhEGKVYAQ0+gDOs= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf09.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.45 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663826625; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=71JdlM018XynYvKifIVO+nx98P3JsHkD4k+O+7efrXg=; b=JjraNFwDFGb2R12b/vuDt64TatMELANos1iHezGvhu5rr205FICurVM4D+uOLFxR7MN7AM LXVl9riIeyyC9NvhjpHOewG3RjSoR70npv1QirPPvlmEIKg1QZMPBFyx2PmRWV1H8RCgwA jDL7cuC+nN1KMeE6BVrQbqD7UxAy+84= X-Rspam-User: X-Stat-Signature: jhgb6zxq6oq8bz14te13einubxdzhkzo X-Rspamd-Queue-Id: 93E81140009 Authentication-Results: imf09.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf09.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.45 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com X-Rspamd-Server: rspam07 X-HE-Tag: 1663826623-369963 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 9/21/2022 2:06 PM, Huang Ying wrote: > This is a preparation patch to batch the page unmapping and moving for > the normal pages and THPs. Based on that we can batch the TLB > shootdown during the page migration and make it possible to use some > hardware accelerator for the page copying. > > In this patch the huge page (PageHuge()) and normal page and THP > migration is separated in migrate_pages() to make it easy to change > the normal page and THP migration implementation. > > Signed-off-by: "Huang, Ying" > Cc: Zi Yan > Cc: Yang Shi > Cc: Baolin Wang > Cc: Oscar Salvador > Cc: Matthew Wilcox > --- > mm/migrate.c | 73 +++++++++++++++++++++++++++++++++++++++++++++------- > 1 file changed, 64 insertions(+), 9 deletions(-) > > diff --git a/mm/migrate.c b/mm/migrate.c > index 571d8c9fd5bc..117134f1c6dc 100644 > --- a/mm/migrate.c > +++ b/mm/migrate.c > @@ -1414,6 +1414,66 @@ int migrate_pages(struct list_head *from, new_page_t get_new_page, > > trace_mm_migrate_pages_start(mode, reason); > > + for (pass = 0; pass < 10 && retry; pass++) { > + retry = 0; > + > + list_for_each_entry_safe(page, page2, from, lru) { > + nr_subpages = compound_nr(page); > + cond_resched(); > + > + if (!PageHuge(page)) > + continue; > + > + rc = unmap_and_move_huge_page(get_new_page, > + put_new_page, private, page, > + pass > 2, mode, reason, > + &ret_pages); > + /* > + * The rules are: > + * Success: hugetlb page will be put back > + * -EAGAIN: stay on the from list > + * -ENOMEM: stay on the from list > + * -ENOSYS: stay on the from list > + * Other errno: put on ret_pages list then splice to > + * from list > + */ > + switch(rc) { > + case -ENOSYS: > + /* Hugetlb migration is unsupported */ > + nr_failed++; > + nr_failed_pages += nr_subpages; > + list_move_tail(&page->lru, &ret_pages); > + break; > + case -ENOMEM: > + /* > + * When memory is low, don't bother to try to migrate > + * other pages, just exit. > + */ > + nr_failed++; > + nr_failed_pages += nr_subpages + nr_retry_pages; > + goto out; > + case -EAGAIN: > + retry++; > + nr_retry_pages += nr_subpages; > + break; > + case MIGRATEPAGE_SUCCESS: > + nr_succeeded += nr_subpages; > + break; > + default: > + /* > + * Permanent failure (-EBUSY, etc.): > + * unlike -EAGAIN case, the failed page is > + * removed from migration page list and not > + * retried in the next outer loop. > + */ > + nr_failed++; > + nr_failed_pages += nr_subpages; > + break; > + } > + } > + } > + nr_failed += retry; Seems we should also record the nr_retry_pages? since the second loop will reset the nr_retry_pages. nr_failed_pages += nr_retry_pages; Besides, I also agree with Zi Yan's comment to simplify this larger function.