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, URIBL_BLOCKED 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 72038C4346E for ; Mon, 21 Sep 2020 18:42:41 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1CF302084C for ; Mon, 21 Sep 2020 18:42:40 +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 1CF302084C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=intel-gfx-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5C75A89C61; Mon, 21 Sep 2020 18:42:40 +0000 (UTC) Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by gabe.freedesktop.org (Postfix) with ESMTPS id A536C6E50C; Mon, 21 Sep 2020 18:42:32 +0000 (UTC) Received: by mail-pf1-x441.google.com with SMTP id b124so10030687pfg.13; Mon, 21 Sep 2020 11:42:32 -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=uFaNq6xR+4ljhAKrBss4l5IeOktZgBXv/nAW/vmiRIZwp4st6auVfSNzq9RkpGDnZs UaSbQshonmRSMlvvsU9UMOCL74PbRRsQkg9IFou8rErdt/W3eKT7UCwYoGXpwglopYEN TGZ23RgpC/yq3OapHzQpJNG28SUH8rK9ldEOrSd41vpOncO0NwsnO80rONMmbFoaAA7U 8usr4GiSYYg4E6sKpXbrq57uC+pzevD1ad1pI60sOQM3goMQqGVk2Izycp4B+EtvzRAq O3/cjtSind+MH+1IkQOMcQKcxjCUkmLS7LETSPs5KXSW7Fym6xaAlIDwjxX9NG4yegpF ZO3A== X-Gm-Message-State: AOAM531GIwGf3aek54ftkCiNWijqTsQ6dFsTJQ0UO3wQNnBHfDGLiLA6 GcQISZr8ijClThR3dO/IClE= 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 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-Disposition: inline In-Reply-To: <20200921181708.GA2067@lst.de> Subject: Re: [Intel-gfx] [PATCH 1/6] zsmalloc: switch from alloc_vm_area to get_vm_area X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Peter Zijlstra , intel-gfx@lists.freedesktop.org, x86@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, dri-devel@lists.freedesktop.org, xen-devel@lists.xenproject.org, Andrew Morton , Boris Ostrovsky , Nitin Gupta Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" 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 _______________________________________________ Intel-gfx mailing list Intel-gfx@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/intel-gfx 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 5803FC4346E for ; Mon, 21 Sep 2020 18:42:56 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 00BCC2084C for ; Mon, 21 Sep 2020 18:42:55 +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 00BCC2084C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kKQln-0007RZ-Sn; Mon, 21 Sep 2020 18:42:35 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kKQlm-0007RU-Dz for xen-devel@lists.xenproject.org; Mon, 21 Sep 2020 18:42:34 +0000 X-Inumbo-ID: e9c464a3-575c-487b-bcbe-227ab60205d4 Received: from mail-pf1-x444.google.com (unknown [2607:f8b0:4864:20::444]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id e9c464a3-575c-487b-bcbe-227ab60205d4; Mon, 21 Sep 2020 18:42:33 +0000 (UTC) Received: by mail-pf1-x444.google.com with SMTP id z18so10067544pfg.0 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=EVPvGaBr2SM38tOZy3Z6Iefqpynk/Vx8iqretR71gEisktSlV5bgG9wCGLWQPsUGTi 6IJEkdc8PFWXw08SpRdq7t2mu0G1ODccEhkOyGSyT+Fw07V8WYuni50RHUQbGmwM/qF6 8IUoL/5esv/70G27wQtHc00hT2zPoYfKaDRf1dVXB8BOzrdE8yvdxjhQqZQ/17wyeobJ viYpkIAdNb60SELCbifw/DLk44LGpC+EXnIA+3E8haTZs3zqUl7GkGO1RFxOQ8MCUpvI DDQsb32owm32va5+2TMD34s1np4k7RlacjeyRsYZ23ILnVQ5PLtOsfVpDb39OB00lE/Y jngw== X-Gm-Message-State: AOAM533Fs61OelPXA+lPRuYS4jdpET9HKqq5vX1rPtftFYugKmQCVIEC oca6Ynkt7fsGGzGUZLXdjqM= 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-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" 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 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, URIBL_BLOCKED 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 ED0BAC4363C for ; Mon, 21 Sep 2020 18:42:42 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A02E32084C for ; Mon, 21 Sep 2020 18:42:42 +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 A02E32084C Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EF1236E523; Mon, 21 Sep 2020 18:42:40 +0000 (UTC) Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by gabe.freedesktop.org (Postfix) with ESMTPS id A536C6E50C; Mon, 21 Sep 2020 18:42:32 +0000 (UTC) Received: by mail-pf1-x441.google.com with SMTP id b124so10030687pfg.13; Mon, 21 Sep 2020 11:42:32 -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=uFaNq6xR+4ljhAKrBss4l5IeOktZgBXv/nAW/vmiRIZwp4st6auVfSNzq9RkpGDnZs UaSbQshonmRSMlvvsU9UMOCL74PbRRsQkg9IFou8rErdt/W3eKT7UCwYoGXpwglopYEN TGZ23RgpC/yq3OapHzQpJNG28SUH8rK9ldEOrSd41vpOncO0NwsnO80rONMmbFoaAA7U 8usr4GiSYYg4E6sKpXbrq57uC+pzevD1ad1pI60sOQM3goMQqGVk2Izycp4B+EtvzRAq O3/cjtSind+MH+1IkQOMcQKcxjCUkmLS7LETSPs5KXSW7Fym6xaAlIDwjxX9NG4yegpF ZO3A== X-Gm-Message-State: AOAM531GIwGf3aek54ftkCiNWijqTsQ6dFsTJQ0UO3wQNnBHfDGLiLA6 GcQISZr8ijClThR3dO/IClE= 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 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-Disposition: inline In-Reply-To: <20200921181708.GA2067@lst.de> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Juergen Gross , Stefano Stabellini , Peter Zijlstra , intel-gfx@lists.freedesktop.org, x86@kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, dri-devel@lists.freedesktop.org, Rodrigo Vivi , xen-devel@lists.xenproject.org, Andrew Morton , Boris Ostrovsky , Nitin Gupta Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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 _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel