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 X-Spam-Level: X-Spam-Status: No, score=-8.3 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id D7334C4346E for ; Mon, 21 Sep 2020 18:17:14 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 4A80920888 for ; Mon, 21 Sep 2020 18:17:14 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4A80920888 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B2B759000A6; Mon, 21 Sep 2020 14:17:13 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ADC5890008B; Mon, 21 Sep 2020 14:17:13 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9F39A9000A6; Mon, 21 Sep 2020 14:17:13 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0080.hostedemail.com [216.40.44.80]) by kanga.kvack.org (Postfix) with ESMTP id 8780890008B for ; Mon, 21 Sep 2020 14:17:13 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 4B939362D for ; Mon, 21 Sep 2020 18:17:13 +0000 (UTC) X-FDA: 77287875546.17.lock56_2f08e6b27147 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 0A528180D0180 for ; Mon, 21 Sep 2020 18:17:13 +0000 (UTC) X-HE-Tag: lock56_2f08e6b27147 X-Filterd-Recvd-Size: 3323 Received: from verein.lst.de (verein.lst.de [213.95.11.211]) by imf27.hostedemail.com (Postfix) with ESMTP for ; Mon, 21 Sep 2020 18:17:12 +0000 (UTC) Received: by verein.lst.de (Postfix, from userid 2407) id 76B4068AFE; Mon, 21 Sep 2020 20:17:08 +0200 (CEST) Date: Mon, 21 Sep 2020 20:17:08 +0200 From: Christoph Hellwig To: Minchan Kim Cc: Christoph Hellwig , Andrew Morton , Peter Zijlstra , Boris Ostrovsky , Juergen Gross , Stefano Stabellini , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Nitin Gupta , x86@kernel.org, xen-devel@lists.xenproject.org, linux-kernel@vger.kernel.org, intel-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org, linux-mm@kvack.org Subject: Re: [PATCH 1/6] zsmalloc: switch from alloc_vm_area to get_vm_area Message-ID: <20200921181708.GA2067@lst.de> References: <20200918163724.2511-1-hch@lst.de> <20200918163724.2511-2-hch@lst.de> <20200921174256.GA387368@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200921174256.GA387368@google.com> User-Agent: Mutt/1.5.17 (2007-11-01) 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: On Mon, Sep 21, 2020 at 10:42:56AM -0700, Minchan Kim wrote: > IIRC, the problem was runtime pte popluating needs GFP_KERNEL but > zs_map_object API runs under non-preemtible section. Make sense. > > - area->vm = alloc_vm_area(PAGE_SIZE * 2, NULL); > > + area->vm = get_vm_area(PAGE_SIZE * 2, 0); > > if (!area->vm) > > return -ENOMEM; > > return 0; > > I think it shoud work. > > diff --git a/mm/memory.c b/mm/memory.c > index 05789aa4af12..6a1e4d854593 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -2232,7 +2232,7 @@ static int apply_to_pte_range(struct mm_struct *mm, pmd_t *pmd, > arch_enter_lazy_mmu_mode(); > > do { > - if (create || !pte_none(*pte)) { > + if ((create || !pte_none(*pte)) && fn) { > err = fn(pte++, addr, data); > if (err) > break; > diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c > index 3e4fe3259612..9ef7daf3d279 100644 > --- a/mm/zsmalloc.c > +++ b/mm/zsmalloc.c > @@ -1116,6 +1116,8 @@ static struct zspage *find_get_zspage(struct size_class *class) > #ifdef CONFIG_ZSMALLOC_PGTABLE_MAPPING > static inline int __zs_cpu_up(struct mapping_area *area) > { > + int ret; > + > /* > * Make sure we don't leak memory if a cpu UP notification > * and zs_init() race and both call zs_cpu_up() on the same cpu > @@ -1125,7 +1127,13 @@ static inline int __zs_cpu_up(struct mapping_area *area) > area->vm = get_vm_area(PAGE_SIZE * 2, 0); > if (!area->vm) > return -ENOMEM; > - return 0; > + > + /* > + * Populate ptes in advance to avoid pte allocation with GFP_KERNEL > + * in non-preemtible context of zs_map_object. > + */ > + ret = apply_to_page_range(&init_mm, NULL, PAGE_SIZE * 2, NULL, NULL); > + return ret; I think this needs the addr from the vm area somewhere.. We probaby want to add a trivial helper to prefault an area instead of the open coded variant.