From patchwork Tue Jul 7 07:44:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joonsoo Kim X-Patchwork-Id: 11647955 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 0A02313B6 for ; Tue, 7 Jul 2020 07:45:37 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CBA1C20708 for ; Tue, 7 Jul 2020 07:45:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Zg+77soX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CBA1C20708 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 2B69A6B0080; Tue, 7 Jul 2020 03:45:35 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 23FA36B0081; Tue, 7 Jul 2020 03:45:35 -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 12F0C6B0082; Tue, 7 Jul 2020 03:45:35 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0102.hostedemail.com [216.40.44.102]) by kanga.kvack.org (Postfix) with ESMTP id E85B06B0080 for ; Tue, 7 Jul 2020 03:45:34 -0400 (EDT) Received: from smtpin12.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id AB4591EF2 for ; Tue, 7 Jul 2020 07:45:34 +0000 (UTC) X-FDA: 77010494988.12.shoes32_520da9326eb2 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin12.hostedemail.com (Postfix) with ESMTP id 708261800EC30 for ; Tue, 7 Jul 2020 07:45:34 +0000 (UTC) X-Spam-Summary: 1,0,0,67ad061f93f47a67,d41d8cd98f00b204,js1304@gmail.com,,RULES_HIT:41:69:355:379:541:800:960:968:973:988:989:1260:1345:1359:1437:1535:1544:1711:1730:1747:1777:1792:2198:2199:2393:2559:2562:2693:2899:3138:3139:3140:3141:3142:3355:3865:3866:3867:3868:3870:3871:3872:3874:4118:4250:4321:4605:5007:6119:6261:6653:7576:7903:8531:8957:9413:9592:10004:11026:11473:11658:11914:12043:12296:12297:12438:12517:12519:12555:12679:12683:12895:13161:13229:14096:14181:14394:14721:21080:21212:21220:21444:21451:21627:21666:21990:30054:30080,0,RBL:209.85.216.67:@gmail.com:.lbl8.mailshell.net-66.100.201.100 62.50.0.100;04yg7g1ptfznuoqn4xdetnbn81hgqyp1f9gy4rsfqzg5bjin94zrb5rycrc3wz6.ycz9ys46fu4xjytw7tw3gsfmk1jd5j6ny3dnbjdrh5wzg8s4nkqt1r4ebtoc3os.1-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: shoes32_520da9326eb2 X-Filterd-Recvd-Size: 7749 Received: from mail-pj1-f67.google.com (mail-pj1-f67.google.com [209.85.216.67]) by imf39.hostedemail.com (Postfix) with ESMTP for ; Tue, 7 Jul 2020 07:45:33 +0000 (UTC) Received: by mail-pj1-f67.google.com with SMTP id cm21so8598399pjb.3 for ; Tue, 07 Jul 2020 00:45:33 -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=+ALly2iCWh0BQrkDtphHPvmMGWbm0eTErSKhy81hot0=; b=Zg+77soXJbGPc0NLsJ1kxiqjpVafBKmMrM7OrBM/xlmVUcDE60zBLnfNUgGGVdVK2s 0w8xvrmQ2Q0eJ+1i+W52IE020sATbBxP2fTnqWsjmH+UR82HhNYSeZaFZe/q3N3qyk6y n4mwItTqjvUKh7fE5iQQoRubyoBMRMOM0WUpaYxYeAR6GdVzsmBmJhfSvsCzvrUj+obn BKdPyYXDG2rNiso+K+HhOJh1dSGn92Yn29xep5Vfe+W9e0AsjcdosphSScN7ixuhtOUz zX0YQpzayUfiJ2AUgxgNL3yPUPW+yhfV26GKkKhdyLODcWkEqp5bgUDt1hWp2sa040i1 ndeQ== 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=+ALly2iCWh0BQrkDtphHPvmMGWbm0eTErSKhy81hot0=; b=SNFJNB1RpyUfoU4aFA9ceniS9WimjagqzKryt0ScLT+oNBmgMeC+/WE1mZ9pTBpMmP Kb20YjKN//cHg1+bgACX8yv0TLfRTbbRnPQdvxUAzp6Oj8qZCbO60aqslc43pI3vUExI 18Y3KL84sk1YzkHP0E1Vk208X1y6BbGmT0Umau76xCJjgioD/D+8jr7SWc4ZsctNP5+7 WrwABQ+uFM+nHDau/yNNPyiGv0ZFTQ8zZl9Hy+a9l1pUx7ma2tjK4wobuex8ZuBNL4LB cS9GTZ+HPEnahcPu+C/FmbNUdrtaRvHeJFYYNmxcWH8O/kFNvWMdmIuF66Nc5ZrKB536 OuBg== X-Gm-Message-State: AOAM5302MGgkYY1VFuklZPKOk/ji03Mqi18h+pmdnBz7l0OXePsVdToF b1/yq+VW/NJMEj+AarpRCaep7Q7J X-Google-Smtp-Source: ABdhPJwQlR9icSQ/ViMylCqjKeK8iBXZ5C6sPnSc8IPP0qMzT56rzVGFjpDNgYoarPioFStmVxlTbw== X-Received: by 2002:a17:902:161:: with SMTP id 88mr16321361plb.325.1594107933119; Tue, 07 Jul 2020 00:45:33 -0700 (PDT) Received: from localhost.localdomain ([114.206.198.176]) by smtp.gmail.com with ESMTPSA id 191sm21330151pfw.150.2020.07.07.00.45.30 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 07 Jul 2020 00:45:32 -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 , Joonsoo Kim Subject: [PATCH v4 07/11] mm/gup: use a standard migration target allocation callback Date: Tue, 7 Jul 2020 16:44:45 +0900 Message-Id: <1594107889-32228-8-git-send-email-iamjoonsoo.kim@lge.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1594107889-32228-1-git-send-email-iamjoonsoo.kim@lge.com> References: <1594107889-32228-1-git-send-email-iamjoonsoo.kim@lge.com> X-Rspamd-Queue-Id: 708261800EC30 X-Spamd-Result: default: False [0.00 / 100.00] X-Rspamd-Server: rspam05 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 There is a well-defined migration target allocation callback. It's mostly similar with new_non_cma_page() except considering CMA pages. This patch adds a CMA consideration to the standard migration target allocation callback and use it on gup.c. Acked-by: Vlastimil Babka Signed-off-by: Joonsoo Kim --- mm/gup.c | 61 +++++++---------------------------------------------------- mm/internal.h | 1 + mm/migrate.c | 9 ++++++++- 3 files changed, 16 insertions(+), 55 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index 2c3dab4..6a74c30 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1608,58 +1608,6 @@ static bool check_dax_vmas(struct vm_area_struct **vmas, long nr_pages) } #ifdef CONFIG_CMA -static struct page *new_non_cma_page(struct page *page, unsigned long private) -{ - /* - * We want to make sure we allocate the new page from the same node - * as the source page. - */ - int nid = page_to_nid(page); - /* - * 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 - * allocation memory. - */ - gfp_t gfp_mask = GFP_USER | __GFP_NOWARN; - - if (PageHighMem(page)) - gfp_mask |= __GFP_HIGHMEM; - -#ifdef CONFIG_HUGETLB_PAGE - if (PageHuge(page)) { - struct hstate *h = page_hstate(page); - - /* - * We don't want to dequeue from the pool because pool pages will - * mostly be from the CMA region. - */ - return alloc_huge_page_nodemask(h, nid, NULL, gfp_mask, true); - } -#endif - if (PageTransHuge(page)) { - struct page *thp; - /* - * ignore allocation failure warnings - */ - 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; - prep_transhuge_page(thp); - return thp; - } - - return __alloc_pages_node(nid, gfp_mask, 0); -} - static long check_and_migrate_cma_pages(struct task_struct *tsk, struct mm_struct *mm, unsigned long start, @@ -1674,6 +1622,11 @@ static long check_and_migrate_cma_pages(struct task_struct *tsk, bool migrate_allow = true; LIST_HEAD(cma_page_list); long ret = nr_pages; + struct migration_target_control mtc = { + .nid = NUMA_NO_NODE, + .gfp_mask = GFP_USER | __GFP_NOWARN, + .skip_cma = true, + }; check_again: for (i = 0; i < nr_pages;) { @@ -1719,8 +1672,8 @@ static long check_and_migrate_cma_pages(struct task_struct *tsk, for (i = 0; i < nr_pages; i++) put_page(pages[i]); - if (migrate_pages(&cma_page_list, new_non_cma_page, - NULL, 0, MIGRATE_SYNC, MR_CONTIG_RANGE)) { + if (migrate_pages(&cma_page_list, alloc_migration_target, NULL, + (unsigned long)&mtc, MIGRATE_SYNC, MR_CONTIG_RANGE)) { /* * some of the pages failed migration. Do get_user_pages * without migration. diff --git a/mm/internal.h b/mm/internal.h index 0beacf3..3236fef 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -619,6 +619,7 @@ struct migration_target_control { int nid; /* preferred node id */ nodemask_t *nmask; gfp_t gfp_mask; + bool skip_cma; }; #endif /* __MM_INTERNAL_H */ diff --git a/mm/migrate.c b/mm/migrate.c index 00cd81c..ab18b9c 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -1539,6 +1539,7 @@ struct page *alloc_migration_target(struct page *page, unsigned long private) struct page *new_page = NULL; int nid; int zidx; + unsigned int flags = 0; mtc = (struct migration_target_control *)private; gfp_mask = mtc->gfp_mask; @@ -1551,9 +1552,12 @@ struct page *alloc_migration_target(struct page *page, unsigned long private) gfp_mask |= htlb_alloc_mask(h); return alloc_huge_page_nodemask(h, nid, mtc->nmask, - gfp_mask, false); + gfp_mask, mtc->skip_cma); } + if (mtc->skip_cma) + flags = memalloc_nocma_save(); + if (PageTransHuge(page)) { /* * clear __GFP_RECALIM since GFP_TRANSHUGE is the gfp_mask @@ -1572,6 +1576,9 @@ struct page *alloc_migration_target(struct page *page, unsigned long private) if (new_page && PageTransHuge(new_page)) prep_transhuge_page(new_page); + if (mtc->skip_cma) + memalloc_nocma_restore(flags); + return new_page; }