From patchwork Wed Jul 15 05:05:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joonsoo Kim X-Patchwork-Id: 11664201 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 78F961392 for ; Wed, 15 Jul 2020 05:05:51 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 458CD2067D for ; Wed, 15 Jul 2020 05:05:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="nuj/Shff" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 458CD2067D Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 3797B6B0006; Wed, 15 Jul 2020 01:05:50 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 2B34C8D0001; Wed, 15 Jul 2020 01:05:50 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1570A6B0008; Wed, 15 Jul 2020 01:05:50 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0032.hostedemail.com [216.40.44.32]) by kanga.kvack.org (Postfix) with ESMTP id EED3A6B0006 for ; Wed, 15 Jul 2020 01:05:49 -0400 (EDT) Received: from smtpin19.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id AC5C48248D51 for ; Wed, 15 Jul 2020 05:05:49 +0000 (UTC) X-FDA: 77039122818.19.shame44_2f062b926ef6 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin19.hostedemail.com (Postfix) with ESMTP id 848EA1AD1B3 for ; Wed, 15 Jul 2020 05:05:49 +0000 (UTC) X-Spam-Summary: 1,0,0,26bcd1eb9f28ad15,d41d8cd98f00b204,js1304@gmail.com,,RULES_HIT:41:355:379:541:800:960:966:968:973:988:989:1260:1345:1359:1437:1535:1543:1711:1730:1747:1777:1792:2196:2198:2199:2200:2393:2559:2562:2693:2895:2899:3138:3139:3140:3141:3142:3355:3865:3867:3868:3870:3871:3872:3874:4117:4250:4321:4385:4605:5007:6119:6261:6653:6742:7576:7901:7903:8957:9413:10004:11026:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12895:13180:13229:14181:14394:14721:21080:21444:21451:21627:21666:21990:30054:30070,0,RBL:209.85.216.68:@gmail.com:.lbl8.mailshell.net-62.18.0.100 66.100.201.100;04yfxkmnmc4gfpr6yrdcsddpdok6kyctruegkmtsp7w5tn96g7qaawhrc1o19tr.ezqh4nqpuufnx69jhexjwbnnfcepo73j694zw6yjcrns8o69qhkjaoady35ifob.h-lbl8.mailshell.net-223.238.255.100,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fp,MSBL:0,DNSBL:neutral,Custom_rules:0:0:0,LFtime:25,LUA_SUMMARY:none X-HE-Tag: shame44_2f062b926ef6 X-Filterd-Recvd-Size: 6575 Received: from mail-pj1-f68.google.com (mail-pj1-f68.google.com [209.85.216.68]) by imf34.hostedemail.com (Postfix) with ESMTP for ; Wed, 15 Jul 2020 05:05:49 +0000 (UTC) Received: by mail-pj1-f68.google.com with SMTP id o22so2332931pjw.2 for ; Tue, 14 Jul 2020 22:05:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=e7byfgHw8QS4EFeIqD5PDYqTNizYFOWzHsxHEo0G+W4=; b=nuj/ShffpoKXVL9Twu4mnjAAGc6trFyAcytARH/jXA7FlxltODfayDtDpf3tZp1bnZ 5ypy2TkSdXVby/FZBmOXGUDefNSH0TGR13s3r4SKlgdonIe+fsACRrFKRNNk320EFflm AeALOCBkibmcwxa7uwGTJIVolr1eOLLqolSKKkmPOhXbyrGyg6RJoA+RRDaBKXL9fa9k qtwjlV1STLsyeJqe/98Rao5M1fvvsBBbhoIanlqO03o5kwLS9IKwqKL4CRDs8HZQ6Yf2 w0XSLF5CqORruKWR0AQCERc/RXk3488q4N6tCnkMxZaqSaUKj/ofOm91Rf7WArXa8FSK sy0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=e7byfgHw8QS4EFeIqD5PDYqTNizYFOWzHsxHEo0G+W4=; b=eT6mzYoGLuNF0+0ChChaC/RwEQX4xlCi2P91QNGd9b5AyhlXZUhkHVKVkMjM2nV4+X RAW6FNR168UxB9Do9lgGAVf0lp/QcqU/w1F/uGmyB6Um7I4VngSwbKZJtK9AhfmhnQNg HZaIHkaOhsPMvzDy+2T6aFnHf1BUAUUY5xDtB7JVpWIQHE5VWb3Y7sAAhljqJXE0z0jZ 9zyDP7MZ5UG/Tj/Mnk2WBvTDnry3bRwngQkhkAQV2CE42WW79Nu9gjdZ4EEcoA+C1A91 +MMD/MLNkKDMpPyJVuHu5/Nw5VqLgs+lAI2YmkoC2xQB49QsyNZfeu2/n5diF2D0Loka IjHw== X-Gm-Message-State: AOAM530pASpbT9gG1mD2wqbDIunIKXH3xSdRkAoWRSYn0wCVanAoF/jB iOw7BbNCQ4kaB8pQLdF3TEI= X-Google-Smtp-Source: ABdhPJyEk74SdinwCEymCOZL8TIvU3lrpB1LNieqQ+aiZb/vLtcI8gc4oa2hwcSXm4m0mHX4JQjJvQ== X-Received: by 2002:a17:90a:a393:: with SMTP id x19mr8520227pjp.228.1594789548231; Tue, 14 Jul 2020 22:05:48 -0700 (PDT) Received: from localhost.localdomain ([114.206.198.176]) by smtp.gmail.com with ESMTPSA id i21sm747251pfa.18.2020.07.14.22.05.45 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Jul 2020 22:05:47 -0700 (PDT) From: js1304@gmail.com X-Google-Original-From: iamjoonsoo.kim@lge.com To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@lge.com, Vlastimil Babka , Christoph Hellwig , Roman Gushchin , Mike Kravetz , Naoya Horiguchi , Michal Hocko , "Aneesh Kumar K . V" , Joonsoo Kim Subject: [PATCH 2/4] mm/gup: restrict CMA region by using allocation scope API Date: Wed, 15 Jul 2020 14:05:27 +0900 Message-Id: <1594789529-6206-2-git-send-email-iamjoonsoo.kim@lge.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1594789529-6206-1-git-send-email-iamjoonsoo.kim@lge.com> References: <1594789529-6206-1-git-send-email-iamjoonsoo.kim@lge.com> X-Rspamd-Queue-Id: 848EA1AD1B3 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam01 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: From: Joonsoo Kim We have well defined scope API to exclude CMA region. Use it rather than manipulating gfp_mask manually. With this change, we can now use __GFP_MOVABLE for gfp_mask and the ZONE_MOVABLE is also searched by page allocator. For hugetlb, gfp_mask is redefined since it has a regular allocation mask filter for migration target. Note that this can be considered as a fix for the commit 9a4e9f3b2d73 ("mm: update get_user_pages_longterm to migrate pages allocated from CMA region"). However, "Fixes" tag isn't added here since it is just suboptimal but it doesn't cause any problem. Suggested-by: Michal Hocko Signed-off-by: Joonsoo Kim --- include/linux/hugetlb.h | 2 ++ mm/gup.c | 17 ++++++++--------- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/include/linux/hugetlb.h b/include/linux/hugetlb.h index 6b9508d..2660b04 100644 --- a/include/linux/hugetlb.h +++ b/include/linux/hugetlb.h @@ -708,6 +708,8 @@ static inline gfp_t htlb_modify_alloc_mask(struct hstate *h, gfp_t gfp_mask) /* Some callers might want to enfoce node */ modified_mask |= (gfp_mask & __GFP_THISNODE); + modified_mask |= (gfp_mask & __GFP_NOWARN); + return modified_mask; } diff --git a/mm/gup.c b/mm/gup.c index 5daadae..bbd36a1 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1619,10 +1619,12 @@ static struct page *new_non_cma_page(struct page *page, unsigned long private) * Trying to allocate a page for migration. Ignore allocation * failure warnings. We don't force __GFP_THISNODE here because * this node here is the node where we have CMA reservation and - * in some case these nodes will have really less non movable + * in some case these nodes will have really less non CMA * allocation memory. + * + * Note that CMA region is prohibited by allocation scope. */ - gfp_t gfp_mask = GFP_USER | __GFP_NOWARN; + gfp_t gfp_mask = GFP_USER | __GFP_MOVABLE | __GFP_NOWARN; if (PageHighMem(page)) gfp_mask |= __GFP_HIGHMEM; @@ -1630,6 +1632,8 @@ static struct page *new_non_cma_page(struct page *page, unsigned long private) #ifdef CONFIG_HUGETLB_PAGE if (PageHuge(page)) { struct hstate *h = page_hstate(page); + + gfp_mask = htlb_modify_alloc_mask(h, gfp_mask); /* * We don't want to dequeue from the pool because pool pages will * mostly be from the CMA region. @@ -1644,11 +1648,6 @@ static struct page *new_non_cma_page(struct page *page, unsigned long private) */ gfp_t thp_gfpmask = GFP_TRANSHUGE | __GFP_NOWARN; - /* - * Remove the movable mask so that we don't allocate from - * CMA area again. - */ - thp_gfpmask &= ~__GFP_MOVABLE; thp = __alloc_pages_node(nid, thp_gfpmask, HPAGE_PMD_ORDER); if (!thp) return NULL; @@ -1794,7 +1793,6 @@ static long __gup_longterm_locked(struct task_struct *tsk, vmas_tmp, NULL, gup_flags); if (gup_flags & FOLL_LONGTERM) { - memalloc_nocma_restore(flags); if (rc < 0) goto out; @@ -1807,9 +1805,10 @@ static long __gup_longterm_locked(struct task_struct *tsk, rc = check_and_migrate_cma_pages(tsk, mm, start, rc, pages, vmas_tmp, gup_flags); +out: + memalloc_nocma_restore(flags); } -out: if (vmas_tmp != vmas) kfree(vmas_tmp); return rc;