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 X-Spam-Level: X-Spam-Status: No, score=-7.0 required=3.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,MAILING_LIST_MULTI, NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=no 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 67108C433C1 for ; Wed, 24 Mar 2021 21:31:56 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DADDD61A1E for ; Wed, 24 Mar 2021 21:31:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DADDD61A1E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 2DB9C6B031E; Wed, 24 Mar 2021 17:31:55 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 28B4F6B0320; Wed, 24 Mar 2021 17:31:55 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 0B69B6B0321; Wed, 24 Mar 2021 17:31:55 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0066.hostedemail.com [216.40.44.66]) by kanga.kvack.org (Postfix) with ESMTP id E189B6B031E for ; Wed, 24 Mar 2021 17:31:54 -0400 (EDT) Received: from smtpin38.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id A95A31833820D for ; Wed, 24 Mar 2021 21:31:54 +0000 (UTC) X-FDA: 77956065348.38.47515D3 Received: from mail-lj1-f172.google.com (mail-lj1-f172.google.com [209.85.208.172]) by imf10.hostedemail.com (Postfix) with ESMTP id D97254080F54 for ; Wed, 24 Mar 2021 21:31:52 +0000 (UTC) Received: by mail-lj1-f172.google.com with SMTP id z25so505871lja.3 for ; Wed, 24 Mar 2021 14:31:54 -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=GXCHwCjIojzQra6Ybo8a6ubZkkqtpIUTfy1bdb9pub8=; b=lrwPb0OwRuF4bqws2EJVVX5j0uiXIFTIr2bAgHN/bzUHYfymLk2LM7VDU3LXmidK0i bXBwWghuY/RV0QdKb7L8MAAwIiU43qvbC2j3VUGxWhINR97vi0mClUWlb0ugOuvrxVhg 7yuaV32pEYwNNMeqBAWYrcA7z5P3Df43dTILzg41SoOUOsqOlSJfc599iONwRuVBj34Q BAMm3RiVw7hYomiB9gt5kUyXp3qNlW4MOKyrfynVuNeC/FrMV0oCSAgbNTNJLB48wzD5 aU46LmJe7lbhAxidq8v3T7oj1diu1Qh7UcoP0B2Cn96LwMxVq1tnOCja0Vb0D9ILq17d 6Fxg== 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=GXCHwCjIojzQra6Ybo8a6ubZkkqtpIUTfy1bdb9pub8=; b=jV0Owbr4OqN7pLd5bRtQ+O0JvsWIZnE+DCUQpvM5o/de7RLZ5VP+hy7bUjf+HiIjmY PPBAmLWC/MdDjE3XahRHgoAs/uq1SDmG9wmXY4JN69xqZtb7DZRzump/v5Ld3IYB45Vl CyxqG2JI128hBWzAEGhgc7/JZMt0ML/OE68TmXMbDLmwWZ0QfP5GihKTe3Vi7KgP1cRe e72qhbaiNFbb1G7c0vm3DN2QnHFP0IPqIrR5fMi6NVq8MyjBJL5+AFQKhNBuoTUAKPw+ BtO3cpvkzusErAL3aZOPSdHMdsB8UsXhPVjqSMCCTA/L9UpJiXFRZpeepoBz6v5GfqRL Bedg== X-Gm-Message-State: AOAM531wH38KX3dgakJdAHHd06zEb0hM7XyVTiCjyhmej1eFwSuwJvJr rd3t4MsxYfvPHrSZu+1IL+E= X-Google-Smtp-Source: ABdhPJzBtOjhGlUc6Vg44/mMvTfBcv1StLpDGOr8ECeh+GUX875JodrX5Ivs3aMrj//h3c23tXyLUw== X-Received: by 2002:a2e:700a:: with SMTP id l10mr3362086ljc.368.1616621512815; Wed, 24 Mar 2021 14:31:52 -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 u9sm444852ljd.130.2021.03.24.14.31.51 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 Mar 2021 14:31:52 -0700 (PDT) Subject: Re: [PATCH v7] 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, Colin Ian King References: <20210324205503.2132082-1-minchan@kernel.org> From: Dmitry Osipenko Message-ID: <65840bfd-4471-7c8d-ce71-c4705baf3bfe@gmail.com> Date: Thu, 25 Mar 2021 00:31:51 +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: <20210324205503.2132082-1-minchan@kernel.org> Content-Type: text/plain; charset=utf-8 Content-Language: en-US X-Stat-Signature: j7xt8nnqa3sx8x5ye59hyutnqerbyb1m X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: D97254080F54 Received-SPF: none (gmail.com>: No applicable sender policy available) receiver=imf10; identity=mailfrom; envelope-from=""; helo=mail-lj1-f172.google.com; client-ip=209.85.208.172 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1616621512-161791 Content-Transfer-Encoding: quoted-printable 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: 24.03.2021 23:55, Minchan Kim =D0=BF=D0=B8=D1=88=D0=B5=D1=82: > 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. >=20 > This patch introduces sysfs statistics for CMA, in order to provide > some basic monitoring of the CMA allocator. >=20 > * the number of CMA page successful allocations > * the number of CMA page allocation failures >=20 > These two values allow the user to calcuate the allocation > failure rate for each CMA area. >=20 > e.g.) > /sys/kernel/mm/cma/WIFI/alloc_pages_[success|fail] > /sys/kernel/mm/cma/SENSOR/alloc_pages_[success|fail] > /sys/kernel/mm/cma/BLUETOOTH/alloc_pages_[success|fail] >=20 > The cma_stat was intentionally allocated by dynamic allocation > to harmonize with kobject lifetime management. > https://lore.kernel.org/linux-mm/YCOAmXqt6dZkCQYs@kroah.com/ >=20 > Reported-by: Dmitry Osipenko > Tested-by: Dmitry Osipenko > Suggested-by: Dmitry Osipenko The tags are incorrect, I haven't suggested this change. > Suggested-by: John Hubbard > Suggested-by: Matthew Wilcox > Reviewed-by: Greg Kroah-Hartman > Reviewed-by: John Hubbard > Addresses-Coverity: ("Dereference after null check") There are no dereferences fixed by this patch. > Signed-off-by: Colin Ian King > Signed-off-by: Minchan Kim > --- ... > #include > +#include > + > +struct cma_kobject { > + struct cma *cma; > + struct kobject kobj; If you'll place the kobj as the first member of the struct, then container_of will be a no-op. ... > +#include > +#include > +#include > + > +#include "cma.h" > + > +void cma_sysfs_account_success_pages(struct cma *cma, unsigned long nr= _pages) > +{ > + atomic64_add(nr_pages, &cma->nr_pages_succeeded); > +} > + > +void cma_sysfs_account_fail_pages(struct cma *cma, unsigned long nr_pa= ges) > +{ > + atomic64_add(nr_pages, &cma->nr_pages_failed); > +} > + > +#define CMA_ATTR_RO(_name) \ > + static struct kobj_attribute _name##_attr =3D __ATTR_RO(_name) nit: #defines and inlined helpers typically are placed at the top of the code, after includes. > +static inline struct cma *cma_from_kobj(struct kobject *kobj) > +{ > + struct cma_kobject *cma_kobj =3D container_of(kobj, struct cma_kobjec= t, > + kobj); > + struct cma *cma =3D cma_kobj->cma; > + > + return cma; nit: you can write this as: return container_of(kobj, struct cma_kobject, kobj)->cma; > +} > + > +static ssize_t alloc_pages_success_show(struct kobject *kobj, > + struct kobj_attribute *attr, char *buf) > +{ > + struct cma *cma =3D cma_from_kobj(kobj); > + > + return sysfs_emit(buf, "%llu\n", > + atomic64_read(&cma->nr_pages_succeeded)); nit: Algnment isn't right, should be better to write it as single line, I= MO. ... > +static int __init cma_sysfs_init(void) > +{ > + struct kobject *cma_kobj_root; > + struct cma_kobject *cma_kobj; > + struct cma *cma; > + int i, err; > + > + cma_kobj_root =3D kobject_create_and_add("cma", mm_kobj); > + if (!cma_kobj_root) > + return -ENOMEM; > + > + for (i =3D 0; i < cma_area_count; i++) { > + cma_kobj =3D kzalloc(sizeof(*cma_kobj), GFP_KERNEL); > + if (!cma_kobj) { > + err =3D -ENOMEM; > + goto out; > + } > + > + cma =3D &cma_areas[i]; > + cma->cma_kobj =3D cma_kobj; > + cma_kobj->cma =3D cma; > + err =3D kobject_init_and_add(&cma_kobj->kobj, &cma_ktype, > + cma_kobj_root, "%s", cma->name); nit: Previousy algnment of the code was better here. Otherwise this is okay to me: Reviewed-by: Dmitry Osipenko Tested-by: Dmitry Osipenko