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 245C6C4332F for ; Fri, 21 Oct 2022 02:52:11 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8A12F8E0002; Thu, 20 Oct 2022 22:52:10 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 851988E0001; Thu, 20 Oct 2022 22:52:10 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 740398E0002; Thu, 20 Oct 2022 22:52:10 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 661A98E0001 for ; Thu, 20 Oct 2022 22:52:10 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 2ACC61C5F97 for ; Fri, 21 Oct 2022 02:52:10 +0000 (UTC) X-FDA: 80043432420.17.56BE56C Received: from out30-130.freemail.mail.aliyun.com (out30-130.freemail.mail.aliyun.com [115.124.30.130]) by imf02.hostedemail.com (Postfix) with ESMTP id F39F18003B for ; Fri, 21 Oct 2022 02:52:08 +0000 (UTC) X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R351e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046049;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=9;SR=0;TI=SMTPD_---0VShO9Hv_1666320722; Received: from 30.97.48.58(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0VShO9Hv_1666320722) by smtp.aliyun-inc.com; Fri, 21 Oct 2022 10:52:04 +0800 Message-ID: <0855246a-8425-2aca-1d67-305d6866ed17@linux.alibaba.com> Date: Fri, 21 Oct 2022 10:51:58 +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: [PATCH 1/2] mm: gup: Re-pin pages in case of trying several times to migrate To: Alistair Popple Cc: "Huang, Ying" , akpm@linux-foundation.org, david@redhat.com, ziy@nvidia.com, shy828301@gmail.com, jingshan@linux.alibaba.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <87r0z2nc6j.fsf@yhuang6-desk2.ccr.corp.intel.com> <87o7u6soip.fsf@nvidia.com> From: Baolin Wang In-Reply-To: <87o7u6soip.fsf@nvidia.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=1666320729; a=rsa-sha256; cv=none; b=dnQmu4wBVk4WgHuBgClQyIYou1AI1XSc/9CYgs+W+QxzdY4A+gXtvA5w8QtaxD6a++Msoo 3wJqTUdNYlq0ao5bX2o4nhtV2Wh/9CxTC6GJACCyVHysbaprXSuIt9ilqmZdB9YjvQpEuw QwQJdDgwQ8931de+TQZm4VLVciDFJNo= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf02.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.130 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=1666320729; 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=l7Lsr0nQMeIq98bIov/x49r61kET2dBX6QXApnAEP1U=; b=8Q4W4fh/6fb5mmq7y5Wf/l99RkTQ7DV1ZgxMmUj4ExLXy82wMFP5anLqtpwFLX8KB4Qpkq 7U7N4YHl/NqiLU85DPwfa0vR7gACWe3XYIWC06UeMilQ5tIrbVU32OmuPFb6UUNSqdAFIt 9WoXxZZgICkru0et1XZN5o/MhirENDE= X-Stat-Signature: xaykop6jbyh9bszzr6ka3z4kdfqhztpo X-Rspamd-Queue-Id: F39F18003B X-Rspam-User: Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf02.hostedemail.com: domain of baolin.wang@linux.alibaba.com designates 115.124.30.130 as permitted sender) smtp.mailfrom=baolin.wang@linux.alibaba.com X-Rspamd-Server: rspam11 X-HE-Tag: 1666320728-332570 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 10/20/2022 7:43 PM, Alistair Popple wrote: > > Baolin Wang writes: > >> On 10/20/2022 4:15 PM, Huang, Ying wrote: >>> Baolin Wang writes: >>> >>>> The migrate_pages() will return the number of {normal page, THP, hugetlb} >>>> that were not migrated, or an error code. That means it can still return >>>> the number of failure count, though the pages have been migrated >>>> successfully with several times re-try. >>> If my understanding were correct, if pages are migrated successfully >>> after several times re-tries, the return value will be 0. There's one >>> possibility for migrate_pages() to return non-zero but all pages are >>> migrated. That is, when THP is split and all subpages are migrated >>> successfully. >> >> Yeah, that's the case I tested. Thanks for pointing out. I'll re-write my >> incorrect commit message next time. > > This is confusing to me. So users of move_page() will see an > unsuccessful migration even when all subpages were migrated? Seems like Yes. > we should fix the return code of migrate_pages() for this case where all > subpages were successfully migrated. After more investigation, some other callers will also check the return value to see of all pages are migrated successfully. So yes, I will change the return value in migrate_pages() to fix this issue for all callers like you and Ying suggested. Thanks. >>>> So we should not use the return value of migrate_pages() to determin >>>> if there are pages are failed to migrate. Instead we can validate the >>>> 'movable_page_list' to see if there are pages remained in the list, >>>> which are failed to migrate. That can mitigate the failure of longterm >>>> pinning. >>> Another choice is to use a special return value for split THP + success >>> migration. But I'm fine to use list_empty(return_pages). >> >> OK. Using list_empty(return_pages) looks more simple. >> >>> >>>> Signed-off-by: Baolin Wang >>>> --- >>>> mm/gup.c | 7 ++++--- >>>> 1 file changed, 4 insertions(+), 3 deletions(-) >>>> >>>> diff --git a/mm/gup.c b/mm/gup.c >>>> index 5182aba..bd8cfcd 100644 >>>> --- a/mm/gup.c >>>> +++ b/mm/gup.c >>>> @@ -1914,9 +1914,10 @@ static int migrate_longterm_unpinnable_pages( >>>> .gfp_mask = GFP_USER | __GFP_NOWARN, >>>> }; >>>> - if (migrate_pages(movable_page_list, alloc_migration_target, >>>> - NULL, (unsigned long)&mtc, MIGRATE_SYNC, >>>> - MR_LONGTERM_PIN, NULL)) { >>>> + ret = migrate_pages(movable_page_list, alloc_migration_target, >>>> + NULL, (unsigned long)&mtc, MIGRATE_SYNC, >>>> + MR_LONGTERM_PIN, NULL); >>>> + if (ret < 0 || !list_empty(movable_page_list)) { >>> It seems that !list_empty() is sufficient here. >> >> OK. Drop the 'ret < 0' >> >>>> ret = -ENOMEM; >>> Why change the error code? I don't think it's a good idea to do that. >> >> The GUP need a -errno for failure or partial success when migration, and we can >> not return the number of pages failed to migrate. So returning -ENOMEM seems >> suitable for both cases? > > Seem reasonable to me. migrate_pages() might return -EAGAIN which would > cause everything to be re-pinned and tried again which is not what you > want here. See the comment at the start of > check_and_migrate_movable_pages().