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 X-Spam-Level: X-Spam-Status: No, score=-16.5 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E99CC64E90 for ; Wed, 2 Dec 2020 05:23:50 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id A2B772065C for ; Wed, 2 Dec 2020 05:23:49 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A2B772065C Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 5D21C8D000B; Wed, 2 Dec 2020 00:23:48 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 583148D0002; Wed, 2 Dec 2020 00:23:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3FD4A8D000B; Wed, 2 Dec 2020 00:23:48 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0183.hostedemail.com [216.40.44.183]) by kanga.kvack.org (Postfix) with ESMTP id 2B8C58D0002 for ; Wed, 2 Dec 2020 00:23:48 -0500 (EST) Received: from smtpin05.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id EDA1C180AD815 for ; Wed, 2 Dec 2020 05:23:47 +0000 (UTC) X-FDA: 77547200094.05.bird03_3a10804273b0 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin05.hostedemail.com (Postfix) with ESMTP id D5A9F1801ABD4 for ; Wed, 2 Dec 2020 05:23:47 +0000 (UTC) X-HE-Tag: bird03_3a10804273b0 X-Filterd-Recvd-Size: 9026 Received: from mail-io1-f68.google.com (mail-io1-f68.google.com [209.85.166.68]) by imf02.hostedemail.com (Postfix) with ESMTP for ; Wed, 2 Dec 2020 05:23:47 +0000 (UTC) Received: by mail-io1-f68.google.com with SMTP id y5so671254iow.5 for ; Tue, 01 Dec 2020 21:23:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=ThlXfcc364FojUO3y5P/ifl4RemTQu3v9eNcTeklg7g=; b=V62z5icg0nzFchCWhHxdLHnEZw8ThRBnzwT84W37nOjJNHZaHjOMna6MYZ/5k2l8y0 iQRgQ3rKIhbf1Y4YPk8dCKgJfeDzOCFNKCLjEf3Tc91smlQ9jjhhQcQ+zZKBSWUI5my7 wszyyjhQcfu6lxWLgH6v2zovh70tmMPk2eV/kqaskr+T12Z3Ihk834pXeAP/GjoI7mFc H+0sCKJYy5tsBosNAupfcsW+nzCuZBmePwqNdzM8MjKpXsYdQWvX629BeG06u5w38qkt IQUNHWugAurAIntDBvxS1L+R/jcHhjSvH1j61JJX9UNngu6CPkHJvC7ksf7wb+y7bm5u xKqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ThlXfcc364FojUO3y5P/ifl4RemTQu3v9eNcTeklg7g=; b=ZzAYSf6aO+JzwnCz6nkqtCngme66RoFhkpSBlIfuFbCs2Lw9RMHLDOZCOhWJHOlU1v KoBy6CNl2zOaeeEMgNggNUo9TRvp2KRa8PTS/vDMC9C/yWoIYJQAEBYwJGKcNR56dcvw opLKL22D0tXdoLC35p9JZAF7Y894F4IILjc0MU78J311WudkdQwjrt/bacqRMshPHf8G ACmVELry0TVxtbrNtXHevUv2g2ZeMJCxAsJ6rgzkiyUYcRSxqw6KgWhvnbF0bYbhYy3c vthc8pmn9H16D6ibFiHdwYMADZuyAr/yW+LO+otAJQJ3k+l081C3kLju5zinZ4sR3LfX PlZQ== X-Gm-Message-State: AOAM5328TJKkNIio8Btc8+5bWjDgmGrIHA2yuEwlnpvvItW8oLw8RnRx F4jjZVEyazhh/4C9uMfytvsvtg== X-Google-Smtp-Source: ABdhPJzTLoCZReLgz51Hrk6XAF0pPmsQoEP7xNffwdXB4knjafqxqpMOhwLiaadyI7uMnqTjiR/W9g== X-Received: by 2002:a05:6602:2209:: with SMTP id n9mr605230ion.181.1606886626860; Tue, 01 Dec 2020 21:23:46 -0800 (PST) Received: from localhost.localdomain (c-73-69-118-222.hsd1.nh.comcast.net. [73.69.118.222]) by smtp.gmail.com with ESMTPSA id m19sm295938ila.81.2020.12.01.21.23.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2020 21:23:46 -0800 (PST) From: Pavel Tatashin To: pasha.tatashin@soleen.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, vbabka@suse.cz, mhocko@suse.com, david@redhat.com, osalvador@suse.de, dan.j.williams@intel.com, sashal@kernel.org, tyhicks@linux.microsoft.com, iamjoonsoo.kim@lge.com, mike.kravetz@oracle.com, rostedt@goodmis.org, mingo@redhat.com, jgg@ziepe.ca, peterz@infradead.org, mgorman@suse.de, willy@infradead.org, rientjes@google.com, jhubbard@nvidia.com Subject: [PATCH 6/6] mm/gup: migrate pinned pages out of movable zone Date: Wed, 2 Dec 2020 00:23:30 -0500 Message-Id: <20201202052330.474592-7-pasha.tatashin@soleen.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20201202052330.474592-1-pasha.tatashin@soleen.com> References: <20201202052330.474592-1-pasha.tatashin@soleen.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: 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 }; =20 diff --git a/include/trace/events/migrate.h b/include/trace/events/migrat= e.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") =20 /* * First define the enums in the above macros to be exported to userspac= e 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 =20 -#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 =3D true; bool migrate_allow =3D true; - LIST_HEAD(cma_page_list); + LIST_HEAD(page_list); long ret =3D nr_pages; struct migration_target_control mtc =3D { .nid =3D NUMA_NO_NODE, @@ -1623,13 +1622,12 @@ static long check_and_migrate_cma_pages(struct mm= _struct *mm, */ step =3D 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))) { if (PageHuge(head)) - isolate_huge_page(head, &cma_page_list); + isolate_huge_page(head, &page_list); else { if (!PageLRU(head) && drain_allow) { lru_add_drain_all(); @@ -1637,7 +1635,7 @@ static long check_and_migrate_cma_pages(struct mm_s= truct *mm, } =20 if (!isolate_lru_page(head)) { - list_add_tail(&head->lru, &cma_page_list); + list_add_tail(&head->lru, &page_list); mod_node_page_state(page_pgdat(head), NR_ISOLATED_ANON + page_is_file_lru(head), @@ -1649,7 +1647,7 @@ static long check_and_migrate_cma_pages(struct mm_s= truct *mm, i +=3D step; } =20 - if (!list_empty(&cma_page_list)) { + if (!list_empty(&page_list)) { /* * drop the above get_user_pages reference. */ @@ -1659,7 +1657,7 @@ static long check_and_migrate_cma_pages(struct mm_s= truct *mm, for (i =3D 0; i < nr_pages; i++) put_page(pages[i]); =20 - if (migrate_pages(&cma_page_list, alloc_migration_target, NULL, + if (migrate_pages(&page_list, alloc_migration_target, NULL, (unsigned long)&mtc, MIGRATE_SYNC, MR_CONTIG_RANGE)) { /* * some of the pages failed migration. Do get_user_pages @@ -1667,17 +1665,16 @@ static long check_and_migrate_cma_pages(struct mm= _struct *mm, */ migrate_allow =3D false; =20 - if (!list_empty(&cma_page_list)) - putback_movable_pages(&cma_page_list); + if (!list_empty(&page_list)) + putback_movable_pages(&page_list); } /* * We did migrate all the pages, Try to get the page references - * again migrating any new CMA pages which we failed to isolate - * earlier. + * again migrating any pages which we failed to isolate earlier. */ ret =3D __get_user_pages_locked(mm, start, nr_pages, - pages, vmas, NULL, - gup_flags); + pages, vmas, NULL, + gup_flags); =20 if ((ret > 0) && migrate_allow) { nr_pages =3D ret; @@ -1688,17 +1685,6 @@ static long check_and_migrate_cma_pages(struct mm_= struct *mm, =20 return ret; } -#else -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) -{ - return nr_pages; -} -#endif /* CONFIG_CMA */ =20 /* * __gup_longterm_locked() is a wrapper for __get_user_pages_locked whic= h @@ -1746,8 +1732,8 @@ static long __gup_longterm_locked(struct mm_struct = *mm, goto out; } =20 - rc =3D check_and_migrate_cma_pages(mm, start, rc, pages, - vmas_tmp, gup_flags); + rc =3D check_and_migrate_movable_pages(mm, start, rc, pages, + vmas_tmp, gup_flags); out: memalloc_nomovable_restore(flags); } --=20 2.25.1