Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp6786196pxb; Wed, 17 Feb 2021 13:27:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJx+iZkcrf4QSjBJqG90TRZNSJElEF/qW69OOFcOMQukr0NA0MgDiSwhVYttIyguXYydTXv/ X-Received: by 2002:a05:6402:a49:: with SMTP id bt9mr762786edb.127.1613597260302; Wed, 17 Feb 2021 13:27:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613597260; cv=none; d=google.com; s=arc-20160816; b=Ec7daGk6S44Q/y9hOGolEa7dLkwg6T3LTQ2UgD774H+HqCXgQ/MA2oj4emrPhtPzGe 26otAz+Gt7fUmBhNmwmse/7Vk3iUk32drxUjQQFKgou9ykvyNQ+6Qn9wmvwn8oK7UUaT mcVFcrh54PElFhumHzvKg22y806ha2dbyh2PiDjGpH2ntE/qj8xDD5k79FsoVQFZtLmo sMQmhFXQwnfOg0NTTJUyzRtvKE9AzZlOX4WkzcKbcUQWt2O8Q+3wH7ljL48+6EYPNJmI lqYjpdrkYbSrHBB1quxfLDFeYcIguidz57og+5p7tfnqhnHF86U7skIk/xhiMkGnuSXT ZOug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:dkim-signature:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=hI0hY92PVZ/Q8bLOHZtIMPTuj0DO35pgrbP+g6IycJk=; b=fe3bW7SwnI5+XAf255Xx6vR7W2E4mHxLH5e9YkWZrI4XjYz3CunPTCL3Eufvknyp/7 yCBpqIKitkJRTB3ESG8Dp+TZtwgGj7nblstqINOgxcm2Sc3Fmaa46phGoF+OAc7kM+V/ mtV6ys3Qr8C/+sEu4jMSp4g0uS5lg5KLHvHwiAznb39+4HtEANgspQWf2CHz+1c2WJNg Foulm10rCdM1hGIHY0lU8zFEMXZZIsSkkPlHJO+txpJ2iLpmRpjGZYKqWa99QmNOqYRF UOxjXniuDCaHpr9emvZiMEZR9Pma42QGnigMxMTRq5Uq9AfhL+UBGhV8vJ4ZlMr7+gol gXyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=f31UQ+73; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v5si2156501edc.346.2021.02.17.13.27.15; Wed, 17 Feb 2021 13:27:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@nvidia.com header.s=n1 header.b=f31UQ+73; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=nvidia.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233238AbhBQU6H (ORCPT + 99 others); Wed, 17 Feb 2021 15:58:07 -0500 Received: from hqnvemgate24.nvidia.com ([216.228.121.143]:8611 "EHLO hqnvemgate24.nvidia.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231766AbhBQU6G (ORCPT ); Wed, 17 Feb 2021 15:58:06 -0500 Received: from hqmail.nvidia.com (Not Verified[216.228.121.13]) by hqnvemgate24.nvidia.com (using TLS: TLSv1.2, AES256-SHA) id ; Wed, 17 Feb 2021 12:57:26 -0800 Received: from [10.2.55.242] (172.20.145.6) by HQMAIL107.nvidia.com (172.20.187.13) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 17 Feb 2021 20:57:25 +0000 Subject: Re: [PATCH] mm: vmstat: add cma statistics To: Minchan Kim , Andrew Morton CC: linux-mm , LKML , , References: <20210217170025.512704-1-minchan@kernel.org> From: John Hubbard Message-ID: <8036d8e6-8e96-7b4e-91c0-e1ae91b637e1@nvidia.com> Date: Wed, 17 Feb 2021 12:57:25 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:85.0) Gecko/20100101 Thunderbird/85.0 MIME-Version: 1.0 In-Reply-To: <20210217170025.512704-1-minchan@kernel.org> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [172.20.145.6] X-ClientProxiedBy: HQMAIL105.nvidia.com (172.20.187.12) To HQMAIL107.nvidia.com (172.20.187.13) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nvidia.com; s=n1; t=1613595446; bh=hI0hY92PVZ/Q8bLOHZtIMPTuj0DO35pgrbP+g6IycJk=; h=Subject:To:CC:References:From:Message-ID:Date:User-Agent: MIME-Version:In-Reply-To:Content-Type:Content-Language: Content-Transfer-Encoding:X-Originating-IP:X-ClientProxiedBy; b=f31UQ+734TU3Iut9TEFTyDhQ6PvmWIYjezGcPbIORNJCP39NI5Fph5I0kpRe72Bf/ UpKtyfwXEnAvDY+pv8butvZABcj2ACipE2xPBQwWFmCzx9DVMTh8fi1HhmbJIQfAsk aeID8fnSAY7VLGN8ss7vxX/3x2y8nVKDn4ncGhBBC4U15nioCJar9pSCLl42rjSGNu uh+xo9BsXK2wphoepTQyYnfDWznq6+AlXYD/dJwtGdswsQtXrO8IqcfB8Apxfb3xTY Op0ply0O2UbEbYCnP9gHV+5uiaAt4xn0n5xU160AnUoUyGBTG0nSCeztKkerncRmBu 1npqpwcE9puZQ== Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/17/21 9:00 AM, Minchan Kim wrote: > 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, This seems wrong: here it's called "alloc", but in the output it's called "alloc success", and in the implementation it's clearly "alloc attempt" that is being counted. Once these are all made consistent, then the bug should naturally go away as part of that. nit: I think the multiple items per line is a weak idea at best, even though it's used here already. Each item is important and needs to be visually compared to it's output item later. So one per line might have helped avoid mismatches, and I think we should change to that to encourage that trend. thanks, -- John Hubbard NVIDIA > #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", >