Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp2197367pxu; Sun, 6 Dec 2020 23:17:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJyoROEcuqnsrm+jCxwq9sCcI6nwyLrLnhnrzXuIFJVTk/TT0qQJYXNevW3BkKL0j5b4rP1d X-Received: by 2002:a50:d6d3:: with SMTP id l19mr7292640edj.340.1607325470227; Sun, 06 Dec 2020 23:17:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1607325470; cv=none; d=google.com; s=arc-20160816; b=N6bj5w/pO3ju06iHmHVlvltc3gIadPbjMPrXp1HupMNwIHJLRIsC8a6lqQjU4kBQnh 6wsjw8ZXawo/uyuovDI9/fkSo+xrspGbpSz3BJ6jwb1VAZCP7nhHK9NVhhaoZ1vTggUE FQWe3a8hcjh/HTa5+gmJEVTRqyeHdnQLlZac9k0WQWXXagdF59CX0o6/VVvtDgALS/dD L0Nk38hgLUwGPf9dF1LZnt0BMcWWZwi5Beqi42GGFN12gmtVAsmGI5AY2KXdI83ettTZ yyXQUgR7CKhXWlNoxbr2S6xSvqYcASop6pBEnMHVZ+Yg2sWNSLH6mIYlbmBawOSsWSSm bQOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=BuegduoTe+wHssZKdFwfVQK5dfW32mpobttg/54Oqek=; b=oDg8noOkIi3sdndkhvEGLU+V7SlX0uXVaxwmtN2ONCH9EA5iPUyxn+Wubvh+vbnEdB ywiYmxTZmuQGeipx9dZ0sxwPT8LEF+Eu8JpL10Sh1hnX83o7VT/6lJN12jMjnQbCCWdz J1QOFv81q+/5xNNi9DqVHc4jwTFeyJP+KYNPRU1hN5niWM1CwmOW4h0YuSy2Jh8TClLA uzXfDSVu3TWwTgtcWReCIu75gEYKg7wBPNMlXKRcN9V7SaRjfh2Dzgd4cI+x+Wd1SZWY 1Xrj3XYykQw3/OFBpYc7W6BcQ3rflZD0NoGtwG67iLuLfO1FIJr1NMEMLO5jk6yW6yoU V4ew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=mhicnEpi; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e22si7519231eds.52.2020.12.06.23.17.27; Sun, 06 Dec 2020 23:17:50 -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=@gmail.com header.s=20161025 header.b=mhicnEpi; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726055AbgLGHO0 (ORCPT + 99 others); Mon, 7 Dec 2020 02:14:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726000AbgLGHO0 (ORCPT ); Mon, 7 Dec 2020 02:14:26 -0500 Received: from mail-pg1-x541.google.com (mail-pg1-x541.google.com [IPv6:2607:f8b0:4864:20::541]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA1E2C0613D0 for ; Sun, 6 Dec 2020 23:13:45 -0800 (PST) Received: by mail-pg1-x541.google.com with SMTP id q3so8157914pgr.3 for ; Sun, 06 Dec 2020 23:13:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=BuegduoTe+wHssZKdFwfVQK5dfW32mpobttg/54Oqek=; b=mhicnEpi95O1H2zQf5C0nreui1P+urNU/iK8Ol2V1uqv1Aha5N5eXnKw45YJWDtQ+q J81nhhHRUaF82tOGP1bTTd2tSTqg5qx85qVeo9Ed/MZyUjq91IDIw/5gm5hDb1wF64U7 cZK/PZD/AiB43FcuElQN5IUha0Mb3QqG7lpAxiaZ1W6kPSsAXoyqXgztvJ7zm+7KdQiW 4sAoSt1XN9PAcTxrQNTS0j+sOnXjR4XTx51BzllD/6YyDRGqYRE0lvXDgDNBJCuyxjhr RXAjuO0MnOWS7zlJSVdwiA2UV/yMrJdcLMDm/saLaoSMlJNK86GiL+xs2sYzhh50ChMH c1PQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=BuegduoTe+wHssZKdFwfVQK5dfW32mpobttg/54Oqek=; b=CbuMQi97cSaU/29sYZzayXFbdPx3cJoCZqveoqj1n4va6kFpyEjR5IygSbvpSYkZcL Gbu4QdEPuXw/QhCIaG0ZxecX6ZpFGCrUBzxvJ8SW1XC9deKnWXkN5IHYh1GZsnvz8zCU NN4cZupjbMI9qVl36XxNjDNqld9pQFMytyRUHtvs9wzKJVo876EWr3z/x3Cjfmbb0CbO 4GwjfnWGG4gVaKYIfzGFabwN8TRVM+p7GPwIWliJnFkDj8Tfc6SOrl0YjdrQfXGG+mik oMogFPtmorX/QpTbWnKw+RxHMFURZKCpFA9gUyiNjymujWAAPk/aL7fEZceM6Sd9vxXT bDJg== X-Gm-Message-State: AOAM533pGFKKSvO4to3W8kXylBz1rREiZzsqzyQFfpM3SnsbET7XcLhn 6O7XFhrNqx5UaBMMvm8wMyI= X-Received: by 2002:a63:1d26:: with SMTP id d38mr17164270pgd.246.1607325225494; Sun, 06 Dec 2020 23:13:45 -0800 (PST) Received: from js1304-desktop ([114.206.198.176]) by smtp.gmail.com with ESMTPSA id z25sm11065754pge.66.2020.12.06.23.13.39 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 06 Dec 2020 23:13:45 -0800 (PST) Date: Mon, 7 Dec 2020 16:13:36 +0900 From: Joonsoo Kim To: Pavel Tatashin 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 Subject: Re: [PATCH 6/6] mm/gup: migrate pinned pages out of movable zone Message-ID: <20201207071335.GB10731@js1304-desktop> References: <20201202052330.474592-1-pasha.tatashin@soleen.com> <20201202052330.474592-7-pasha.tatashin@soleen.com> <20201204041358.GB17056@js1304-desktop> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.24 (2015-08-30) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Dec 04, 2020 at 12:43:29PM -0500, Pavel Tatashin wrote: > 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) Yep! Thanks.