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 55739CD13CF for ; Mon, 2 Sep 2024 17:05:04 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DEAD78D00FA; Mon, 2 Sep 2024 13:05:03 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D73A48D00EF; Mon, 2 Sep 2024 13:05:03 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BED5B8D00FA; Mon, 2 Sep 2024 13:05:03 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 9C2728D00EF for ; Mon, 2 Sep 2024 13:05:03 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 4FA321C19B9 for ; Mon, 2 Sep 2024 17:05:03 +0000 (UTC) X-FDA: 82520423286.15.E819C4E Received: from mail-il1-f175.google.com (mail-il1-f175.google.com [209.85.166.175]) by imf07.hostedemail.com (Postfix) with ESMTP id 66AC640009 for ; Mon, 2 Sep 2024 17:05:01 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=1Nw8gHqD; spf=pass (imf07.hostedemail.com: domain of yuzhao@google.com designates 209.85.166.175 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=1725296576; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=b2sUViWtGSE+SSQUfzqcc8NDtch4cMUiPSrgHV/FWcs=; b=1CoJx9teSgnuHF/R5eWK5Ywooq3Zio8rRooVNC7Bvm0VDHYC479Lig8tMTUHPBsupSH/v4 kgop3WH9c+82kKiuIaQ9kfhvxkCA3yDayypOkivam1kEE/7VBhqnfYIivZmsjZNP7GWKfc HJjP7CnJXbWQPWLTHHNHFsrb7NJ6Iso= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=1Nw8gHqD; spf=pass (imf07.hostedemail.com: domain of yuzhao@google.com designates 209.85.166.175 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=1725296576; a=rsa-sha256; cv=none; b=wlvIiHYEBN3QpRr75FR7HybtrZ4sxH/Mvgn6t5oja9Ih8ah0cOnK8NowoTdn0JuGg7pyOL zH6tT9uvLkre/flt+uWr7jho8sYu3xoa7I63ItIo14CUpXDZS3DiI76+jdXsTaGDtbugNs ksnH4bXJIiNaKMcPt1TT7h0O5iDk/3U= Received: by mail-il1-f175.google.com with SMTP id e9e14a558f8ab-39f37a5a091so14847305ab.1 for ; Mon, 02 Sep 2024 10:05:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1725296700; x=1725901500; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=b2sUViWtGSE+SSQUfzqcc8NDtch4cMUiPSrgHV/FWcs=; b=1Nw8gHqDbtF9ErYmhTfi1QS74syf5XRQXR7GSNv67ved2AoOBdNyZBpl3S+e3sUZ40 uG81eqBChKdEsEItXITy4YAjtfAqnr4PJgT2xc+xgBTlDQZwl/Ak3I2rnlaPufMW4IfA h75S07uLBJYrwz3YYC/IAbF+yzcXdcYbIMmGY+6dNR/TuuFURmomnZourz3hx3qoKuzw q6q0R1Ps+cCG+74nxkk8aFE+1USNm8jpOd5pVF3hqKPRWVHLFq31dyLtCAvl1ztOgPvA yWPWMXe2ACLAErocf5z1Ha6wmmKyBDgW/3vlZqbB/ON0O2+5j0m7u+2Joc+FNuUB+vci bvBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725296700; x=1725901500; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=b2sUViWtGSE+SSQUfzqcc8NDtch4cMUiPSrgHV/FWcs=; b=tjDgnUMDJ9gc+IrjKCykLXrlPcUd2Mg84tLdQ1UCyc8wYhuMXlNLJu9+hBQxK+HDHz 45Khh6ZZPVJWOPtLqwOygFx4TtC+8diMXAEkwunByCsTicMnFbys98aHnXbLsmo9ksRi B2CTQP0CMbkExnQyfU3Ux3jYzE3QDR1Hn+iik5WZJsOFu0Xlb929GmXSaxxJAWAwjBxP +ow3KFWOMxebmxODLxVxxHUooRT9kU1+bznJ+h1S9SRCt7oIb6f3iVSOR8GXPe0VYcM7 smZB/r/f/76kbw4QrDCyc2S4IAxwr/i4BARZm1wRme4TcaXWCPgvELyYOy0DB0XvYSG3 bmbA== X-Forwarded-Encrypted: i=1; AJvYcCXhD6db/pkkcYxE+5r551v+G7deP/SJ+wSsTbMnZ3Rot6ulqJgOj+4FnP0E1MqAsA5dkvFD/pEQxw==@kvack.org X-Gm-Message-State: AOJu0YzU1RP0cm/hKgIuz5HOlaSrCm2yj7/bF1onTgYNn8zm5gmrbE/w Qr5X5vsNcyQ2ONUtJ25KUelvh2wOOBtcMuDmTgBw8ji2gsB3hRs/H4ARxb7pxQ== X-Google-Smtp-Source: AGHT+IF1Ibh5hMTxP/3lB9P/E9K7M2mspEronZFTVewKXeI3jF3D1jNGtcJqhlIkQf6SIKHS5LHCJQ== X-Received: by 2002:a05:6e02:1c89:b0:398:fa06:1d71 with SMTP id e9e14a558f8ab-39f49a31d36mr85422125ab.7.1725296700079; Mon, 02 Sep 2024 10:05:00 -0700 (PDT) Received: from google.com ([2a00:79e0:2e28:6:485e:a0d2:7c59:d251]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-39f3afaf38bsm26864565ab.19.2024.09.02.10.04.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Sep 2024 10:04:59 -0700 (PDT) Date: Mon, 2 Sep 2024 11:04:51 -0600 From: Yu Zhao To: Andrew Morton , Muchun Song Cc: "Matthew Wilcox (Oracle)" , Zi Yan , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH mm-unstable v2 2/3] mm/cma: add cma_{alloc,free}_folio() Message-ID: References: <20240814035451.773331-1-yuzhao@google.com> <20240814035451.773331-3-yuzhao@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 66AC640009 X-Stat-Signature: yg48o3ieuc73qo15ajg5btxzsyaj94sb X-Rspam-User: X-HE-Tag: 1725296701-694103 X-HE-Meta: U2FsdGVkX19/9mggER0smtOGx2Xigbo58Sg5XbfOiVOovhyez6n6aL36Qr79sI//QkFS6OqBU4ZOOgrUYb7YquI5CEL5x8rBhGxVX/Cy1RVX8PtctYtI53poKj9X0qPgltcoQ7pljGVaN8YirVI6A65pWddCnBtmMxMSZAriuqq9+Ng/rGvw/+zC3OY9HSaK1mLyzkh47OzWsLJz1Qk9uiq7wCLA5je0vIrEqwjehaHJx33cLwn3WGyBc+luSiCqDXr/99Qc8agvvgkpbqn9n7PRTZj3ItXGejgpqcWtDmNcvhEAHRWmY70Lb5bCU1ZUkXXIpLN2mWVttmdBDRUNIZrkx41qgZItv/0l7c+IOTGcpb8j6rgsF75dcd63/OHWwUJMqAGmjQ/qlzalGoHWfZqrUYjbKSY+bHs7vOJ8ZZskFUhNpC+NrVKow9sNqH0oXpBa2rrEQvnDTS1jtJQtFyeUGVVL0cIsJU0KDqGKuEdi4ju7ynXphED9W6DB0q7b53zF1hirsRkaUFUtcPapjJdl0llzqK23WHahNq2f8BGHPooCGklORuu9l1MZ+7haNBqVIUw+bjTC7rSH9ptTfwYhU17y3G7ncyRuwmjEC0nCthvUS9lYq9FthQACul1LvIHpPwb6j+i3+pV5CyVVhRP9u+40+Kjy7pdDHxQfVYReZEydi1e/+fRTwjZgXUhHeB8Q/NWnTqwhDP/1aW6gdf8hTQxpj6v9xRcWghLJuX/v35GNIOkuWXKdyXnBZT2csdqDI9x3P6bWm5EQzE9HOg4f8OUfFF6Gl7BfkBNgnO9cKrp9kGwfQ3MBhErxqu2xQ7ol0zAqo213TUnVGERuQH6c7WLR5uQFj1MknVF8IEYzlHe+cGaAJWJMaqx8Z/0lC8+9BmksHneKPrZa1r2Ylu7uNUkO4jhG826J4RUELiY+8PyKW84KuPNLCa32Ohh//XRXMpw0SM3zowcx1qL b3Y8Hgdr HhUb1gQhAPwlERZPrsuVHsN2z/8eWMUfa0O9SROnJlecb0r4WncF1wd4uBpU9WLs1LGIYhNsHGgWcZwaQuCRUpnTJE6/nO3GExSr6QnVLqMv+45FCQR+04WSVO1FGuUQyrRCtWqc3A0JFmRBmJBUMoLhhx3SqLURsh/ttoV/5cQEQDi5gKOtu5NNja/hyTaR0GDLWI0G5Uegl7xTfRbXTw4s3nJH+C/2ndswyhnp79kg9FKdeUMDId2+QaF0g4Jf5f/mXLNnC0H/Jt1IvObq/Ks4keVvZgv13uxjLajoDE8ggILo5M6bFVY4+/CCdCFufdshvN1+ArF6KVrij7muX1+DlnSpjaSHaNmR2CrJ6Eu+JeoUXsl1xMGU4mg== 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 22, 2024 at 11:24:14AM -0600, Yu Zhao wrote: > On Tue, Aug 13, 2024 at 09:54:50PM -0600, 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_free_folio(). > > > > Signed-off-by: Yu Zhao > > --- > > include/linux/cma.h | 16 +++++++++++++ > > mm/cma.c | 55 ++++++++++++++++++++++++++++++++------------- > > 2 files changed, 56 insertions(+), 15 deletions(-) > > > > diff --git a/include/linux/cma.h b/include/linux/cma.h > > index 9db877506ea8..d15b64f51336 100644 > > --- a/include/linux/cma.h > > +++ b/include/linux/cma.h > > @@ -52,4 +52,20 @@ extern bool cma_release(struct cma *cma, const struct page *pages, unsigned long > > extern int cma_for_each_area(int (*it)(struct cma *cma, void *data), void *data); > > > > extern void cma_reserve_pages_on_error(struct cma *cma); > > + > > +#ifdef CONFIG_CMA > > +struct folio *cma_alloc_folio(struct cma *cma, int order, gfp_t gfp); > > +bool cma_free_folio(struct cma *cma, const struct folio *folio); > > +#else > > +static inline struct folio *cma_alloc_folio(struct cma *cma, int order, gfp_t gfp) > > +{ > > + return NULL; > > +} > > + > > +static inline bool cma_free_folio(struct cma *cma, const struct folio *folio) > > +{ > > + return false; > > +} > > +#endif > > + > > #endif > > diff --git a/mm/cma.c b/mm/cma.c > > index 95d6950e177b..4354823d28cf 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 performed. > > - * @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 = -1; > > @@ -463,8 +453,7 @@ struct page *cma_alloc(struct cma *cma, unsigned long count, > > > > pfn = cma->base_pfn + (bitmap_no << cma->order_per_bit); > > mutex_lock(&cma_mutex); > > - ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA, > > - GFP_KERNEL | (no_warn ? __GFP_NOWARN : 0)); > > + ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA, gfp); > > mutex_unlock(&cma_mutex); > > if (ret == 0) { > > page = pfn_to_page(pfn); > > @@ -494,7 +483,7 @@ struct page *cma_alloc(struct cma *cma, unsigned long 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 pages, 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 long count, > > return page; > > } > > > > +/** > > + * cma_alloc() - allocate pages from contiguous area > > + * @cma: Contiguous memory region for which the allocation is performed. > > + * @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 ? __GFP_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))) > > And here too. Thank you. > > diff --git a/mm/cma.c b/mm/cma.c > index 4354823d28cf..2d9fae939283 100644 > --- a/mm/cma.c > +++ b/mm/cma.c > @@ -522,7 +522,7 @@ struct folio *cma_alloc_folio(struct cma *cma, int order, gfp_t gfp) > { > struct page *page; > > - if (WARN_ON(!order || !(gfp | __GFP_COMP))) > + if (WARN_ON(!order || !(gfp & __GFP_COMP))) > return NULL; > > page = __cma_alloc(cma, 1 << order, order, gfp); And the following instead of the above, if we don't want to warn the potential bug. diff --git a/mm/cma.c b/mm/cma.c index 2d9fae939283..00c30dcee200 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -522,10 +522,7 @@ 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 = __cma_alloc(cma, 1 << order, order, gfp); + page = __cma_alloc(cma, 1 << order, order, gfp | __GFP_COMP); return page ? page_folio(page) : NULL; }