Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp1565928ybf; Thu, 27 Feb 2020 13:33:09 -0800 (PST) X-Google-Smtp-Source: APXvYqxqejfqCeUeIM4Ue0skUOqaQRokuWvhzhhdKsaMSql6oFF6fn+Ib4bZIp2cOrQiz9kiqZol X-Received: by 2002:a9d:7d9a:: with SMTP id j26mr714145otn.21.1582839189055; Thu, 27 Feb 2020 13:33:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582839189; cv=none; d=google.com; s=arc-20160816; b=mfwOQb4iqWQWH2N1U30C9EJUIQx8uN8maUvlA9r8drp73TAPtfIu0MiGvdku21FewP FtJmkl4SaOrSXJVVjG4UQrogtICQJ0f1Hj0zXSFBOqWiSnHTHt0aGyLy17lFfBC/D4SJ xw0dQKxp7L38ycLETEl8QJjcJEwE+iw24NWi+NX70+X4I09SYRiohxXOBoNxGkN4B+At yOnUmO+1i74n//3crKAf/MgFMFfidLuuMgUtgTaCYr16foPxVPu2CH4r7C7sJvZW+Wlo 5sXQRsYtiLm81DUd6JoDoIPq8QbWkoRHEDaAL4b2NqODgpJnILzSpAIPaWcgS38xf4i1 X26Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=4BEEWsjoMI/SIVcV6+MvT4mzjOYgMoANa7lfWLTiXm0=; b=k1swIfc1xfuthdiZtZT8xanjE6+mS7wy2dtJupss5ZkVH0QRwkNB4oMsmMEzYkcv8Q APekHG6BqWZOLOPeICoMjvUb4O01BbPtH3KQzvjY+o4UihhUE6zkxlMUgPZQR8n8XVYI CJ9kAKrilP/kWfAO1r8rnW99AV6NDRHR6spOzRmjIn8P2ZKd88EBuGVqB6NIuYSa0cnm rd762+SVWvJqOmHUXkrWeWaH5tCcV2SZnTR1NiynJxlpcfbcUraEgFUgeRsduFj/neDB 2uKYVcUV36/BrdfQHER6v8FlyGh3bIdBYYSI1B3173HLXFcZSYztdLH8MLuabeu23Y57 8qWw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l1si279787otn.213.2020.02.27.13.32.57; Thu, 27 Feb 2020 13:33:09 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730031AbgB0Vcs (ORCPT + 99 others); Thu, 27 Feb 2020 16:32:48 -0500 Received: from shelob.surriel.com ([96.67.55.147]:46266 "EHLO shelob.surriel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729974AbgB0Vcs (ORCPT ); Thu, 27 Feb 2020 16:32:48 -0500 Received: from imladris.surriel.com ([96.67.55.152]) by shelob.surriel.com with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.3) (envelope-from ) id 1j7Qlq-0007O1-WC; Thu, 27 Feb 2020 16:32:39 -0500 From: Rik van Riel To: linux-kernel@vger.kernel.org Cc: kernel-team@fb.com, akpm@linux-foundation.org, linux-mm@kvack.org, mhocko@kernel.org, vbabka@suse.cz, mgorman@techsingularity.net, rientjes@google.com, aarcange@redhat.com, ziy@nvidia.com, Rik van Riel Subject: [PATCH v2 2/2] mm,thp,compaction,cma: allow THP migration for CMA allocations Date: Thu, 27 Feb 2020 16:32:29 -0500 Message-Id: <20200227213238.1298752-2-riel@surriel.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The code to implement THP migrations already exists, and the code for CMA to clear out a region of memory already exists. Only a few small tweaks are needed to allow CMA to move THP memory when attempting an allocation from alloc_contig_range. With these changes, migrating THPs from a CMA area works when allocating a 1GB hugepage from CMA memory. Signed-off-by: Rik van Riel Reviewed-by: Zi Yan --- mm/compaction.c | 22 +++++++++++++--------- mm/page_alloc.c | 9 +++++++-- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/mm/compaction.c b/mm/compaction.c index 672d3c78c6ab..000ade085b89 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -894,12 +894,13 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, /* * Regardless of being on LRU, compound pages such as THP and - * hugetlbfs are not to be compacted. We can potentially save - * a lot of iterations if we skip them at once. The check is - * racy, but we can consider only valid values and the only - * danger is skipping too much. + * hugetlbfs are not to be compacted unless we are attempting + * an allocation much larger than the huge page size (eg CMA). + * We can potentially save a lot of iterations if we skip them + * at once. The check is racy, but we can consider only valid + * values and the only danger is skipping too much. */ - if (PageCompound(page)) { + if (PageCompound(page) && !cc->alloc_contig) { const unsigned int order = compound_order(page); if (likely(order < MAX_ORDER)) @@ -969,7 +970,7 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, * and it's on LRU. It can only be a THP so the order * is safe to read and it's 0 for tail pages. */ - if (unlikely(PageCompound(page))) { + if (unlikely(PageCompound(page) && !cc->alloc_contig)) { low_pfn += compound_nr(page) - 1; goto isolate_fail; } @@ -981,12 +982,15 @@ isolate_migratepages_block(struct compact_control *cc, unsigned long low_pfn, if (__isolate_lru_page(page, isolate_mode) != 0) goto isolate_fail; - VM_BUG_ON_PAGE(PageCompound(page), page); + /* The whole page is taken off the LRU; skip the tail pages. */ + if (PageCompound(page)) + low_pfn += compound_nr(page) - 1; /* Successfully isolated */ del_page_from_lru_list(page, lruvec, page_lru(page)); - inc_node_page_state(page, - NR_ISOLATED_ANON + page_is_file_cache(page)); + mod_node_page_state(page_pgdat(page), + NR_ISOLATED_ANON + page_is_file_cache(page), + hpage_nr_pages(page)); isolate_success: list_add(&page->lru, &cc->migratepages); diff --git a/mm/page_alloc.c b/mm/page_alloc.c index a36736812596..6257c849cc00 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -8253,14 +8253,19 @@ struct page *has_unmovable_pages(struct zone *zone, struct page *page, /* * Hugepages are not in LRU lists, but they're movable. + * THPs are on the LRU, but need to be counted as #small pages. * We need not scan over tail pages because we don't * handle each tail page individually in migration. */ - if (PageHuge(page)) { + if (PageHuge(page) || PageTransCompound(page)) { struct page *head = compound_head(page); unsigned int skip_pages; - if (!hugepage_migration_supported(page_hstate(head))) + if (PageHuge(page) && + !hugepage_migration_supported(page_hstate(head))) + return page; + + if (!PageLRU(head) && !__PageMovable(head)) return page; skip_pages = compound_nr(head) - (page - head); -- 2.24.1