From patchwork Tue Feb 25 11:13:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasant Hegde X-Patchwork-Id: 1244004 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48Rbsy4gbKz9sPk for ; Tue, 25 Feb 2020 22:14:14 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 48Rbsy1Rd0zDqT2 for ; Tue, 25 Feb 2020 22:14:14 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=hegdevasant@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 48Rbsf5Wv4zDqSV for ; Tue, 25 Feb 2020 22:13:58 +1100 (AEDT) Received: from pps.filterd (m0127361.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01PBCOJj020810 for ; Tue, 25 Feb 2020 06:13:53 -0500 Received: from e06smtp07.uk.ibm.com (e06smtp07.uk.ibm.com [195.75.94.103]) by mx0a-001b2d01.pphosted.com with ESMTP id 2yb00aa95d-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 25 Feb 2020 06:13:53 -0500 Received: from localhost by e06smtp07.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 25 Feb 2020 11:13:50 -0000 Received: from b06avi18878370.portsmouth.uk.ibm.com (9.149.26.194) by e06smtp07.uk.ibm.com (192.168.101.137) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 25 Feb 2020 11:13:47 -0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06avi18878370.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 01PBDkK330343516 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 Feb 2020 11:13:46 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 3DC5EAE055; Tue, 25 Feb 2020 11:13:46 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 40D4BAE059; Tue, 25 Feb 2020 11:13:45 +0000 (GMT) Received: from hegdevasant.in.ibm.com (unknown [9.193.108.153]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 25 Feb 2020 11:13:45 +0000 (GMT) From: Vasant Hegde To: skiboot@lists.ozlabs.org Date: Tue, 25 Feb 2020 16:43:27 +0530 X-Mailer: git-send-email 2.21.1 MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 20022511-0028-0000-0000-000003DDCCE3 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20022511-0029-0000-0000-000024A2E507 Message-Id: <20200225111328.25763-1-hegdevasant@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-02-25_03:2020-02-21, 2020-02-25 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 bulkscore=0 priorityscore=1501 lowpriorityscore=0 clxscore=1015 impostorscore=0 suspectscore=1 adultscore=0 phishscore=0 mlxlogscore=887 malwarescore=0 mlxscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002250091 Subject: [Skiboot] [PATCH 1/2] list: Add list_add_after() X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Signed-off-by: Vasant Hegde --- ccan/list/list.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/ccan/list/list.h b/ccan/list/list.h index fdeddeb4d..1d75dd92a 100644 --- a/ccan/list/list.h +++ b/ccan/list/list.h @@ -183,6 +183,25 @@ static inline void list_add_before(struct list_head *h, struct list_node *n, (void)list_debug(h); } +/** + * list_add_after - add an entry after another entry. + * @h: the list_head to add the node to (we use it for debug purposes, can be NULL) + * @n: the list_node to add to the list. + * @p: the list_node of the other entry + * + * The list_node does not need to be initialized; it will be overwritten. + */ +static inline void list_add_after(struct list_head *h, struct list_node *n, + struct list_node *p) +{ + n->next = p->next; + n->prev = p; + p->next = n; + n->next->prev = n; + if (h) + (void)list_debug(h); +} + /** * list_add_tail - add an entry at the end of a linked list. * @h: the list_head to add the node to From patchwork Tue Feb 25 11:13:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasant Hegde X-Patchwork-Id: 1244005 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48RbtM3yVxz9sPk for ; Tue, 25 Feb 2020 22:14:35 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 48RbtM1fv5zDqT2 for ; Tue, 25 Feb 2020 22:14:35 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=linux.vnet.ibm.com (client-ip=148.163.156.1; helo=mx0a-001b2d01.pphosted.com; envelope-from=hegdevasant@linux.vnet.ibm.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=linux.vnet.ibm.com Received: from mx0a-001b2d01.pphosted.com (mx0a-001b2d01.pphosted.com [148.163.156.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 48Rbsg2YYczDqSs for ; Tue, 25 Feb 2020 22:13:58 +1100 (AEDT) Received: from pps.filterd (m0098404.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 01PB8vit102678 for ; Tue, 25 Feb 2020 06:13:55 -0500 Received: from e06smtp03.uk.ibm.com (e06smtp03.uk.ibm.com [195.75.94.99]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ycxcxreu6-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Tue, 25 Feb 2020 06:13:54 -0500 Received: from localhost by e06smtp03.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Tue, 25 Feb 2020 11:13:52 -0000 Received: from b06avi18626390.portsmouth.uk.ibm.com (9.149.26.192) by e06smtp03.uk.ibm.com (192.168.101.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Tue, 25 Feb 2020 11:13:48 -0000 Received: from d06av26.portsmouth.uk.ibm.com (d06av26.portsmouth.uk.ibm.com [9.149.105.62]) by b06avi18626390.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 01PBCpjg10027270 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 25 Feb 2020 11:12:51 GMT Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id B12ABAE057; Tue, 25 Feb 2020 11:13:47 +0000 (GMT) Received: from d06av26.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AA3B1AE055; Tue, 25 Feb 2020 11:13:46 +0000 (GMT) Received: from hegdevasant.in.ibm.com (unknown [9.193.108.153]) by d06av26.portsmouth.uk.ibm.com (Postfix) with ESMTP; Tue, 25 Feb 2020 11:13:46 +0000 (GMT) From: Vasant Hegde To: skiboot@lists.ozlabs.org Date: Tue, 25 Feb 2020 16:43:28 +0530 X-Mailer: git-send-email 2.21.1 In-Reply-To: <20200225111328.25763-1-hegdevasant@linux.vnet.ibm.com> References: <20200225111328.25763-1-hegdevasant@linux.vnet.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 x-cbid: 20022511-0012-0000-0000-0000038A1740 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 20022511-0013-0000-0000-000021C6B9A0 Message-Id: <20200225111328.25763-2-hegdevasant@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.138, 18.0.572 definitions=2020-02-25_03:2020-02-21, 2020-02-25 signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 malwarescore=0 bulkscore=0 impostorscore=0 lowpriorityscore=0 adultscore=0 clxscore=1015 suspectscore=3 mlxlogscore=999 phishscore=0 mlxscore=0 priorityscore=1501 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2001150001 definitions=main-2002250091 Subject: [Skiboot] [PATCH 2/2] memory: Sort memory regions list X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" local_alloc() function tries to find first allocatable local region and tries to allocate memory. If that region doesn't have sufficient memory to allocate then it will log below warning and tries to allocate memory from next available region. Warning: -------- [ 268.346728058,3] mem_alloc(0x800000, 0x800000, "hw/xive.c:1630", ibm,firmware-allocs-memory@0) failed ! [ 268.346732718,6] Memory regions: [ 268.346734353,6] 0x000030500000..000030ffffff : ibm,firmware-heap [ 268.346833468,5] 420 allocs of 0x00000058 bytes at core/device.c:41 (total 0x9060) [ 268.346978805,5] 2965 allocs of 0x00000038 bytes at core/device.c:424 (total 0x28898) [ 268.347035614,5] 434 allocs of 0x00000040 bytes at core/device.c:424 (total 0x6c80) [ 268.347093567,5] 365 allocs of 0x00000028 bytes at libc/string/strdup.c:23 (total 0x3908) [ 268.347136818,5] 84 allocs of 0x00000048 bytes at core/device.c:424 (total 0x17a0) [ 268.347179123,5] 21 allocs of 0x00000030 bytes at libc/string/strdup.c:23 (total 0x3f0) .... .... Hostboot reserves memory for various nodes and passes this information via HDAT. In some cases there will be small memory holes between two reservations (ex: 16MB free space between two reservation). add_region() function adds new region to the head of regions list. mem_region_init() adds OPAL regions first and then hostboot regions. So these smaller regions will be added to head of list. If we have smaller free regions then we may hit above warning. Hostboot uses top of the memory for various reservations. So if we sort memory regions then allocator will use bigger region (region after OPAL memory) for local allocation. And we will not hit above warning. Memory region layout with this patch: 0 - 756MB : OS reserved region (for loading kernel) 756MB - ~856MB : OPAL memory (actual size depends on PIR) 856MB - ~956MB : Memory for MPIPL (actual size depends on OPAL runtime size) 956MB - ... : We will have free memory after 956MB which we can use for local_alloc(). Typically this will be multiple GBs. So it works fine. .... - top_mem: Hostboot reservations + small holes Signed-off-by: Vasant Hegde --- core/mem_region.c | 20 ++++++++++++++++--- core/test/run-mem_region_next.c | 4 ++-- .../run-mem_region_release_unused_noalloc.c | 2 +- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/core/mem_region.c b/core/mem_region.c index eb48a1a11..003a91812 100644 --- a/core/mem_region.c +++ b/core/mem_region.c @@ -734,7 +734,7 @@ static bool maybe_split(struct mem_region *r, uint64_t split_at) return false; /* Tail add is important: we may need to split again! */ - list_add_tail(®ions, &tail->list); + list_add_after(®ions, &tail->list, &r->list); return true; } @@ -763,6 +763,20 @@ static struct mem_region *get_overlap(const struct mem_region *region) return NULL; } +static void add_region_to_regions(struct mem_region *region) +{ + struct mem_region *r; + + list_for_each(®ions, r, list) { + if (r->start < region->start) + continue; + + list_add_before(®ions, ®ion->list, &r->list); + return; + } + list_add_tail(®ions, ®ion->list); +} + static bool add_region(struct mem_region *region) { struct mem_region *r; @@ -807,7 +821,7 @@ static bool add_region(struct mem_region *region) } /* Finally, add in our own region. */ - list_add(®ions, ®ion->list); + add_region_to_regions(region); return true; } @@ -1091,7 +1105,7 @@ void mem_region_init(void) prerror("MEM: Could not add mem region %s!\n", i->name); abort(); } - list_add(®ions, ®ion->list); + add_region_to_regions(region); if ((start + len) > top_of_ram) top_of_ram = start + len; unlock(&mem_region_lock); diff --git a/core/test/run-mem_region_next.c b/core/test/run-mem_region_next.c index b14e41d07..bab214f74 100644 --- a/core/test/run-mem_region_next.c +++ b/core/test/run-mem_region_next.c @@ -85,13 +85,13 @@ int main(void) r = mem_region_next(NULL); assert(r); - assert(r->start == 0x2000); + assert(r->start == 0x1000); assert(r->len == 0x1000); assert(r->type == REGION_RESERVED); r = mem_region_next(r); assert(r); - assert(r->start == 0x1000); + assert(r->start == 0x2000); assert(r->len == 0x1000); assert(r->type == REGION_RESERVED); diff --git a/core/test/run-mem_region_release_unused_noalloc.c b/core/test/run-mem_region_release_unused_noalloc.c index aa8c23a26..5c4b1ddce 100644 --- a/core/test/run-mem_region_release_unused_noalloc.c +++ b/core/test/run-mem_region_release_unused_noalloc.c @@ -147,8 +147,8 @@ int main(void) * only in test and only for valgrind */ free((void*)r->name); + last = r->name; } - last = r->name; } dt_free(dt_root);