Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp564703pxu; Fri, 4 Dec 2020 09:49:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJwUuW6H5C0XvJ6z+SIGJGG0wKZvdyeycYLavcPk9DMW0FHdrow7YVeS0mbzAUx50mkzr4w1 X-Received: by 2002:a05:6402:16cb:: with SMTP id r11mr8546895edx.335.1607104148997; Fri, 04 Dec 2020 09:49:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607104148; cv=none; d=google.com; s=arc-20160816; b=hNwxeYaB7hZNU5jNoVTd1r5haxUf9Vb4sUpCjaqxYpz1sowKHf/do1zLXp5gjNWt0K 7e1KNEjBZomp7NCSX5+I1XhQxfnPHNH9I7L90Z/7bgHe0B9KUkTVL40Hgc2eIzBs8xG0 hTCkCCZs7wamqehPqp+40x4cDaBKaF9cczBAJFS5QRGGUAxJwHGUoTa6oKeDMcT0QpMv IlsNh2G+xY9LJVHFgLXXyEsE7eai99bXCjCO3TZvOT6f+129N+ag8+TuJQA4WHB1JWb1 RXS5+HMU+Fb0hHsg+KQonyNBoN+c/aT0UaICUqemsHAR5vMYpfO0PYwd82rAHNy06plu uTtg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=oymlK03Wh8YRUzVLq1s/12paUCKiSfJbtYoo+/za7mY=; b=P6MKSwMis5kY0LaJRDxco00V9nou8LJcNI8lGyUy7A89ohRJn57lMlqWzvgN9KVuPu GZAP8/5CzwfxPNihWyYbR8XV6qzt8EBL7/hTS75K4yPjI7lFxQfanEBr6G5etbXI5m98 678iYICTq/nqgiKmlozp+n2/tHPP2KEa0ZC78Fs42yBGvSMVVs6XzEia7xG2RoqA6/Wd KXTCFJOWZo/QPSnHBWwzGwbRpHes6TGnXovonNIsrFMxGc1diVo479XULBWBxis3XD+Z lMehjNPJuhcZuSSrnZFaiwzK5Ru8ECtMh0mZqZdMU3MuA8WTdQwIjPdqBG+rjUM6jOEt gBvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@soleen.com header.s=google header.b=OCb5ganc; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id ss12si1746703ejb.55.2020.12.04.09.48.44; Fri, 04 Dec 2020 09:49:08 -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; dkim=pass header.i=@soleen.com header.s=google header.b=OCb5ganc; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731429AbgLDRos (ORCPT + 99 others); Fri, 4 Dec 2020 12:44:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39522 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728129AbgLDRor (ORCPT ); Fri, 4 Dec 2020 12:44:47 -0500 Received: from mail-ej1-x644.google.com (mail-ej1-x644.google.com [IPv6:2a00:1450:4864:20::644]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 567AEC0613D1 for ; Fri, 4 Dec 2020 09:44:07 -0800 (PST) Received: by mail-ej1-x644.google.com with SMTP id lt17so9900015ejb.3 for ; Fri, 04 Dec 2020 09:44:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=oymlK03Wh8YRUzVLq1s/12paUCKiSfJbtYoo+/za7mY=; b=OCb5gancMDQQAwGdeUcoXjOdlLRXM+2LpnxejfSTQEo2rna1ODp8elvvMBODJeLQQQ OsuetAzdlgl2nFEUlecLwdOOZBqSlhF4r3/XBRJdnlvnK/gHXp8JHAzcU+q5fHXgLj+S C+fZOEymqDxZfsqGfCO5JxiRddXMKNACa96CdP/4jxu49n8DOPRZKjI9Ew7y21t3/1+q 5J/iA7tcf0SUYeBZqwB3qyw/pp3Ex3iJSsx4GCMKu29Ar5X24G13/X+gQ0g6aOh5YJtI UPaia4dxHqlwxWhJ5X/yv/6GAfPawdlvkfPW/lme/BNoyqbOjl4dg4lTxixKMhY42Qit 1Z8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=oymlK03Wh8YRUzVLq1s/12paUCKiSfJbtYoo+/za7mY=; b=XiAZCH9sbVjIRY+dijCg/IELqJY4PcrPWaanYX9HwyH2PQeSPXBRfs4ncgqmGSMEN2 WRylF/p2cl7tCMf2fjqjDHp750w3ppCDTjBIswHS8FTq8T3mHCjSpHKnnaP5vgGsURfA N98qljWZPB7V9mXuQiWjHNPnXGFrnOAviCKKKnigzohvPh07HBTViMbTKDj58ZY/Uhcu hfGBSQhVvSISlaezVcPFcfja0IFXVjv5HSyjy1z2ExyXuYZxS5CJRyUW16jIR5poau3o zPoG6dsI2nxi29D06rXWnDPpctD2ChT+eVJOm3fDkzKpVMPd5KmTRDZKJPZs+K7/13DA z4+g== X-Gm-Message-State: AOAM530r/k7LZqj4YIH97Tncz7+CamZZTfLsTkwvN5gaNY8SHOjpUKs/ FEv/SB/FkTtJ4oOX4UWDe6DYvUCfArH19Z49BkaeRA== X-Received: by 2002:a17:906:ce51:: with SMTP id se17mr8106464ejb.314.1607103845993; Fri, 04 Dec 2020 09:44:05 -0800 (PST) MIME-Version: 1.0 References: <20201202052330.474592-1-pasha.tatashin@soleen.com> <20201202052330.474592-7-pasha.tatashin@soleen.com> <20201204041358.GB17056@js1304-desktop> In-Reply-To: <20201204041358.GB17056@js1304-desktop> From: Pavel Tatashin Date: Fri, 4 Dec 2020 12:43:29 -0500 Message-ID: Subject: Re: [PATCH 6/6] mm/gup: migrate pinned pages out of movable zone To: Joonsoo Kim Cc: LKML , linux-mm , Andrew Morton , Vlastimil Babka , Michal Hocko , David Hildenbrand , Oscar Salvador , Dan Williams , Sasha Levin , Tyler Hicks , mike.kravetz@oracle.com, Steven Rostedt , Ingo Molnar , Jason Gunthorpe , Peter Zijlstra , Mel Gorman , Matthew Wilcox , David Rientjes , John Hubbard Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Dec 3, 2020 at 11:14 PM Joonsoo Kim wrote: > > On Wed, Dec 02, 2020 at 12:23:30AM -0500, Pavel Tatashin wrote: > > We do not allocate pin pages in ZONE_MOVABLE, but if pages were already > > allocated before pinning they need to migrated to a different zone. > > Currently, we migrate movable CMA pages only. Generalize the function > > that migrates CMA pages to migrate all movable pages. > > > > Signed-off-by: Pavel Tatashin > > --- > > include/linux/migrate.h | 1 + > > include/trace/events/migrate.h | 3 +- > > mm/gup.c | 56 +++++++++++++--------------------- > > 3 files changed, 24 insertions(+), 36 deletions(-) > > > > diff --git a/include/linux/migrate.h b/include/linux/migrate.h > > index 0f8d1583fa8e..00bab23d1ee5 100644 > > --- a/include/linux/migrate.h > > +++ b/include/linux/migrate.h > > @@ -27,6 +27,7 @@ enum migrate_reason { > > MR_MEMPOLICY_MBIND, > > MR_NUMA_MISPLACED, > > MR_CONTIG_RANGE, > > + MR_LONGTERM_PIN, > > MR_TYPES > > }; > > > > diff --git a/include/trace/events/migrate.h b/include/trace/events/migrate.h > > index 4d434398d64d..363b54ce104c 100644 > > --- a/include/trace/events/migrate.h > > +++ b/include/trace/events/migrate.h > > @@ -20,7 +20,8 @@ > > EM( MR_SYSCALL, "syscall_or_cpuset") \ > > EM( MR_MEMPOLICY_MBIND, "mempolicy_mbind") \ > > EM( MR_NUMA_MISPLACED, "numa_misplaced") \ > > - EMe(MR_CONTIG_RANGE, "contig_range") > > + EM( MR_CONTIG_RANGE, "contig_range") \ > > + EMe(MR_LONGTERM_PIN, "longterm_pin") > > > > /* > > * First define the enums in the above macros to be exported to userspace > > diff --git a/mm/gup.c b/mm/gup.c > > index 724d8a65e1df..1d511f65f8a7 100644 > > --- a/mm/gup.c > > +++ b/mm/gup.c > > @@ -1593,19 +1593,18 @@ static bool check_dax_vmas(struct vm_area_struct **vmas, long nr_pages) > > } > > #endif > > > > -#ifdef CONFIG_CMA > > -static long check_and_migrate_cma_pages(struct mm_struct *mm, > > - unsigned long start, > > - unsigned long nr_pages, > > - struct page **pages, > > - struct vm_area_struct **vmas, > > - unsigned int gup_flags) > > +static long check_and_migrate_movable_pages(struct mm_struct *mm, > > + unsigned long start, > > + unsigned long nr_pages, > > + struct page **pages, > > + struct vm_area_struct **vmas, > > + unsigned int gup_flags) > > { > > unsigned long i; > > unsigned long step; > > bool drain_allow = true; > > bool migrate_allow = true; > > - LIST_HEAD(cma_page_list); > > + LIST_HEAD(page_list); > > long ret = nr_pages; > > struct migration_target_control mtc = { > > .nid = NUMA_NO_NODE, > > @@ -1623,13 +1622,12 @@ static long check_and_migrate_cma_pages(struct mm_struct *mm, > > */ > > step = compound_nr(head) - (pages[i] - head); > > /* > > - * If we get a page from the CMA zone, since we are going to > > - * be pinning these entries, we might as well move them out > > - * of the CMA zone if possible. > > + * If we get a movable page, since we are going to be pinning > > + * these entries, try to move them out if possible. > > */ > > - if (is_migrate_cma_page(head)) { > > + if (is_migrate_movable(get_pageblock_migratetype(head))) { > > is_migrate_movable() isn't a check for the ZONE. It's a check for the > MIGRATE_TYPE. MIGRATE_TYPE doesn't require hard guarantee for > migration, and, most of memory, including ZONE_NORMAL, is > MIGRATE_MOVABLE. With this code, long term gup would always fails due > to not enough memory. I think that correct change would be > "is_migrate_cma_page(hear) && zone == ZONE_MOVABLE". Good point. The above should be OR not AND. zone_idx(page_zone(head)) == ZONE_MOVABLE || is_migrate_cma_page(hear) Pasha