From patchwork Sun Sep 29 03:27:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiang Gao X-Patchwork-Id: 13814808 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 AFDF1CF6491 for ; Sun, 29 Sep 2024 03:28:07 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C2FA36B0181; Sat, 28 Sep 2024 23:28:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BDFDF6B0183; Sat, 28 Sep 2024 23:28:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AA70A6B0187; Sat, 28 Sep 2024 23:28:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 8D4436B0181 for ; Sat, 28 Sep 2024 23:28:06 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 3F14CC1660 for ; Sun, 29 Sep 2024 03:28:06 +0000 (UTC) X-FDA: 82616342172.25.67F6704 Received: from mail-pl1-f176.google.com (mail-pl1-f176.google.com [209.85.214.176]) by imf30.hostedemail.com (Postfix) with ESMTP id 8627180004 for ; Sun, 29 Sep 2024 03:28:04 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=eKR1KbM8; spf=pass (imf30.hostedemail.com: domain of gxxa03070307@gmail.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=gxxa03070307@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727580360; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=UE8V6Td1Fw+A1+MJmjCr8qJzqzcVKk/EZFo8rjJKFqU=; b=DffSJgphw88pn65ribNPtkj7afM8a1HYbHQWHJ/kcppHIpg8Nb6G646GW/2gz5qM5AJPOU vE3qXNles56TqBBCMOv2v24W6y+n/+01iSteQrG3fyur6PmXClZE19lUd99Od4sgqaCJNf hRw2vebg9AyghI7gbb4F9CJdsARosqU= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727580360; a=rsa-sha256; cv=none; b=UxVrSZk0GFP+kBAkyumlPXyZ6VVWl6XfXKXy6JbeW/NCl95Q+J8Ten3boRoDDWuYxqFbEU dIuRns/e6tsmNTYk5UH0ODpMjmsi76qeYNJte878o9n1eqvVAcHBhP+AgSqxth6jQ28hA5 2SHjAqy8UgrIhwsnS2PIIkNzZnJsVYU= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=eKR1KbM8; spf=pass (imf30.hostedemail.com: domain of gxxa03070307@gmail.com designates 209.85.214.176 as permitted sender) smtp.mailfrom=gxxa03070307@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f176.google.com with SMTP id d9443c01a7336-2053525bd90so31209875ad.0 for ; Sat, 28 Sep 2024 20:28:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727580483; x=1728185283; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=UE8V6Td1Fw+A1+MJmjCr8qJzqzcVKk/EZFo8rjJKFqU=; b=eKR1KbM8fdR4Dir76nbui9fp390aNaIImPvTmNbgl5bMh0fbIOknODjlKYYRUCLa6x IiaSHDjwMAWJpmJ8O234aaRSJQorDuzsuxWTZ4SGMgAPF/9qONXDmmrWoyqnCFxnqPIH +yY9iNqEMIMZosfk7AYlf8r2cMk85KMK51/eTZ5B2i7r8cTa7hZlColAhOG2hE6j0PWV 96UO4AQ97dR5ckmHFX/8/J1/SHidAy7fOEqtIiap9f/Wcwp4T+nlckuAhGQ+14S0VODW 14ybW9GjGSbTnC5ifwKTaNAZLjxwMkCN//vPHuH9uFv/XRPZH+00eIewT4Dr42h5K7G4 shSA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727580483; x=1728185283; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=UE8V6Td1Fw+A1+MJmjCr8qJzqzcVKk/EZFo8rjJKFqU=; b=uAPx2nXWk8oj7tP+XukvEjtiXXpJwmdBZtQG7kByP7ugKYI6JkWLJeWxoUNQAJ/jFL TeK11k1fqWSNRq95Z/gWSr4Ixd4nrq1XuhGvHmuUO3QmMiCLLdlrLv5jkj4tRVZ0PJhp r01Ex+k6KBE1xLimooxqIkLopH/8gsygdiLhjwxxTxElA7TRjp8sGzI0UKe7ZN2/dvJG scMulChc+47NsraZjA0bTcgPb1FhY340ZLGyMUlfqoye3RmCycpCiQZ19G4Srf0FfQLn w51ZVy38mzdutlRbTSa8nbmSZh8C6IDzCdZ5FV2G0x9j9G+luwDpNTUIHZONEExe5opi xOzA== X-Gm-Message-State: AOJu0YzcDCbCZ+LTa0lHnpFvyry5yxQ30FTC+0NhfMDGoVREkMMO2dGE dnbnaLPEOmJ8jTtTN09nni2b7sYKX1dSxTO+UWoAZoZ4ahxQ/hRD X-Google-Smtp-Source: AGHT+IHsKCSR+OwxmfRjQdp2L2pSY3A7ZWZwjGQdY2SI2pU6AjcDsn4M0sLY7hurx0bNFRDEB1l1mw== X-Received: by 2002:a17:902:d4c3:b0:20b:7731:e3f8 with SMTP id d9443c01a7336-20b7731e676mr8372045ad.26.1727580483093; Sat, 28 Sep 2024 20:28:03 -0700 (PDT) Received: from xiaoa.mioffice.cn ([43.224.245.180]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20b37e115e7sm33482265ad.153.2024.09.28.20.28.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Sep 2024 20:28:02 -0700 (PDT) From: Xiang Gao To: akpm@linux-foundation.org Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, gaoxiang17 Subject: [PATCH v2] mm/cma: print total and used count in cma_alloc() Date: Sun, 29 Sep 2024 11:27:57 +0800 Message-Id: <20240929032757.404707-1-gxxa03070307@gmail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Stat-Signature: 5p8n9mm9tczdmjf5ud87mqz7z14hxrhz X-Rspamd-Queue-Id: 8627180004 X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1727580484-316594 X-HE-Meta: U2FsdGVkX19SS4mtMxJbb6Aa6bxaZ2xe45fwKy6Onj9Z4livEZ0uqI42b7FzJBP0SlOJhIkZ63yp53S5n6AxM3dM+ccp3QYtRhdSMWw+1Atgw+8Q5/Msnu2Nl16OHNz3z5zTNlEz4ldVyS2be8IyPpWohSsfLq6TPUvBLSPVN0A0CXT8g89+8L3DLKyrZplNaYc3H2txQkIDUtyDDpi9jH3Yj51DmoyMv7xHEjT33h4/w4QfSWWmFA0uuoEjpLQYWO6YyOg92Hz+DXd02xJ6NkDQciizijjJyNEirH25b+Cjsw197811keaIObj0Gj/YiVp2NGiPTKToveAFY/7ueQHZUEJ8H9aXXuzEeUHu2pW6rbQA/oKWhY6TZvcRlZKoI1Sg5A9exg4/Z5hQb8qeiKx37akR2ZShW79lHX79oOfIfDIAF5A+hZFAMpLBiPzLtW6iBw3u9ZjCpAXmD7qMb/UfXFYRqLrrgyo0JLaXLuoxhczh5wNlC3Q5ggdusY05oIjtVB9nR+ESmKGyO9DU4YMohBIlLGV7D7XCrEESJyLL+pamMEjb75Y4WrdnPsM78Zaxr3FfDzIUpP9RJ7RjZvF+LSbO0dufmFkvc1XvK02KlaJEQZE4Whoysxhg5M2TJ59wu0La0MEVC8ow5l/H2m2EtUDczebiFQ5FcQCGxZrGa4FRav09O1llnlzNcaiFbl1+r2f3uvuTYRUO6UTIFwPUspfyEOMd3rFkVNsrYXA0tn1J5VZEJn+HiHoHFbL1qmCflaWE9MbqbSzHio9pDEbw+0955CT8nuvCyNueThK5BAzN/IgL9Tfmb4vJH9VLplphTZTkuDg06mKlNyX4N98We8vM9xqLjgfMCIgt7zpxZMZkR7wCf3PJXt2yA3Q1MZyrarUkjSIQSwDexoEQgpztyQey6YnWpAw+625j09jpLKyTcubjlTeNYeVJ+0OK0PXhO2fexg5Zt0onhPS Lm5Ao8AU vxc+YzV7cn+TgdqsAheEf52YBi1E/6nGJ8bpt8H118xb0t54W2yL+5nej7VhIUGFHrMB6Mq3+Ii1C6gbgIRcikd+oZdFwVcP6WIpZANWppgKl1wG2G7WYqqGowDRsrY+SBIY0HIOv7pOXRqjuTBiWx2kuDsNfRkA/59sXftq03iogOKJDHHNi7WQAzYcV73zcgfTPjD8K9EGcbfSI2fcSaIZbdFyW8tgibou16CQcuWiWZMW0mbaC5HDewS1IdFs0oSqLgNzHQ7H/nb2f8vGi8Vu67uQ8WrInqlOEIeB221l30JccdOed0D3bDsYdxmLjDs+jDP7G7B3ujeqY6WnFNHi4iDF6ZfEG6Cboe9OtOhRhIvSwuuTg07zats3jQwukiD70x09QFUo5qgmFbdybKbTgL7U9bSUE1w2WDYfwWSsV2mw= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000498, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: gaoxiang17 before: [ 24.407814] cma: cma_alloc(cma (____ptrval____), name: reserved, count 1, align 0) [ 24.413397] cma: cma_alloc(cma (____ptrval____), name: reserved, count 1, align 0) [ 24.415886] cma: cma_alloc(cma (____ptrval____), name: reserved, count 1, align 0) after: [ 24.069738] cma: cma_alloc(cma (____ptrval____), name: reserved, total pages: 16384, used pages: 64, request pages: 1, align 0) [ 24.075317] cma: cma_alloc(cma (____ptrval____), name: reserved, total pages: 16384, used pages: 65, request pages: 1, align 0) [ 24.078455] cma: cma_alloc(cma (____ptrval____), name: reserved, total pages: 16384, used pages: 66, request pages: 1, align 0) Signed-off-by: gaoxiang17 --- mm/cma.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/mm/cma.c b/mm/cma.c index 2d9fae939283..90b3fdbac19c 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -403,6 +403,17 @@ static void cma_debug_show_areas(struct cma *cma) spin_unlock_irq(&cma->lock); } +static unsigned long cma_get_used_pages(struct cma *cma) +{ + unsigned long used; + + spin_lock_irq(&cma->lock); + used = bitmap_weight(cma->bitmap, (int)cma_bitmap_maxno(cma)); + spin_unlock_irq(&cma->lock); + + return used << cma->order_per_bit; +} + static struct page *__cma_alloc(struct cma *cma, unsigned long count, unsigned int align, gfp_t gfp) { @@ -420,8 +431,8 @@ static struct page *__cma_alloc(struct cma *cma, unsigned long count, if (!cma || !cma->count || !cma->bitmap) return page; - pr_debug("%s(cma %p, name: %s, count %lu, align %d)\n", __func__, - (void *)cma, cma->name, count, align); + pr_debug("%s(cma %p, name: %s, total pages: %lu, used pages: %lu, request pages: %lu, align %d)\n", __func__, + (void *)cma, cma->name, cma->count, cma_get_used_pages(cma), count, align); if (!count) return page;