Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp5779760pxu; Thu, 22 Oct 2020 10:48:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxPyj86I4zbFK2fKkMxBzzFeDk5dabenaqDtM+L/MDB20sJZ2waoTMI2zaNb4iq8Z7rbnTn X-Received: by 2002:a17:906:4dc7:: with SMTP id f7mr3304865ejw.73.1603388933210; Thu, 22 Oct 2020 10:48:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1603388933; cv=none; d=google.com; s=arc-20160816; b=HhjF/Y4yt89T/Z5nbbMX6iAWujfw8yLRpnpj3/451j9sYTkBSgyyO5Jo/h2xCIdyBT ZvcH6UJcPc3pwDSn115E8ktRGVYUQz2aIF8ug5DsB0d4eCeGXFL9mBCxS8D3n7xIr1XD tTQ2XlVsHknbAG6wPRqn4iyI3wRoG7ytOOcZZlSZBo1fwO2jWn0gJdElx4xCk1AvFxN4 vwF8yEc0uV5X+6Fjji6cNl2NYDi3IJeOJRjEuE+lGLO4mtqTGPM1o7qYAJnHbf7tIpWS 45RVdt1SBXbdclqWgP6h8PijcTgsBhoOW3I7IVwYadAZvwKqACf0g1Gz2ZJ7JycYpIR5 q4mA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject; bh=UacyC3Fql6UQxznwh3Ll5KOox2327KkLhB9iplMBIEo=; b=xnBeYzMr+P+BFI+HSLbB0evrqVZahIfW+hSML+7inktQxx96RqDLkE37Y4Gpjuayjq tkZQMHpxw/5OYMouhfYMjA+iZjbBD1v2WvGziidvfy18s1tN7jDVEy4LKTR32MgDOyL2 ctFhYBisFH4Rg7v1VR0cHiimjYe54eYZMXBJZ/6kWfg+iK/bqlnD1NvHVSCvzKWa5y8K Gv1f7GN8dYfMOrSo01HG2T0d1eQhHohjjkN+znUtNoEMn/9MX8zvc04cgVXSbxQNu5Z8 POpZClK06mcaK3rv/nPNg6FiDT4JoI9GMmvvhR7KQJ2jQvgihDKgjz3EtjU15qSiIbPh zTLw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id op13si1297891ejb.645.2020.10.22.10.48.31; Thu, 22 Oct 2020 10:48:53 -0700 (PDT) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S368208AbgJVOvr (ORCPT + 99 others); Thu, 22 Oct 2020 10:51:47 -0400 Received: from mx2.suse.de ([195.135.220.15]:55654 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S368201AbgJVOvr (ORCPT ); Thu, 22 Oct 2020 10:51:47 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id A1B4EAC6C; Thu, 22 Oct 2020 14:51:45 +0000 (UTC) Subject: Re: [PATCH] mm,thp,shmem: limit shmem THP alloc gfp_mask To: Rik van Riel , Hugh Dickins Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, kernel-team@fb.com, Mel Gorman , Andrea Arcangeli , Matthew Wilcox , Michal Hocko References: <20201021234846.5cc97e62@imladris.surriel.com> From: Vlastimil Babka Message-ID: <06c1e573-cddd-c17c-9f18-3af2d9d09f80@suse.cz> Date: Thu, 22 Oct 2020 16:51:44 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.3.2 MIME-Version: 1.0 In-Reply-To: <20201021234846.5cc97e62@imladris.surriel.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 10/22/20 5:48 AM, Rik van Riel wrote: > The allocation flags of anonymous transparent huge pages can be controlled > through the files in /sys/kernel/mm/transparent_hugepage/defrag, which can > help the system from getting bogged down in the page reclaim and compaction > code when many THPs are getting allocated simultaneously. > > However, the gfp_mask for shmem THP allocations were not limited by those > configuration settings, and some workloads ended up with all CPUs stuck > on the LRU lock in the page reclaim code, trying to allocate dozens of > THPs simultaneously. > > This patch applies the same configurated limitation of THPs to shmem > hugepage allocations, to prevent that from happening. > > This way a THP defrag setting of "never" or "defer+madvise" will result > in quick allocation failures without direct reclaim when no 2MB free > pages are available. > > Signed-off-by: Rik van Riel FTR, a patch to the same effect was sent by Xu Yu: https://lore.kernel.org/r/11e1ead211eb7d141efa0eb75a46ee2096ee63f8.1603267572.git.xuyu@linux.alibaba.com > --- > > diff --git a/include/linux/gfp.h b/include/linux/gfp.h > index c603237e006c..0a5b164a26d9 100644 > --- a/include/linux/gfp.h > +++ b/include/linux/gfp.h > @@ -614,6 +614,8 @@ bool gfp_pfmemalloc_allowed(gfp_t gfp_mask); > extern void pm_restrict_gfp_mask(void); > extern void pm_restore_gfp_mask(void); > > +extern gfp_t alloc_hugepage_direct_gfpmask(struct vm_area_struct *vma); > + > #ifdef CONFIG_PM_SLEEP > extern bool pm_suspended_storage(void); > #else > diff --git a/mm/huge_memory.c b/mm/huge_memory.c > index 9474dbc150ed..9b08ce5cc387 100644 > --- a/mm/huge_memory.c > +++ b/mm/huge_memory.c > @@ -649,7 +649,7 @@ static vm_fault_t __do_huge_pmd_anonymous_page(struct vm_fault *vmf, > * available > * never: never stall for any thp allocation > */ > -static inline gfp_t alloc_hugepage_direct_gfpmask(struct vm_area_struct *vma) > +gfp_t alloc_hugepage_direct_gfpmask(struct vm_area_struct *vma) > { > const bool vma_madvised = !!(vma->vm_flags & VM_HUGEPAGE); > > diff --git a/mm/shmem.c b/mm/shmem.c > index 537c137698f8..d1290eb508e5 100644 > --- a/mm/shmem.c > +++ b/mm/shmem.c > @@ -1545,8 +1545,11 @@ static struct page *shmem_alloc_hugepage(gfp_t gfp, > return NULL; > > shmem_pseudo_vma_init(&pvma, info, hindex); > - page = alloc_pages_vma(gfp | __GFP_COMP | __GFP_NORETRY | __GFP_NOWARN, > - HPAGE_PMD_ORDER, &pvma, 0, numa_node_id(), true); > + /* Limit the gfp mask according to THP configuration. */ > + gfp |= __GFP_COMP | __GFP_NORETRY | __GFP_NOWARN; > + gfp &= alloc_hugepage_direct_gfpmask(&pvma); > + page = alloc_pages_vma(gfp, HPAGE_PMD_ORDER, &pvma, 0, numa_node_id(), > + true); > shmem_pseudo_vma_destroy(&pvma); > if (page) > prep_transhuge_page(page); >