Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4825561pxb; Mon, 15 Feb 2021 02:10:32 -0800 (PST) X-Google-Smtp-Source: ABdhPJz/pYILAL1Hnwp3gQc93SSW6Lgk62O0rHLGbtOVgJK1+5PBTKdtAxLfpoCNbkiBcFAfI9Ib X-Received: by 2002:a17:906:cd02:: with SMTP id oz2mr8911808ejb.116.1613383831852; Mon, 15 Feb 2021 02:10:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613383831; cv=none; d=google.com; s=arc-20160816; b=0oQ9FI2leooXkjMeNKTz+4Vz5O46BoF7U7rAYMRYCULEO/Uim1m7LyEaUidxs76x2u 1I1JUDWmbPYU3NxwPwW989jSelHXrzbnbbaoGsg9L/LcMIjcoVO0Vyx2CUWof3l+wnq3 nSwNoAnIuU+wB533vamSF+1Kw65vchjo2FNuacSjeB31Eri6p1XaFQHAMxepqLyYh2WT oLCHt3o0aGD0uQzRmG+Yj0j41JR5LPeIqWh03zR0+JE3O/HIB5B0pEkVFZ6VBJUlbqHc 92dRmKuLejYSV2uHAipeiFCl+Hs0NRMsxnH8q1cCCCO1pi8/qg2Kh9hZuKwQOqzcojg7 ko6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=DmRB0K44KO7vG/sp1xtUpHVwS6fGMWfTKOE8QU8jS6g=; b=TOJ0qEUW1BplmfOLpNVKvRQK0BBD4idRxUa6OHEzSxdxH+M9Mk2XnMRBasxqcOQCNE SD38Q/4wEUOkYvFeMffU1R43klqcOUEDxYUoHpfhrT3uQ/M++o272+8UpP0Nq0h/XRl0 3W7ZNurgZgJa3sR+Xy6bfqX5F3dpmDCjT8nawMHOFtbACqqhQqmkbPoRPqWl/MNwHiSq xdh8PCNgbyAi826Zpm3eF94rZhwgc1M4RFK1iVwFD46In5OmxAlCc0C5I4bM0wE43Uxv DgbEkZTPMo6qgivkk/mUvUq6ZcAhuaM4hmUxIeSHeNJihzWvik7ov59P/hMEzOj3QYXn mmJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=EhjrjjBY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id e21si12036556ejt.485.2021.02.15.02.10.07; Mon, 15 Feb 2021 02:10:31 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=EhjrjjBY; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230005AbhBOKGZ (ORCPT + 99 others); Mon, 15 Feb 2021 05:06:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53806 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229811AbhBOKGX (ORCPT ); Mon, 15 Feb 2021 05:06:23 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E488BC061574 for ; Mon, 15 Feb 2021 02:05:42 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id q72so3433879pjq.2 for ; Mon, 15 Feb 2021 02:05:42 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=DmRB0K44KO7vG/sp1xtUpHVwS6fGMWfTKOE8QU8jS6g=; b=EhjrjjBYBupuI5im9doAwVzO+jGLquTgwobo7U7h3v0K1j4+obz4rjNleNiQ0aPEqZ IHY9+7M4Vd2XXMsNbJe5aNZpoMy2ArzXBurcksVbF1YUiMH6cgwm5mfd+RCu2K0PHI9O hGXGA7Uc5JkSiWzC7Yv18dOIaqkgGJgRdDPb+vfGpEG+wi4fLoHCujyw4qC1yH2f2NID LRnAWqpTTUrx1HSRDEPr9KBqy2AXz3oPQnSljzqgZXbZ5hc5MRdxm7Z16NvzEEX4OGyn AAuHKLuXnOWV0VUvted7bLe42IU2y8LNp07b53RTcEthwczxVjWkAD21NW5756+5CSmx vyiw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=DmRB0K44KO7vG/sp1xtUpHVwS6fGMWfTKOE8QU8jS6g=; b=elpvVP9NdvTLTLvnvAIAU8j17h8bsMq/ixpGa149bIWXvhH+QtEnvcl3nfimscbVS0 0G4rgqnWGt/aLgNtqKyn4zgludL1q3Y/PtdC/HvoOm+rHAOqDF7JzjWDgrj8Rg3rvsHS bTKWYdjKctf+4YW4b+r9UVgb7HGk7c1UlnTxiXhsYZlZ5demxHv4/kuYG0BguiRlx/p5 6i4/avVG4WpAUr5jd/ZNDjcYezYTgIqInjRgAoif2Wjt/9VgnjaOH1fzGq2l9Y93fd9m GKQnisJ4HExb7a8N1FJJpDjab4ol5djpf7Y5tVsmj56TVnGAhjqcYYO+OHT/h3asIAh+ tkzw== X-Gm-Message-State: AOAM533Ssq5DKC8pn/7EIEA+3BRmpPaxNE1AbSGO9ZVmkkSWWh1ZlIQ3 lXdoFAyi9/yXI4zNflxIqCyhxGGao9yCMEG9VVM/dA== X-Received: by 2002:a17:902:7290:b029:e3:1dcf:f3ec with SMTP id d16-20020a1709027290b02900e31dcff3ecmr14638057pll.20.1613383542493; Mon, 15 Feb 2021 02:05:42 -0800 (PST) MIME-Version: 1.0 References: <20210208085013.89436-1-songmuchun@bytedance.com> <20210208085013.89436-5-songmuchun@bytedance.com> In-Reply-To: From: Muchun Song Date: Mon, 15 Feb 2021 18:05:06 +0800 Message-ID: Subject: Re: [External] Re: [PATCH v15 4/8] mm: hugetlb: alloc the vmemmap pages associated with each HugeTLB page To: Michal Hocko Cc: Jonathan Corbet , Mike Kravetz , Thomas Gleixner , mingo@redhat.com, bp@alien8.de, x86@kernel.org, hpa@zytor.com, dave.hansen@linux.intel.com, luto@kernel.org, Peter Zijlstra , viro@zeniv.linux.org.uk, Andrew Morton , paulmck@kernel.org, mchehab+huawei@kernel.org, pawan.kumar.gupta@linux.intel.com, Randy Dunlap , oneukum@suse.com, anshuman.khandual@arm.com, jroedel@suse.de, Mina Almasry , David Rientjes , Matthew Wilcox , Oscar Salvador , "Song Bao Hua (Barry Song)" , David Hildenbrand , =?UTF-8?B?SE9SSUdVQ0hJIE5BT1lBKOWggOWPoyDnm7TkuZ8p?= , Joao Martins , Xiongchun duan , linux-doc@vger.kernel.org, LKML , Linux Memory Management List , linux-fsdevel Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 12, 2021 at 11:32 PM Michal Hocko wrote: > > On Mon 08-02-21 16:50:09, Muchun Song wrote: > > When we free a HugeTLB page to the buddy allocator, we should allocate the > > vmemmap pages associated with it. But we may cannot allocate vmemmap pages > > when the system is under memory pressure, in this case, we just refuse to > > free the HugeTLB page instead of looping forever trying to allocate the > > pages. > > Thanks for simplifying the implementation from your early proposal! > > This will not be looping for ever. The allocation will usually trigger > the OOM killer and sooner or later there will be a memory to allocate > from or the system panics when there are no eligible tasks to kill. This > is just a side note. > > I think the changelog could benefit from a more explicit documentation > of those error failures. There are different cases when the hugetlb page > is freed. It can be due to an admin intervention (decrease the pool), > overcommit, migration, dissolving and likely some others. Most of them > should be fine to stay in the pool which would just increase the surplus > pages in the pool. I am not so sure about dissolving path. Thanks. I will update the changelog. > [...] > > diff --git a/mm/hugetlb_vmemmap.c b/mm/hugetlb_vmemmap.c > > index 0209b736e0b4..3d85e3ab7caa 100644 > > --- a/mm/hugetlb_vmemmap.c > > +++ b/mm/hugetlb_vmemmap.c > > @@ -169,6 +169,8 @@ > > * (last) level. So this type of HugeTLB page can be optimized only when its > > * size of the struct page structs is greater than 2 pages. > > */ > > +#define pr_fmt(fmt) "HugeTLB: " fmt > > + > > #include "hugetlb_vmemmap.h" > > > > /* > > @@ -198,6 +200,34 @@ static inline unsigned long free_vmemmap_pages_size_per_hpage(struct hstate *h) > > return (unsigned long)free_vmemmap_pages_per_hpage(h) << PAGE_SHIFT; > > } > > > > +int alloc_huge_page_vmemmap(struct hstate *h, struct page *head) > > +{ > > + int ret; > > + unsigned long vmemmap_addr = (unsigned long)head; > > + unsigned long vmemmap_end, vmemmap_reuse; > > + > > + if (!free_vmemmap_pages_per_hpage(h)) > > + return 0; > > + > > + vmemmap_addr += RESERVE_VMEMMAP_SIZE; > > + vmemmap_end = vmemmap_addr + free_vmemmap_pages_size_per_hpage(h); > > + vmemmap_reuse = vmemmap_addr - PAGE_SIZE; > > + > > + /* > > + * The pages which the vmemmap virtual address range [@vmemmap_addr, > > + * @vmemmap_end) are mapped to are freed to the buddy allocator, and > > + * the range is mapped to the page which @vmemmap_reuse is mapped to. > > + * When a HugeTLB page is freed to the buddy allocator, previously > > + * discarded vmemmap pages must be allocated and remapping. > > + */ > > + ret = vmemmap_remap_alloc(vmemmap_addr, vmemmap_end, vmemmap_reuse, > > + GFP_ATOMIC | __GFP_NOWARN | __GFP_THISNODE); > > I do not think that this is a good allocation mode. GFP_ATOMIC is a non > sleeping allocation and a medium memory pressure might cause it to > fail prematurely. I do not think this is really an atomic context which > couldn't afford memory reclaim. I also do not think we want to grant Because alloc_huge_page_vmemmap is called under hugetlb_lock now. So using GFP_ATOMIC indeed makes the code more simpler. From the document of the kernel, I learned that __GFP_NOMEMALLOC can be used to explicitly forbid access to emergency reserves. So if we do not want to use the reserve memory. How about replacing it to GFP_ATOMIC | __GFP_NOMEMALLOC | __GFP_NOWARN | __GFP_THISNODE Thanks. > access to memory reserve is reasonable. Just think of a huge number of > hugetlb pages being freed which can deplete the memory reserve for > atomic allocations. I think that you want > GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN | __GFP_THISNODE > > for an initial implementation. The justification being that the > allocation should at least try to reclaim but it shouldn't cause any > major disruption because the failure is not fatal. If the failure rate > would be impractically high then just drop NORETRY part. You can replace > it by __GFP_RETRY_MAYFAIL but that shouldn't be strictly necessary > because __GFP_THISNODE on its own implies on OOM killer, but that is > kinda ugly to rely on. > -- > Michal Hocko > SUSE Labs