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=-10.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,MENTIONS_GIT_HOSTING, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,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 DF701C4727D for ; Tue, 22 Sep 2020 16:33:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8883823A69 for ; Tue, 22 Sep 2020 16:33:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726623AbgIVQdv (ORCPT ); Tue, 22 Sep 2020 12:33:51 -0400 Received: from verein.lst.de ([213.95.11.211]:45428 "EHLO verein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726508AbgIVQdv (ORCPT ); Tue, 22 Sep 2020 12:33:51 -0400 Received: by verein.lst.de (Postfix, from userid 2407) id DF8FD67373; Tue, 22 Sep 2020 18:33:46 +0200 (CEST) Date: Tue, 22 Sep 2020 18:33:46 +0200 From: Christoph Hellwig To: Tvrtko Ursulin Cc: Christoph Hellwig , Matthew Wilcox , Juergen Gross , Stefano Stabellini , linux-mm@kvack.org, Peter Zijlstra , Boris Ostrovsky , x86@kernel.org, linux-kernel@vger.kernel.org, Minchan Kim , dri-devel@lists.freedesktop.org, xen-devel@lists.xenproject.org, Andrew Morton , intel-gfx@lists.freedesktop.org, Nitin Gupta , Chris Wilson , Matthew Auld Subject: Re: [Intel-gfx] [PATCH 3/6] drm/i915: use vmap in shmem_pin_map Message-ID: <20200922163346.GA1701@lst.de> References: <20200918163724.2511-1-hch@lst.de> <20200918163724.2511-4-hch@lst.de> <20200921191157.GX32101@casper.infradead.org> <20200922062249.GA30831@lst.de> <43d10588-2033-038b-14e4-9f41cd622d7b@linux.intel.com> <20200922143141.GA26637@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.17 (2007-11-01) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Sep 22, 2020 at 05:13:45PM +0100, Tvrtko Ursulin wrote: >> void *shmem_pin_map(struct file *file) >> { >> - const size_t n_pte = shmem_npte(file); >> - pte_t *stack[32], **ptes, **mem; > > Chris can comment how much he'd miss the 32 page stack shortcut. I'd like to see a profile that claim that kmalloc matters in a path that does a vmap and reads pages through the page cache. Especially when the kmalloc saves doing another page cache lookup on the free side. > Is there something in vmap() preventing us from freeing the pages array > here? I can't spot anything that is holding on to the pointer. Or it was > just a sketch before you realized we could walk the vm_area? > > Also, I may be totally misunderstanding something, but I think you need to > assign area->pages manually so shmem_unpin_map can access it below. We need area->pages to hold the pages for the free side. That being said the patch I posted is broken because it never assigned to that. As said it was a sketch. This is the patch I just rebooted into on my Laptop: http://git.infradead.org/users/hch/misc.git/commitdiff/048522dfa26b6667adfb0371ff530dc263abe829 it needs extra prep patches from the series: http://git.infradead.org/users/hch/misc.git/shortlog/refs/heads/alloc_vm_area >> mapping_clear_unevictable(file->f_mapping); >> - __shmem_unpin_map(file, ptr, shmem_npte(file)); >> + for (i = 0; i < shmem_npages(file); i++) >> + put_page(area->pages[i]); >> + kvfree(area->pages); >> + vunmap(ptr); > > Is the verdict from mm experts that we can't use vfree due __free_pages vs > put_page differences? Switched to vfree now. > Could we get from ptes to pages, so that we don't have to keep the > area->pages array allocated for the duration of the pin? We could do vmalloc_to_page, but that is fairly expensive (not as bad as reading from the page cache..). Are you really worried about the allocation?