Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4580782pxf; Tue, 23 Mar 2021 14:23:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxUDLN4uSy+fnIISzbQSmxagZT1Xik5POvHUgQPOZLcxNTQgqpjsoINjDFYhS7FpTZWj6Fl X-Received: by 2002:a17:906:c143:: with SMTP id dp3mr166035ejc.499.1616534593330; Tue, 23 Mar 2021 14:23:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616534593; cv=none; d=google.com; s=arc-20160816; b=qMG1RhqNI7J5FIEQxDjRwBPlECKd7KoMPdT399lUbNQSdZYo8VONLZPH8VWYCSyoyL NvDfTrDSPM20WiQ7ffwpwIqUkiCYo59jOLgEJSF6AQ13yZeOyxICgOYv3JsO70QPUhcZ iODvmT1zJ5lsl9OvN305oKKX7djAAtvg2i5zAMGkBhS7ljwp2BpD6Rf/9zX3jeOaPoOb Bi5/hySRIpNRFk7zn4by/0nKPLFhGU1KyOP/oCoeozKDccVXi25J/C4gdttMdEaz6t0j E50VYsd6tH+PvCMAdvNy0wilZsWT0mAnslrJd5AYU5MD4dB4plqNLSKx7JCVREsIllwi mWug== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:content-language :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:dkim-signature; bh=q/Hv2aIHg4JAKeZX5bEtyhlfR532pZFH6Gq8JpGYfrs=; b=bUBoez/8CsGkTchbRNE8KrnFKcnWKoA0adjnANzF2IhEC/vsLoe5tn2SFDJtfflIa1 qbeKznMOLq3dpk9hP5q0maq8egiTJyPieVLT9J2A4U7HmhH7vS69608/Uf6CPtZ6pUqe 2oWY5aT6EGvbGnqZN3gHywahpLvkkfNi/1H3U6uZM95f7oixCK3MPfT6JXMnHfxQ0fSJ p25d+Zp96k29ZZpKYYWqDwRk6Um0rP7XPzGGhqiGAhK5naMPrJAMoqkO7eozovR8JgY2 28vPWfpcTFHurdyPUO9wjm9/gSA/5YHhoFDTTLTqIT68838oiYO5RZcrbrhptbddHQt/ XIxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=AykGKCzm; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b65si118895edf.391.2021.03.23.14.22.50; Tue, 23 Mar 2021 14:23:13 -0700 (PDT) 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=@gmail.com header.s=20161025 header.b=AykGKCzm; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233537AbhCWVTa (ORCPT + 99 others); Tue, 23 Mar 2021 17:19:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233506AbhCWVTF (ORCPT ); Tue, 23 Mar 2021 17:19:05 -0400 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [IPv6:2a00:1450:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6019DC061574 for ; Tue, 23 Mar 2021 14:19:05 -0700 (PDT) Received: by mail-lj1-x234.google.com with SMTP id z25so27515930lja.3 for ; Tue, 23 Mar 2021 14:19:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=q/Hv2aIHg4JAKeZX5bEtyhlfR532pZFH6Gq8JpGYfrs=; b=AykGKCzmwCD/OTQb8N2wMNlDfjjxXFR5hxmBI1h9pbEUd6BoIpScFqBflU4vrvhEn2 m+rik5VFAvaSx+g8wbd8lentwQdcOXAI/MD8vjOPuG+SYP48vjpVcSbj0ZvVJSd2ThU6 BiLXDal9b6HEDlRWoKfw3ud5L1tgXDSEhKeFJOJY1kTmCRQBa3ne03u2HFkudHdlpMLc VPw0ZuKqWDj76wjtbaZrShf4pihvolt/OiKFbbsK3Ix6VO9i8lzfLETLyG+EIRpeXv6T izloky1TGxj+6QZlHzOJS1BCpK+kpv4nrD1l2rpZRpYYM7DJcKV13HM5c/2Xnm/f12rN WwZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=q/Hv2aIHg4JAKeZX5bEtyhlfR532pZFH6Gq8JpGYfrs=; b=jA1REURUT9MFOM3D25oap+Y7CI62JzTV8n3eMKMurYN7zFW+aRmQe01foDKDn6NwRC Hz2BLNLemP6AkSYg7g/e1rBqMIW4h49Fhj8Asrs8bs+xApzXq7euCN/BcuAS4j5k8QZ3 AgsyL+TxFaGpDKleBEy3Mv1qiMe0l3TRkfV08PbqT1+IdMvPlV1xKt0bbRfRl30WJN+v SnBuyxViX26jjnZUxMK5ta3XgQssN29aojUlkxcUWa5+Wf4xHqVCHH0wKYRQUDtHp9Ba yMf/Og0lJCXmPeqb0CLpXR8dYF+rqkMfW8ku0cZ/FaB95i1XJ3KgzYvPIEJ8842OGEtR QTeQ== X-Gm-Message-State: AOAM532xmA+OtZI5e8kKkEdTekennUaK96FRM+9VzjyD1AduADVk6XNo dHC7EXLqGIHRYftI4kzWzAM= X-Received: by 2002:a2e:919a:: with SMTP id f26mr4383249ljg.508.1616534343912; Tue, 23 Mar 2021 14:19:03 -0700 (PDT) Received: from [192.168.2.145] (109-252-193-60.dynamic.spd-mgts.ru. [109.252.193.60]) by smtp.googlemail.com with ESMTPSA id i18sm24489lfl.22.2021.03.23.14.19.03 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 23 Mar 2021 14:19:03 -0700 (PDT) Subject: Re: [PATCH v5] mm: cma: support sysfs To: Minchan Kim , Andrew Morton Cc: linux-mm , LKML , gregkh@linuxfoundation.org, surenb@google.com, joaodias@google.com, jhubbard@nvidia.com, willy@infradead.org References: <20210323195050.2577017-1-minchan@kernel.org> From: Dmitry Osipenko Message-ID: Date: Wed, 24 Mar 2021 00:19:02 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210323195050.2577017-1-minchan@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 23.03.2021 22:50, Minchan Kim пишет: > Since CMA is getting used more widely, it's more important to > keep monitoring CMA statistics for system health since it's > directly related to user experience. > > This patch introduces sysfs statistics for CMA, in order to provide > some basic monitoring of the CMA allocator. > > * the number of CMA page successful allocations > * the number of CMA page allocation failures > > These two values allow the user to calcuate the allocation typo: calculate > struct cma { > unsigned long base_pfn; > @@ -16,6 +22,14 @@ struct cma { > struct debugfs_u32_array dfs_bitmap; > #endif > char name[CMA_MAX_NAME]; > +#ifdef CONFIG_CMA_SYSFS > + /* the number of CMA page successful allocations */ > + atomic64_t nr_pages_succeeded; > + /* the number of CMA page allocation failures */ > + atomic64_t nr_pages_failed; > + /* kobject requires dynamic objecjt */ typo: object ... > +static void cma_kobj_release(struct kobject *kobj) > +{ > + struct cma_kobject *cma_kobj = > + container_of(kobj, struct cma_kobject, kobj); I'd add a to_cma_kobject() helper to improve readability. > + struct cma *cma = cma_kobj->cma; > + > + kfree(cma_kobj); > + cma->kobj = NULL; > +} > + > +static struct attribute *cma_attrs[] = { > + &alloc_pages_success_attr.attr, > + &alloc_pages_fail_attr.attr, > + NULL, > +}; > +ATTRIBUTE_GROUPS(cma); > + > +static struct kobject *cma_kobj_root; > + > +static struct kobj_type cma_ktype = { > + .release = cma_kobj_release, > + .sysfs_ops = &kobj_sysfs_ops, > + .default_groups = cma_groups > +}; > + > +static int __init cma_sysfs_init(void) > +{ > + int i = 0; unsigned int, for consistency There is no need to initialize this variable. > + struct cma *cma; > + > + cma_kobj_root = kobject_create_and_add("cma", mm_kobj); > + if (!cma_kobj_root) > + return -ENOMEM; > + > + for (i = 0; i < cma_area_count; i++) { > + struct cma_kobject *kobj; > + > + cma = &cma_areas[i]; > + kobj = kzalloc(sizeof(struct cma_kobject), GFP_KERNEL); Checkpatch should warn that kzalloc(*kobj, ..) is a better variant. I'd also rename kobj to cma_kobj everywhere, for clarity. > + if (!kobj) > + goto out; > + > + kobj->cma = cma; > + cma->kobj = kobj; > + if (kobject_init_and_add(&cma->kobj->kobj, &cma_ktype, > + cma_kobj_root, "%s", cma->name)) { > + kobject_put(&cma->kobj->kobj); > + goto out; > + } > + } > + > + return 0; > +out: > + kobject_put(cma_kobj_root); > + > + return -ENOMEM; kobject_init_and_add returns a error code, it could be different from ENOMEM. Won't hurt to propagate the proper error code.