From patchwork Wed Feb 17 17:00:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Minchan Kim X-Patchwork-Id: 12091917 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=-16.8 required=3.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 20D5BC433DB for ; Wed, 17 Feb 2021 17:00:33 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 9DD3064DF0 for ; Wed, 17 Feb 2021 17:00:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9DD3064DF0 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 28D7A6B0071; Wed, 17 Feb 2021 12:00:32 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 23DED6B0072; Wed, 17 Feb 2021 12:00:32 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 153EF6B0073; Wed, 17 Feb 2021 12:00:32 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0114.hostedemail.com [216.40.44.114]) by kanga.kvack.org (Postfix) with ESMTP id 00B296B0071 for ; Wed, 17 Feb 2021 12:00:31 -0500 (EST) Received: from smtpin06.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay05.hostedemail.com (Postfix) with ESMTP id 992F71803A550 for ; Wed, 17 Feb 2021 17:00:31 +0000 (UTC) X-FDA: 77828373462.06.AB7F153 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by imf29.hostedemail.com (Postfix) with ESMTP id 1A116F2 for ; Wed, 17 Feb 2021 17:00:30 +0000 (UTC) Received: by mail-pj1-f52.google.com with SMTP id t2so2029968pjq.2 for ; Wed, 17 Feb 2021 09:00:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=ieECyghvBmC2satFZ6K4eL8/reOcYYWCYp0/BHVv4Os=; b=QA0EM6cke64ioEYU1NPofPda1QzGLV12C9sjiG+Dba8gviDszYiUWjOErf3QrrE3Vw SYLNaWdKykzhugsP+AaFbK+wn+IYtS/pDpTtoSHsphS2nlncH4K1xK0TKzvkyWsUGbe6 4qnS0TnZY1NCRGWB79gGsF4xdTb3tDfVIKol1pDja3gmPS/adYeUDkWlquD2E6dT/AFb q2JvXJopIkSd5bdYUOybfDii4KBR8DRrp5NjmbmgGjnxg/QPnBQQV2uExdABJ1bNcvEI l5V4W35VaRgeuJTLtTi1eGGWOL1ALigd7Jozp99KFztfgL4YYxU0z3QcWLVjeRz2F/uB kf4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :mime-version:content-transfer-encoding; bh=ieECyghvBmC2satFZ6K4eL8/reOcYYWCYp0/BHVv4Os=; b=bYbhs/7lkNngMUCxFs4YvTDrwTDX7oAE0+j8h9TuxsC//4E6gT9fTIlrUEJar1ts0f dcR+Xp/PnsFF7RRL5CRsPW2aoodeHVOSPKTqCOWriJs+u46+rLtKg5XhEkc8w347V1lo vyllxrdzgfYYTveTvsylj2qL/jsCo6T7cmneRb+ouETonFdpT85Jofml7keV5/qAKi9v 4n3jkJPm9TaowWAh13lfLhGmoMsvnRUC677t3FcDG5msLRQpg1ZW49uBvUeK9V0RVvkn pS61ZLVOunXVH/yT35t/iwZolr++f5bvKWFrbUBO+QOQF5ZyBe1u3IoCcAWBo0X9zfpf UL4A== X-Gm-Message-State: AOAM532ijeYuq6n/DlVlHUZa3xUZZfhKZZrcXeprD7v2QfXH11oKG7xK q4EiHoocF8uvupPGRXESOq8= X-Google-Smtp-Source: ABdhPJz1vnmsl7qVhNZA1McdS5wSOaQXvHZL2mpixQck6Em2l2+hJ9DSFJ4wrgozlLmAQ7NvNVqT1w== X-Received: by 2002:a17:90a:70c1:: with SMTP id a1mr10231855pjm.19.1613581229975; Wed, 17 Feb 2021 09:00:29 -0800 (PST) Received: from bbox-1.mtv.corp.google.com ([2620:15c:211:201:cdf7:1c5d:c444:e341]) by smtp.gmail.com with ESMTPSA id k31sm2992096pgi.5.2021.02.17.09.00.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 17 Feb 2021 09:00:29 -0800 (PST) From: Minchan Kim To: Andrew Morton Cc: linux-mm , LKML , surenb@google.com, joaodias@google.com, jhubbard@nvidia.com, Minchan Kim Subject: [PATCH] mm: vmstat: add cma statistics Date: Wed, 17 Feb 2021 09:00:25 -0800 Message-Id: <20210217170025.512704-1-minchan@kernel.org> X-Mailer: git-send-email 2.30.0.478.g8a0d178c01-goog MIME-Version: 1.0 X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 1A116F2 X-Stat-Signature: e4d1qzfhgyzo6mbfsysdwtjj8dkx8ygx Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf29; identity=mailfrom; envelope-from=""; helo=mail-pj1-f52.google.com; client-ip=209.85.216.52 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1613581230-378408 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: Since CMA is used more widely, it's worth to have CMA allocation statistics into vmstat. With it, we could know how agressively system uses cma allocation and how often it fails. Signed-off-by: Minchan Kim --- include/linux/vm_event_item.h | 3 +++ mm/cma.c | 12 +++++++++--- mm/vmstat.c | 4 ++++ 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/include/linux/vm_event_item.h b/include/linux/vm_event_item.h index 18e75974d4e3..0c567014ce82 100644 --- a/include/linux/vm_event_item.h +++ b/include/linux/vm_event_item.h @@ -70,6 +70,9 @@ enum vm_event_item { PGPGIN, PGPGOUT, PSWPIN, PSWPOUT, #endif #ifdef CONFIG_HUGETLB_PAGE HTLB_BUDDY_PGALLOC, HTLB_BUDDY_PGALLOC_FAIL, +#endif +#ifdef CONFIG_CMA + CMA_ALLOC, CMA_ALLOC_FAIL, #endif UNEVICTABLE_PGCULLED, /* culled to noreclaim list */ UNEVICTABLE_PGSCANNED, /* scanned for reclaimability */ diff --git a/mm/cma.c b/mm/cma.c index 23d4a97c834a..ea1e39559526 100644 --- a/mm/cma.c +++ b/mm/cma.c @@ -434,14 +434,16 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align, struct page *page = NULL; int ret = -ENOMEM; + count_vm_event(CMA_ALLOC); + if (!cma || !cma->count || !cma->bitmap) - return NULL; + goto out; pr_debug("%s(cma %p, count %zu, align %d)\n", __func__, (void *)cma, count, align); if (!count) - return NULL; + goto out; mask = cma_bitmap_aligned_mask(cma, align); offset = cma_bitmap_aligned_offset(cma, align); @@ -449,7 +451,7 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align, bitmap_count = cma_bitmap_pages_to_bits(cma, count); if (bitmap_count > bitmap_maxno) - return NULL; + goto out; for (;;) { mutex_lock(&cma->lock); @@ -506,6 +508,10 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align, } pr_debug("%s(): returned %p\n", __func__, page); +out: + if (!page) + count_vm_event(CMA_ALLOC_FAIL); + return page; } diff --git a/mm/vmstat.c b/mm/vmstat.c index 97fc32a53320..d8c32a33208d 100644 --- a/mm/vmstat.c +++ b/mm/vmstat.c @@ -1305,6 +1305,10 @@ const char * const vmstat_text[] = { #ifdef CONFIG_HUGETLB_PAGE "htlb_buddy_alloc_success", "htlb_buddy_alloc_fail", +#endif +#ifdef CONFIG_CMA + "cma_alloc_success", + "cma_alloc_fail", #endif "unevictable_pgs_culled", "unevictable_pgs_scanned",