From patchwork Sun Sep 8 14:05:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13795494 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 DDC48E6FE49 for ; Sun, 8 Sep 2024 14:06:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2377A6B00CE; Sun, 8 Sep 2024 10:06:18 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1C2586B00CF; Sun, 8 Sep 2024 10:06:18 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 015186B00D0; Sun, 8 Sep 2024 10:06:17 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id CEF1B6B00CE for ; Sun, 8 Sep 2024 10:06:17 -0400 (EDT) Received: from smtpin10.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 81E5C41C47 for ; Sun, 8 Sep 2024 14:06:17 +0000 (UTC) X-FDA: 82541745594.10.327B382 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) by imf25.hostedemail.com (Postfix) with ESMTP id B6767A001D for ; Sun, 8 Sep 2024 14:06:15 +0000 (UTC) Authentication-Results: imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=GFJ3zaq6; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf25.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.167.52 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1725804294; a=rsa-sha256; cv=none; b=2trzT0CTdv2ofwr828tP6SR4X23AtJp3ionVzFfAWMqjgsr3RpaQD8KVKXkh+smaeT6Nl5 hK4dUJOoAlZGdo9pHcAhichF4oeDfHS+yeDHCfhY7uXNgumNTpR0n2MDFJ5WOt60fSUjGa MMg7+DrUy0F8oKc39B81dKvMoZSh0lA= ARC-Authentication-Results: i=1; imf25.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=GFJ3zaq6; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf25.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.167.52 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1725804294; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:content-type: content-transfer-encoding:in-reply-to:in-reply-to: references:references:dkim-signature; bh=DtE8y+JoGkMU0EtGjA8BDr7YhcjruLSNcD2Q4LOUFNQ=; b=vhRwvuexI/zEu1hXI+NlRDhbRCdqgAC+crZA32DbWd+etmNyltKEFXHfWMVJ/d4OkXLszx zHnOWjnEzLulf2iSOFT8Ijay3vMFoVXfeviI0ZwN7ygdCwWYBTCIZpnjcTCizSTEJ7g25p 8AJocw8+mGNkpIIsxMC+/LfTak5K7Bw= Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-53661ac5ba1so970468e87.2 for ; Sun, 08 Sep 2024 07:06:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1725804374; x=1726409174; darn=kvack.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=DtE8y+JoGkMU0EtGjA8BDr7YhcjruLSNcD2Q4LOUFNQ=; b=GFJ3zaq6426wRUMLawD1s3CFo0R8QedNgcPHJOSlH5KGRvC2cdOSjpmD1jhF3ic41d o0LQVc23pK2zz/Bj0aWCVdl5ZLSm6JSNNA/3YEEk9jgl/0hl/ESIugbJ2p6hEFCw40XJ iyJt6HYJG/FmQndBTaBZNKwPbUXl4DP2t2ta7qJsobCqQqUwyUkXO0erTnGhIwpzJxta GTWnyWlPR2O77Wfk8wIzBDf/vWP/cAT3fNoYLJfCJtpoFaBC/L0uuCR+t8X86WzgQcBy iQqKF5qGpAFCnpBF4pnKWmInVlMMtPXjKFdcx90zoUbI4M3crpwpL/RKX3SKGX9LnP0r Dijg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1725804374; x=1726409174; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=DtE8y+JoGkMU0EtGjA8BDr7YhcjruLSNcD2Q4LOUFNQ=; b=XGJz4OqKXdPuQjn6vErwQfLHmafwWTTbaMrLR+8S4CWecQtb7gdaBpvsCeymyO6GVi QRms9wIneT6GIWwsMusmrQ7Y1eV2jPXAwm3pIGTJ3ZGB2bZUTKrIG3fd3gflANj0C5HZ RrNOo3nQo/FEPAWprAoCSVBE+jUmdRyAcNaNk3TsnOnDPkhwkKfwZ46FYv6iD6oGBMX/ M6roputraNuvGKmLqxI06UcXqBTwijNvWePjCx0QYvSZJkvzUu8MHolV5AgESlhTWHx9 BmHRc3YUGRdhQSh6T3KcxDhg75G6mEspQcPR9fVdXZ+y34sN/MeRXKGd6qplGd2A8TeW xTmg== X-Forwarded-Encrypted: i=1; AJvYcCVejB2qHK3SSwMaw2USrhJ1h74QEkTQ6yNIEuAPqUQ5qqLt/E/SsukxiazV3cf2KioNMRelhGffmQ==@kvack.org X-Gm-Message-State: AOJu0YwDwLF/gz6PZrmwNS8M82HNlepgI3MYqehmf0cBVeWucU4qHOrb WFazzLMl5tP/jTEi6bIZEIwLETpOPVVJqFti8fFwWkzdrUdkQ+cn X-Google-Smtp-Source: AGHT+IE5RwOMG+w4AYwQwqH5newKa0DDKgBPIskfrRQfnaLQOK5GMCB/fZcudQwWb+ZRuV9wn8qLFA== X-Received: by 2002:a05:6512:3b8b:b0:530:ea2b:1a92 with SMTP id 2adb3069b0e04-536587fce7dmr5726629e87.43.1725804373394; Sun, 08 Sep 2024 07:06:13 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a8d25a25897sm207852466b.87.2024.09.08.07.06.12 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sun, 08 Sep 2024 07:06:12 -0700 (PDT) From: Wei Yang To: akpm@linux-foundation.org, Liam.Howlett@oracle.com Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org, Wei Yang , "Liam R . Howlett" Subject: [PATCH v2 2/2] maple_tree: memset maple_big_node as a whole Date: Sun, 8 Sep 2024 14:05:54 +0000 Message-Id: <20240908140554.20378-3-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20240908140554.20378-1-richard.weiyang@gmail.com> References: <20240908140554.20378-1-richard.weiyang@gmail.com> X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: B6767A001D X-Stat-Signature: yjk8ga588j3eseyxkt1efdzubq7r5yao X-Rspam-User: X-HE-Tag: 1725804375-496756 X-HE-Meta: U2FsdGVkX1+P43WZPhrnNNsOfsx+1b0KRzG4VwvaX9m6NBK+O98+21x6q1MrUAhQ/rDd24fdalwuxDm2goidoIOqG1LUTRnaH3de1riu3uXtTiqvCVVdahAAwFpG1GilDKqjLSPAY/cgqVed8a1YvmxiHVjyxruqe80S+0AcUjUHmUNULGHu8YuDdcyk4xEECGAihGOQgjY8Ghv0QeYNK9Sgz6SN1NBEQZbxCQIawvQCmlLlre+e74ehyB1ntRmrStOyk7iBN1KIn5hJGWD98AEnIbzRKhuXMkr6BNTCQP1mIfh8sikj7IpgAXfIso9kYL1jgE7cXPiBy2lkFTaWuoaXepQ6HRp/s/qTn4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qVjoWjhCCdwVae/Lwuw3qGQ0eR/Pq0CYDKULOYBA4dhtzewUWmP45emdYt X-Bogosity: Ham, tests=bogofilter, spamicity=0.020151, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: In function mast_fill_bnode(), we first clear some fields of maple_big_node and set the 'type' unconditionally before return. This means we won't leverage any information in maple_big_node and it is safe to clear the whole structure. In maple_big_node, we define slot and padding/gap in a union. And based on current definition of MAPLE_BIG_NODE_SLOTS/GAPS, padding is always less than slot and part of the gap is overlapped by slot. For example on 64bit system: MAPLE_BIG_NODE_SLOT is 34 MAPLE_BIG_NODE_GAP is 21 With this knowledge, current code may clear some space by twice. And this could be avoid by clearing the structure as a whole. Signed-off-by: Wei Yang CC: Liam R. Howlett Reviewed-by: Liam R. Howlett --- v2: correct the change log on clearing all maple_big_node currently --- lib/maple_tree.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index c3370c7449c2..b459fe1a3ebe 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -3134,10 +3134,7 @@ static inline void mast_fill_bnode(struct maple_subtree_state *mast, bool cp = true; unsigned char split; - memset(mast->bn->gap, 0, sizeof(unsigned long) * ARRAY_SIZE(mast->bn->gap)); - memset(mast->bn->slot, 0, sizeof(unsigned long) * ARRAY_SIZE(mast->bn->slot)); - memset(mast->bn->pivot, 0, sizeof(unsigned long) * ARRAY_SIZE(mast->bn->pivot)); - mast->bn->b_end = 0; + memset(mast->bn, 0, sizeof(struct maple_big_node)); if (mte_is_root(mas->node)) { cp = false;