Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp3386163pxk; Mon, 21 Sep 2020 12:16:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyOX77FocOQF3QVC6w7tySnH77DgTzxmCHj6MbD1OkO8ZcWNpHjmakmycPI/27pGajSCO0X X-Received: by 2002:a50:9b5e:: with SMTP id a30mr409529edj.49.1600715783249; Mon, 21 Sep 2020 12:16:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600715783; cv=none; d=google.com; s=arc-20160816; b=HZtT96kHiyAbOTkDRJmWoSbqs+Iq/6otXQaDlU3MaThu8vqcZlaze67/hZMRGFV6wo +ayrzG1aZ7WAjwIyQloDYNxyRE642J1PHYfobBW9JhbfJEQuB1SnR2u16UkfQXknCC34 OEgCVgU0ZVn8YArkIZxprBKuIoOfCkwtCNvNohzWAkJCCbm/92LK0T1AvpLAPBNQUhw5 lKVr6wK9CsuqGwFL0W4hJrjgc6IShk2tWnvgKOw+OET/ggR0CDtFp0z34zBraoizvPls QaEUDSa0Fqzu8PtSjY3CqMJBPBP9t+GoWX2vdHGeFK0CqCrcnSS5xDzQG+2HPOatb2Kp rQIw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=8o7GVAomh929Hvy+xaXufBwE8CQqTnicVvJhMbCZ9+k=; b=ruspm1WRvxetx/reuy/x0mSduTAKb8KQYdu24amKdlzD2Pj0kumaaiIVslYVmf0SvL bpOXwk4OzPrAWTE3mGSG4vFYatGZPYbGNn2IFkBxxB/SYdiDDZLgVs+yhk3zyKioAerH iUT0rNaPYRZDWKNQf+mEG0jKnOVA1Mpdjw6cJs4sam6DNMqUy+5brTl6UFfEJ3rJF8E3 lUJsN9fuezCnqAt3kDwN337w5Cl13wI/ZxDVm1ARtIi7G2+4Ld6NDoezaPIz3Xiydzie LMLoXDnEety4c7JYC13LGcZOFbWAk8Xs7WWwZV1Z1pl5JithFg4VS22dTJbyisDyKYay Ctug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=mehcTMqJ; 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 v23si9162588ejf.312.2020.09.21.12.16.00; Mon, 21 Sep 2020 12:16:23 -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; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=mehcTMqJ; 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 S1727976AbgIUTMQ (ORCPT + 99 others); Mon, 21 Sep 2020 15:12:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56986 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726886AbgIUTMQ (ORCPT ); Mon, 21 Sep 2020 15:12:16 -0400 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E052BC061755 for ; Mon, 21 Sep 2020 12:12:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=8o7GVAomh929Hvy+xaXufBwE8CQqTnicVvJhMbCZ9+k=; b=mehcTMqJtwQu3rPUjsEisC7ECq 7+58K3Z4EekBFXZ3wYEUeQuCa/fWdcNhiPeHAeErok/v8ZUYK3e3gg5/B4dsAsGOOcHKMJll0ZrgT uIxyCNSUGOAg2UN4gsizGdkbduG7XDlLurQP7j3hPoeoUDi05V5iO3YFhaKjX5x3pQ8mdKFxJmqgA L9SsTOYSux1ZLBO0Whate1mY/A8G4ym2vhOpFFpaMiIWVUAzrHfwOrb8cuL3VnUqrmtLSbCIIumHR mHpwBBr1xVe0+QICrLKcrhz2TwTDJC2BnukZFO6wyPDyqecyMJcK7af7LQwFO3njp1VzvRCXlr6uE ADgc0Q1w==; Received: from willy by casper.infradead.org with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1kKRED-0003Cg-2P; Mon, 21 Sep 2020 19:11:57 +0000 Date: Mon, 21 Sep 2020 20:11:57 +0100 From: Matthew Wilcox To: Christoph Hellwig Cc: Andrew Morton , Peter Zijlstra , Boris Ostrovsky , Juergen Gross , Stefano Stabellini , Jani Nikula , Joonas Lahtinen , Rodrigo Vivi , Minchan Kim , 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 3/6] drm/i915: use vmap in shmem_pin_map Message-ID: <20200921191157.GX32101@casper.infradead.org> References: <20200918163724.2511-1-hch@lst.de> <20200918163724.2511-4-hch@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200918163724.2511-4-hch@lst.de> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Sep 18, 2020 at 06:37:21PM +0200, Christoph Hellwig wrote: > void shmem_unpin_map(struct file *file, void *ptr) > { > + long i = shmem_npages(file); > + > mapping_clear_unevictable(file->f_mapping); > - __shmem_unpin_map(file, ptr, shmem_npte(file)); > + vunmap(ptr); > + > + for (i = 0; i < shmem_npages(file); i++) { > + struct page *page; > + > + page = shmem_read_mapping_page_gfp(file->f_mapping, i, > + GFP_KERNEL); > + if (!WARN_ON(IS_ERR(page))) { > + put_page(page); > + put_page(page); > + } > + } > } This is awkward. I'd like it if we had a vfree() variant which called put_page() instead of __free_pages(). I'd like it even more if we used release_pages() instead of our own loop that called put_page(). Perhaps something like this ... +++ b/mm/vmalloc.c @@ -2262,7 +2262,7 @@ static void __vunmap(const void *addr, int deallocate_page s) vm_remove_mappings(area, deallocate_pages); - if (deallocate_pages) { + if (deallocate_pages == 1) { int i; for (i = 0; i < area->nr_pages; i++) { @@ -2271,8 +2271,12 @@ static void __vunmap(const void *addr, int deallocate_pages) BUG_ON(!page); __free_pages(page, 0); } - atomic_long_sub(area->nr_pages, &nr_vmalloc_pages); + } else if (deallocate_pages == 2) { + release_pages(area->pages, area->nr_pages); + } + if (deallocate_pages) { + atomic_long_sub(area->nr_pages, &nr_vmalloc_pages); kvfree(area->pages); } @@ -2369,6 +2373,14 @@ void vunmap(const void *addr) } EXPORT_SYMBOL(vunmap); +void vunmap_put_pages(const void *addr) +{ + BUG_ON(in_interrupt()); + might_sleep(); + if (addr) + __vunmap(addr, 2); +} + /** * vmap - map an array of pages into virtually contiguous space * @pages: array of page pointers only with kernel-doc and so on. I bet somebody has a better idea for a name.