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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 268FAC6FA82 for ; Tue, 20 Sep 2022 01:58:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8AC8D80007; Mon, 19 Sep 2022 21:58:47 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8353F940007; Mon, 19 Sep 2022 21:58:47 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6D58780007; Mon, 19 Sep 2022 21:58:47 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 52EC7940007 for ; Mon, 19 Sep 2022 21:58:47 -0400 (EDT) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 2C4CEA02D6 for ; Tue, 20 Sep 2022 01:58:47 +0000 (UTC) X-FDA: 79930805094.25.AE9C5A5 Received: from out30-43.freemail.mail.aliyun.com (out30-43.freemail.mail.aliyun.com [115.124.30.43]) by imf16.hostedemail.com (Postfix) with ESMTP id 71810180006 for ; Tue, 20 Sep 2022 01:58:45 +0000 (UTC) X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R191e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018046060;MF=xhao@linux.alibaba.com;NM=1;PH=DS;RN=5;SR=0;TI=SMTPD_---0VQGhopY_1663639121; Received: from 30.240.98.170(mailfrom:xhao@linux.alibaba.com fp:SMTPD_---0VQGhopY_1663639121) by smtp.aliyun-inc.com; Tue, 20 Sep 2022 09:58:42 +0800 Message-ID: <10f3f03d-e616-0619-cbe1-8515a3d7fc0e@linux.alibaba.com> Date: Tue, 20 Sep 2022 09:58:41 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH v1 2/2] mm/damon/sysfs: use kzmalloc instead kmalloc to simplify codes To: SeongJae Park Cc: akpm@linux-foundation.org, damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <20220919172251.61428-1-sj@kernel.org> From: haoxin In-Reply-To: <20220919172251.61428-1-sj@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1663639126; a=rsa-sha256; cv=none; b=WExdQ0/mCSJZy9o+LrUTTPlCW2I0sT+zHRKa4C5BEae5Pp+gX0CJk1MuLu1bHRodw/CQ16 QjCFLCfrNn+fJABxGlNrN/EJR+YIDMkq4nxq5Pcmuw3LO40j+L5fJO702RqnFH8ScqThv0 1y4iju75eo8pGNF2q+jxQgib+fOwhaM= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf16.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.43 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1663639126; 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-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=fV3sU54xgw/OZZQsFWqIAlAqtVLOU5WA9pjdDAlImx8=; b=Galynhtiem501penjRt9epFaFQJvwZhT/eyvlwxM716AOPdJXsirqP7aUvgBkFtiudISiQ GDOEr2CR1r4BE86z02XrYLTPDkQbWUtqa1wVxBFJlV1o37PkDqtf0NMAGIQ2DzX2gzo5DC xcaprrBU9lYOD+6K2vd0A90EORnry4A= Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=pass (policy=none) header.from=alibaba.com; spf=pass (imf16.hostedemail.com: domain of xhao@linux.alibaba.com designates 115.124.30.43 as permitted sender) smtp.mailfrom=xhao@linux.alibaba.com X-Rspam-User: X-Rspamd-Server: rspam11 X-Stat-Signature: heag454wzs9kzpxizre3s17bstfrrk6k X-Rspamd-Queue-Id: 71810180006 X-HE-Tag: 1663639125-721478 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: 在 2022/9/20 上午1:22, SeongJae Park 写道: > On Mon, 19 Sep 2022 23:12:01 +0800 Xin Hao wrote: > >> In damon_sysfs_access_pattern_alloc() adn damon_sysfs_attrs_alloc(), >> we can use kzmalloc to alloc instance of the related structs, This makes >> the function code much cleaner. > This definitely makes the code cleaner, thank you. But, the initial intent of > the code is to initialize the fiedls that really need to be initialized at the > point, for the efficiency and also for making it clear which field is needed to > be initialized to what value here. It's also intended to make readers wonder > about where and how the remaining fields are initialized. Maybe the other func like damon_sysfs_kdamonds_alloc() also need to do like this, you can see it return directly by kzalloc. static struct damon_sysfs_kdamonds *damon_sysfs_kdamonds_alloc(void) {             return kzalloc(sizeof(struct damon_sysfs_kdamonds), GFP_KERNEL); } > So, to my humble eyes, this change looks like making the code a little bit > inefficient and unclear, sorry. > > > Thanks, > SJ > >> Signed-off-by: Xin Hao >> --- >> mm/damon/sysfs.c | 15 ++------------- >> 1 file changed, 2 insertions(+), 13 deletions(-) >> >> diff --git a/mm/damon/sysfs.c b/mm/damon/sysfs.c >> index b852a75b9f39..06154ece7960 100644 >> --- a/mm/damon/sysfs.c >> +++ b/mm/damon/sysfs.c >> @@ -657,13 +657,7 @@ struct damon_sysfs_access_pattern { >> static >> struct damon_sysfs_access_pattern *damon_sysfs_access_pattern_alloc(void) >> { >> - struct damon_sysfs_access_pattern *access_pattern = >> - kmalloc(sizeof(*access_pattern), GFP_KERNEL); >> - >> - if (!access_pattern) >> - return NULL; >> - access_pattern->kobj = (struct kobject){}; >> - return access_pattern; >> + return kzalloc(sizeof(struct damon_sysfs_access_pattern), GFP_KERNEL); >> } >> >> static int damon_sysfs_access_pattern_add_range_dir( >> @@ -1620,12 +1614,7 @@ struct damon_sysfs_attrs { >> >> static struct damon_sysfs_attrs *damon_sysfs_attrs_alloc(void) >> { >> - struct damon_sysfs_attrs *attrs = kmalloc(sizeof(*attrs), GFP_KERNEL); >> - >> - if (!attrs) >> - return NULL; >> - attrs->kobj = (struct kobject){}; >> - return attrs; >> + return kzalloc(sizeof(struct damon_sysfs_attrs), GFP_KERNEL); >> } >> >> static int damon_sysfs_attrs_add_dirs(struct damon_sysfs_attrs *attrs) >> -- >> 2.31.0