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=-9.9 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,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 4EA78C2D0F4 for ; Wed, 8 Apr 2020 19:45:46 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B73282075E for ; Wed, 8 Apr 2020 19:45:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="CechIr8L" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B73282075E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=fb.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 247008E000D; Wed, 8 Apr 2020 15:45:45 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F7BA8E0006; Wed, 8 Apr 2020 15:45:45 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0C12B8E000D; Wed, 8 Apr 2020 15:45:45 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0149.hostedemail.com [216.40.44.149]) by kanga.kvack.org (Postfix) with ESMTP id E86868E0006 for ; Wed, 8 Apr 2020 15:45:44 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id A7FBDB7AC for ; Wed, 8 Apr 2020 19:45:44 +0000 (UTC) X-FDA: 76685717808.27.shock64_14f5358ecd644 X-HE-Tag: shock64_14f5358ecd644 X-Filterd-Recvd-Size: 5411 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf25.hostedemail.com (Postfix) with ESMTP for ; Wed, 8 Apr 2020 19:45:43 +0000 (UTC) Received: from pps.filterd (m0044012.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 038Jjf6W025506 for ; Wed, 8 Apr 2020 12:45:41 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : mime-version : content-transfer-encoding : content-type; s=facebook; bh=S/pCWxjqeTsD2gyHb5J2r/7EG42OJcrb5pPllXyPYxM=; b=CechIr8Lj/Qu37HVwVGkONa2BciNOoTMa0BH0vipd2aFgvJBqlUMP/qx1sobQbuwGLtf vOwkvzUzl6PRKt2CrRfJZ/j+eb4UvabSYPWqbGwmNKxAaJUs2ecr5C5qI5Q+9BsbjO+v qrtnsQqAysxvJJrzkLYDvnI+CDBlSqL8Q/U= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 3091m5egks-2 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Wed, 08 Apr 2020 12:45:41 -0700 Received: from intmgw002.06.prn3.facebook.com (2620:10d:c085:108::8) by mail.thefacebook.com (2620:10d:c085:11d::4) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1847.3; Wed, 8 Apr 2020 12:45:31 -0700 Received: by devvm2643.prn2.facebook.com (Postfix, from userid 111017) id 794F93CA399FE; Wed, 8 Apr 2020 12:41:22 -0700 (PDT) Smtp-Origin-Hostprefix: devvm From: Roman Gushchin Smtp-Origin-Hostname: devvm2643.prn2.facebook.com To: Andrew Morton CC: Michal Hocko , , , , Rik van Riel , Mel Gorman , Vlastimil Babka , Qian Cai , Andrea Arcangeli , Joonsoo Kim , Roman Gushchin Smtp-Origin-Cluster: prn2c23 Subject: [PATCH RFC] mm: compaction: avoid migrating non-cma pages to a cma area Date: Wed, 8 Apr 2020 12:41:19 -0700 Message-ID: <20200408194119.1076232-1-guro@fb.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-FB-Internal: Safe Content-Type: text/plain X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.676 definitions=2020-04-07_10:2020-04-07,2020-04-07 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 mlxscore=0 lowpriorityscore=0 malwarescore=0 priorityscore=1501 spamscore=0 suspectscore=0 phishscore=0 adultscore=0 clxscore=1015 bulkscore=0 mlxlogscore=926 impostorscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2004080138 X-FB-Internal: deliver 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: Compaction does treat cma pageblocks on pair with any movable pageblocks. It means it can easily move non-cma pages into a cma zone. It can create problems for the cma allocator. The particular problem I'm looking at is related to btrfs metadata pages, which are allocated without __GFP_MOVABLE, but beside that are generic pagecache pages. In fact, they are sometimes movable and sometimes not, depending on whether they are dirty and also on the extent buffer reference counter. Compaction moves them to the hugetlb_cma area, and then sometimes the cma allocator fails to move them back from the cma area. It results in failures of gigantic hugepages allocations. Also in general cma areas are reserved close to the end of a zone, and it's where compaction tries to migrate pages. It means compaction will aggressively fill cma areas, which makes not much sense. So to avoid it, let's preserve non-cma pages from being moved into a cma area. Because cma areas are usually quite large and the number of areas is small, it should not significantly affect the memory fragmentation. Signed-off-by: Roman Gushchin --- mm/compaction.c | 6 ++++++ mm/internal.h | 1 + 2 files changed, 7 insertions(+) diff --git a/mm/compaction.c b/mm/compaction.c index 46f0fcc93081..9b047cbb1c74 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1159,6 +1159,10 @@ static bool suitable_migration_target(struct compa= ct_control *cc, return false; } =20 + /* Do not bring pages non-cma pages into a cma area */ + if (is_migrate_cma(get_pageblock_migratetype(page)) && !cc->cma) + return false; + if (cc->ignore_block_suitable) return true; =20 @@ -1832,6 +1836,8 @@ static isolate_migrate_t isolate_migratepages(struc= t compact_control *cc) if (!low_pfn) return ISOLATE_ABORT; =20 + cc->cma =3D is_migrate_cma(get_pageblock_migratetype(page)); + /* * Either we isolated something and proceed with migration. Or * we failed and compact_zone should decide if we should diff --git a/mm/internal.h b/mm/internal.h index b5634e78f01d..0ce649da824b 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -232,6 +232,7 @@ struct compact_control { bool contended; /* Signal lock or sched contention */ bool rescan; /* Rescanning the same pageblock */ bool alloc_contig; /* alloc_contig_range allocation */ + bool cma; /* migratepages contains cma pages */ }; =20 /* --=20 2.25.1