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=-6.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 98FA2C35257 for ; Mon, 21 Sep 2020 18:42:35 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 0A4622084C for ; Mon, 21 Sep 2020 18:42:34 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PJIO62lj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0A4622084C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 40DF66B00D3; Mon, 21 Sep 2020 14:42:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3BDFE90008B; Mon, 21 Sep 2020 14:42:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 285236B00D5; Mon, 21 Sep 2020 14:42:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0041.hostedemail.com [216.40.44.41]) by kanga.kvack.org (Postfix) with ESMTP id 0FFDD6B00D3 for ; Mon, 21 Sep 2020 14:42:34 -0400 (EDT) Received: from smtpin23.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id C9D138249980 for ; Mon, 21 Sep 2020 18:42:33 +0000 (UTC) X-FDA: 77287939386.23.deer11_391681527147 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin23.hostedemail.com (Postfix) with ESMTP id A08EF37609 for ; Mon, 21 Sep 2020 18:42:33 +0000 (UTC) X-HE-Tag: deer11_391681527147 X-Filterd-Recvd-Size: 7073 Received: from mail-pg1-f195.google.com (mail-pg1-f195.google.com [209.85.215.195]) by imf06.hostedemail.com (Postfix) with ESMTP for ; Mon, 21 Sep 2020 18:42:33 +0000 (UTC) Received: by mail-pg1-f195.google.com with SMTP id f2so9811386pgd.3 for ; Mon, 21 Sep 2020 11:42:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=GC8sasDcUUtfwQI8cKe8C4MyvaXt20t2jZSBkvmxcKE=; b=PJIO62ljOyN+1oeIjex1hvkPe/kAXRdHMt2EuQnA7LXWMDOfzFJMe9X1NF6dCxKuIh EhFxtVsOp5Dj9ZEIJWRwPrIwHfaaa+nrRPykZYIAImOwzeCkt2RIpZu/a8MFyx/1HUYu JPeseNB397GZY/NIsuxhnZcN+rfWQhgzOB3CbDYGMxzldcRBPGGrvGQLvcSbfPtCzSnN 8IpqjPYrO7za6eiQMYDcaiwTFY5V0R0Up+iputxQPdeN3wyYPyeJeDCwnYfUzTuu39gr zSX+fTMi1+vbhHa3PM7rwXb3APyjh8XPjYeiQH8eQIRJUs0AbvMttuiUz20Vdld2OX3J Dteg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=GC8sasDcUUtfwQI8cKe8C4MyvaXt20t2jZSBkvmxcKE=; b=BcnrMY7Xro8aPt2H30BvtYfDevIPtdeg6vn0NFu5CWxYo5IQoIf1fJ/ytjXwQkAepP XRn5MpIAoiSceQN4pPi8d9LfMC5nRL1Czs/QnwaeRhf8iwvKnPLwznZR7YsPACwZInlV x/KRbz6nKIsdSoiFrPlk+FfRhFS6J2l58IKETyxsmVqEmCUbsi3lcswWmQjssTxHhAhj /GyGGzreso8jSoERR6bwnCeoV1Klv5l7UeYX8R++kUve9J33qGusN3fS/JEOyULnPBJV u78m6GWMdJtsgVEH0guO3MArOpQYWfTYd7xDyTd1o94QQxyv9QL17co49cPQEZqwCM4o yHhQ== X-Gm-Message-State: AOAM531GVDsfFYwsVyj1qjbMI6c0B/RzpuCdTv6ficbYbebKpNxVAf5P 0i7YbLFPTMxfLsXMOX4/iYM= X-Google-Smtp-Source: ABdhPJyIYDaB5wxRnaHeVNF92ISZZsgvCaNReLLtTysYEz7UGmPMJ8HW/tA7CIa5ivCFQs4Qv4vx5Q== X-Received: by 2002:aa7:8a46:0:b029:142:2501:398a with SMTP id n6-20020aa78a460000b02901422501398amr993477pfa.79.1600713752207; Mon, 21 Sep 2020 11:42:32 -0700 (PDT) Received: from google.com ([2620:15c:211:1:7220:84ff:fe09:5e58]) by smtp.gmail.com with ESMTPSA id i25sm13004358pgi.9.2020.09.21.11.42.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Sep 2020 11:42:31 -0700 (PDT) Date: Mon, 21 Sep 2020 11:42:29 -0700 From: Minchan Kim To: Christoph Hellwig , Andrew Morton Cc: 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: <20200921184229.GA422329@google.com> References: <20200918163724.2511-1-hch@lst.de> <20200918163724.2511-2-hch@lst.de> <20200921174256.GA387368@google.com> <20200921181708.GA2067@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200921181708.GA2067@lst.de> 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 08:17:08PM +0200, Christoph Hellwig wrote: > 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.. Yeah, let's assign the addres we got get_vm_area. > > We probaby want to add a trivial helper to prefault an area instead of > the open coded variant. It seems zsmalloc is only customer the function so let's have the helper when we see another customer. If we don't have objection, I'd like to ask to Andrew fold this up. --- mm/memory.c | 2 +- mm/zsmalloc.c | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) 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..918c7b019b3d 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -1125,7 +1125,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. + */ + return apply_to_page_range(&init_mm, (unsigned long)area->vm->addr, + PAGE_SIZE * 2, NULL, NULL); } static inline void __zs_cpu_down(struct mapping_area *area) -- 2.28.0.681.g6f77f65b4e-goog