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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 360BBC52D7C for ; Thu, 15 Aug 2024 18:05:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C72D86B0198; Thu, 15 Aug 2024 14:05:05 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C22D06B0199; Thu, 15 Aug 2024 14:05:05 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AEA866B019A; Thu, 15 Aug 2024 14:05:05 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 8F5246B0198 for ; Thu, 15 Aug 2024 14:05:05 -0400 (EDT) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 09F2FC175C for ; Thu, 15 Aug 2024 18:05:05 +0000 (UTC) X-FDA: 82455256170.07.545C666 Received: from mail-vs1-f51.google.com (mail-vs1-f51.google.com [209.85.217.51]) by imf15.hostedemail.com (Postfix) with ESMTP id 1C903A0006 for ; Thu, 15 Aug 2024 18:05:02 +0000 (UTC) Authentication-Results: imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=obRyGRMX; spf=pass (imf15.hostedemail.com: domain of yuzhao@google.com designates 209.85.217.51 as permitted sender) smtp.mailfrom=yuzhao@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1723745006; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=Z5Us/X2wfBtenEMzSp227D6K2gQmF1SnwKG1OtyaOow=; b=60/Hh5loXIQRpjgNPsOy53v5VqV4No/RX2BOBaeGZGsfie7Zoo5CosQRmk+EvWERSAjsAL OzFikkRuYSIyPAmivEMzW1Tsk53R664DUDhoewYI54GjAKQwpl/WvqmjQwM8lxw7UodStu Jjkn3by4S3QAAh6Quzui3w++RVAkeH0= ARC-Authentication-Results: i=1; imf15.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=obRyGRMX; spf=pass (imf15.hostedemail.com: domain of yuzhao@google.com designates 209.85.217.51 as permitted sender) smtp.mailfrom=yuzhao@google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1723745006; a=rsa-sha256; cv=none; b=ljIPaM2F2rbSTWUu5OEEuxOithijQt5b2g+Tsn4lsibTiB2LgS9OFthLSOl+uMGLWidvE9 xB2zGduoPX82MATBdc2+7z6GsciEPjI4L8AIZHTp8629BcFeSB7f+RS2eYteftcG2CfkQ3 uqQrBKnRieXKKaGiBZ+1Ywr/dfmdP5I= Received: by mail-vs1-f51.google.com with SMTP id ada2fe7eead31-49288fafca9so454356137.3 for ; Thu, 15 Aug 2024 11:05:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1723745102; x=1724349902; darn=kvack.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Z5Us/X2wfBtenEMzSp227D6K2gQmF1SnwKG1OtyaOow=; b=obRyGRMXb3tmzdl+uEkQtN97Hwmt09UFgOZEXfr4hDTrcogQ4dfSuxWGjtSkobwmjO 0UI7Sc5eqfZ3XthqQKEWuv+9fYETKxta+SEx4A+sYSRFKhfckWA6iSti5R9SWv5SlV0S 7KRfOxLDwJgjPjepfQT+Ech5E0cLqEfqEwpji82dseT1kKSJj5Sw3tDjedQqG63T4gBw rF1JGpKFmMYVkQrqMo7x8FGOMIfpCOaZyeSKvA++athvFHrn1YwVqA3JR4QxT2mFSk++ +a1YY967k6M0OXPt0b99S15yvEm0m4uZzUh32D0iqPOXaXqoidYCDHYsg9/7WwF6hOGk blpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723745102; x=1724349902; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Z5Us/X2wfBtenEMzSp227D6K2gQmF1SnwKG1OtyaOow=; b=ocUVaGCvreFiTXlfMvDI93D1ELxBq60PT14B4WRFkFWsJ4j0Lm0/YdiMuPRUD5Wa67 PvlqtiPGGBqdhPfLP/3NANR1RogU3YYhrQES3Xhgu70iAIlpL+9V5D9fVjYGol5v8qxs 64nXAdeoBbSnH8GZDyG05nhdfJ6rgUhWDK+GIuCRxQoMCaqiqEJ5/zayQxA0KoPVMPU6 VSma5vOgJWru5ZCVYAF6LWKhVIbfXgp2J90R5+ep2ADa2u5/ZeyDkNSrefQCSyW51AXh RXIz3XXxzYhM0IXNHvIURLtO/wfBS5VWMak1G2AKnGQ+F6APRWOF+xSQfzXw1MGIiqtS adpw== X-Forwarded-Encrypted: i=1; AJvYcCXyIpspmq0tNVUnMafqTrpbo0vbzAC81Z5Gwq0bOoNNxRHB3Biq1phEsu+c1Z2u1/l7+WUqCVysY3CmiE//osjlRf8= X-Gm-Message-State: AOJu0YzJ4Q051APi1/b+YzdqEAqszh0GcH9Nf/ilJ5iLMXbiWrC9it4V 4rYu/ayJ+nggzuWs81JOTi1tRYZN8wznjMM8jndhq6PYFJAaLCE/hNRuOO0oUiZlpBQnqGz6obS TxTd8NzGs5s0IkMnevzHYH36AO2xLdr80VW9oVsAGmsYtyacF3Yab X-Google-Smtp-Source: AGHT+IEpY1C8Xn02YoSSkv/8rKqTGWB40QjknSmPTnz1yERD6wKxUFKF8bdDsGxfyEBrkMXojDAVqMjxJ/gh3kXVtS0= X-Received: by 2002:a05:6102:419e:b0:493:b006:e1a with SMTP id ada2fe7eead31-497798b92eemr810832137.7.1723745101741; Thu, 15 Aug 2024 11:05:01 -0700 (PDT) MIME-Version: 1.0 References: <20240811212129.3074314-1-yuzhao@google.com> <20240811212129.3074314-3-yuzhao@google.com> <6d19d790-92d2-40f9-9797-cc08bf3921fe@huawei.com> In-Reply-To: <6d19d790-92d2-40f9-9797-cc08bf3921fe@huawei.com> From: Yu Zhao Date: Thu, 15 Aug 2024 12:04:23 -0600 Message-ID: Subject: Re: [PATCH mm-unstable v1 2/3] mm/cma: add cma_alloc_folio() To: Kefeng Wang Cc: Andrew Morton , Muchun Song , "Matthew Wilcox (Oracle)" , Zi Yan , linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 1C903A0006 X-Stat-Signature: ich9qxgyx1xrgndyfimfj3pf3zqjfxfo X-Rspam-User: X-HE-Tag: 1723745102-353365 X-HE-Meta: U2FsdGVkX1+Zr1MiYHUktvHT+3x2kE0KH3dPPm6bVCA39oL4iTyfjHS6gBoWJ9kukxq5LEcXLhajWQgzne7KZpgmhGBSUkCUTykrZRb+D3/wSpV0ek4LAl+a2uE4wGfm68z0dvf6y/uE3IM7toEpTJOfcLcfkgRYWh+pRtdsyuHWu7yRus3ScRnoso5g1L+Ye1NBAC3miZ89XHMm2sxzcwzWmNr1l/0/8byBGjLkiZL1XqivT3v44kyiS93WngNYdUR3HR+hcWsFSLJ02Z3PkDKRTqi5F5fLN8YtyMD2v3fTaP3ZP6u1TUKZAZ2AfK5UIYet8wqxDpsBnZNsHT1Dx7/ETkkpgr2xzOyYEMJSVUhWewYDgpofoCAFFoR8nt+owh+w5ryJeyoVtBPfA+4fLaM5ZbpSb8uwjS+23sBv35saUfo0cmknAX49GDqrDrCyy70CubJgRkQm+IgPAkkJfBeCS5ShPHCW2k73yTpOkImHEm/qQahLvsqLw4jXgxEXX8nZAzUoBGIZ5TOHfKk/puO1udwHV613jQY3OGVA+dFyDFj8LovvGGYWX9F9uEkK6ttrDNMOuZjhsYGMYp6ZBtbuSMqZG1VLx8f1yplJxrXUTMPvnrIz8AiCvN/EJLwTGTnF/LAUnwehVBGQBS/F5/NIFzre132QG5pAufymGsGdBZVrmOgDkQ9GsZOEvhFRXclb2sPqGBw6BUEZmuZZVXZImcXvEByjuWDm0k7iwPYl/+3zZGhQJkKZ1f7OCLeAg5u5+ISExBz1RyIkTjsC3c5J5t0VKIHjAPY7yWQ9nj51rOoTfUgYsvfggpM0O+J8qRj0PR3psUqxaQvPIw+o1zdeECIShhj4VzXEkbbAhakJCasM6GKeY119g9SZ5/4sye0wwY4KdGAwdx1lKxuH5FIOEnVBa0A+XRWTA2YVf8YzGlZpEFibVWGHE/yspT9xY4F1C3SxdCDj053ERvJ gsNOnM81 TQb6i8lxJvSWB4Cslsq3Jcy+1chkiHW9JZQajDzRnUSeO54Khz6ukUkAFOqG9logJypvggglNsMtIaKueZ5iLEj3dggV01epA3/vOLZcSby1RNP0fv75SUGjoA8nNPq4d4fx+nVrhIJRdvVFJLSBTJqqEpngrrkTBYlRj5pXGLtvP0PMf1Z9l7yJ4+uj17XgkY2/8txD/s1kwsodePBt3NcKUuXKoq+HeEbs7drBhCYCUxAjqhRozlHMhg7j7wKiQku9TxMz7Xx+oSy3BYHu4DCzJhCKBnbDu5fTPl9gQyZ2oJOTYGyYXp8QPyCWbeP4ljUWAU97T3dKq7RvTXscLAhk4fQ== 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: List-Subscribe: List-Unsubscribe: On Thu, Aug 15, 2024 at 8:41=E2=80=AFAM Kefeng Wang wrote: > > > > On 2024/8/12 5:21, Yu Zhao wrote: > > With alloc_contig_range() and free_contig_range() supporting large > > folios, CMA can allocate and free large folios too, by > > cma_alloc_folio() and cma_release(). > > > > Signed-off-by: Yu Zhao > > --- > > include/linux/cma.h | 1 + > > mm/cma.c | 47 ++++++++++++++++++++++++++++++--------------= - > > 2 files changed, 33 insertions(+), 15 deletions(-) > > > > diff --git a/include/linux/cma.h b/include/linux/cma.h > > index 9db877506ea8..086553fbda73 100644 > > --- a/include/linux/cma.h > > +++ b/include/linux/cma.h > > @@ -46,6 +46,7 @@ extern int cma_init_reserved_mem(phys_addr_t base, ph= ys_addr_t size, > > struct cma **res_cma); > > extern struct page *cma_alloc(struct cma *cma, unsigned long count, u= nsigned int align, > > bool no_warn); > > +extern struct folio *cma_alloc_folio(struct cma *cma, int order, gfp_t= gfp); > > extern bool cma_pages_valid(struct cma *cma, const struct page *pages= , unsigned long count); > > extern bool cma_release(struct cma *cma, const struct page *pages, un= signed long count); > > > > diff --git a/mm/cma.c b/mm/cma.c > > index 95d6950e177b..46feb06db8e7 100644 > > --- a/mm/cma.c > > +++ b/mm/cma.c > > @@ -403,18 +403,8 @@ static void cma_debug_show_areas(struct cma *cma) > > spin_unlock_irq(&cma->lock); > > } > > > > -/** > > - * cma_alloc() - allocate pages from contiguous area > > - * @cma: Contiguous memory region for which the allocation is perfor= med. > > - * @count: Requested number of pages. > > - * @align: Requested alignment of pages (in PAGE_SIZE order). > > - * @no_warn: Avoid printing message about failed allocation > > - * > > - * This function allocates part of contiguous memory on specific > > - * contiguous memory area. > > - */ > > -struct page *cma_alloc(struct cma *cma, unsigned long count, > > - unsigned int align, bool no_warn) > > +static struct page *__cma_alloc(struct cma *cma, unsigned long count, > > + unsigned int align, gfp_t gfp) > > { > > unsigned long mask, offset; > > unsigned long pfn =3D -1; > > @@ -463,8 +453,7 @@ struct page *cma_alloc(struct cma *cma, unsigned lo= ng count, > > > > pfn =3D cma->base_pfn + (bitmap_no << cma->order_per_bit)= ; > > mutex_lock(&cma_mutex); > > - ret =3D alloc_contig_range(pfn, pfn + count, MIGRATE_CMA, > > - GFP_KERNEL | (no_warn ? __GFP_NOWARN= : 0)); > > + ret =3D alloc_contig_range(pfn, pfn + count, MIGRATE_CMA,= gfp); > > mutex_unlock(&cma_mutex); > > if (ret =3D=3D 0) { > > page =3D pfn_to_page(pfn); > > @@ -494,7 +483,7 @@ struct page *cma_alloc(struct cma *cma, unsigned lo= ng count, > > page_kasan_tag_reset(nth_page(page, i)); > > } > > > > - if (ret && !no_warn) { > > + if (ret && !(gfp & __GFP_NOWARN)) { > > pr_err_ratelimited("%s: %s: alloc failed, req-size: %lu p= ages, ret: %d\n", > > __func__, cma->name, count, ret); > > cma_debug_show_areas(cma); > > @@ -513,6 +502,34 @@ struct page *cma_alloc(struct cma *cma, unsigned l= ong count, > > return page; > > } > > > > +/** > > + * cma_alloc() - allocate pages from contiguous area > > + * @cma: Contiguous memory region for which the allocation is perfor= med. > > + * @count: Requested number of pages. > > + * @align: Requested alignment of pages (in PAGE_SIZE order). > > + * @no_warn: Avoid printing message about failed allocation > > + * > > + * This function allocates part of contiguous memory on specific > > + * contiguous memory area. > > + */ > > +struct page *cma_alloc(struct cma *cma, unsigned long count, > > + unsigned int align, bool no_warn) > > +{ > > + return __cma_alloc(cma, count, align, GFP_KERNEL | (no_warn ? __G= FP_NOWARN : 0)); > > +} > > + > > +struct folio *cma_alloc_folio(struct cma *cma, int order, gfp_t gfp) > > +{ > > + struct page *page; > > + > > + if (WARN_ON(order && !(gfp | __GFP_COMP))) > > + return NULL; > > + > > + page =3D __cma_alloc(cma, 1 << order, order, gfp); > > + > > + return page ? page_folio(page) : NULL; > > We don't set large_rmappable for cma alloc folio, which is not consistent > with other folio allocation, eg folio_alloc/folio_alloc_mpol(), > there is no issue for HugeTLB folio, and for HugeTLB folio must without > large_rmappable, but once we use it for mTHP/THP, it need some extra > handle, maybe we set large_rmappable here, and clear it in > init_new_hugetlb_folio()? I want to hear what Matthew thinks about this. My opinion is that we don't want to couple largely rmappable (or deferred splittable) with __GFP_COMP, and for that matter, with large folios, because the former are specific to THPs whereas the latter can potentially work for most types of high order allocations. Again, IMO, if we want to seriously answer the question of Can we get rid of non-compound multi-page allocations? [1] then we should start planning on decouple large rmappable from the generic folio allocation API. [1] https://lpc.events/event/18/sessions/184/#20240920