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 6BD72C3DA49 for ; Fri, 26 Jul 2024 08:38:12 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C1FA46B0096; Fri, 26 Jul 2024 04:38:11 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BCFA96B0099; Fri, 26 Jul 2024 04:38:11 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A97BC6B009B; Fri, 26 Jul 2024 04:38:11 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8AB1B6B0096 for ; Fri, 26 Jul 2024 04:38:11 -0400 (EDT) Received: from smtpin06.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 08CC81615AB for ; Fri, 26 Jul 2024 08:38:11 +0000 (UTC) X-FDA: 82381251582.06.8E8DF49 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf06.hostedemail.com (Postfix) with ESMTP id 18AA3180014 for ; Fri, 26 Jul 2024 08:38:08 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JuxpdlXm; spf=pass (imf06.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1721983039; 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:dkim-signature; bh=/SxC9xKVmwfr4DdNRvxjCA1uiQ+xbWfNcBvzTm1f7yo=; b=XeG1yZimbkkaHJqpzEiCERpxa+IJKWUC+FbqSNNx13x40Lqr24TEAqf7rVnSVZEk/St20M Vgm5cnjf7adudX7AaBLA0xEhDFxKc8Rz+/XRgzUp1B+2YUHMdO96YUnoErOVIpk86G4wuK chUeBdm0Qp3KIiMmSeB+WHF4VKeyqVM= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1721983039; a=rsa-sha256; cv=none; b=MxmC3SSB0eh7slKvISq209Txk7j9oV7NbG59UMu8ENeObw0sX3ssqsPMCooqfhKjnXFxzQ mHOqUSXcmOIYDUWzihZPEAIt0s/QQTojEIo4c6Yy+OZSdd/xWNX85ARjlvj0PAF2Chadmi Gn4W9Dq45p8BtHveR/QQw/lu1oFzHis= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=JuxpdlXm; spf=pass (imf06.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1721983088; h=from:from: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=/SxC9xKVmwfr4DdNRvxjCA1uiQ+xbWfNcBvzTm1f7yo=; b=JuxpdlXm8WolyOi2aecUZ9dYeLp1VzASMR7eLwDA1wGVv/WWG52CpERaM7d968A1RqN0C2 oWL59jsegH2RubDOznWsRCv6+rX/ua5RWK3aSEVEYraWGiIELbcTCsZzOMIKzyeNraeT1l nldjj/VkfxPROrSyWjJAItKxNxcv+Ws= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-656-Cc5i_KRENiuTTqDYOVR4UQ-1; Fri, 26 Jul 2024 04:38:04 -0400 X-MC-Unique: Cc5i_KRENiuTTqDYOVR4UQ-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id D8610195608B; Fri, 26 Jul 2024 08:38:01 +0000 (UTC) Received: from localhost (unknown [10.72.112.25]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id CF7C63000194; Fri, 26 Jul 2024 08:37:59 +0000 (UTC) Date: Fri, 26 Jul 2024 16:37:55 +0800 From: Baoquan He To: Barry Song <21cnbao@gmail.com> Cc: Hailong Liu , Andrew Morton , Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes , Vlastimil Babka , Michal Hocko , Matthew Wilcox , Tangquan Zheng , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [RFC PATCH v2] mm/vmalloc: fix incorrect __vmap_pages_range_noflush() if vm_area_alloc_pages() from high order fallback to order0 Message-ID: References: <20240725035318.471-1-hailong.liu@oppo.com> <20240725164003.ft6huabwa5dqoy2g@oppo.com> <20240726040052.hs2gvpktrnlbvhsq@oppo.com> <20240726050356.ludmpxfee6erlxxt@oppo.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 X-Stat-Signature: mseuxocxeks5ebp985i3jmhmthe54e7n X-Rspamd-Queue-Id: 18AA3180014 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1721983088-624590 X-HE-Meta: U2FsdGVkX18Ezbgem08/ZcmuDLykIM4x/F3Y5M8Df2EauADY0w7QWFfbUvmGeNQXYZJJjM2tMPUhHmW9vSlvk14swb2UMApPToLb34G8Rz5Hg/PQPbkCjf7csPrGn5qopKvCw4yapTxskequnYV3Hk9TxQwnhQpQKcgtVD/KwFhyPYXK6WdL51WYZaFO/AvVIqPVgHFObXT1t5wPeJBVSsfef0tpsotKQCTIBbMoVYMEnsDnILqA8gwy7SGaKM1A+nCHQR+eR4PA3Q03J8/+a0xuS8MygmyfFWQzmtr1L8l9iR9GB58CxKuuQWi3+xXP8mEmcjmzYurOuIl8MdtndlfT+hsNKG6s5mqTgvFfSslD/dO7tD8mvU0WcKBiGsIf34fIqzW1GKawenAU2INcRr/1M7yJhCX81WEtm6BIT83TbrIoRYV6MmpYFL3EjwXKGueRXRBZORxFovo4XWIYnqJsycSWUDHfFG3jIubcIwxT1VgvBWLId5YfQyvTzsbYxiGuq/yJzOWJLMn9KZ6CrDSPnNBqZsGGgjCJ0OSrJuvyWKZ0qJtiMD35v1ISOzPQYdu38UsLRQDsnudBo4FtT9ziP2e+7SXz9Q2WVvNIrMnzAip4mvb+STAXnnslbQaIQ8W9eqJyp9Lgtdod2/YsjSY7dUhy9QUwwhzB87eVCU2kJnoA+QIDnAMndueHqnjqeSjn6OkHVbVOLOQIW0KwwahiQgRgTZVXca7iL6oOov5aFATEsw2RaX75KnuudtfAyaYACvAm8ka5oYjUkpNQz1ZHJduTOO3r7FBaHTr8t7LFkickkczwErFokwff0gX6clEZR0qHtEU3pirDkRDb0q9CjFfBDSSsqAid2IwOVsMCe+wD44XC5tcA7gPP0VbAMUDw2iUwRfaHa5DSPQl7H/gP/D0cgKqCBW1LUtJd1+PGCdzE3OtPzuDr+kxTezo4LUQr1QUOm6ToAv1exiq RCQVK2Ym z5KP4np9ZKmrwbyQqpJR4EbthAoB7kkghI8kUeK70v4Jg+5x5Azo8D1chcwjM0YF/COYUug+MBZdl+16fCbr1DVXMlOn4oEXAb4uY+FIMsMpEmELXwUeTTUCr7jzc4GCHu6Zh/VOCPDV7FcFCKCAQBnpWVQAzRCjEwQLk2XT0e2RnXeO4C7Fo/9rYblFv8foGZZPgjfowXRlgV5jUrU9K4m65TwRVtw0j7858DMqlzFvYeAbD8XdI7gDm/QTZyYZ1uIWGZLDnisaD3u2PJCIFjNUiTVcjwVQMIUV9rdT4sZj6karwvX1gPBlS5+50xDwEHl8WEs+f2NK0NB0j6k0hlxLk1qLatr7KS8KDEp+Bd1xcjrVOTkyvEkr0TGaAp7LmfrJ7sx/5Ir3sUIc2dtWp7ckdkIE26AZ4mfqdamk11CD0Svx2Vb3Clwy5/Vf0isRMMXHMFb9goKiq0QQ= 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 07/26/24 at 05:29pm, Barry Song wrote: > On Fri, Jul 26, 2024 at 5:04 PM Hailong Liu wrote: > > > > On Fri, 26. Jul 12:00, Hailong Liu wrote: > > > On Fri, 26. Jul 10:31, Baoquan He wrote: > > > [...] > > > > > The logic of this patch is somewhat similar to my first one. If high order > > > > > allocation fails, it will go normal mapping. > > > > > > > > > > However I also save the fallback position. The ones before this position are > > > > > used for huge mapping, the ones >= position for normal mapping as Barry said. > > > > > "support the combination of PMD and PTE mapping". this will take some > > > > > times as it needs to address the corner cases and do some tests. > > > > > > > > Hmm, we may not need to worry about the imperfect mapping. Currently > > > > there are two places setting VM_ALLOW_HUGE_VMAP: __kvmalloc_node_noprof() > > > > and vmalloc_huge(). > > > > > > > > For vmalloc_huge(), it's called in below three interfaces which are all > > > > invoked during boot. Basically they can succeed to get required contiguous > > > > physical memory. I guess that's why Tangquan only spot this issue on kvmalloc > > > > invocation when the required size exceeds e.g 2M. For kvmalloc_node(), > > > > we have told that in the code comment above __kvmalloc_node_noprof(), > > > > it's a best effort behaviour. > > > > > > > Take a __vmalloc_node_range(2.1M, VM_ALLOW_HUGE_VMAP) as a example. > > > because the align requirement of huge. the real size is 4M. > > > if allocation first order-9 successfully and the next failed. becuase the > > > fallback, the layout out pages would be like order9 - 512 * order0 > > > order9 support huge mapping, but order0 not. > > > with the patch above, would call vmap_small_pages_range_noflush() and do normal > > > mapping, the huge mapping would not exist. > > > > > > > mm/mm_init.c <> > > > > table = vmalloc_huge(size, gfp_flags); > > > > net/ipv4/inet_hashtables.c <> > > > > new_hashinfo->ehash = vmalloc_huge(ehash_entries * sizeof(struct inet_ehash_bucket), > > > > net/ipv4/udp.c <> > > > > udptable->hash = vmalloc_huge(hash_entries * 2 * sizeof(struct udp_hslot) > > > > > > > > Maybe we should add code comment or document to notice people that the > > > > contiguous physical pages are not guaranteed for vmalloc_huge() if you > > > > use it after boot. > > > > > > > > > > > > > > IMO, the draft can fix the current issue, it also does not have significant side > > > > > effects. Barry, what do you think about this patch? If you think it's okay, > > > > > I will split this patch into two: one to remove the VM_ALLOW_HUGE_VMAP and the > > > > > other to address the current mapping issue. > > > > > > > > > > -- > > > > > help you, help me, > > > > > Hailong. > > > > > > > > > > > > > > > I check the code, the issue only happen in gfp_mask with __GFP_NOFAIL and > > fallback to order 0, actuaally without this commit > > e9c3cda4d86e ("mm, vmalloc: fix high order __GFP_NOFAIL allocations") > > if __vmalloc_area_node allocation failed, it will goto fail and try order-0. > > > > fail: > > if (shift > PAGE_SHIFT) { > > shift = PAGE_SHIFT; > > align = real_align; > > size = real_size; > > goto again; > > } > > > > So do we really need fallback to order-0 if nofail? > > Good catch, this is what I missed. I feel we can revert Michal's fix. > And just remove __GFP_NOFAIL bit when we are still allocating > by high-order. When "goto again" happens, we will allocate by > order-0, in this case, we keep the __GFP_NOFAIL. With Michal's patch, the fallback will be able to satisfy the allocation for nofail case because it fallback to 0-order plus __GFP_NOFAIL. The 'if (shift > PAGE_SHIFT)' conditional checking and handling may be problemtic since it could jump to fail becuase vmap_pages_range() invocation failed, or partially allocate huge parges and break down, then it will ignore the already allocated pages, and do all the thing again. The only thing 'if (shift > PAGE_SHIFT)' checking and handling makes sense is it fallback to the real_size and real_align. BUT we need handle the fail separately, e.g 1)__get_vm_area_node() failed; 2)vm_area_alloc_pages() failed when shift > PAGE_SHIFT and non-nofail; 3)vmap_pages_range() failed; Honestly, I didn't see where the nofail is mishandled, could you point it out specifically? I could miss it. Thanks Baoquan