From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1963F214228 for ; Tue, 2 Dec 2025 14:03:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764684197; cv=none; b=gEic0ngWEjLO2CHclNH//TE56Mp8QAn3tRxhkLuhufvZ+lUw69f+lY3gUkoF1il4NSi6EckEsVg47KQb4bUdQfS0Fls+SJWVyDgr00SZ+46h+a9SkZuuTNQGo2eZWAZLDKhKiUI5AupeAT+mLpaRuABlM91PpFA6BIjK/4Ip09I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1764684197; c=relaxed/simple; bh=51HA4kszeefbLH/zdthS5lnS/8T7ynKQZgoCCZI4TKc=; h=From:Date:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=o1CLA+NWeoLblICQVlshDA7tH1gVTOFy3++CrMg6AHLxsuZKZer3irMr6uLY4fD19UpOAaRA4FFpOMv/66nDDQunIikG90vpBhQG9H9dUl07be0OoE+kIAVDJP6fla5fzY+h5RR5A52z4ppfjwfiIFDi/jnVVL1d6l5yrGUyDP4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=R9kSqZuZ; arc=none smtp.client-ip=209.85.208.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="R9kSqZuZ" Received: by mail-lj1-f182.google.com with SMTP id 38308e7fff4ca-37ba5af5951so53638831fa.1 for ; Tue, 02 Dec 2025 06:03:15 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1764684194; x=1765288994; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:date:from:from:to :cc:subject:date:message-id:reply-to; bh=Qv1K7J2piWEBLYsmYS5El8b8US/OwNpgXHLpQ7GMrlY=; b=R9kSqZuZyJLw9gcmKpvFSiz2VvEA4njON40Msc/9GljFQpGX50ZcgyeNOsHz+7rBxx EsV0Gj6R8cjkCbGaWOPyfwfILRjbqXzylWkPsoEaK3BqEFkTmlA8uf12F4QrXagxmf8l 8ztGVpvPB+Ie+f/siSfMGVXYAD0ghWP7mhPJpu3XsOf8nxqGOiMuBH/BnGgm1pMbL/YP jzQXABJ15REh6Cw6jCA0rC03bnMRdLqDfdMAl9uPKwYsHbuIbzgJAI3bhNy2TA4dDbOb bWVU/F5Lv7ecWjoCuoazz0olO9+4yTtBKfhox5YLziNbaswDPu7FIOo2MosNtEmvspug nxBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1764684194; x=1765288994; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:date:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=Qv1K7J2piWEBLYsmYS5El8b8US/OwNpgXHLpQ7GMrlY=; b=GE4huX1ZGRzCtwaa3d7foGfXLI/Vir27h8L1hpK/QiC+MhNEG54vun9AJ3ghGuQXXG Hq+MLyHK+F4blqyyGPd7m8OrXm2qWR6ViW46ixMcXFE/t3UvuqE/G6k/xhI3/oX3vQ3+ SF6X1wULoImbMNJhPKmKkoDzCnOoAwuKsNSjBlKatM5c0azyS2T3P/Swsk0fsEoYsyLs GwEhpFCAhHCM2/MG+v35Ztwe8igXu/kPXjoPnub8ePlIbXca7DLGLYIUJUY++86m1n7w kNyP02S13RFCrfe8YRfNoycRo+YBlBognm/pbDoy171DevqncQTiRZ+KGIrU+8LsjbWw iWWQ== X-Forwarded-Encrypted: i=1; AJvYcCXh1vZjm52UHIYurjZg+cfuqJwwgHwPJCdZD+7qBbqPiZBJiJ9FbzjD0d8wuhaLskB+ys15t04jaUStWuE=@vger.kernel.org X-Gm-Message-State: AOJu0YwdTifB+zySBBn0oOg+IOr7CYob/Z5Dqb236cM9gvbVdf2WyKFu i+hXRriajCiwgzv8xRGOsraM/6kbqyPtHsW1sSlyI/RPRL1oFqeAG0P7 X-Gm-Gg: ASbGncviFy1TetNbgX/gJua8IbAl/yHejwXN0v3n9unLvH4FYr16vqkzyBVah4TlWnx W1x1y6B9Gb86b81rKCweCd61+xNeuAKSvYN1Ukx6yNYqtKf3GNp4jA4/Xg05+EGnedDxJS01y4Y Kvmby9gWt6FFoT937Sf/WgyuFs5fu2ZpyVUnMuw7YImQTb2BoCUeFPmV2RH8Lqz/0ouvVAIrEP5 ABQTN8bbmDNB0Z9cyuDEpboEtvNNPCuRSXaxgj9aToB64BFg00Su2RmyUMw9Tvh306Ne/YoRRVs M02A5Re2PXCDF+YywJOve64oC0TeIhaS2/v6riTdsz1loK466bnXAePt9wesPSdamLZfRjXliKu qKovgtVVKDnZugiTvcBnabNi01hbjejk+GDX+RvkLb7pp0OqymWquUU0neYvS5r/kuL7j//Adj8 42wnEb8+2LXinmOvcigtTIivrE4f+uzl3X X-Google-Smtp-Source: AGHT+IFMPwW4Ci4ma2kd/bf6E5zfBDbaLqbg0ejouUGZkkjz6Fd31OThqfP5IxcvJU8zZMZi6pGF4A== X-Received: by 2002:a05:6512:1149:b0:595:90f9:b9d2 with SMTP id 2adb3069b0e04-596a3ea67c2mr17072594e87.3.1764684193847; Tue, 02 Dec 2025 06:03:13 -0800 (PST) Received: from pc636 (host-95-203-3-14.mobileonline.telia.com. [95.203.3.14]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-596bfa48c5dsm4644152e87.77.2025.12.02.06.03.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Dec 2025 06:03:12 -0800 (PST) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Tue, 2 Dec 2025 15:03:10 +0100 To: Barry Song <21cnbao@gmail.com> Cc: Uladzislau Rezki , akpm@linux-foundation.org, linux-mm@kvack.org, linux-media@vger.kernel.org, dri-devel@lists.freedesktop.org, linaro-mm-sig@lists.linaro.org, linux-kernel@vger.kernel.org, Barry Song , Sumit Semwal , John Stultz , Maxime Ripard Subject: Re: [PATCH RFC] mm/vmap: map contiguous pages in batches whenever possible Message-ID: References: <20251122090343.81243-1-21cnbao@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Tue, Dec 02, 2025 at 06:05:56AM +0800, Barry Song wrote: > On Mon, Dec 1, 2025 at 7:08 PM Uladzislau Rezki wrote: > > > > On Fri, Nov 28, 2025 at 04:43:54AM +0800, Barry Song wrote: > > > > > > > > > > + /* > > > > > + * Some users may allocate pages from high-order down to order 0. > > > > > + * We roughly check if the first page is a compound page. If so, > > > > > + * there is a chance to batch multiple pages together. > > > > > + */ > > > > > if (!IS_ENABLED(CONFIG_HAVE_ARCH_HUGE_VMALLOC) || > > > > > - page_shift == PAGE_SHIFT) > > > > > + (page_shift == PAGE_SHIFT && !PageCompound(pages[0]))) > > > > > > > > > Do we support __GFP_COMP as vmalloc/vmap flag? As i see from latest: > > > > > > This is not the case for vmalloc, but applies to dma-bufs that are allocated > > > using alloc_pages() with GFP_COMP. > > > > > > #define LOW_ORDER_GFP (GFP_HIGHUSER | __GFP_ZERO) > > > #define HIGH_ORDER_GFP (((GFP_HIGHUSER | __GFP_ZERO | __GFP_NOWARN \ > > > | __GFP_NORETRY) & ~__GFP_RECLAIM) \ > > > | __GFP_COMP) > > > > > > > > > > > /* > > > > * See __vmalloc_node_range() for a clear list of supported vmalloc flags. > > > > * This gfp lists all flags currently passed through vmalloc. Currently, > > > > * __GFP_ZERO is used by BPF and __GFP_NORETRY is used by percpu. Both drm > > > > * and BPF also use GFP_USER. Additionally, various users pass > > > > * GFP_KERNEL_ACCOUNT. Xfs uses __GFP_NOLOCKDEP. > > > > */ > > > > #define GFP_VMALLOC_SUPPORTED (GFP_KERNEL | GFP_ATOMIC | GFP_NOWAIT |\ > > > > __GFP_NOFAIL | __GFP_ZERO | __GFP_NORETRY |\ > > > > GFP_NOFS | GFP_NOIO | GFP_KERNEL_ACCOUNT |\ > > > > GFP_USER | __GFP_NOLOCKDEP) > > > > > > > > Could you please clarify when PageCompound(pages[0]) returns true? > > > > > > > > > > In this case, dma-buf attempts to allocate as many compound high-order pages > > > as possible, falling back to 0-order allocations if necessary. > > > > > OK, it is folio who uses it. > > > > > Then, dma_buf_vmap() is called by the GPU drivers: > > > > > > 1 404 drivers/accel/amdxdna/amdxdna_gem.c <> > > > dma_buf_vmap(abo->dma_buf, map); > > > 2 1568 drivers/dma-buf/dma-buf.c <> > > > ret = dma_buf_vmap(dmabuf, map); > > > 3 354 drivers/gpu/drm/drm_gem_shmem_helper.c > > > <> > > > ret = dma_buf_vmap(obj->import_attach->dmabuf, map); > > > 4 85 drivers/gpu/drm/etnaviv/etnaviv_gem_prime.c > > > <> > > > ret = dma_buf_vmap(etnaviv_obj->base.import_attach->dmabuf, &map); > > > 5 433 drivers/gpu/drm/vmwgfx/vmwgfx_blit.c <> > > > ret = dma_buf_vmap(bo->tbo.base.dma_buf, map); > > > 6 88 drivers/gpu/drm/vmwgfx/vmwgfx_gem.c <> > > > ret = dma_buf_vmap(obj->import_attach->dmabuf, map); > > > > > Thank you for clarification. That would be good to reflect it in the > > commit message. Also, please note that: > > Sure. > > > > > > if (!IS_ENABLED(CONFIG_HAVE_ARCH_HUGE_VMALLOC) || > > > - page_shift == PAGE_SHIFT) > > > + (page_shift == PAGE_SHIFT && !PageCompound(pages[0]))) > > > > > we rely on page_shift == PAGE_SHIFT condition for the non-sleep vmalloc() > > allocations(GFP_ATOMIC, GFP_NOWAIT), so we go via vmap_small_pages_range_noflush() > > path. Your patch adds !PageCompound(pages[0]) also. It is not a problem > > since it is vmap() path but we need to comment that. > > Sure. Would the following work? > > /* > * For vmap(), users may allocate pages from high orders down > to order 0, > * while always using PAGE_SHIFT as the page_shift. > * We first check whether the initial page is a compound page. If so, > * there may be an opportunity to batch multiple pages together. > */ > if (!IS_ENABLED(CONFIG_HAVE_ARCH_HUGE_VMALLOC) || > (page_shift == PAGE_SHIFT && !PageCompound(pages[0]))) > return vmap_small_pages_range_noflush(addr, end, prot, pages); > Sounds good! Thank you. -- Uladzislau Rezki