From nobody Mon Apr 6 00:16:34 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C4C0ECAAD8 for ; Tue, 13 Sep 2022 18:27:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232688AbiIMS1d (ORCPT ); Tue, 13 Sep 2022 14:27:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56698 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232356AbiIMS0u (ORCPT ); Tue, 13 Sep 2022 14:26:50 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B42F5C363 for ; Tue, 13 Sep 2022 10:45:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 9702DB80CBC for ; Tue, 13 Sep 2022 17:44:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F29C2C433D7; Tue, 13 Sep 2022 17:44:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1663091097; bh=0FJOrqHiBH1OMZ45Xdi5Z4U0goCpXjUFgshxwmAlQlU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=es99vqn1ffMbBBFLbtJGVKcjrXyHgR79vSQyF0z+ScdGpaJVr4lW+yHoZQY+cSeoA sDnWKHHLwouvB+Zqwonl+asV8uuQ5yR3RntZz1IOzHkyWWrBqHL+dCMk1djGjKD2w/ cadkRl8b9QdRMDShd4e8ji6ZM44RrDr5DaZoBADBZCiKrMoShbygsJBMtDTVNIH9fJ bZLFnSUNJJ1OTq/ZZO/TQSFP2yIjj3mZpxhQA4R/6qcuZYoCskfcc+6uDPI8/TywE6 Lw9m7KejLWOzndrIP8VeFBEQAs1J/S2f7h+Q5xNCBA33BVfctyyg2DNBGdTuErwq+U uoTiG3DLxRwoA== From: SeongJae Park To: Andrew Morton Cc: SeongJae Park , damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 03/22] mm/damon/core: copy struct-to-struct instead of field-to-field in damon_new_scheme() Date: Tue, 13 Sep 2022 17:44:30 +0000 Message-Id: <20220913174449.50645-4-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220913174449.50645-1-sj@kernel.org> References: <20220913174449.50645-1-sj@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The function for new 'struct damos' creation, 'damon_new_scheme()', copies each field of the struct one by one, though it could simply copied via struct to struct. This commit replaces the unnecessarily verbose field-to-field copies with struct-to-struct copies to make code simple and short. Signed-off-by: SeongJae Park --- mm/damon/core.c | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) diff --git a/mm/damon/core.c b/mm/damon/core.c index c21f5fe5928a..27e0c312f7a5 100644 --- a/mm/damon/core.c +++ b/mm/damon/core.c @@ -276,22 +276,13 @@ struct damos *damon_new_scheme(struct damos_access_pa= ttern *pattern, scheme =3D kmalloc(sizeof(*scheme), GFP_KERNEL); if (!scheme) return NULL; - scheme->pattern.min_sz_region =3D pattern->min_sz_region; - scheme->pattern.max_sz_region =3D pattern->max_sz_region; - scheme->pattern.min_nr_accesses =3D pattern->min_nr_accesses; - scheme->pattern.max_nr_accesses =3D pattern->max_nr_accesses; - scheme->pattern.min_age_region =3D pattern->min_age_region; - scheme->pattern.max_age_region =3D pattern->max_age_region; + scheme->pattern =3D *pattern; scheme->action =3D action; scheme->stat =3D (struct damos_stat){}; INIT_LIST_HEAD(&scheme->list); =20 - scheme->quota.ms =3D quota->ms; - scheme->quota.sz =3D quota->sz; - scheme->quota.reset_interval =3D quota->reset_interval; - scheme->quota.weight_sz =3D quota->weight_sz; - scheme->quota.weight_nr_accesses =3D quota->weight_nr_accesses; - scheme->quota.weight_age =3D quota->weight_age; + scheme->quota =3D *quota; + /* caller might not zero-initialized the private fileds */ scheme->quota.total_charged_sz =3D 0; scheme->quota.total_charged_ns =3D 0; scheme->quota.esz =3D 0; @@ -300,11 +291,7 @@ struct damos *damon_new_scheme(struct damos_access_pat= tern *pattern, scheme->quota.charge_target_from =3D NULL; scheme->quota.charge_addr_from =3D 0; =20 - scheme->wmarks.metric =3D wmarks->metric; - scheme->wmarks.interval =3D wmarks->interval; - scheme->wmarks.high =3D wmarks->high; - scheme->wmarks.mid =3D wmarks->mid; - scheme->wmarks.low =3D wmarks->low; + scheme->wmarks =3D *wmarks; scheme->wmarks.activated =3D true; =20 return scheme; --=20 2.25.1