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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4293AC00448 for ; Thu, 25 Aug 2022 02:34:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229646AbiHYCeY (ORCPT ); Wed, 24 Aug 2022 22:34:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48544 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229490AbiHYCeW (ORCPT ); Wed, 24 Aug 2022 22:34:22 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0E3149A981 for ; Wed, 24 Aug 2022 19:34:21 -0700 (PDT) Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4MCn544Krgz19S4g; Thu, 25 Aug 2022 10:30:48 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggpemm500021.china.huawei.com (7.185.36.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 25 Aug 2022 10:34:19 +0800 Received: from [10.174.177.243] (10.174.177.243) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Thu, 25 Aug 2022 10:34:18 +0800 Message-ID: Date: Thu, 25 Aug 2022 10:34:18 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH 2/2] mm: slince possible data races about pgdat->kswapd Content-Language: en-US To: David Hildenbrand , Andrew Morton , CC: , References: <20220824071909.192535-1-wangkefeng.wang@huawei.com> <20220824071909.192535-2-wangkefeng.wang@huawei.com> From: Kefeng Wang In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.177.243] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2022/8/24 16:24, David Hildenbrand wrote: > On 24.08.22 09:19, Kefeng Wang wrote: >> The pgdat->kswapd could be accessed concurrently by kswapd_run() and >> kcompactd(), it don't be protected by any lock, which could leads to >> data races, adding READ/WRITE_ONCE() to slince it. > Okay, I think this patch here makes it clearer that we really just want > proper synchronization instead of hacking around it. > > What speaks against protecting pgdat->kswapd this using some proper > locking primitive? as comments about kswapd in struct pglist_data,  pgdat->kswapd should be protected by mem_hotplug_begin/done(), how about this way? diff --git a/mm/compaction.c b/mm/compaction.c index 640fa76228dd..62018f35242a 100644 --- a/mm/compaction.c +++ b/mm/compaction.c @@ -1983,7 +1983,13 @@ static inline bool is_via_compact_memory(int order)  static bool kswapd_is_running(pg_data_t *pgdat)  { -       return pgdat->kswapd && task_is_running(pgdat->kswapd); +       bool running; + +       mem_hotplug_begin(); +       running = pgdat->kswapd && task_is_running(pgdat->kswapd); +       mem_hotplug_end(); + +       return running;  }