Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp4912449pxb; Mon, 15 Feb 2021 04:48:47 -0800 (PST) X-Google-Smtp-Source: ABdhPJxPzHBw2tds6ubxgZ9mEyqrTSeR/dukMlaWhC8USRNmLrDBfn2QPFahwjInVLZpT/6DdFFB X-Received: by 2002:a17:907:da3:: with SMTP id go35mr14832672ejc.26.1613393327313; Mon, 15 Feb 2021 04:48:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613393327; cv=none; d=google.com; s=arc-20160816; b=sHBgFeTzQQiDx1iwLvyLI7ttL/3PSHrWgiqAD6Wn+bE9eD9GhyjfUlCauvhmeqo5oY Z7DKwbd92j5cIaYuayDMyjsF0PV+9ynNVv9VEnEPf1pRea0mYoMXjskkkAxtiZQ+WM7z m5Ys2GC5aNZbY794i7QTngKSJ44WdkKlAjwnzWPalWAHETt/Csf/7NVtE2+QX8GJD83Z D/dyg60TiVNvh1J6WNfS/dvRcZDILJZSpORnRDCl/Is0jZ5WWlslZ8DHxdzdhP8Bn8mk iUZdM9hFn3qodVJSZ4y8C8PyiCiGCE9RHaC9jApArD5c2ie+YQL2SK0ZS6InBWI9b5oH WI7w== 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=B/Q6VwPDe6I6EirNcsyicnPy138BEVcOe0YKhiLSwKI=; b=NnmlgY9gXBquOqx4cBH1MvtGr1voWTE3OWOzYkaK6y44xdTQ2zP148Gnp5FOghnham KbGGX6dtGVwRf+QDSFOVvomh7XviLPzkiSda8o9aC68yr5t99FK8JIy4+8NFzI8Bv+Dh P8APTqtu1ohm11ApZk1p9W4+uHffEnb4hsNkdKQrSVvM4xI9nvzCGN644QF+mJmT0hpf IHxUXCva+CzNjWpzROTlW+6AGZgP/Ixd709Mh0eNiDy1T/4on/3qgIFxowvP3lgvDR3E w0+RASLGJ6UhHw9gA3cLyI3MyAQkdbF9Xh6qnCDYReFVBzb/UzAw1lBkx0hhGrvLUeQW BaYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20150623.gappssmtp.com header.s=20150623 header.b=bFnBs52A; 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 ds7si14430333ejc.212.2021.02.15.04.48.23; Mon, 15 Feb 2021 04:48:47 -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=bFnBs52A; 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 S230091AbhBOMrS (ORCPT + 99 others); Mon, 15 Feb 2021 07:47:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230380AbhBOMqO (ORCPT ); Mon, 15 Feb 2021 07:46:14 -0500 Received: from mail-pg1-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3B42C0613D6 for ; Mon, 15 Feb 2021 04:45:33 -0800 (PST) Received: by mail-pg1-x530.google.com with SMTP id z68so4177384pgz.0 for ; Mon, 15 Feb 2021 04:45:33 -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=B/Q6VwPDe6I6EirNcsyicnPy138BEVcOe0YKhiLSwKI=; b=bFnBs52Ad4AzO3WrtmP1t4dKywjpPzK+A482Eht6ojz0TpmO7rLiExFrSiXmi1S2/N JVPugG3EVQe37M9ZZbqQbe3vnUWlJ02gF52OhqtjzccwxgbMqN7glFsab53y34iAsFbL 4kjXYxYj4ufcMKtowhp4K7R5ARxG1wIl53SN1GNMvPvMAMKzWhz6Z+F9q9iOjCnhqXEO hfWRa/ZSRjqL+PRzodxE8JEJzZg0064aea6im6iFOGyV3tcqTSjWLMisoHnAe4KdD2lI 4nfmAWUZN/9VffDyOGlST7TAebdEl3HRz5sKQJHvXGJxwQT0NXRV4c1fT6gYDqLv/YA2 QAHA== 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=B/Q6VwPDe6I6EirNcsyicnPy138BEVcOe0YKhiLSwKI=; b=BsnSR8LVfhMIjOQW0eNL/7960/KT9UrL/6wPhBoV19apBbQREcULIx6AqYD1WX6Xby idDifhb0Ko0S36gcxPSqicHGN5+pkC8KgAJfqVtnd/+wA2QrivKIsaqOkUKEw4BeaiJE sO12z2ICVaykkesBGruLhmEUyIxwNPPdY59ljE8kpG2HrFGhfm5ASXxNfBmbSg11kRIp cA0dmSHXdSPi0jSePA/kD3BCTVCz3B9k8GABsI8BTUvBQ5GjpzWiVS44deOHhnTZijCp CUVGDYBKIseRUgm2DihcQdI9e1t2W4Pubm6Tz7yQTPrcJX24FBMyFLmhmPcgKj97Vrh/ BqeA== X-Gm-Message-State: AOAM5300nMCEvlvdv0cSmxytrFAu4KjW5pedn0Ds3c+uojZN6qnf83Bh MuAcWYBf1c5qtp/0rlvfD22LTLNLjtqx4yn7wHbGcw== X-Received: by 2002:a63:de0e:: with SMTP id f14mr14400347pgg.273.1613393133150; Mon, 15 Feb 2021 04:45:33 -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 20:44:57 +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 Mon, Feb 15, 2021 at 8:18 PM Michal Hocko wrote: > > On Mon 15-02-21 20:00:07, Muchun Song wrote: > > On Mon, Feb 15, 2021 at 7:51 PM Muchun Song wrote: > > > > > > On Mon, Feb 15, 2021 at 6:33 PM Michal Hocko wrote: > > > > > > > > On Mon 15-02-21 18:05:06, Muchun Song wrote: > > > > > On Fri, Feb 12, 2021 at 11:32 PM Michal Hocko wrote: > > > > [...] > > > > > > > +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. > > > > > > > > You can have a preallocated list of pages prior taking the lock. > > > > > > A discussion about this can refer to here: > > > > > > https://patchwork.kernel.org/project/linux-mm/patch/20210117151053.24600-5-songmuchun@bytedance.com/ > > > > > > > Moreover do we want to manipulate vmemmaps from under spinlock in > > > > general. I have to say I have missed that detail when reviewing. Need to > > > > think more. > > > > > > > > > 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 > > > > > > > > The whole point of GFP_ATOMIC is to grant access to memory reserves so > > > > the above is quite dubious. If you do not want access to memory reserves > > > > > > Look at the code of gfp_to_alloc_flags(). > > > > > > static inline unsigned int gfp_to_alloc_flags(gfp_t gfp_mask) > > > { > > > [...] > > > if (gfp_mask & __GFP_ATOMIC) { > > > /* > > > * Not worth trying to allocate harder for __GFP_NOMEMALLOC even > > > * if it can't schedule. > > > */ > > > if (!(gfp_mask & __GFP_NOMEMALLOC)) > > > alloc_flags |= ALLOC_HARDER; > > > [...] > > > } > > > > > > Seems to allow this operation (GFP_ATOMIC | __GFP_NOMEMALLOC). > > Please read my response again more carefully. I am not claiming that > combination is not allowed. I have said it doesn't make any sense in > this context. I see you are worried that using GFP_ATOMIC will use reverse memory unlimited. So I think that __GFP_NOMEMALLOC may be suitable for us. Sorry, I may not understand the point you said. What I missed? > > -- > Michal Hocko > SUSE Labs