From patchwork Tue Sep 24 12:39:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13810895 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 B84E0CF9C6B for ; Tue, 24 Sep 2024 12:41:40 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 318C36B008A; Tue, 24 Sep 2024 08:41:40 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2C8536B008C; Tue, 24 Sep 2024 08:41:40 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 190256B0092; Tue, 24 Sep 2024 08:41:40 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id E17B96B008A for ; Tue, 24 Sep 2024 08:41:39 -0400 (EDT) Received: from smtpin01.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id A55381A112F for ; Tue, 24 Sep 2024 12:41:39 +0000 (UTC) X-FDA: 82599593118.01.9EFA240 Received: from mail-lf1-f52.google.com (mail-lf1-f52.google.com [209.85.167.52]) by imf11.hostedemail.com (Postfix) with ESMTP id DCBC640013 for ; Tue, 24 Sep 2024 12:41:37 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WcsvGR6Y; spf=pass (imf11.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.167.52 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727181662; 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=oNxGQ+aYB9uCw8MY4JmeL6xnjWLzH1FdLZAcUc6N6U0=; b=OM0Suq6qOdiJ2WVwVsWtssVk9OLS32JZVIXqKNWa6+5P2FlZKcNqoOz08MZcXoke3Ynk65 8crvi6K/qDw/vJ0pfWXLDqcVhxRNhpPbmmKaADhaShg+2Bkw+epUUJwx67bkwcR++bySXt JGAeLTBmSjOQ30oRzKUI2eVBG3srF6g= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=WcsvGR6Y; spf=pass (imf11.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.167.52 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727181662; a=rsa-sha256; cv=none; b=GQ8afrUExszXVWguqn+lNBO0X+G0WpD4W9HdMaXprnskLbRRGhwo6yBwuj7lENT+2junw9 j5WCMLK1kAZ6q5yKjohHr4feTVQR9dBQDgjDxw9mSjg+GCoqx9QHI/BPahnsS9ezF3locY 5HW4yx7SA8KlNoqGuwtpckTzq5PKOYY= Received: by mail-lf1-f52.google.com with SMTP id 2adb3069b0e04-5365aa568ceso6409185e87.0 for ; Tue, 24 Sep 2024 05:41:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727181696; x=1727786496; 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=oNxGQ+aYB9uCw8MY4JmeL6xnjWLzH1FdLZAcUc6N6U0=; b=WcsvGR6Ydep4FVe72/un7+MS3Hao6TPCDX5voBLTBtoaCB2IY0cI76duMIIAG1PFqE /dqgzHbnjHlCZ9+F2S3iT0SgjxPWDvkxUFXoVe2EKhvDlV7wKgAWgSa42YyWn5TA3Bx8 3g4/rOY49cnDh8eMPW/6MFdM7Kft96zSag6nAenGWjyVVCxAUzi9YUuXdZ9QdkfmKYpm w3DkMy4bWTQcblLKEK/WVmkYAYO4UGD7bAYj2Et5uSGXCcJVFLnp1SD+6kbVq9oBnDzg wARjxmbGsvTw8ri2XZJFgixKywVeuU+9JG1tL1Kr8pw1gxC16IkR04OpfotRWUqJDCqH cDrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727181696; x=1727786496; 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=oNxGQ+aYB9uCw8MY4JmeL6xnjWLzH1FdLZAcUc6N6U0=; b=O6igELdyUrCSw6XLurjvWYOBXW6deDns6yodj5vGomrrM06WKQzOu6TIzn+Ka1pd8c 5xIVXBsnUgpppv3xPZk/zk5tc6JMsjoKo5WcxeA4z0sLjO7G1poj7SlgtS/KmeIdVb/O 9lB7Og7FKtg7g3NCOX7avE9shlhcON4dyYo+ZaI4QFTMeR31GaC9JdOrzjUfjNBefYHa xCzrMmWlWFquwXQ4XkRHP592pbVVc3deB/RWjjauZ8y0bGQObjuRUO18DBiFNkXvfKBR 7wUZTrjsfqYG5bRCZaeBFAc4z4cTDrQQIUYv6kH54ZwZfD2Hsqrcu2vxuvWplVGqWHJY 15lg== X-Forwarded-Encrypted: i=1; AJvYcCXz5kAmmLV5JETsO9OWiRpMq6AIcdnNEe2TMdgq6JuYFfTXG2eg6ZcnBH5ACtcnp6FHrTjHyHIdxA==@kvack.org X-Gm-Message-State: AOJu0YwHgC97CWtN6OoZNKhBvZCYhZ4lSLq9jCR2b8fOINKmCkiQBxqW vcX1r/kNqb+tCxMr2L6ZaafgRfv91xQ2bjy5WqG1znE+1b4T+fC4 X-Google-Smtp-Source: AGHT+IElonvP7Jn72Wkfz10aUqBKxkesxTOzLAO2vhcX2eYVvOsVaMsi0+sEkvgT7u0gZDTZzSGYEg== X-Received: by 2002:a05:6512:2395:b0:531:8f2f:8ae7 with SMTP id 2adb3069b0e04-536ac2f5196mr10275125e87.25.1727181695883; Tue, 24 Sep 2024 05:41:35 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a9392f5466asm80151166b.76.2024.09.24.05.41.35 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Sep 2024 05:41:35 -0700 (PDT) From: Wei Yang To: Liam.Howlett@oracle.com, akpm@linux-foundation.org Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org, Wei Yang , "Liam R . Howlett" , Sidhartha Kumar Subject: [PATCH 1/4] maple_tree: clear request_count for new allocated one Date: Tue, 24 Sep 2024 12:39:51 +0000 Message-Id: <20240924123954.18933-2-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20240924123954.18933-1-richard.weiyang@gmail.com> References: <20240924123954.18933-1-richard.weiyang@gmail.com> X-Rspam-User: X-Stat-Signature: gzxhypdeu1s8qpc8ufd7ijs3rkn3jioo X-Rspamd-Queue-Id: DCBC640013 X-Rspamd-Server: rspam11 X-HE-Tag: 1727181697-287570 X-HE-Meta: U2FsdGVkX1/dgnZnnRTEzmyVPdTcT8PtF8Q7akV0x8akk5F/aId56pBI4ouq6aMNRyAS13fuA1P/JoGtPLDKRIf5GtCwcoa2bmb7NrDVvRNwE4FtvLUnY3j417eJJXWZ4eFn4XTgNsry6I+6OzYn/3XPSf6AQG0VxZwpb6BxN+FkegTgXzdTp0jYs2XHKIWncRRqdLJXhP0LQC4HKfJYlnB/EVOGvsoX2pyOOAYI2MrqaEUX+VWOy6MOCqeTuOigMlS1y+K5hYpKfsGnefqPM5Mjb+BQhgMqPI1UIzYtlB4dQmFIQn4n2eQWcBRnzfo4Uqbz1qTHJpR9RcH5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HC+Qmy79YLEsr7qHA7m/Oqhju/BEteJuc/SGXyBg4gGNeSNnwuTsgbZqRyVGvBPEvc/P0s5nbP02ux+5QLuF985882NZhA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.001503, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: If this is not a new allocated one, the request_count has already been cleared in mas_set_alloc_req(). Signed-off-by: Wei Yang CC: Liam R. Howlett CC: Sidhartha Kumar Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index fab1610dc800..75be2c81f0e2 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -1250,11 +1250,11 @@ static inline void mas_alloc_nodes(struct ma_state *mas, gfp_t gfp) mas->alloc = node; node->total = ++allocated; + node->request_count = 0; requested--; } node = mas->alloc; - node->request_count = 0; while (requested) { max_req = MAPLE_ALLOC_SLOTS - node->node_count; slots = (void **)&node->slot[node->node_count]; From patchwork Tue Sep 24 12:39:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13810896 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 04A25CF9C6F for ; Tue, 24 Sep 2024 12:41:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A92866B0092; Tue, 24 Sep 2024 08:41:41 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id A41916B0093; Tue, 24 Sep 2024 08:41:41 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 895746B0095; Tue, 24 Sep 2024 08:41:41 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 6105A6B0092 for ; Tue, 24 Sep 2024 08:41:41 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 0FC1A1C6B3C for ; Tue, 24 Sep 2024 12:41:41 +0000 (UTC) X-FDA: 82599593202.09.3C49C74 Received: from mail-ej1-f48.google.com (mail-ej1-f48.google.com [209.85.218.48]) by imf07.hostedemail.com (Postfix) with ESMTP id 4F6F840017 for ; Tue, 24 Sep 2024 12:41:39 +0000 (UTC) Authentication-Results: imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ksZKYuhm; spf=pass (imf07.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.48 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727181581; 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=7ukK8M8lT8M3ISBtZtHKSux3K616jUxUW6DFx49LVxk=; b=gPJ7KkL3XyND/g21YNyBLCDf+ISb6NvPnM+WXRrwWRx/lrGqKflWXYJJ0uC1xmBl65mfGL LkQDMCZW1qfXIcVK/qXJkMxkbhzBNMeVGU34ZX7TsvQW3sY9cWT6DY4HUA92iJqBTec7X8 kExGJbH+jOnoM6h5GHnzCuZfbJRELMQ= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727181581; a=rsa-sha256; cv=none; b=END9eeQapNyXdT4T+KdIaylONablSdeflpyLBrSWUv2Yla+MNFqeZU8ZOCa2drXUJ/Hzq6 P87CPkYmJV1C0KnPTWnGYLaPct5S21BD7KZWxbxpvZq4LgkIsw+E/YF03i2uezlXLtPBgK kSPDKutpe+YtcVuHRT8AkM86pY+3lr4= ARC-Authentication-Results: i=1; imf07.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=ksZKYuhm; spf=pass (imf07.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.218.48 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-ej1-f48.google.com with SMTP id a640c23a62f3a-a8d51a7d6f5so822652066b.2 for ; Tue, 24 Sep 2024 05:41:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727181698; x=1727786498; 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=7ukK8M8lT8M3ISBtZtHKSux3K616jUxUW6DFx49LVxk=; b=ksZKYuhmjxw4T9elHV8j0x+HtkgYEO7TmTZBcc1g9jmyp76nM9GnPCzb9/BpU21Ctx ugA1BQF9BSpNsXqiu0zKTCnGVeE6PUCenUTP81o73RG3RUED/N/bgCUp3q9VK+dpEGrJ +mUi0XF/iF+DhHs+L7KpVeK1JBUfMXAwDXniZin54uW3C1WclzlzrzXCG46tizOjLldX +hCRVMnGM6/14v+etJQwC6gQrWYmIFKbOFxoDqkP7pOVE8Gsnj+i8lmFH6ZAxyUOTwX0 owlNrdgaz+jSA96Cjmc59yuCaRpNZseFvrdDx10dTefCTZ/Y3qVLgZS7Lkrjdi9PD1/b hVcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727181698; x=1727786498; 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=7ukK8M8lT8M3ISBtZtHKSux3K616jUxUW6DFx49LVxk=; b=OvpcVi8SJ8z0nipIQkwsj13kyun/eMiWhJHdr2MyAAQ+GFtMVUbifpTC6ubd8rR4Gn 6pLFUdhgOID8XX9g258aA5IgTGOy91//HLQhMM12mgWGy5cjUkAH1jJ5QWffM2xhG8er ACAbmj/e6NUMJffh62K/YAWOIQnnk/dqmGHFTsN+vdpEB1UPCtZQLBdLHAB9W5rMxpOS fg2UNY02M8xA2CmauWG04zQKLHQ/VUnjE59G5qvkGjtjuaAl8Tuxc1xKNMe9eBm9AXE5 Jym4pM8RvlfY8KESKZVesaVHp36/ZRnX8VoPmNSFuNpxqmqaLh+LdxNhlUMyfuN7Wnek Esgw== X-Forwarded-Encrypted: i=1; AJvYcCV8XQwDRS40FeGC8u/7WyF08EoHeC6GP8fjg0Dj0yqpCJV4WaMp1Yyop2TM7aCQiTaWWmaObUovIw==@kvack.org X-Gm-Message-State: AOJu0YyR1dsK5j0a+p1dH4ZmIYs7GeH9KbcdN9NEQ+Kx81aBEj8k/fy9 pOApnMy6ODmB5CLql0L7Hga2t2klV0iURD/ZwBzSs3+lK+MEvbEzzbF3xjCT X-Google-Smtp-Source: AGHT+IFACUJu2dw+Qf9lNGpIaoQCjyd2WIgKuG+GqbRuI1Gg+VeYxr/0igAOcu09yw/MQAvhIj18vQ== X-Received: by 2002:a17:907:e269:b0:a8f:f799:e7db with SMTP id a640c23a62f3a-a90d4ffd95bmr1297917866b.16.1727181697569; Tue, 24 Sep 2024 05:41:37 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93930f79ddsm79709266b.158.2024.09.24.05.41.36 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Sep 2024 05:41:36 -0700 (PDT) From: Wei Yang To: Liam.Howlett@oracle.com, akpm@linux-foundation.org Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org, Wei Yang , "Liam R . Howlett" , Sidhartha Kumar Subject: [PATCH 2/4] maple_tree: total is not changed for nomem_one case Date: Tue, 24 Sep 2024 12:39:52 +0000 Message-Id: <20240924123954.18933-3-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20240924123954.18933-1-richard.weiyang@gmail.com> References: <20240924123954.18933-1-richard.weiyang@gmail.com> X-Rspamd-Queue-Id: 4F6F840017 X-Stat-Signature: p6gihscp5dhpiw7fuq4g7rgtefaumq3b X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1727181699-76632 X-HE-Meta: U2FsdGVkX19xXBcdxLQ2mAHBUj3TDr/21JPP1+D+EVuX55E8VMS1EN34cIToqMdcs2mIE3x6ajx1Ib/ogvdvv1vMbxZg8nPX4/zZAedukl1FnYfQdiCq58YlHpg/lLghni+7UA4oE3/yD4z7JL20XI9afaLim1oIdrYVtQlloeTZD0C80J+5DYSN6lF+UuoLP4in6pra9rfWiJx7dsi4mA4sX9gB5W9pStDYTjOm7vZ/JQvqhaUZelt/X2aGOAIvs0SsjXDNwiXG+P3eoKJV+28l4RnnaOLGlCK5gSfU3P4M6V963AEZdSc125i6QiPOo5C4H9xWoLkEXlSjh9UUspFmZ/uGzMk1dp0j+JugqbPy8hpXcVv7P3Ecaf8cTwYzL5faTQfEGDWnd2++IuB+1fxYM6/oWPzrzF6v6XvCwZQ3zxurj7iqRYetwgQl2ZM2GFF+uA8rBvFgt6Giyh+dKNdzZBFNkU05hHCMTOVoriJT445ff+j5gsX3Pd1DbCv3inlwv5sCpZTGFRZgjR5ybGjfhOWbhboV/7x6i4Q5suC+XZP25uqfBoU2FRizfusfhUoWx0KLbd2mF0htyZRrju4Pi8UzHlnJAnPw4n8Chs5RfO7whBfq8DlKCo3ZxgSv3y55cKfVS+8rxRO2B+G2DjDLkuSgKrwUFgl29vN+i+KwA0sN5+aZPl9mwOSrXT26fu9NRElEgkOEoI/YY6TIH/ZBwnEKvM9WUXwQgAGiig7eHFL1yVxvXKLmBg45AxTqMOZ6chJwkZsga/h6yHTF/Jzhy+ooI11bKstxKKOaoP1i6PHDKpg7IvOWscgiqxTDq79z4YTN+Z56yPwaWvR0c7c3WObNtF4FrqAbDXXwNVeRXJUi/ljYJpHjQRAAKsPyysEJDqbY1N3DA3Fgb0NvnrxepLMJpWi+JnuJdRlw6epk9L5cGLtUDcOAd+5nU2aKwGNs06cLtrTNgmBx6ps no4UwHLI p+UHdX3ZJzyU1/mRAdgbEdMTnaW5uW2BLFs4pmRpmDXyuftJxJcJ2LLVX+bwjObew1AsoBdG5T8T3kYLHpYYwfOyMm4eeRYbBGSDipFb1gAJVJj2X84SZF5xZts+UrSMSnbEi3WD7jedLGTZLebE/eg/50XE7h4yjvCcpnU1bKaA7YOs+kcjeuw4KK01OeI+tWj671BNc/dkNjx/juwBpJSv920Vf9dmlml/NYJz8FZq0sN29BQ9zcYo6b0IYEC7QngMFKmX/74eIOqPZOCWSIx9+GDCK6vGrk2+3SaLvuSn2sptQ2otqcBcm7+5BHamgVIWbWepkZFGl+jMlNnDkqcxayQwN3wxCfelfzkUKoeN2l6Vl5AgSBQMADh5AuuDOrIoCLtwlCAeQy8pK/fTWnjydzoDx2kGOWfGdHbQn2s5JY6F7HeOCU1+rxWAVHOLUZN9TS64IVvJmhSR7B73gL/w9L95HjZLT/mL2g/Cu8YWk0HNf/XfKfeJfaIFtmO6N6qh8dYsvArXHH7ykXd7HiHB5sg== 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: List-Subscribe: List-Unsubscribe: If it jumps to nomem_one, the total allocated number is not changed. So we don't need to adjust it. For the nomem_bulk case, we know there is a valid mas->alloc. So we don't need to do the check. Signed-off-by: Wei Yang CC: Liam R. Howlett CC: Sidhartha Kumar Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 75be2c81f0e2..c1fb67540cc9 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -1279,10 +1279,9 @@ static inline void mas_alloc_nodes(struct ma_state *mas, gfp_t gfp) nomem_bulk: /* Clean up potential freed allocations on bulk failure */ memset(slots, 0, max_req * sizeof(unsigned long)); + mas->alloc->total = allocated; nomem_one: mas_set_alloc_req(mas, requested); - if (mas->alloc && !(((unsigned long)mas->alloc & 0x1))) - mas->alloc->total = allocated; mas_set_err(mas, -ENOMEM); } From patchwork Tue Sep 24 12:39:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Yang X-Patchwork-Id: 13810897 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 8D6BACF9C6F for ; Tue, 24 Sep 2024 12:41:45 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 90D386B0093; Tue, 24 Sep 2024 08:41:44 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 89FB26B0098; Tue, 24 Sep 2024 08:41:44 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 70E0F6B0096; Tue, 24 Sep 2024 08:41:44 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 524096B0093 for ; Tue, 24 Sep 2024 08:41:44 -0400 (EDT) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 14F2D141A1C for ; Tue, 24 Sep 2024 12:41:44 +0000 (UTC) X-FDA: 82599593328.11.4870E60 Received: from mail-ed1-f44.google.com (mail-ed1-f44.google.com [209.85.208.44]) by imf19.hostedemail.com (Postfix) with ESMTP id 458931A001D for ; Tue, 24 Sep 2024 12:41:41 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=POt2Pgi0; spf=pass (imf19.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.44 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1727181583; 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=DTCX2QOThzsuQGVtvyCK7mVFsPrbNpg/YVipOq7FEAY=; b=bDHzdp1hQPMBk7aj0jrWGeQsJUgdrk7RtOc1HXirb4tCcnpWZXiaU492bJKhxUZa84NROk oMBvJhJc6HfdGnI/Q0G+IvXItYNJfG+ffAt9yHkNNU5rh1ZN4ASghCz6KrmhinivxKP9zO kscNh2Q1sBCBdXeQ2A+oxQJaLvM5dk0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727181583; a=rsa-sha256; cv=none; b=yyj6LKI9kJ44/nLKxwZTVdiKzIdeg0yQZNWu7mDZ887puol8UqYylLWBDf2L4LCgEeHKVc NLTwNohXTvRAtcSdpu1L2wftMWsoKwKPKiJ9koeiH6d3iZhDkq9E5yw3Vd1bGCR7AjcG37 dz56ETM6bOzgM9MJ+2UbPVJ60uKdxzE= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=POt2Pgi0; spf=pass (imf19.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.208.44 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-ed1-f44.google.com with SMTP id 4fb4d7f45d1cf-5c26815e174so6894116a12.0 for ; Tue, 24 Sep 2024 05:41:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727181701; x=1727786501; 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=DTCX2QOThzsuQGVtvyCK7mVFsPrbNpg/YVipOq7FEAY=; b=POt2Pgi0FIX9nEbQhLNbzOlBnMxnSZq9okmLj9MQL3pWXOLbDDjW7mnFkFH4z1XKqi BDmCYXArVeSDHRDm9co1Wj0P85riA9HqFwMdlPZqXe6OZsvIKQNOc2aAzjVL9Mb3S1DL a+cM8DJj/HIvE4WXjJK5ZBNZeaOGz8hnvg9mpfAPI84CvEOJG1oHfB2jaitsTIO6dhDK 5vJTHuNPFoDifnXAZ3kFr/q59/RhUYEDzKU0VV5IPao7jhR3/oJRotYKk9Mv9P/+eOFc XE2cvNZRlr/LaMVNqojHcGZFFuNW7mx8xEAwLGkkk/zF2pSH8s3cXWKWlRPoMyy1o7My i4kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727181701; x=1727786501; 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=DTCX2QOThzsuQGVtvyCK7mVFsPrbNpg/YVipOq7FEAY=; b=BEjvuPpNWqCs4F71s2xfp222t+vw2gfXgwZoA7DMfftdwVbvw5p9F3mb1QnW9snoGj 0+aiChRqNLWDIhbJnPtDXGhYEeLzYlQ8XJKORLITHaTjkJSr0NzCgOZ7dSV5s3UUmP1S tHy9+YvYk0vVrJWu4CoDHgXQNRH2Qzm9YhyH1I2zD7XqC+bxWf4li16Q5nTGUXhcske6 cUER0AyJScUmdlnu2t+mjm/cUZqD1Xi62pFF+aRObJ2jkFEIPTwWZPjTZJLjOMufbn1q S1oZzxjbFU3ljERZfTGBQcu9Vo7H9bdMf/Thv/H0XZH6cYdZFKkY1im1thCt3g26/7iJ I4Fg== X-Forwarded-Encrypted: i=1; AJvYcCVnFEuTHOcVv7XOguaxGcXJbaQizLLjdSinjw9Co2T+XFABReLJL+0JN01IdVNmScP4hTEgBN7p/w==@kvack.org X-Gm-Message-State: AOJu0YzEpq6k7Oe0wopiC+oY9PmaFmshGeoIVv+YkHp9p1AH+z7olB2i SoI1k49CFHZq6Yp8DFsOvRpROCq/U+bNlyD8whA9C3USlTxU3ToV X-Google-Smtp-Source: AGHT+IH+XP6lIGGVxVF9U71t98fzOQtKGbu57SrPwdbiI8wl2USUAsjdeJpinlo18qkAYo0Pny21Uw== X-Received: by 2002:a05:6402:13d6:b0:5c4:6568:736c with SMTP id 4fb4d7f45d1cf-5c4656874bcmr15847420a12.0.1727181700529; Tue, 24 Sep 2024 05:41:40 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c5cf4d78b1sm717610a12.87.2024.09.24.05.41.38 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Sep 2024 05:41:38 -0700 (PDT) From: Wei Yang To: Liam.Howlett@oracle.com, akpm@linux-foundation.org Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org, Wei Yang , "Liam R . Howlett" , Sidhartha Kumar Subject: [PATCH 3/4] maple_tree: simplify mas_push_node() Date: Tue, 24 Sep 2024 12:39:53 +0000 Message-Id: <20240924123954.18933-4-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20240924123954.18933-1-richard.weiyang@gmail.com> References: <20240924123954.18933-1-richard.weiyang@gmail.com> X-Stat-Signature: bx3d8agdiqzi7ptzrddzo847s86n4x68 X-Rspamd-Queue-Id: 458931A001D X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1727181701-7520 X-HE-Meta: U2FsdGVkX18n780AtaolJiDuU00cw5uyuDhbqYoqY5iS5NOqvlLf7fXt9kGmgIKambw3eelx98y3oaokny+LLmqrScLta72Cr11zfJ2w4+jwEFvgiPpgTRD9X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NaHRrI+1WYE7oHg1lqCLd5FNmChjkcEAqjRXLwNyQseelTxHiJ2L2TIyFt4veiOT4l0IBBfvch3EokzEwvzL0vXMbtUFXIk7xkV+RsOUK2jzWfjkne/ws4fneY+xMgF2w/kOv38bjyvfFK+lgpo63VNtc7WkoIVwnZlvmnl2PB3LuAO9+xBSMefsGnu0v2LA7npwA/J+LO4yUhJXa+0zf8t2R711FBP5FXWSxQzxO1ij+w14C2WCHGqLd+u2YiFgwPjA670Q6FszpAGKTccsI7lPaYt9OtRgm87cXecCd6p4DPsRK58VAldbytlq3f X-Bogosity: Ham, tests=bogofilter, spamicity=0.000165, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: When count is not 0, we know head is valid. So we can put the assignment in if(count) instead of check head again. Also count represents current total, we can assign the new total by increasing count at last. Signed-off-by: Wei Yang CC: Liam R. Howlett CC: Sidhartha Kumar Reviewed-by: Liam R. Howlett --- lib/maple_tree.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index c1fb67540cc9..1cbc5f7ca40d 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -1192,19 +1192,17 @@ static inline void mas_push_node(struct ma_state *mas, struct maple_node *used) reuse->request_count = 0; reuse->node_count = 0; - if (count && (head->node_count < MAPLE_ALLOC_SLOTS)) { - head->slot[head->node_count++] = reuse; - head->total++; - goto done; - } - - reuse->total = 1; - if ((head) && !((unsigned long)head & 0x1)) { + if (count) { + if (head->node_count < MAPLE_ALLOC_SLOTS) { + head->slot[head->node_count++] = reuse; + head->total++; + goto done; + } reuse->slot[0] = head; reuse->node_count = 1; - reuse->total += head->total; } + reuse->total = count + 1; mas->alloc = reuse; done: if (requested > 1) From patchwork Tue Sep 24 12:39: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: 13810898 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 BCA56CF9C6F for ; Tue, 24 Sep 2024 12:41:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7378E6B0098; Tue, 24 Sep 2024 08:41:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6E7276B0099; Tue, 24 Sep 2024 08:41:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 587DB6B009A; Tue, 24 Sep 2024 08:41:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 365316B0098 for ; Tue, 24 Sep 2024 08:41:46 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id E744641A20 for ; Tue, 24 Sep 2024 12:41:45 +0000 (UTC) X-FDA: 82599593370.13.DD43788 Received: from mail-lf1-f51.google.com (mail-lf1-f51.google.com [209.85.167.51]) by imf29.hostedemail.com (Postfix) with ESMTP id 2158712000F for ; Tue, 24 Sep 2024 12:41:43 +0000 (UTC) Authentication-Results: imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=JtQOMD1y; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.167.51 as permitted sender) smtp.mailfrom=richard.weiyang@gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1727181689; a=rsa-sha256; cv=none; b=AQ7oJos9eeeBdHls5SNvdZtY3Ci+S6ylHjAXTeGV2nLWfoGJQUlY24cmW5oCK8dG9NI8Wz ukQ6v0J9q06S/3QzR4gqImrlCscluARKQoNzXEVZDYiA3w9tNsMLWM9svvuBEc7ufCzRDl LnbDjLZMYpq/l/dj2pXIOd+ZP6Qcgnw= ARC-Authentication-Results: i=1; imf29.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=JtQOMD1y; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (imf29.hostedemail.com: domain of richard.weiyang@gmail.com designates 209.85.167.51 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=1727181689; 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=N+Q8uXR3KF+LFZVg2KeHpqpEsXhd/DDR99/6oIBSVFg=; b=n+RkxoHnPA4TrLqSEYXBHNUADS4zFf16B5RUMfvA0Dhu75myFSDDvNbwdAlVtuOALbuA31 9XJC1E+ZzYh+4OL+FyNtyraGrfMyT8LjkSar1akJpI5hMqJE2Y8DOa29ojQ08Iqhg+K7kD 9L1KlanR7eIfGwLWnWgTcPPYsD9dui8= Received: by mail-lf1-f51.google.com with SMTP id 2adb3069b0e04-535be093a43so6721450e87.3 for ; Tue, 24 Sep 2024 05:41:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1727181702; x=1727786502; 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=N+Q8uXR3KF+LFZVg2KeHpqpEsXhd/DDR99/6oIBSVFg=; b=JtQOMD1ya3ywG21MwuUE6MPhE4tZloaG2H+mAx1EY07Eh2cdN186sxLyacQoHRrfaL zwRXUrO0MZ86dPFvd5sYqaUGrtOIUY9WMfd+wvi+FIOOpNx28WbM/ydrL4uBRPBI0tmC DHhjJ4VGk4cgYfBGd7qLnZS+d02q1rp/sVLibuMnA1eGcP/OjIsTXBQXml/W6esDhe/q dEuo5/YJNK+fWrpBSH+NnsEiTA9JYImAad0fpqdvaNMPUC4Bxk1bz6jLuyebrzWjZE/e xq7mu1Bk29IEtvQufna+M2oFTGkaD9rccOVO/+8ddiMIjuClniM3X6B0g/HvQ4hYeY/Z unMg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727181702; x=1727786502; 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=N+Q8uXR3KF+LFZVg2KeHpqpEsXhd/DDR99/6oIBSVFg=; b=vJsTy9G/APmySPKg9bIGgxnFB8xvfAizDFVzqf95yYTeiWZSaKiF9jnSFWM6NveYTf Ds8RtKalMQJsSzNhFRjCkaNS7NTd6rZcG73uQDDGwFahf9I4e+Ao6VxCeUwMNd4YkvbP vRpJMoqTaYUAKQkWMDYDu+fh/gUazX7LLpYetRPHnIWpLcKJE0m2sV/COBxgO/M4lEFF 079Rys0Cy2qX1bmISjRmVbLb8Gtez7ANDPgIJS400XQ+9CzTy6+wavahPXJ1n6rpKm+Q lwpvsCcZCKrTJjzMin3w2ZUZ5yoj+WDN9xVlMNEV02V4GzFJtNJGxiQW4N6ZDkOWXCUE 2epw== X-Forwarded-Encrypted: i=1; AJvYcCVRyq0++OnMB6FgGMPf3MxT/ue/Z/0thSiX7XxisFf3mj+tz6fIowi/vjHzvVCfzfDm9mKco5BAow==@kvack.org X-Gm-Message-State: AOJu0Yyx8R9el2PmPmKRKZqBMjs3usyzLZrHN4MNeWAOnD+o4fuq6tYk 3E0ht3ojgubgNWxp1ANcyUO11u/ud5C/bJn/OXEiP/TI6CnVCFlt+/ZvYeSq X-Google-Smtp-Source: AGHT+IFC23anDxrBlCXEF3fnkai7bSJ7FqtvuC6+XpVduVYlswcgim0J9o4MTyHSDyJ1LRFZFi8AZQ== X-Received: by 2002:a05:6512:12d1:b0:52c:c032:538d with SMTP id 2adb3069b0e04-536ac2f466amr8144316e87.27.1727181702153; Tue, 24 Sep 2024 05:41:42 -0700 (PDT) Received: from localhost ([185.92.221.13]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-5c5cf4d8960sm686824a12.97.2024.09.24.05.41.40 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 24 Sep 2024 05:41:41 -0700 (PDT) From: Wei Yang To: Liam.Howlett@oracle.com, akpm@linux-foundation.org Cc: maple-tree@lists.infradead.org, linux-mm@kvack.org, Wei Yang , "Liam R . Howlett" , Sidhartha Kumar Subject: [PATCH 4/4] maple_tree: fix potential allocation failure even has memory Date: Tue, 24 Sep 2024 12:39:54 +0000 Message-Id: <20240924123954.18933-5-richard.weiyang@gmail.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20240924123954.18933-1-richard.weiyang@gmail.com> References: <20240924123954.18933-1-richard.weiyang@gmail.com> X-Rspam-User: X-Stat-Signature: mofbuh4kaw6wgtfwmsuds97p3sh8neut X-Rspamd-Queue-Id: 2158712000F X-Rspamd-Server: rspam02 X-HE-Tag: 1727181703-27281 X-HE-Meta: U2FsdGVkX1/CCmcoqTKFf3Utxfseo+Uc0hWxiL4mhEy61MAr02tu6qNVYfSNsH67an4WTSBu05BnL0jzhgOR6VdEx3FajL+SwyJilGhrUVKPuS8Va9nXyls+rht0JztIAaVVBXoRjZVXR9jwqqD+3c2hq4lqega47EweuShfNQ/bcVudZR770aRlh6EymrcPgOMKLEIK6c2yFgje+Sz+szHDTeXNtniHEVWa6Yqnck5lo6dzZs/fco0roL5gpEPGdeTeZm39F2c7l7kw+xriBVj/oKZt5rU5lODWp+jtEbNDC8WD+77gS5Q7kTq+E96XwX0Eg9FcOSCiiEOOvD89z9SGa/M7xZi25jOSMZnbY1bUKh+kJLQloAzVPZHDS3UCEtsFAdOgWwFf3xF30L1xV6l5KrkvxLYfnQsRoJry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+z4MQCDiDVuuCp98STaU 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: List-Subscribe: List-Unsubscribe: We got an rare case when mas_node_count() would fail even there is enough memory. The reason is the maple_alloc grows downward. And when hit a full maple_alloc, the max_req would be 0. This leads to mt_alloc_bulk() return 0, which means failure here. For example, here is the test code: expect = MAPLE_ALLOC_SLOTS + 1; mas_node_count(&ms, expect); pr_info("expect %d allocated %lu\n", expect, mas_allocated(&ms)); expect = MAPLE_ALLOC_SLOTS * 2 + 2; mas_node_count(&ms, expect); pr_info("expect %d allocated %lu\n", expect, mas_allocated(&ms)); We will get the following output, which shows we fail to allocate the required number of nodes. expect 31 allocated 31 expect 62 allocated 61 The straight forward way to fix it is go down one level more. Signed-off-by: Wei Yang CC: Liam R. Howlett CC: Sidhartha Kumar --- lib/maple_tree.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/maple_tree.c b/lib/maple_tree.c index 1cbc5f7ca40d..dd33d0793dd1 100644 --- a/lib/maple_tree.c +++ b/lib/maple_tree.c @@ -1253,8 +1253,10 @@ static inline void mas_alloc_nodes(struct ma_state *mas, gfp_t gfp) } node = mas->alloc; - while (requested) { + for (; requested; node = node->slot[0]) { max_req = MAPLE_ALLOC_SLOTS - node->node_count; + if (unlikely(!max_req)) + continue; slots = (void **)&node->slot[node->node_count]; max_req = min(requested, max_req); count = mt_alloc_bulk(gfp, max_req, slots); @@ -1268,7 +1270,6 @@ static inline void mas_alloc_nodes(struct ma_state *mas, gfp_t gfp) node->node_count += count; allocated += count; - node = node->slot[0]; requested -= count; } mas->alloc->total = allocated;