From patchwork Fri Apr 3 11:18:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aslan Bakirov X-Patchwork-Id: 11472547 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 C9B9181 for ; Fri, 3 Apr 2020 11:19:04 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 8D11D20737 for ; Fri, 3 Apr 2020 11:19:04 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="GuMNLp28" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8D11D20737 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 9E9668E0009; Fri, 3 Apr 2020 07:19:03 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 999468E0007; Fri, 3 Apr 2020 07:19:03 -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 889478E0009; Fri, 3 Apr 2020 07:19:03 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0239.hostedemail.com [216.40.44.239]) by kanga.kvack.org (Postfix) with ESMTP id 6EEFC8E0007 for ; Fri, 3 Apr 2020 07:19:03 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 311E7181AEF1A for ; Fri, 3 Apr 2020 11:19:03 +0000 (UTC) X-FDA: 76666296966.18.snow06_6c1652493763a X-Spam-Summary: 2,0,0,dce30dce1480ba9f,d41d8cd98f00b204,prvs=1362849eaa=aslan@fb.com,,RULES_HIT:2:41:355:379:541:800:960:966:973:988:989:1260:1261:1277:1311:1313:1314:1345:1431:1437:1513:1515:1516:1518:1521:1535:1605:1606:1730:1747:1777:1792:2196:2198:2199:2200:2393:2559:2562:2693:2899:3138:3139:3140:3141:3142:3865:3866:3867:3868:3870:3871:3872:3874:4119:4250:4321:4385:4605:5007:6119:6261:6653:7875:7903:8603:9163:10004:11026:11473:11658:11914:12043:12296:12297:12438:12555:12663:12895:14096:14097:14394:21067:21080:21324:21451:21627:21740:21990:30003:30012:30029:30054:30064,0,RBL:67.231.153.30:@fb.com:.lbl8.mailshell.net-62.12.0.100 64.201.201.201,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:24,LUA_SUMMARY:none X-HE-Tag: snow06_6c1652493763a X-Filterd-Recvd-Size: 8178 Received: from mx0b-00082601.pphosted.com (mx0b-00082601.pphosted.com [67.231.153.30]) by imf04.hostedemail.com (Postfix) with ESMTP for ; Fri, 3 Apr 2020 11:19:02 +0000 (UTC) Received: from pps.filterd (m0109331.ppops.net [127.0.0.1]) by mx0a-00082601.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 033BJ1Ri024696 for ; Fri, 3 Apr 2020 04:19:02 -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=POliylQHnadVcZ/lLIE6UlF5yDLxBLN21yBGuch3mZc=; b=GuMNLp28HwajDJpuV3zAPd5l01vBrgTWBnTiQzXiyShvWCNmzRBA3RoG8zBNM4WY2zUd o/Ryaa0CgpPfZFeKjDLr0z8L8QkEjmzPHo5qBHsZKe/QU8lktIwspFOCtf9iybPbDfbs tfagh8ZoOsG43jkMQcRpduRQH6XEEUcyw0k= Received: from mail.thefacebook.com ([163.114.132.120]) by mx0a-00082601.pphosted.com with ESMTP id 304cxbxex5-7 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 03 Apr 2020 04:19:01 -0700 Received: from intmgw003.03.ash8.facebook.com (2620:10d:c085:108::8) by mail.thefacebook.com (2620:10d:c085:11d::6) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1847.3; Fri, 3 Apr 2020 04:18:38 -0700 Received: by devbig020.ftw1.facebook.com (Postfix, from userid 179119) id 6C27C58C06B4; Fri, 3 Apr 2020 04:18:36 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Aslan Bakirov Smtp-Origin-Hostname: devbig020.ftw1.facebook.com To: CC: , , , , , , , Aslan Bakirov Smtp-Origin-Cluster: ftw1c07 Subject: [PATCH 1/2] mm: cma: NUMA node interface Date: Fri, 3 Apr 2020 04:18:11 -0700 Message-ID: <20200403111812.705955-1-aslan@fb.com> X-Mailer: git-send-email 2.24.1 MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.676 definitions=2020-04-03_07:2020-04-02,2020-04-03 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 malwarescore=0 phishscore=0 suspectscore=1 mlxlogscore=999 mlxscore=0 clxscore=1015 spamscore=0 impostorscore=0 priorityscore=1501 lowpriorityscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2004030099 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: I've noticed that there is no interfaces exposed by CMA which would let me to declare contigous memory on particular NUMA node. This patchset adds the ability to try to allocate contiguous memory on specific node. It will fallback to other nodes if the specified one doesn't work. Implement a new method for declaring contigous memory on particular node and keep cma_declare_contiguous() as a wrapper. Signed-off-by: Aslan Bakirov --- include/linux/cma.h | 13 +++++++++++-- include/linux/memblock.h | 3 +++ mm/cma.c | 16 +++++++++------- mm/memblock.c | 2 +- 4 files changed, 24 insertions(+), 10 deletions(-) diff --git a/include/linux/cma.h b/include/linux/cma.h index 190184b5ff32..eae834c2162f 100644 --- a/include/linux/cma.h +++ b/include/linux/cma.h @@ -24,10 +24,19 @@ extern phys_addr_t cma_get_base(const struct cma *cma); extern unsigned long cma_get_size(const struct cma *cma); extern const char *cma_get_name(const struct cma *cma); -extern int __init cma_declare_contiguous(phys_addr_t base, +extern int __init cma_declare_contiguous_nid(phys_addr_t base, phys_addr_t size, phys_addr_t limit, phys_addr_t alignment, unsigned int order_per_bit, - bool fixed, const char *name, struct cma **res_cma); + bool fixed, const char *name, struct cma **res_cma, + int nid); +static inline int __init cma_declare_contiguous(phys_addr_t base, + phys_addr_t size, phys_addr_t limit, + phys_addr_t alignment, unsigned int order_per_bit, + bool fixed, const char *name, struct cma **res_cma) +{ + return cma_declare_contiguous_nid(base, size, limit, alignment, + order_per_bit, fixed, name, res_cma, NUMA_NO_NODE); +} extern int cma_init_reserved_mem(phys_addr_t base, phys_addr_t size, unsigned int order_per_bit, const char *name, diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 079d17d96410..6bc37a731d27 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -348,6 +348,9 @@ static inline int memblock_get_region_node(const struct memblock_region *r) phys_addr_t memblock_phys_alloc_range(phys_addr_t size, phys_addr_t align, phys_addr_t start, phys_addr_t end); +phys_addr_t memblock_alloc_range_nid(phys_addr_t size, + phys_addr_t align, phys_addr_t start, + phys_addr_t end, int nid, bool exact_nid); phys_addr_t memblock_phys_alloc_try_nid(phys_addr_t size, phys_addr_t align, int nid); static inline phys_addr_t memblock_phys_alloc(phys_addr_t size, diff --git a/mm/cma.c b/mm/cma.c index be55d1988c67..0463ad2ce06b 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -220,7 +220,7 @@ int __init cma_init_reserved_mem(phys_addr_t base, phys_addr_t size, } /** - * cma_declare_contiguous() - reserve custom contiguous area + * cma_declare_contiguous_nid() - reserve custom contiguous area * @base: Base address of the reserved area optional, use 0 for any * @size: Size of the reserved area (in bytes), * @limit: End address of the reserved memory (optional, 0 for any). @@ -229,6 +229,7 @@ int __init cma_init_reserved_mem(phys_addr_t base, phys_addr_t size, * @fixed: hint about where to place the reserved area * @name: The name of the area. See function cma_init_reserved_mem() * @res_cma: Pointer to store the created cma region. + * @nid: nid of the free area to find, %NUMA_NO_NODE for any node * * This function reserves memory from early allocator. It should be * called by arch specific code once the early allocator (memblock or bootmem) @@ -238,10 +239,11 @@ int __init cma_init_reserved_mem(phys_addr_t base, phys_addr_t size, * If @fixed is true, reserve contiguous area at exactly @base. If false, * reserve in range from @base to @limit. */ -int __init cma_declare_contiguous(phys_addr_t base, +int __init cma_declare_contiguous_nid(phys_addr_t base, phys_addr_t size, phys_addr_t limit, phys_addr_t alignment, unsigned int order_per_bit, - bool fixed, const char *name, struct cma **res_cma) + bool fixed, const char *name, struct cma **res_cma, + int nid) { phys_addr_t memblock_end = memblock_end_of_DRAM(); phys_addr_t highmem_start; @@ -336,14 +338,14 @@ int __init cma_declare_contiguous(phys_addr_t base, * memory in case of failure. */ if (base < highmem_start && limit > highmem_start) { - addr = memblock_phys_alloc_range(size, alignment, - highmem_start, limit); + addr = memblock_alloc_range_nid(size, alignment, + highmem_start, limit, nid, false); limit = highmem_start; } if (!addr) { - addr = memblock_phys_alloc_range(size, alignment, base, - limit); + addr = memblock_alloc_range_nid(size, alignment, base, + limit, nid, false); if (!addr) { ret = -ENOMEM; goto err; diff --git a/mm/memblock.c b/mm/memblock.c index 4d06bbaded0f..c79ba6f9920c 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -1349,7 +1349,7 @@ __next_mem_pfn_range_in_zone(u64 *idx, struct zone *zone, * Return: * Physical address of allocated memory block on success, %0 on failure. */ -static phys_addr_t __init memblock_alloc_range_nid(phys_addr_t size, +phys_addr_t __init memblock_alloc_range_nid(phys_addr_t size, phys_addr_t align, phys_addr_t start, phys_addr_t end, int nid, bool exact_nid) From patchwork Fri Apr 3 11:18:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Aslan Bakirov X-Patchwork-Id: 11472545 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 5438781 for ; Fri, 3 Apr 2020 11:19:01 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 20E6F2073B for ; Fri, 3 Apr 2020 11:19:01 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=fb.com header.i=@fb.com header.b="YKTjNsZt" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 20E6F2073B 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 443748E0008; Fri, 3 Apr 2020 07:19:00 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 3F4068E0007; Fri, 3 Apr 2020 07:19:00 -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 2E27E8E0008; Fri, 3 Apr 2020 07:19:00 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0146.hostedemail.com [216.40.44.146]) by kanga.kvack.org (Postfix) with ESMTP id 1258D8E0007 for ; Fri, 3 Apr 2020 07:19:00 -0400 (EDT) Received: from smtpin20.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id BBD942466 for ; Fri, 3 Apr 2020 11:18:59 +0000 (UTC) X-FDA: 76666296798.20.pump53_6b8ba6e00a75e X-Spam-Summary: 2,0,0,8b2e3f44266f5591,d41d8cd98f00b204,prvs=1362849eaa=aslan@fb.com,,RULES_HIT:41:69:355:379:541:800:960:973:988:989:1260:1261:1277:1311:1313:1314:1345:1359:1431:1437:1513:1515:1516:1518:1521:1535:1542:1711:1730:1747:1777:1792:2194:2198:2199:2200:2393:2559:2562:2693:2731:3138:3139:3140:3141:3142:3354:3865:3866:3867:3868:3870:3871:3872:3874:4250:5007:6119:6261:6653:7875:7903:8603:9592:10004:10400:10946:11026:11233:11473:11658:11914:12043:12296:12297:12438:12555:12683:12895:14181:14394:14721:14819:21080:21324:21451:21627:21796:30003:30036:30054:30056:30064:30070,0,RBL:67.231.145.42:@fb.com:.lbl8.mailshell.net-64.201.201.201 62.12.0.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:24,LUA_SUMMARY:none X-HE-Tag: pump53_6b8ba6e00a75e X-Filterd-Recvd-Size: 5439 Received: from mx0a-00082601.pphosted.com (mx0a-00082601.pphosted.com [67.231.145.42]) by imf49.hostedemail.com (Postfix) with ESMTP for ; Fri, 3 Apr 2020 11:18:58 +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 033BF6Rh020188 for ; Fri, 3 Apr 2020 04:18:57 -0700 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fb.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding : content-type; s=facebook; bh=vFXE1v1dpXNsso07ONV8QkrZjI6HvkS+wYQRkAeyH5w=; b=YKTjNsZtRPZXqyyfQsUiDPNgUF+gRzzHE1nbzzeV/ETTWDmwEucDLFziBFJJ3tnuqByK VmzixDuzhulmoyNSal4oNuj+TxngC6Qp9UeAYm4bLiufhhAEao03xI4oTsP8rw6JBbAt bR62pWykFm6OtFQJlhaFr0OBdl0MS8y6qDE= Received: from maileast.thefacebook.com ([163.114.130.16]) by mx0a-00082601.pphosted.com with ESMTP id 305upk9tx1-11 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Fri, 03 Apr 2020 04:18:57 -0700 Received: from intmgw001.08.frc2.facebook.com (2620:10d:c0a8:1b::d) by mail.thefacebook.com (2620:10d:c0a8:83::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.1847.3; Fri, 3 Apr 2020 04:18:49 -0700 Received: by devbig020.ftw1.facebook.com (Postfix, from userid 179119) id E2A1358C06B4; Fri, 3 Apr 2020 04:18:47 -0700 (PDT) Smtp-Origin-Hostprefix: devbig From: Aslan Bakirov Smtp-Origin-Hostname: devbig020.ftw1.facebook.com To: CC: , , , , , , , Aslan Bakirov , Michal Hocko Smtp-Origin-Cluster: ftw1c07 Subject: [PATCH 2/2] mm: hugetlb: Use node interface of cma Date: Fri, 3 Apr 2020 04:18:12 -0700 Message-ID: <20200403111812.705955-2-aslan@fb.com> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200403111812.705955-1-aslan@fb.com> References: <20200403111812.705955-1-aslan@fb.com> MIME-Version: 1.0 X-FB-Internal: Safe X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138,18.0.676 definitions=2020-04-03_07:2020-04-02,2020-04-03 signatures=0 X-Proofpoint-Spam-Details: rule=fb_default_notspam policy=fb_default score=0 malwarescore=0 bulkscore=0 mlxscore=0 adultscore=0 impostorscore=0 lowpriorityscore=0 priorityscore=1501 spamscore=0 suspectscore=1 mlxlogscore=999 phishscore=0 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2003020000 definitions=main-2004030099 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: With introduction of numa node interface for CMA, this patch is for using that interface for allocating memory on numa nodes if NUMA is configured. This will be more efficient and cleaner because first, instead of iterating mem range of each numa node, cma_declare_contigueous_nid() will do its own address finding if we pass 0 for both min_pfn and max_pfn, second, it can also handle caseswhere NUMA is not configured by passing NUMA_NO_NODE as an argument. In addition, checking if desired size of memory is available or not, is happening in cma_declare_contiguous_nid() because base and limit will be determined there, since 0(any) for base and 0(any) for limit is passed as argument to the function. Signed-off-by: Aslan Bakirov Acked-by: Michal Hocko --- mm/hugetlb.c | 34 ++++++---------------------------- 1 file changed, 6 insertions(+), 28 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c index b9f0c903c4cf..8fbf11de747b 100644 --- a/mm/hugetlb.c +++ b/mm/hugetlb.c @@ -5573,42 +5573,20 @@ void __init hugetlb_cma_reserve(int order) reserved = 0; for_each_node_state(nid, N_ONLINE) { - unsigned long min_pfn = 0, max_pfn = 0; int res; -#ifdef CONFIG_NUMA - unsigned long start_pfn, end_pfn; - int i; - for_each_mem_pfn_range(i, nid, &start_pfn, &end_pfn, NULL) { - if (!min_pfn) - min_pfn = start_pfn; - max_pfn = end_pfn; - } -#else - min_pfn = min_low_pfn; - max_pfn = max_low_pfn; -#endif size = min(per_node, hugetlb_cma_size - reserved); size = round_up(size, PAGE_SIZE << order); - if (size > ((max_pfn - min_pfn) << PAGE_SHIFT) / 2) { - pr_warn("hugetlb_cma: cma_area is too big, please try less than %lu MiB\n", - round_down(((max_pfn - min_pfn) << PAGE_SHIFT) * - nr_online_nodes / 2 / SZ_1M, - PAGE_SIZE << order)); - break; - } - - res = cma_declare_contiguous(PFN_PHYS(min_pfn), size, - PFN_PHYS(max_pfn), + res = cma_declare_contiguous_nid(0, size, + 0, PAGE_SIZE << order, 0, false, - "hugetlb", &hugetlb_cma[nid]); + "hugetlb", &hugetlb_cma[nid], nid); + if (res) { - phys_addr_t begpa = PFN_PHYS(min_pfn); - phys_addr_t endpa = PFN_PHYS(max_pfn); - pr_warn("%s: reservation failed: err %d, node %d, [%pap, %pap)\n", - __func__, res, nid, &begpa, &endpa); + pr_warn("%s: reservation failed: err %d, node %d\n", + __func__, res, nid); break; }