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 9FB00C83F15 for ; Sat, 26 Aug 2023 20:28:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F01088E0005; Sat, 26 Aug 2023 16:28:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id EB1D88D0001; Sat, 26 Aug 2023 16:28:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D9FED8E0005; Sat, 26 Aug 2023 16:28:48 -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 CAAF48D0001 for ; Sat, 26 Aug 2023 16:28:48 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 9A3351401C8 for ; Sat, 26 Aug 2023 20:28:48 +0000 (UTC) X-FDA: 81167394336.17.BA2F6A8 Received: from casper.infradead.org (casper.infradead.org [90.155.50.34]) by imf09.hostedemail.com (Postfix) with ESMTP id 76D2E14000D for ; Sat, 26 Aug 2023 20:28:46 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=LdYwvMXr; spf=none (imf09.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1693081727; a=rsa-sha256; cv=none; b=tQwjH+64cjmEPYErpuqHx4KWz0qFGchHzchvI/uTKpB8e16k6msLzKLn9W4llRicR7Pr4g j0uVwp4jMzFSyG8f11KK7srMHzNscv4Ql627S18kEtpTEqjWJoz0193g3iPjRYFcERFOyi uJS3RcwRqq232C0t3Sqli52vog14/MY= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=infradead.org header.s=casper.20170209 header.b=LdYwvMXr; spf=none (imf09.hostedemail.com: domain of willy@infradead.org has no SPF policy when checking 90.155.50.34) smtp.mailfrom=willy@infradead.org; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1693081727; 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=GQbLFOOBAbkQ+pMFo1tY5HOEbzfs6NK86EY1TrLGlT8=; b=adXEaRpYML2PSgie9rPE70GCdN5pdeB3JLF89flkRn77A6MteDazjVgVMokZlf8FWy+iax Xl7EbBQw4EvYQyIUnQ7d427WvRaGAnxiZOSFyCmbBjlkDkCGHTw5chDRHmYIzrJPQdiq6s JPZPKtYGZJXzVxGOhxxh6rM6nxSU+xY= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=GQbLFOOBAbkQ+pMFo1tY5HOEbzfs6NK86EY1TrLGlT8=; b=LdYwvMXrpVavNV7//q6Vty51Hq OCPautXtKdR3XtxES41NiGunhEyaALsAfzGwvQ2cv5td32/RwX4nSr1wX9xAS+yUTbgveMc6krFr5 KPZ+3+r+SKOa9ezWPDfjo7u/MmjI184tNuRRgwoBmS/UoVUQDha+tMVeWoBHUZ4KxSxknoZyus8rM 7yZ+jOGT/G/DD0emJyEe7Pj1UbyUJ0LYP59u2Ha3n4BZDHvX8uPkpCI/Q+O/cDoAj403dSc7m/WPs 1L2G1gQcIObJfkqyNUmf5GxGO7wUfAH43NnYGZy2mvjhy5dWY6q3Ms0YtBB0ykWH9agvBpIGXdQS7 5Pvz4hlw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1qZztE-007aFb-MY; Sat, 26 Aug 2023 20:28:12 +0000 Date: Sat, 26 Aug 2023 21:28:12 +0100 From: Matthew Wilcox To: Tong Tiangen Cc: Naoya Horiguchi , "Paul E. McKenney" , Andrew Morton , Naoya Horiguchi , Miaohe Lin , wangkefeng.wang@huawei.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm: memory-failure: use rcu lock instead of tasklist_lock when collect_procs() Message-ID: References: <20230821091312.2034844-1-tongtiangen@huawei.com> <0bbbb7d8-699b-30ac-9657-840112c41a78@huawei.com> <20230825060221.GA3948311@ik1-406-35019.vs.sakura.ne.jp> <9e205429-1f27-4d18-faca-8a4fe9d429e3@huawei.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <9e205429-1f27-4d18-faca-8a4fe9d429e3@huawei.com> X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 76D2E14000D X-Stat-Signature: j6u6wjg4ezmu9rfeujf85qnsrehwakmx X-Rspam-User: X-HE-Tag: 1693081726-826139 X-HE-Meta: U2FsdGVkX19t7Aovs8RK06l0s1mFNyzkXepI8cupau9swzREg5Ewn2VE3aqLYT12UvsK7XCTb8N4dVWVSWqO/dwDxccJDIsP/9p8JbhBoxlXUN/5wXShHwTBuQY/c/3jOtqkdsqGwwkH9ScgI//tonRF/SqPi9v3SJN9i5keLevDQ9cxXuyC3TBfamwP1wCq0EaV/0hgS4txF0RWrZskz8se7zVd+A0/iiJn2s/alJNuhUO7uGrxWLrM0ZxUid6SjMdfIy/U7jDawpaEIKoVIwFk9H+cwJuKT3lwGu2KNiQSrQI+pwoBHb42y40bEOS6GsZazqUxS8E4fPr9wtNYftwUKTZ2eoomTHLpp4YGQ6y6MyGob76UmXwz6kyhjXC9htioFV5dQlMvoWyy3Vp/wE4bva67XgsrMybScvZzIGOvLEJZjm5RgkXQApZrxihCpQjp5oWEgdsWeNH0SXMgYLUULW/dfEpYEuroGmSylPiUPhEDC9ZBvB6OA/daU3Betkm/zKcdSubQuM/BuKWuoy1h5HMxWGIqoIc4/BiADbflgD937kVn+2Og8UFmq1Usg6BTr/oJ3n3ZON57mLNdL8l+C9YF3urvp+QqgVqgP20jDOHCtQyy+ykzXoT/9Mpv+1CHEO3tarQxY1N7AUBiCYpvf6Lw4mUGVj7n31z0l3+R33+YaafHvXnX6XetL9PVhhssVjQoZpzpMJyYS8IfpQjPvIiC5CAwe7F8200TKysc3GRPeEJX5S/4JkheuCMB4+ZqR23kC3sMINBEbtoYd//+Z2SIdOIFqz5+A5ad5Z7cTxCY0vYt0JEt1JTgzUV+g54y+0z9IfhHQGVbkf5Gm34CajaISDdiGcPuPVp9pyMm5sMxipRqXidliygFyoYSiqghmLcr06WLfGacDkSqOxb5ipRcrpvoelf6nZEUb7O+ISUAK+Plaogd1+TbomHpUxeKK9Dd8/yN0Cu3wlm uM4zwEwl zhz5VBYo1HJKW42ArLax2s/4HU+eaYyHF+XQhdTv+iJaVFTqxSYKYhaZg2tFJnQaIec/pyF7F7T9W+4WCxDf/uLqCMB7S7rwSgLKrTULih9VTS03WnI34VMIGrvyxJc34kqGSuCULc4VTkrSVdRoS0D6/DqvLXWHX85+kvsoJdQ8J3bPAdARtCRxoBg== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000004, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Sat, Aug 26, 2023 at 09:46:53AM +0800, Tong Tiangen wrote: > " the ``task_struct`` object is freed only after one or more > grace periods elapse, with the help of call_rcu(), which is invoked via > put_task_struct_rcu_user(). " > > Combined with the code,when the task exits: > > release_task() > __exit_signal() > __unhash_process() > list_del_rcu(&p->tasks) > > put_task_struct_rcu_user() > call_rcu(&task->rcu, delayed_put_task_struct); > > delayed_put_task_struct() > put_task_struct() > if (refcount_sub_and_test(nr, &t->usage)) > __put_task_struct() > free_task() > > The code is consistent with the description in the document. > > According to this understanding, i think for_each_process() under the > protection of rcu locl is safe, that is, task_struct in the list will not be > destroyed, and get_task_struct() is also safe. Aha! This is different from the usual pattern. What I'm used to seeing is: if (refcount_sub_and_test()) { list_del_rcu(); rcu_free(); } and then on the read side you need a refcount_inc_not_zero(), which we didn't have here. Given this new information you've found, I withdraw my objection. It'd be nice to include some of this analysis in an updated changelog (and maybe improved documentation for tasklist?).