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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0F232C3DA49 for ; Thu, 25 Jul 2024 12:19:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7FB836B0096; Thu, 25 Jul 2024 08:19:25 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7AAB16B0098; Thu, 25 Jul 2024 08:19:25 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 699986B0099; Thu, 25 Jul 2024 08:19:25 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 4C3746B0096 for ; Thu, 25 Jul 2024 08:19:25 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id AE3BDA4508 for ; Thu, 25 Jul 2024 12:19:24 +0000 (UTC) X-FDA: 82378180248.05.8E02116 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf26.hostedemail.com (Postfix) with ESMTP id C193214000E for ; Thu, 25 Jul 2024 12:19:20 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf26.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721909925; a=rsa-sha256; cv=none; b=r2nkrwgQWlH1foeT/4p4a751EtOuKL3yIDLIna5lAQjah/pRsSZJLfCYT7/WqXycES6zIN jig6KWAntIEmtK7K3KbvG7aIqYgn7jHgOXJQN6KMHCs4+zi396LnValLpf/5GYjZ0BKeo+ faywz+wUMT2qvPTKJXEm2S3HvAbstDk= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf26.hostedemail.com: domain of linyunsheng@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=linyunsheng@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721909925; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LtH6gCW13T0FacrPmyl0K4P3uxu78RC8RBvVaMr+A5s=; b=S4qJ6bjT5N3S+qW5FUBAcfW5zhl7tntfhv3CQj50uNf3iYEge/IlrTJ76ldCqX6YpJO14t YP8la1Pq4zseqi13hkJfBSYcwMuJ58gbDC44i+ufjifCQs2SdgauXeAu0w8T0Bmln6tm+E m8fxkCsR2yEe9QzU7xfjSjNkXJwbQQs= Received: from mail.maildlp.com (unknown [172.19.162.254]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4WV90s1GdWzxV4Q; Thu, 25 Jul 2024 20:19:09 +0800 (CST) Received: from dggpemf200006.china.huawei.com (unknown [7.185.36.61]) by mail.maildlp.com (Postfix) with ESMTPS id E901A180101; Thu, 25 Jul 2024 20:19:12 +0800 (CST) Received: from [10.67.120.129] (10.67.120.129) by dggpemf200006.china.huawei.com (7.185.36.61) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1544.11; Thu, 25 Jul 2024 20:19:12 +0800 Message-ID: <5df99f22-801c-4b0a-a3bc-0e2e0fadfdd3@huawei.com> Date: Thu, 25 Jul 2024 20:19:12 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [RFC v11 09/14] mm: page_frag: use __alloc_pages() to replace alloc_pages_node() To: Alexander Duyck CC: , , , , , Andrew Morton , References: <20240719093338.55117-1-linyunsheng@huawei.com> <20240719093338.55117-10-linyunsheng@huawei.com> Content-Language: en-US From: Yunsheng Lin In-Reply-To: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8bit X-Originating-IP: [10.67.120.129] X-ClientProxiedBy: dggems703-chm.china.huawei.com (10.3.19.180) To dggpemf200006.china.huawei.com (7.185.36.61) X-Rspamd-Queue-Id: C193214000E X-Rspam-User: X-Rspamd-Server: rspam05 X-Stat-Signature: 4uubpcjfxwqop5zwu4niakpdh7mnomrm X-HE-Tag: 1721909960-3317 X-HE-Meta: U2FsdGVkX18aLTyFJ07AqUT1GMHO/OLWrAEThRg4xIGIJ9CpquCLe5M14wA/DqPz/ORuYejr7wIeT4l0eh9VMG1byHVv3EivA9rchYl6celWPHtq5fc5NYVYlG6HbGfexvbK/xTBJJ5OiyaglZMPvwvEiftqdANos4+oAnQ7oHSj5GJz5C/xuys4rLRh1Hg5cnO8UK7qv7EvYkhreQ4ZNZAGDAHxieKZUZnMnpIdsOG3qKb4/3NjrxJKf58tq+zzdbUi8onLS7QzIaiQCI8a3vInKVQcc57EGFod/akwpXvgXe9YtXq4vApVDbIrPCsWxBVwfSa9SCMomJpHXkb0PXsWwgDVfwrfd94KoVNdzQpWFY+PN0TxcYUAWLC0rnUmCkAXoKFEhj4DWhGckWl+xzxhM9p6IJGYoBWY0amkmMOgW2b0XcPXY4e1H5fiffQ9paPbUTjlRfkjAFv5odjfZYBpkwoKta5aYYlSH4RWgP+bLw8wsC05cvNbrDl5niDggRX1yPcoH/DVhshzE/0gTWLMZTGnJRWl/UOy27Xrm2rucgyRS+YN/YqwXLika9y5xU9t/ahkzGL4raa1j8XpvJrfCc1VbfsHg5nbcVQNqVTm1By3OXz2JI1k2iO1Wae7FeNy/Y/vXLvbInpfWTv6uJCw/artnFnHvpob7ok1+KnhZfZYtcosLSUbrbNbu7h353cE5kbuLPwDiqkbqVOiVYC34Em/liI6zCscE4tBBV79lMETEvmY45sC13fEpsdFc1axkViiqiV2EZhkWBDWkXfOC5tiOXlJhGRy/u570Rxw6znf259ZGbCq5YlkBmXvX503P19VI3VdSGkMolfljIYUi2lY3095QxdLmb5MqWddLeJAabarCGQfalFIZ4dAZ/9tcROxz4ItCbckJm8XGDUsO6taOk0Ur/687wIu7k/oDe3dVG/agtc4CRrm2gzHkxwxlpWORnZtmP1+vjw EgIxa8MW bCI1iKs6vMJg05rQ/WAny0MsyJoFFaAs7lp5DO2Ww9mPOinswx3b3UMG032NO047VFJoyVScU1h8RN3ux96OleTxMYapPvw55gQkaeDdYQNUwvIsPJqZI70Mt0FhP8XiL9YuMX/f7SHdlchGwF2YLSio0MSF5K6fRANRL81bg2I5JIfPls3uHYjpmo8nkDIKsbUdknFSOJY3yyIuyoLsOKNtDa3mPZmxPTRszUvEEaD/hKesaQKh5d/6samKgPIvpHO7eZE0aj+/HZ0CJVvkd4kXF77wMwNXKR7jCBwWRvkoe+oRkplLufCYpMpsB/jAWVHodcgWrNI3JVG1zXa3quUaaGnMrT77guwYbBqEWDVTvceLW6ko5ubpTB1pXDrplTAI6NHJmYY6dl7k= 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: List-Subscribe: List-Unsubscribe: On 2024/7/24 23:03, Alexander Duyck wrote: > On Wed, Jul 24, 2024 at 5:55 AM Yunsheng Lin wrote: >> >> On 2024/7/22 5:41, Alexander H Duyck wrote: >> >> ... >> >>>> if (unlikely(!page)) { >>>> - page = alloc_pages_node(NUMA_NO_NODE, gfp, 0); >>>> + page = __alloc_pages(gfp, 0, numa_mem_id(), NULL); >>>> if (unlikely(!page)) { >>>> memset(nc, 0, sizeof(*nc)); >>>> return NULL; >>> >>> So if I am understanding correctly this is basically just stripping the >>> checks that were being performed since they aren't really needed to >>> verify the output of numa_mem_id. >>> >>> Rather than changing the code here, it might make more sense to update >>> alloc_pages_node_noprof to move the lines from >>> __alloc_pages_node_noprof into it. Then you could put the VM_BUG_ON and >>> warn_if_node_offline into an else statement which would cause them to >>> be automatically stripped for this and all other callers. The benefit >> >> I suppose you meant something like below: >> >> @@ -290,10 +290,14 @@ struct folio *__folio_alloc_node_noprof(gfp_t gfp, unsigned int order, int nid) >> static inline struct page *alloc_pages_node_noprof(int nid, gfp_t gfp_mask, >> unsigned int order) >> { >> - if (nid == NUMA_NO_NODE) >> + if (nid == NUMA_NO_NODE) { >> nid = numa_mem_id(); >> + } else { >> + VM_BUG_ON(nid < 0 || nid >= MAX_NUMNODES); >> + warn_if_node_offline(nid, gfp_mask); >> + } >> >> - return __alloc_pages_node_noprof(nid, gfp_mask, order); >> + return __alloc_pages_noprof(gfp_mask, order, nid, NULL); >> } > > Yes, that is more or less what I was thinking. > >>> would likely be much more significant and may be worthy of being >>> accepted on its own merit without being a part of this patch set as I >>> would imagine it would show slight gains in terms of performance and >>> binary size by dropping the unnecessary instructions. >> >> Below is the result, it does reduce the binary size for >> __page_frag_alloc_align() significantly as expected, but also >> increase the size for other functions, which seems to be passing >> a runtime nid, so the trick above doesn't work. I am not sure if >> the overall reduction is significant enough to justify the change? >> It seems that depends on how many future callers are passing runtime >> nid to alloc_pages_node() related APIs. >> >> [linyunsheng@localhost net-next]$ ./scripts/bloat-o-meter vmlinux.org vmlinux >> add/remove: 1/2 grow/shrink: 13/8 up/down: 160/-256 (-96) >> Function old new delta >> bpf_map_alloc_pages 708 764 +56 >> its_probe_one 2836 2860 +24 >> iommu_dma_alloc 984 1008 +24 >> __iommu_dma_alloc_noncontiguous.constprop 1180 1192 +12 >> e843419@0f3f_00011fb1_4348 - 8 +8 >> its_vpe_irq_domain_deactivate 312 316 +4 >> its_vpe_irq_domain_alloc 1492 1496 +4 >> its_irq_domain_free 440 444 +4 >> iommu_dma_map_sg 1328 1332 +4 >> dpaa_eth_probe 5524 5528 +4 >> dpaa2_eth_xdp_xmit 676 680 +4 >> dpaa2_eth_open 564 568 +4 >> dma_direct_get_required_mask 116 120 +4 >> __dma_direct_alloc_pages.constprop 656 660 +4 >> its_vpe_set_affinity 928 924 -4 >> its_send_single_command 340 336 -4 >> its_alloc_table_entry 456 452 -4 >> dpaa_bp_seed 232 228 -4 >> arm_64_lpae_alloc_pgtable_s1 680 676 -4 >> __arm_lpae_alloc_pages 900 896 -4 >> e843419@0473_00005079_16ec 8 - -8 >> e843419@0189_00001c33_1c8 8 - -8 >> ringbuf_map_alloc 612 600 -12 >> __page_frag_alloc_align 740 536 -204 >> Total: Before=30306836, After=30306740, chg -0.00% > > I'm assuming the compiler must have uninlined > __alloc_pages_node_noprof in the previous version of things for the > cases where it is causing an increase in the code size. > > One alternative approach we could look at doing would be to just add > the following to the start of the function: > if (__builtin_constant_p(nid) && nid == NUMA_NO_NODE) > return __alloc_pages_noprof(gfp_mask, order, numa_mem_id(), NULL); > > That should yield the best result as it essentially skips over the > problematic code at compile time for the constant case, otherwise the > code should be fully stripped so it shouldn't add any additional > overhead. Just tried it, it seems it is more complicated than expected too. For example, the above changing seems to cause alloc_slab_page() to be inlined to new_slab() and other inlining/uninlining that is hard to understand. [linyunsheng@localhost net-next]$ ./scripts/bloat-o-meter vmlinux.org vmlinux add/remove: 1/2 grow/shrink: 16/11 up/down: 432/-536 (-104) Function old new delta new_slab 808 1124 +316 its_probe_one 2836 2876 +40 dpaa2_eth_set_dist_key 1096 1112 +16 e843419@0f3f_00011fb1_4348 - 8 +8 rx_default_dqrr 2776 2780 +4 pcpu_unmap_pages 356 360 +4 its_vpe_irq_domain_alloc 1492 1496 +4 iommu_dma_init_fq 520 524 +4 iommu_dma_alloc 984 988 +4 hns3_nic_net_timeout 704 708 +4 hns3_init_all_ring 1168 1172 +4 hns3_clear_all_ring 372 376 +4 enetc_refill_rx_ring 448 452 +4 enetc_free_rxtx_rings 276 280 +4 dpaa2_eth_xdp_xmit 676 680 +4 dpaa2_eth_rx 1716 1720 +4 ___slab_alloc 2120 2124 +4 pcpu_free_pages.constprop 236 232 -4 its_alloc_table_entry 456 452 -4 hns3_reset_notify_init_enet 628 624 -4 dpaa_cleanup_tx_fd 556 552 -4 dpaa_bp_seed 232 228 -4 blk_update_request 944 940 -4 blk_execute_rq 540 536 -4 arm_64_lpae_alloc_pgtable_s1 680 676 -4 __kmalloc_large_node 340 336 -4 __arm_lpae_unmap 1588 1584 -4 e843419@0473_00005079_16ec 8 - -8 __page_frag_alloc_align 740 536 -204 alloc_slab_page 284 - -284 Total: Before=30306836, After=30306732, chg -0.00%