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 F3DB4C77B7A for ; Tue, 16 May 2023 10:53:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 867DB28000F; Tue, 16 May 2023 06:53:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 817E6280001; Tue, 16 May 2023 06:53:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6E07828000F; Tue, 16 May 2023 06:53:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id 5FCFC280001 for ; Tue, 16 May 2023 06:53:50 -0400 (EDT) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 3793D16015B for ; Tue, 16 May 2023 10:53:50 +0000 (UTC) X-FDA: 80795807820.20.309D07B Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) by imf08.hostedemail.com (Postfix) with ESMTP id 6466E160017 for ; Tue, 16 May 2023 10:53:47 +0000 (UTC) Authentication-Results: imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Sc33jbHF; spf=pass (imf08.hostedemail.com: domain of zhangpeng.00@bytedance.com designates 209.85.214.180 as permitted sender) smtp.mailfrom=zhangpeng.00@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1684234428; 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:dkim-signature; bh=n626oaPkQJb0yVduT/hXLekvHPq7ugOQkvnQZLORBVs=; b=pGslArWeBT6PPLZ4JzkfIkdS2pFgfyqlOxVPxI2z+YGAUajeBh+zc+VFbajMuo+d10dFmZ M9yqYdbuEQvtD9oCETIDFlRmFvFPe/2g4Iy6lmAMXKgLnGBvroLcUMCNyltkZM+sIWbD25 0mDQabBgItQ4XZNBbbia9wA3lp4CTmE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1684234428; a=rsa-sha256; cv=none; b=0BEKdXSOxm2v+M725+XK65LRbt/K9LhbsrUXLzmFYEivFvkxHhf9vbb4vS+8OT40Wi3OdR Osy07x37ZTgHELRIw89BKQkuAvUxmzVOe83CG8iFZzGGjDRZcmh8ulGvTbv2jI5rCWoVte mAsdbR4XU7pfMywX2IC4txmKL6cUyXk= ARC-Authentication-Results: i=1; imf08.hostedemail.com; dkim=pass header.d=bytedance.com header.s=google header.b=Sc33jbHF; spf=pass (imf08.hostedemail.com: domain of zhangpeng.00@bytedance.com designates 209.85.214.180 as permitted sender) smtp.mailfrom=zhangpeng.00@bytedance.com; dmarc=pass (policy=quarantine) header.from=bytedance.com Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1aaf21bb42bso98921545ad.2 for ; Tue, 16 May 2023 03:53:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance.com; s=google; t=1684234426; x=1686826426; h=content-transfer-encoding:in-reply-to:from:cc:references:to:subject :user-agent:mime-version:date:message-id:from:to:cc:subject:date :message-id:reply-to; bh=n626oaPkQJb0yVduT/hXLekvHPq7ugOQkvnQZLORBVs=; b=Sc33jbHFBWIl+idyGSuvHTzkB5uy2T0qJJr6vFv9fig/cTa1qfp++Q8NraXhnN6PSa ZNfKkaPoJDIwVLH3Kqjy621jzqy3Zr1rar/fCN1E8NdZ3veZ1cpteBrNV4xYYDFeVuwU Vy/pdHsbxsQUPhNXlSJ9w6tYpLxmCWGt6BE08CwxEBdcxeDUdCrwNcQrxTZSbN3bnkUC VSyyVc2Xmzm6uTHufUjLvD5kueb8j/ty3ivLrOijcPa+ZEsGWIt5ivnzUlFFH4lDvye8 d8qbeoa2KxPMyzrXTkH6bS6flCjA2XiiAJXtTrzw0vHO99txCDG8YfOMQWoCDWTwAa56 iGlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1684234426; x=1686826426; h=content-transfer-encoding:in-reply-to:from:cc:references:to:subject :user-agent:mime-version:date:message-id:x-gm-message-state:from:to :cc:subject:date:message-id:reply-to; bh=n626oaPkQJb0yVduT/hXLekvHPq7ugOQkvnQZLORBVs=; b=UW575IUltGtV+biL2ow2vi/hSElDa3IDc/j41QawOqOSBVrKYQRkpaL6vOMpXH9rC6 m87/bUNdC9cy/tAhuPDytXgyD6yYBx0hkdWgrPkeAVGDJW5zyswBFutR7fVjAXWlkguG r2LmqMrpvysdX9ybv1AW5qTwGMIcsumwWiNdSP/5sDrzr/UTjyssPYxPm/gpNsniuBFT NLhT7qeKzUyJU2bKfCetCsKYzfmgZlEYgzSlNTpvcaRyM5Evcu3AC19+O/lm6abnC8cE KLaLhediTy+cs4xhh+Ebl0MPnlI+sPz+H/ZTKooAeFrsqMHHsbJ9un1rBQBY8BHxuIe6 liDA== X-Gm-Message-State: AC+VfDzPfkrrFptUWWaMTBh7Or2pQyeOaIZlbCkhCU+1WwB4yCF3T5Wp sXg+Q6/L8DWqPaVYGIg2VEl0Cg== X-Google-Smtp-Source: ACHHUZ5AQfk++7pQRRXrAeOET+n8VfLHWJwlbGOEJClVwFhamRZRow7rehPU2kjHi+vGVg4AzEgu1g== X-Received: by 2002:a17:903:120f:b0:1ac:6d4c:c265 with SMTP id l15-20020a170903120f00b001ac6d4cc265mr38206074plh.28.1684234426023; Tue, 16 May 2023 03:53:46 -0700 (PDT) Received: from [10.200.9.178] ([139.177.225.227]) by smtp.gmail.com with ESMTPSA id i2-20020a170902c94200b001a988a71617sm15185678pla.192.2023.05.16.03.53.43 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 16 May 2023 03:53:45 -0700 (PDT) Message-ID: Date: Tue, 16 May 2023 18:53: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.10.1 Subject: Re: [PATCH 10/10] maple_tree: Simplify and clean up mas_wr_node_store() To: "Liam R. Howlett" References: <20230515131757.60035-1-zhangpeng.00@bytedance.com> <20230515131757.60035-11-zhangpeng.00@bytedance.com> <20230515185810.esnbqaybs5ivttwq@revolver> Cc: Peng Zhang , akpm@linux-foundation.org, linux-mm@kvack.org, linux-kernel@vger.kernel.org, maple-tree@lists.infradead.org From: Peng Zhang In-Reply-To: <20230515185810.esnbqaybs5ivttwq@revolver> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 6466E160017 X-Stat-Signature: kkr55rjaqdnbhw98mhruucamgnyk8yq3 X-Rspam-User: X-Rspamd-Server: rspam09 X-HE-Tag: 1684234427-390161 X-HE-Meta: U2FsdGVkX19A2i6LrQuutxuxclZ68o8uG9wNAq4E8w+miVZURnIemkM3dgQIn2jYpsFybp+uPbtW+PGqX/l18fKoAnUtCh+6lxWjKo3h9owTnpxB+i0DnRpk/74A49XVC1BoskYAdFsBrHVmHKsglmalfsGdUDnj4rqT+fH5PqTqlef4a0trWir/Me3jGbI5ARErfG55CZWWtXzBRqBnoeLSsjKwUrBUi7r4JCO2Lyvi2RVQv9UTmLkxNm6LgSkdZbjTyTXrB2As7+EPrY8v5xCO0L6nn8hYymbiTzxer6H8+hQ8GC1v9fLQXVTO6oSCuhqwMFcZA+soH0nTRTUNVI33dLH2eNQnfN2e7Qm8YKNBSEylIGlnaTBJh+9XShHxk3UD00OsoPtaF78RKi43TAQIjY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h1R6jkk/PUSCFp+Iwu1 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: 在 2023/5/16 02:58, Liam R. Howlett 写道: > * Peng Zhang [230515 09:18]: >> Simplify and clean up mas_wr_node_store(), remove unnecessary code. > > This change fails the userspace testing for me. > >> >> Signed-off-by: Peng Zhang >> --- >> lib/maple_tree.c | 75 +++++++++++++----------------------------------- >> 1 file changed, 20 insertions(+), 55 deletions(-) >> >> diff --git a/lib/maple_tree.c b/lib/maple_tree.c >> index d558e7bcb6da8..ff4aa01cf88b6 100644 >> --- a/lib/maple_tree.c >> +++ b/lib/maple_tree.c >> @@ -4066,46 +4066,21 @@ static inline int mas_wr_spanning_store(struct ma_wr_state *wr_mas) >> * >> * Return: True if stored, false otherwise >> */ >> -static inline bool mas_wr_node_store(struct ma_wr_state *wr_mas) >> +static inline bool mas_wr_node_store(struct ma_wr_state *wr_mas, >> + unsigned char new_end) >> { >> struct ma_state *mas = wr_mas->mas; >> void __rcu **dst_slots; >> unsigned long *dst_pivots; >> unsigned char dst_offset; >> - unsigned char new_end = wr_mas->node_end; >> - unsigned char offset; >> - unsigned char node_slots = mt_slots[wr_mas->type]; >> struct maple_node reuse, *newnode; >> - unsigned char copy_size, max_piv = mt_pivots[wr_mas->type]; >> + unsigned char copy_size, node_pivots = mt_pivots[wr_mas->type]; >> bool in_rcu = mt_in_rcu(mas->tree); >> >> - offset = mas->offset; >> - if (mas->last == wr_mas->r_max) { >> - /* runs right to the end of the node */ >> - if (mas->last == mas->max) >> - new_end = offset; >> - /* don't copy this offset */ >> + if (mas->last == wr_mas->end_piv) >> wr_mas->offset_end++; I guess there is a problem here? If we modify wr_mas->offset_end, but this function fails to try the fast path, it will enter the slow path with the modified offset_end. But it also has this problem in the previous version. I applied this patch to linux-next/master but it passed the userspace tests. I need more information to confirm what the problem is. Thanks. >> - } else if (mas->last < wr_mas->r_max) { >> - /* new range ends in this range */ >> - if (unlikely(wr_mas->r_max == ULONG_MAX)) >> - mas_bulk_rebalance(mas, wr_mas->node_end, wr_mas->type); >> - >> - new_end++; >> - } else { >> - if (wr_mas->end_piv == mas->last) >> - wr_mas->offset_end++; >> - >> - new_end -= wr_mas->offset_end - offset - 1; >> - } >> - >> - /* new range starts within a range */ >> - if (wr_mas->r_min < mas->index) >> - new_end++; >> - >> - /* Not enough room */ >> - if (new_end >= node_slots) >> - return false; >> + else if (unlikely(wr_mas->r_max == ULONG_MAX)) >> + mas_bulk_rebalance(mas, wr_mas->node_end, wr_mas->type); >> >> /* Not enough data. */ >> if (!mte_is_root(mas->node) && (new_end <= mt_min_slots[wr_mas->type]) && >> @@ -4128,47 +4103,36 @@ static inline bool mas_wr_node_store(struct ma_wr_state *wr_mas) >> dst_pivots = ma_pivots(newnode, wr_mas->type); >> dst_slots = ma_slots(newnode, wr_mas->type); >> /* Copy from start to insert point */ >> - memcpy(dst_pivots, wr_mas->pivots, sizeof(unsigned long) * (offset + 1)); >> - memcpy(dst_slots, wr_mas->slots, sizeof(void *) * (offset + 1)); >> - dst_offset = offset; >> + memcpy(dst_pivots, wr_mas->pivots, sizeof(unsigned long) * mas->offset); >> + memcpy(dst_slots, wr_mas->slots, sizeof(void *) * mas->offset); >> >> /* Handle insert of new range starting after old range */ >> if (wr_mas->r_min < mas->index) { >> - mas->offset++; >> - rcu_assign_pointer(dst_slots[dst_offset], wr_mas->content); >> - dst_pivots[dst_offset++] = mas->index - 1; >> + rcu_assign_pointer(dst_slots[mas->offset], wr_mas->content); >> + dst_pivots[mas->offset++] = mas->index - 1; >> } >> >> /* Store the new entry and range end. */ >> - if (dst_offset < max_piv) >> - dst_pivots[dst_offset] = mas->last; >> - mas->offset = dst_offset; >> - rcu_assign_pointer(dst_slots[dst_offset], wr_mas->entry); >> + if (mas->offset < node_pivots) >> + dst_pivots[mas->offset] = mas->last; >> + rcu_assign_pointer(dst_slots[mas->offset], wr_mas->entry); >> >> /* >> * this range wrote to the end of the node or it overwrote the rest of >> * the data >> */ >> - if (wr_mas->offset_end > wr_mas->node_end || mas->last >= mas->max) { >> - new_end = dst_offset; >> + if (wr_mas->offset_end > wr_mas->node_end) >> goto done; >> - } >> >> - dst_offset++; >> + dst_offset = mas->offset + 1; >> /* Copy to the end of node if necessary. */ >> copy_size = wr_mas->node_end - wr_mas->offset_end + 1; >> memcpy(dst_slots + dst_offset, wr_mas->slots + wr_mas->offset_end, >> sizeof(void *) * copy_size); >> - if (dst_offset < max_piv) { >> - if (copy_size > max_piv - dst_offset) >> - copy_size = max_piv - dst_offset; >> + memcpy(dst_pivots + dst_offset, wr_mas->pivots + wr_mas->offset_end, >> + sizeof(unsigned long) * (copy_size - 1)); >> >> - memcpy(dst_pivots + dst_offset, >> - wr_mas->pivots + wr_mas->offset_end, >> - sizeof(unsigned long) * copy_size); >> - } >> - >> - if ((wr_mas->node_end == node_slots - 1) && (new_end < node_slots - 1)) >> + if (new_end < node_pivots) >> dst_pivots[new_end] = mas->max; >> >> done: >> @@ -4429,7 +4393,8 @@ static inline void mas_wr_modify(struct ma_wr_state *wr_mas) >> >> if (new_end == wr_mas->node_end && mas_wr_slot_store(wr_mas)) >> return; >> - else if (mas_wr_node_store(wr_mas)) >> + >> + if (mas_wr_node_store(wr_mas, new_end)) >> return; >> >> if (mas_is_err(mas)) >> -- >> 2.20.1 >>