Received: by 2002:a05:6358:e9c4:b0:b2:91dc:71ab with SMTP id hc4csp1058195rwb; Thu, 4 Aug 2022 16:31:27 -0700 (PDT) X-Google-Smtp-Source: AA6agR5UubXZdcv3mTCFOSwelqThrn6b3rg4cbSHu3l8jUZl1I5Jmd0jKdvgI0TN9d0jJmlVuyqd X-Received: by 2002:a05:6402:189:b0:437:8a8a:d08a with SMTP id r9-20020a056402018900b004378a8ad08amr4121507edv.241.1659655886978; Thu, 04 Aug 2022 16:31:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1659655886; cv=pass; d=google.com; s=arc-20160816; b=btNrcN+2RoM0aLbxhv84Eev5MmPlk2xgEoEu4PpKNm1g1BVeQgvkKheBMeW7X8re/t k9Kkzard22jUIwd1GA5RKpt/MCJRlccn1bJQYugqi8XoNM79aEboWOUXK1GUV8IMK8kA g1JfI1xyJknEYY449bSGiE0D7k/4/PaVz8aXO0aEc3a1bd1EmYre/hjLyKqwRXsgiH/G YXnL1x36uT6Ukdlv3kLXQSTIPubJH67+4LQFw9X/0BCnSQSIIIq221n2dezZEHTvwxJc QmmrQaqR9kK6cgMf1VbEZhxQxvD3VhGBVZ0XhhONKD7R+dUG42zU+ceByRhuLI6AgyJX 8+5w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:content-transfer-encoding :in-reply-to:from:references:cc:to:content-language:subject :user-agent:date:message-id:dkim-signature; bh=q0Pmop7LwqhKRr4IdKIT/wx0yeiKpn6Qujr0PcaYYpo=; b=z/TK1MLek7ujaP1emq9tOYYNG/zHm5ay43ZG6nuBl2/yxEDxr4chha0+pMshxJAXyA DanRkMQOBdu5K//28ftCCZhX4RSDo01WCQvtxxeIufJRoPMpw1srBYYj5LLOeDDvqSUS IC5EcdGFWVT8qAtEASv21cjj9jD1u2MUO3E+eJ/vpZFdjWIyUN26KiOSjooNsD/St0Lo h0TfPABIQFehNTUXiJecwCdeU4zBTAkdYl0xecJMkE6ukWhPsUSFoetbVY+bLdzBJFz6 yfvffQWrCgnOWC4WAZ61b8EMWx0v00eM5Xz7qyKjRZJ1GDhR/SNrc99sbaEDE7OSlfOh rL4Q== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=NeugPlrR; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id gt37-20020a1709072da500b00711f55a31casi2484636ejc.775.2022.08.04.16.31.02; Thu, 04 Aug 2022 16:31:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@Nvidia.com header.s=selector2 header.b=NeugPlrR; arc=pass (i=1 spf=pass spfdomain=nvidia.com dkim=pass dkdomain=nvidia.com dmarc=pass fromdomain=nvidia.com); spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240110AbiHDXHP (ORCPT + 99 others); Thu, 4 Aug 2022 19:07:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234270AbiHDXHM (ORCPT ); Thu, 4 Aug 2022 19:07:12 -0400 Received: from NAM11-CO1-obe.outbound.protection.outlook.com (mail-co1nam11on2041.outbound.protection.outlook.com [40.107.220.41]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A28F101F9 for ; Thu, 4 Aug 2022 16:07:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c99mq13Om/V78Gu84wJnzs+aqJqbhkjHX00Xpi1CXBgO33HfHnBz9o3GCjfV4Advrf9qBHrdBCbOA9n1HakHOwKo/ArP76Rs7MxjjOHMEbCxD6iEuXQsl46n7Tkcn6BKG0/rQK6jcIRJ5jITaOQOgTwTKcgqsp67/1lW6wWvCUCYY9R4c/rviIWJ6Xo/qcdx9VBJ82xNVP5ggF7B/BekSKeu5Q0KQJ271K52WHJ3EbbnCjwvDjlUk4qKEc6a2RZxWwNS6dnkUZ7i6EMx8UPp78pRule/CnjZLNYytxFQddJzcbOZ/+uTN3FL2rKw+Y2ZjZjJEBsMJsk2LU+Fcm1Emg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=q0Pmop7LwqhKRr4IdKIT/wx0yeiKpn6Qujr0PcaYYpo=; b=Fl8sY3NoO8PsyvAHOWKQ7M/BDdemrbvrOj+2gei1skOQXBTv/q8zMmPyLQA0/PEDRfAfPGByEG7tUybPErs3pk1F1cL/6mH/Odyd0Q8toSk+ijtJiNWFVnFNP2Hw3vBArCGcUnbxvJ7zIO7naTGy0iNWHD7AmBz261/smmFrTtqA1txlXnyxzy0FsIyHI/1QxSBHrAfUTF8llTbzamtzwEQDyqm7AH3m+5NEZYmCiRnzimndRyLqhP5Cy4jHeCBkMDpBNqogaCMSMeEEFnC8stT4xIzBwtwh++p1r5Ze5Cwuj+k32kHqaOOryldrA6kyuJOYE7utBUMXvCvsW4uBYw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nvidia.com; dmarc=pass action=none header.from=nvidia.com; dkim=pass header.d=nvidia.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Nvidia.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=q0Pmop7LwqhKRr4IdKIT/wx0yeiKpn6Qujr0PcaYYpo=; b=NeugPlrRX3iZBYFw57bw/sI5FQpFl9/chiAppfoj1ThbbUD/Nl9igPBvTckTkWw9wRPFvlg/vNnMyFpswR0jbMCogra+bJ28nil79MrOeH4YxbJRcWJl/xNlDD1hSLlXDCBAkkS0E+ZKbCKxCDYrw3gGwlpbC2CDX8tMg/npxapMGl9DW5oZCR/EO59f0HOI52Ce867GsSIv4JOlwbyt7+DUApIJFlsUiAP8CNkTN9gWi3kdGHDdjud9K9UjKUueECgKCM/8NpX/s5YEQPifxJkXI1X6xO+6s4gltiuzwcdYPsJzuiaTsP67OZeATaRnbAvI5+ib6xFmxANIKiY/Ug== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nvidia.com; Received: from BY5PR12MB4130.namprd12.prod.outlook.com (2603:10b6:a03:20b::16) by BL0PR12MB2354.namprd12.prod.outlook.com (2603:10b6:207:44::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5504.14; Thu, 4 Aug 2022 23:07:00 +0000 Received: from BY5PR12MB4130.namprd12.prod.outlook.com ([fe80::508d:221c:9c9e:e1a5]) by BY5PR12MB4130.namprd12.prod.outlook.com ([fe80::508d:221c:9c9e:e1a5%9]) with mapi id 15.20.5504.014; Thu, 4 Aug 2022 23:07:00 +0000 Message-ID: Date: Thu, 4 Aug 2022 16:06:56 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.11.0 Subject: Re: [PATCH] mm/gup.c: Refactor check_and_migrate_movable_pages() Content-Language: en-US To: Alistair Popple , linux-mm@kvack.org Cc: akpm@linux-foundation.org, linux-kernel@vger.kernel.org, "Sierra Guiza, Alejandro (Alex)" , Chaitanya Kulkarni , Dan Williams , Felix Kuehling , Jason Gunthorpe , Logan Gunthorpe , Miaohe Lin , Muchun Song , Pasha Tatashin , Ralph Campbell References: <20220804032241.859891-1-apopple@nvidia.com> From: John Hubbard In-Reply-To: <20220804032241.859891-1-apopple@nvidia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-ClientProxiedBy: BYAPR07CA0093.namprd07.prod.outlook.com (2603:10b6:a03:12b::34) To BY5PR12MB4130.namprd12.prod.outlook.com (2603:10b6:a03:20b::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: f787fa18-77cd-4ea3-7a1f-08da766e091c X-MS-TrafficTypeDiagnostic: BL0PR12MB2354:EE_ X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KhZ+u5KybOdE/eVlhfuahi26t1CIOD4XLR8HX1XkSevdu2+UE9sIpfStNumymj4briwcCs624PIVmNtszUDF13tTDtNEVXalWOFiiK36++4cqsqjyD8KI6Xm8Fo05dvoIliQvrDfM0kIUV61OuBQcK48zsy2wz8YQniFFJ7UtV2wzdlAeeGPasZWIyYESKOsnaybL51eQ+Ta8bz6oZpftCTBTV4HWxnhEhIenZhyn88VYOssgrE4txkaj3uz1uXW2I6ndAydea347nvR0Ny0u0VaGXgB+en/HQUCQfbYVIMiJ/UvHpKyjbLq/AO0Zjxmi7nLu7qpS0AaAwzJOlhaVQW7D0i6yqfGuaTVWlzkykEW/TL59Kd4DKvpKChouwfg/2jXDHkEoqqOUZ++nCgFJDXqJzGn1v9YwyjnIsXXgDTgQ6m8kIp3lCUW3v1RnKYfgsAkiQtlmYaVa/qkotQYXBlW5Hh4SFQVm/JQ5lxgHupjjEBJRu0EuL3eF82qQpSqIhlJHXka11PLUO3GsbK9Xep28q490N4BzZ3Rxr8SebtfTnbv3gJYCHszmUOnXEXdZCuCpJdWYfllm61D/pQa5bejsczDf6drM/8OuupsUTVGaCYski205gT6cNQuK/JcUxb5CkNYEyM/C36iLx0tDvuX+QDZc6abZa3vveF/kF+89huFOXiCZUP/uhkS88GFO50oEf/RsReQsRmfsrlqTI4rp7mKODGS2oKxbVn8ACNuRlpLIMFZaVSl0Xoh/vJq4uNGW4klZBShHFh5b5opifnKpRJJgbO2cuGm07JOSB2nDlItkdGgAlzqs2f48xfRY0FJJ8t1DUPYDRc5LvU93w== X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:BY5PR12MB4130.namprd12.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230016)(4636009)(136003)(346002)(39860400002)(376002)(366004)(396003)(53546011)(54906003)(186003)(41300700001)(86362001)(6512007)(6506007)(107886003)(6666004)(26005)(36756003)(316002)(2616005)(66556008)(66946007)(8676002)(4326008)(2906002)(478600001)(5660300002)(6486002)(7416002)(8936002)(31696002)(38100700002)(66476007)(31686004)(45980500001)(43740500002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?utf-8?B?eDRrbzNHSmN2YjV0TjhLVXQ2R2cyZm12enRxMnRLUkpsejZtdW10V3pRbTRM?= =?utf-8?B?TnpKZDhrVC9HRGtnM042WG1tMlA4cW9kdmNESGRJQmwzRUk2dWZzMllhcExi?= =?utf-8?B?RmJaR3pSMUVaaWxUaWVIWTMrTGVGeWt0YlBmQWFTK3FDaTNFZjE4R0pKN1Vs?= =?utf-8?B?d2ZzVUtKTnNPazA5bythQ2s0dHRaTjgwcDk5NE5EalNFb2hTUG5YcmduSi9m?= =?utf-8?B?b1FC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LytzS3dtSnJ5anh4Q05vOE13b3BQ?= =?utf-8?B?NHU2SElPV0R6ZVJiVFh3aGdmSjJrRzlTb3BhTkJuY1VLd3hNSUQwRmorZ3BE?= =?utf-8?Q?dHi9Mm7ER743F/W3/hh/hhA+7?= X-OriginatorOrg: Nvidia.com X-MS-Exchange-CrossTenant-Network-Message-Id: f787fa18-77cd-4ea3-7a1f-08da766e091c X-MS-Exchange-CrossTenant-AuthSource: BY5PR12MB4130.namprd12.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Aug 2022 23:07:00.0343 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 43083d15-7273-40c1-b7db-39efd9ccc17a X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: CYz0RHwfK6iCFY6Kv0AaqBDuVovlfGXcGBltQXViqNJLdFslAwHrEGX5/0tFhANEqaNUwrKcVltV1KVJ350+CA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BL0PR12MB2354 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FORGED_SPF_HELO, NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_NONE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 8/3/22 20:22, Alistair Popple wrote: > @@ -1970,29 +1968,25 @@ static long check_and_migrate_movable_pages(unsigned long nr_pages, > drain_allow = false; > } > > - if (folio_isolate_lru(folio)) { > - isolation_error_count++; > + if (folio_isolate_lru(folio)) > continue; > - } > + > list_add_tail(&folio->lru, &movable_page_list); > node_stat_mod_folio(folio, > NR_ISOLATED_ANON + folio_is_file_lru(folio), > folio_nr_pages(folio)); > } > > - if (!list_empty(&movable_page_list) || isolation_error_count || > - coherent_pages) > - goto unpin_pages; > - > /* > - * If list is empty, and no isolation errors, means that all pages are > - * in the correct zone. > + * All pages are still pinned and in the correct zone. > */ > - return nr_pages; > + if (list_empty(&movable_page_list) && !coherent_pages) > + return 0; > At this point, a second part of the (rather long) routine begins. If I were refactoring this, I'd split it into a top level routine that calls the two parts: check_and_migrate_movable_pages() collect_migration_candidates() unpin_and_migrate_pages() ...which I think would further help in working with this thing. (I realize that this is additional work. And that it's best done as a separate patch. And it's just a suggestion.) > -unpin_pages: > /* > - * pages[i] might be NULL if any device coherent pages were found. > + * Unpin all pages. If device coherent pages were found > + * migrate_deivce_coherent_page() will have already dropped the pin and "migrate_device_coherent_page()" thanks, -- John Hubbard NVIDIA